AutoHotkey Community

It is currently May 25th, 2012, 4:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: September 16th, 2007, 3:51 am 
Offline

Joined: September 12th, 2005, 2:12 am
Posts: 190
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 16th, 2007, 6:37 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 16th, 2007, 11:20 pm 
Offline

Joined: September 12th, 2005, 2:12 am
Posts: 190
Thank you! I've been trying to get this to work forever. :D :D :D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 17th, 2007, 8:31 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
lexikos wrote:
You most likely need to set +WS_CHILD -WS_POPUP for the child window.


Thanks for this useful info. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 17th, 2007, 5:31 pm 
Offline

Joined: September 12th, 2005, 2:12 am
Posts: 190
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. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2007, 1:17 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
:lol:

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


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, ogrish, Pulover, rbrtryn, vsub, Zaelia and 26 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group