Talk:Check whether your application is running: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
m (Reverted edits by 199.168.142.166 to last version by Kichik)
 
(3 intermediate revisions by 2 users not shown)
(No difference)

Latest revision as of 20:36, 8 December 2011

Sometimes, the Window class or title are not unique. Then, you have to loop over the found handles and check the window titles one by one. You cannot use the message WM_GETTEXT to retrieve the window title, because it does not return a window title if the window has been created by another process than the owner of the current process. In this case, you have to use GetWindowText. [1]

Example:

loop:
   ; find first windows of class "SunAwtFrame" and store handle in $2
   FindWindow $2 "SunAwtFrame" "" 0 $1
   ; If nothing is found skip following check
   IntCmp $2 0 nothingFound
      ; try to retrieve the window title of window $2, store in $3
      System::Call /NOUNLOAD 'user32::GetWindowText(i r2, t .r3, i ${NSIS_MAX_STRLEN})'
      ; Copy the first 6 characters of $3 in $4
      StrCpy $4 $3 6
      ; Compare the 6 characters with "Matlab"
      StrCmp $4 "Matlab" foundMatlab loop
foundMatlab:
   MessageBox MB_OK "Found Matlab window, handle=$2, title=$3"
nothingFound:

[1] http://msdn.microsoft.com/en-us/library/aa928060.aspx