Mat Posted October 16, 2009 Posted October 16, 2009 (edited) here is a better version using a suggestion from yashied using WinApi_GetParent. I've been trying to do this for ages as using GUISwitch never seemed to work perfectly... Anyhow, Turns out I need to find all the windows under the Autoit PID and then use those... Here it is then Func _GUIGetCur ($bFindHidden = False) If Not IsBool ($bFindHidden) Then Return SetError (1, 0, -1) Local $alist = WinList (), $aRet[1] = [0] ; List windows under @AutoitPID For $i = 1 to $alist[0][0] If $alist[$i][0] <> "" then If Not $bFindHidden And Not (BitAND (WinGetState ($aList[$i][0]), 2)) Then ContinueLoop If WinGetProcess ($alist[$i][0]) = @AutoitPID Then Redim $aRet[UBound ($aRet) + 1] $aRet[UBound ($aRet) - 1] = $alist[$i][0] $aRet[0] += 1 EndIf EndIf Next ; Check Number of GUI's found If $aRet[0] = 0 Then Return SetError (1, 0, -1) ; No windows If $aRet[0] = 1 Then Return WinGetHandle ($aRet[1]) ; More than 1 GUI used, check for current! Local $ret = GUISwitch (WinGetHandle ($aRet[1])) GUISwitch ($ret) Return $ret EndFunc ; ==> _GUIGetCur Mat Edit: Solved problem with returning a window title when only one window exists... Edited October 17, 2009 by Mat AutoIt Project Listing
Sunaj Posted October 17, 2009 Posted October 17, 2009 On 10/16/2009 at 3:54 PM, 'Mat said: I've been trying to do this for ages as using GUISwitch never seemed to work perfectly... Anyhow, Turns out I need to find all the windows under the Autoit PID and then use those... Here it is then Hi Mat,Looks like well thought out little function to me Not to nitpick or anything but shouldn't this be renamed to something along the lines of "GUISetAndGetCur()" though?!Cheers, [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list]
Mat Posted October 17, 2009 Author Posted October 17, 2009 No... It does reset it back to the original, so no switching actually occurs (Well... It does but its undone by the end of the function, You won't notice the difference) Mat AutoIt Project Listing
Yashied Posted October 17, 2009 Posted October 17, 2009 Where I can use this function? My UDFs: Reveal hidden contents iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Sunaj Posted October 17, 2009 Posted October 17, 2009 On 10/17/2009 at 8:50 AM, 'Mat said: No... It does reset it back to the original, so no switching actually occurs (Well... It does but its undone by the end of the function, You won't notice the difference)MatGot it, thanks for clearing that up for me. [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list]
Mat Posted October 17, 2009 Author Posted October 17, 2009 (edited) I made it for use with UDF's that use custom GUI's etc, so that it returns to the GUI that you want. that prbably makes no sense, so heres an example: expandcollapse popupGlobal $hMyGUI, $hUDFGUI ; Example 1 - Not using any switch $hMyGUI = GUICreate ("This is the user created GUI...", 400, 100, 0, 0) GUICtrlCreateLabel ("This is a user created label, at start!", 2, 2, 200, 20) GUISetState () _UDF1 () GUICtrlCreateLabel ("This is a user created label, after UDF", 2, 24, 200, 20) While GUIGetMsg () <> -3 Sleep (10) WEnd GUIDelete ($hMyGUI) GUIDelete ($hUDFGUI) Func _UDF1 () $hUDFGUI = GUICreate ("This is a UDF's GUI", 400, 100, 0, 150) GUICtrlCreateLabel ("This is a UDF Label, at start!", 2, 2, 200, 20) GUISetState () EndFunc ; ==> _UDF1 ; Example 2 - using switch $hMyGUI = GUICreate ("This is the user created GUI...", 400, 100, 0, 0) GUICtrlCreateLabel ("This is a user created label, at start!", 2, 2, 200, 20) GUISetState () _UDF2 () GUICtrlCreateLabel ("This is a user created label, after UDF", 2, 24, 200, 20) While GUIGetMsg () <> -3 Sleep (10) WEnd GUIDelete ($hMyGUI) GUIDelete ($hUDFGUI) Func _UDF2 () $hCur = _GUIGetCur () $hUDFGUI = GUICreate ("This is a UDF's GUI", 400, 100, 0, 150) GUICtrlCreateLabel ("This is a UDF Label, at start!", 2, 2, 200, 20) GUISetState () GUISwitch ($hCur) ; <<<< Switch back to original! EndFunc ; ==> _UDF2 Func _GUIGetCur ($bFindHidden = False) If Not IsBool ($bFindHidden) Then Return SetError (1, 0, -1) Local $alist = WinList (), $aRet[1] = [0] ; List windows under @AutoitPID For $i = 1 to $alist[0][0] If $alist[$i][0] <> "" then If Not $bFindHidden And Not (BitAND (WinGetState ($aList[$i][0]), 2)) Then ContinueLoop If WinGetProcess ($alist[$i][0]) = @AutoitPID Then Redim $aRet[UBound ($aRet) + 1] $aRet[UBound ($aRet) - 1] = $alist[$i][0] $aRet[0] += 1 EndIf EndIf Next ; Check Number of GUI's found If $aRet[0] = 0 Then Return SetError (1, 0, -1) ; No windows If $aRet[0] = 1 Then Return WinGetHandle ($aRet[1]) ; More than 1 GUI used, check for current! Local $ret = GUISwitch (WinGetHandle ($aRet[1])) GUISwitch ($ret) Return $ret EndFunc ; ==> _GUIGetCur Hope that shows it clearly... Its not needed when the GUI is deleted at the end of the UDF, but for some they need the GUI to stay shown. Mat Edit: @Sunaj , There would be no point in a switch, as that would be reinventing the wheel, but square! Edited October 17, 2009 by Mat AutoIt Project Listing
Yashied Posted October 17, 2009 Posted October 17, 2009 But is the user himself can not switch the GUI directly? My UDFs: Reveal hidden contents iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Mat Posted October 17, 2009 Author Posted October 17, 2009 Yes they could, but they shouldn't have to. If you look at a real example like my PopupMenu UDF, that creates a GUI in the background permanently, and to anyone who has not read the source code, that GUI does not exist... I haven't implemented this in there yet, but I will be soon. (incidentally, both of you replied in that thread too , I am still working on an easy way to integrate Hotkey.au3 in there Yashied.Mat AutoIt Project Listing
Yashied Posted October 17, 2009 Posted October 17, 2009 (edited) OK Maybe this will be easier. #Include <WinAPI.au3> $hGUI1 = GUICreate('') $hGUI2 = GUICreate('') ConsoleWrite('Gui1: ' & $hGUI1 & @CR) ConsoleWrite('Gui2: ' & $hGUI2 & @CR) $Label = GUICtrlCreateLabel('', 0, 0, 0, 0) $hWnd = _WinAPI_GetParent(GUICtrlGetHandle($Label)) GUICtrlDelete($Label) ConsoleWrite('Current: ' & $hWnd & @CR) Edited October 17, 2009 by Yashied My UDFs: Reveal hidden contents iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Mat Posted October 17, 2009 Author Posted October 17, 2009 That would be a lot easier Yashied... I didn't realise you could do that!! I will have a look at how that works. Thanks Mat AutoIt Project Listing
Mat Posted October 17, 2009 Author Posted October 17, 2009 kk, I had a look in WinApi.au3 and its a simple DllCall, so to save on the include I've got this: Func _GUIGetCur () Local $hLabel = GUICtrlCreateLabel ("", -99, -99, 1, 1), $aRet $aRet = DllCall ("User32.dll", "hwnd", "GetParent", "hwnd", GUICtrlGetHandle ($hLabel)) If @Error Then Return SetError(@Error, 0 * GUICtrlDelete ($hLabel), 0) GUICtrlDelete ($hLabel) Return $aRet[0] EndFunc ; ==> _GUIGetCur Thats a lot nicer Yashied, with no loops! Mat AutoIt Project Listing
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