SetWindowPos Changes Focus
12/2/2007
Occasionally when I call:
SetWindowPos(hWnd, NULL, x, y, cx, cy, SWP_NOACTIVATE|SWP_NOZORDER);
The focus unexpectedly changes to hWnd. This is annoying and I don't understand why this happens. Anybody care to shed some light on the inner workings of SetWindowPos?

This can be seen in Scribe when you select the root node of the folder tree and the focus disappears. I'm trialing some code that gets the current focus, calls SetWindowPos and then checks the current focus against the old focus, if it's changed it just resets it. But this is a ugly hack and I'd rather just fix the root cause.

It's also annoying users.


Comments:

Carlos Rocha
14/02/2007 4:49am
My Win32SDK Help says "An application cannot activate an inactive window without also bringing it to the top of the Z order". Is this the case?
fret
14/02/2007 6:06am
I would expect that is the case for a top level window, but I'm using SetWindowPos on a child window, specifically Scribe's splitter control, which is a parent to the tree and list control's in the main window. When I call SetWindowPos(splitter, ...) when the tree control has the focus, the focus jumps to the splitter, which isn't even a tab stop.


From:
Email (optional): (Will be HTML encoded to evade harvesting)
Message:
 
Remember username and/or email in a cookie.
Notify me of new posts in this thread via email.
BBcode:
[q]text[/q]
[url=link]description[/url]
[img]url_to_image[/img]
[pre]some_code[/pre]
[b]bold_text[/b]
Post