How do you get the hwnd to the active child window? I want to give it focus when my main window regains focus.
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.
Donkey
Donkey
Use API GetWindow with the GW_CHILD as uCmd.
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.
Puzzled
Puzzled
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.
Donkey
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.
Donkey
cath the window handle from LBN_SETFOCUS (or NM_SETFOCUS for listviews) message and restore handle when receiving WM_SETFOCUS.
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.
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.
For anyone interested this seems to work.
WndProc proc uses ebx edi esi, hwin, umsg, wparam, lparam
local hactive
...
case WM_ACTIVATE
.if word ptr wparam == WA_INACTIVE
invoke GetFocus
.if eax != hwin && eax
mov hactive, eax
.endif
.else
invoke SetFocus, hactive
.endif