View Single Post
Old 1st April 2016, 20:15   #6
Senior Member
r2du-soft's Avatar
Join Date: Nov 2013
Location: Iran
Posts: 342
Originally Posted by T.Slappy View Post
You can call Windows API functions (like GetForegroundWindow) from NSIS by using the System plug-in.

Also you can declare variables like structs, integers etc. in NSIS with this plug-in.

I am not a VB coder but it looks like VB is using the same. E.g. this line:

Private Declare Function GetActiveWindow Lib "user32" () As Long looks like it is calling GetActiveWindow from user32.dll library which is pretty the same as NSIS System plug-in does.

thanks mr T.Slappy

im trying to conver vb code to nsis code but i think my convert is wrong!:

HTML Code:

Function TrimText
 Exch $R0 ; char
 Exch $R1 ; length
 Exch 2
 Exch $R2 ; text
 Push $R3
 Push $R4
 StrLen $R3 $R2
 IntCmp $R3 $R1 Done Done
 StrCpy $R2 $R2 $R1
 StrCpy $R3 0
  IntOp $R3 $R3 + 1
  StrCpy $R4 $R2 1 -$R3
  StrCmp $R4 "" Done
  StrCmp $R4 $R0 0 -3
  IntOp $R3 $R3 + 1
  StrCpy $R4 $R2 1 -$R3
  StrCmp $R4 "" Done
  StrCmp $R4 $R0 -3
  IntOp $R3 $R3 - 1
  StrCpy $R2 $R2 -$R3
  StrCpy $R2 $R2...
 StrCpy $R0 $R2
 Pop $R4
 Pop $R3
 Pop $R2
 Pop $R1
 Exch $R0 ; output

!macro TrimText Text Length Char Var
Push "${Text}"
Push "${Length}"
Push "${Char}"
 Call TrimText
Pop "${Var}"

!define TrimText "!insertmacro TrimText"

Var foreground_hwnd
Var txt
Var length

System::Call user32::GetForegroundWindow('')i.r0
StrCpy $foreground_hwnd $0

System::Call 'user32::GetWindowText(i r2, t .r3, i ${NSIS_MAX_STRLEN})'
StrCpy $length $2($foreground_hwnd, $txt, ${NSIS_MAX_STRLEN})

;StrCpy $txt ${TrimText} "$txt" ${NSIS_MAX_STRLEN} " " $R0
${TrimText} "$txt" ${NSIS_MAX_STRLEN} " " $R0

StrCpy $txt $R0
is possible help in convert that code from vb to nsis?

in vb code GetActiveWindow is no needing for work vb code.i nust remove that.

just i want convert this code to nsis:

HTML Code:
Option Explicit

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long

Private Sub Timer1_Timer()

Dim foreground_hwnd As Long
Dim txt As String
Dim length As Long

    foreground_hwnd = GetForegroundWindow()

    txt = Space$(1024)
    length = GetWindowText(foreground_hwnd, txt, Len(txt))
    txt = Left$(txt, length)
    lblCaption = txt
End Sub
r2du-soft is offline   Reply With Quote