How do you get the hwnd to the active child window? I want to give it focus when my main window regains focus.
Posted on 2003-03-05 20:09:04 by gfalen
Process the WM_KILLFOCUS message and store the currently focused control handle with GetFocus, when you recieve a WM_SETFOCUS message you restore the focus to the control using SetFocus.

Posted on 2003-03-05 23:00:40 by donkey
Use API GetWindow with the GW_CHILD as uCmd.
Posted on 2003-03-06 01:10:14 by roticv
donkey - it does'nt work! That's the first thing I tried. I have two list boxes side by side and naturally I want to restore focus to the correct one. But when I leave and return to the window I find that I can't cursor up/down with the keyboard - the SetFocus did not work.

Posted on 2003-03-06 01:18:50 by gfalen
Hi gfalen,

Yes you're right, it wouldn't work. Sorry it was late and I wasn't thinking perfectly clearly, I look at it in the clear light of morning and I ask myself "where did I get that from ?". I had seen that your post had received no replies and was in danger of being pushed off page one into obscurity so I decided to answer, but I should have thought more about it.

Posted on 2003-03-06 09:07:33 by donkey
cath the window handle from LBN_SETFOCUS (or NM_SETFOCUS for listviews) message and restore handle when receiving WM_SETFOCUS.
Posted on 2003-03-06 11:16:03 by japheth
Yes japeth, I'm trying to get around having to do this. It is only a partial solution. As soon as you add new controls you have to add 'special' code to proccess they're XX_KILLFOCUS messages too!

I'm having some luck with the WM_ACTIVATE message. It works in all cases except when you minimize from the system menu or the minimize button.

So I'm looking into the WM_SYSCOMMAND message right now.
Posted on 2003-03-06 11:23:28 by gfalen
For anyone interested this seems to work.


WndProc proc uses ebx edi esi, hwin, umsg, wparam, lparam
local hactive


.if word ptr wparam == WA_INACTIVE
invoke GetFocus
.if eax != hwin && eax
mov hactive, eax
invoke SetFocus, hactive

Posted on 2003-03-06 16:25:02 by gfalen