 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Mistrel
Joined: 12 Sep 2005 Posts: 188
|
Posted: Sun Sep 16, 2007 3:51 am Post subject: How to prevent the parent window from losing focus? |
|
|
When I set a window as a child of another using SetParent how can I prevent a loss of focus of the parent window (the title bar greying out) when I select the child inside?
Is there some way to group all of these windows into a single focus? |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Sun Sep 16, 2007 6:37 am Post subject: |
|
|
| Quote: | | Is there some way to group all of these windows into a single focus? | That's the default behaviour for child windows & their parent.
You most likely need to set +WS_CHILD -WS_POPUP for the child window. For instance: | Code: | Gui, 1:+LastFound
hwnd1 := WinExist()
Gui, 2:+LastFound
Gui, 2:+0x40000000 -0x80000000 ; Add WS_CHILD, remove WS_POPUP
hwnd2 := WinExist()
DllCall("SetParent", "uint", hwnd2, "uint", hwnd1)
Gui, 2:Show, x0 y0 w200 h200, GUI 2
Gui, 1:Show, w400 h400, GUI 1
return
GuiClose:
ExitApp | If you uncomment the Gui, 2:+0x4... line, GUI 2 is set as the foreground window whenever you try to focus GUI 1. Pressing Alt+F4 closes GUI 2 (or does nothing if it's already closed), and pressing GUI 1's close button doesn't work.
After adding WS_CHILD and removing WS_POPUP, AHK Window Info shows that GUI 1 is the foreground/active window, and GUI 2 is the focused control.
| MSDN wrote: | | For compatibility reasons, SetParent does not modify the WS_CHILD or WS_POPUP window styles of the window whose parent is being changed. Therefore, if hWndNewParent is NULL, you should also clear the WS_CHILD bit and set the WS_POPUP style after calling SetParent. Conversely, if hWndNewParent is not NULL and the window was previously a child of the desktop, you should clear the WS_POPUP style and set the WS_CHILD style before calling SetParent. |
|
|
| Back to top |
|
 |
Mistrel
Joined: 12 Sep 2005 Posts: 188
|
Posted: Sun Sep 16, 2007 11:20 pm Post subject: |
|
|
Thank you! I've been trying to get this to work forever.  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5890
|
Posted: Mon Sep 17, 2007 8:31 am Post subject: |
|
|
| lexikos wrote: | | You most likely need to set +WS_CHILD -WS_POPUP for the child window. |
Thanks for this useful info.  |
|
| Back to top |
|
 |
Mistrel
Joined: 12 Sep 2005 Posts: 188
|
Posted: Mon Sep 17, 2007 5:31 pm Post subject: |
|
|
With this I can actually embed one program into another seamlessly by parenting it to a child window or an MDI window and setting these flags to prevent loss of focus from the main application.  |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Fri Nov 30, 2007 1:17 pm Post subject: |
|
|
It just occurred to me that since the hWndParent parameter of CreateWindowEx (the function used to create a window) is either the parent window or owner window (depending on whether you specify the WS_CHILD style), we don't even need SetParent when dealing with our own GUIs:
| Code: | Gui, 1:+LastFound ; ensure GUI 1 exists before creating GUI 2
Gui, 2:+0x40000000 -0x80000000 +Owner1 ; Add WS_CHILD, remove WS_POPUP, set owner/parent
Gui, 2:Show, x0 y0 w200 h200, GUI 2
Gui, 1:Show, w400 h400, GUI 1
return
GuiClose:
ExitApp |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|