MiserableLife Posted December 21, 2009 Share Posted December 21, 2009 (edited) I've been walking around the autoit forum and i found a nice tutorial from monoceres link.and when i read to page 6, I couldn't get the "FindWindow" function working....(msdn said the function will return the handle)Can someone tell me what went wrong?$title = "autoit" $gui = GUICreate($title) GUISetState(@SW_SHOW) $i = DllCall("user32.dll","HWND","FindWindow","str","","str",$title) IF @error Then msgbox(0,'',@error) ;~ $i = WinGetHandle ("autoit") IF $gui = $i[0] Then msgbox(0,'','They Match' & @CRLF & $gui & @CRLF & $i[0]) Else msgbox(0,'','They do not Match'& @CRLF & $gui & @CRLF & $i[0]) EndIf Edited December 21, 2009 by MiserableLife Link to comment Share on other sites More sharing options...
Richard Robertson Posted December 21, 2009 Share Posted December 21, 2009 (edited) You need to use null as the window class, not an empty string. Try passing 0 as the first string parameter. If all you need is the handle though, why not just use WinGetHandle? Edited December 21, 2009 by Richard Robertson Link to comment Share on other sites More sharing options...
MiserableLife Posted December 21, 2009 Author Share Posted December 21, 2009 So i changed it to $i = DllCall("user32.dll","HWND","FindWindow","str",0,"str",$title) but still returns 0x00000000. And the reason for not using WinGetHandle, is becuase i wanted to learn how to use dllcall. Link to comment Share on other sites More sharing options...
MiserableLife Posted December 21, 2009 Author Share Posted December 21, 2009 @@ I found that it is working with a class param filled. $title = "autoit" $gui = GUICreate($title) GUISetState(@SW_SHOW) $i = DllCall("user32.dll","HWND","FindWindow","str","AutoIt v3 GUI","str",$title) IF @error Then msgbox(0,'',@error) ;~ $i = WinGetHandle ("autoit") IF $gui = $i[0] Then msgbox(0,'','They Match' & @CRLF & $gui & @CRLF & $i[0]) Else msgbox(0,'','They do not Match'& @CRLF & $gui & @CRLF & $i[0]) EndIf Now... my question is .... how to i put a NULL in to the param? Link to comment Share on other sites More sharing options...
Richard Robertson Posted December 21, 2009 Share Posted December 21, 2009 Ah. Try changing the parameter type to "ptr" and passing 0. Link to comment Share on other sites More sharing options...
MiserableLife Posted December 21, 2009 Author Share Posted December 21, 2009 Yeah!!! It worked!!! Thank you!! Link to comment Share on other sites More sharing options...
Authenticity Posted December 21, 2009 Share Posted December 21, 2009 $sTitle = "autoit" $sClass = "AutoIt v3 GUI" $gui = GUICreate($sTitle) GUISetState(@SW_SHOW) $hWnd = __WinAPI_FindWindow($sClass, $sTitle) IF @error Then msgbox(0,'',@error) IF $gui = $hWnd Then msgbox(0,'','They Match' & @CRLF & $gui & @CRLF & $hWnd) Else msgbox(0,'','They do not Match'& @CRLF & $gui & @CRLF & $hWnd) EndIf $hWnd = __WinAPI_FindWindow(0, $sTitle) IF @error Then msgbox(0,'',@error) IF $gui = $hWnd Then msgbox(0,'','They Match' & @CRLF & $gui & @CRLF & $hWnd) Else msgbox(0,'','They do not Match'& @CRLF & $gui & @CRLF & $hWnd) EndIf Func __WinAPI_FindWindow($vClass, $sName) Local $sType, $aResult If IsString($vClass) Then $sType = "str" Else $sType = "ptr" EndIf $aResult = DllCall("user32.dll", "hwnd", "FindWindow", $sType, $vClass, "str", $sName) If @error Then Return SetError(1, 0, 0) Return SetError($aResult[0] = 0, 0, $aResult[0]) EndFunc Link to comment Share on other sites More sharing options...
MiserableLife Posted December 21, 2009 Author Share Posted December 21, 2009 @@ very detailed!!! Thank you too. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now