Set/Kill Focus events when the window get or lose focus

Started by hfheatherfox07, September 02, 2011, 03:11:46 AM

Previous topic - Next topic

hfheatherfox07

Hi;
I was wondering how to  Set/Kill Focus events when the window get or lose focus 

I am familiar with setting focus on an edit window or even the main window ...but how does the app know when it is out of focus?

I have found WM_KILLFOCUS .... I have even thought of setting WM_SETFOCUS state to true at the beginning but how does a window know wen you clicked out side of it?

What I am using this for is my windows 7 Aero glass theme... it seems that when a window loses focus the close button turns gray ... I want to make the Aero Glass skin as correct as possible!

Thank you

dedndave

WM_KILLFOCUS and WM_SETFOCUS are messages that your DlgProc will receive to inform you that focus has changes
you use the SetFocus function to change the focus between windows
if you invoke that function, you will receive the appropriate message if it alters the state of your window

hfheatherfox07

Quote from: dedndave on September 02, 2011, 03:16:47 AM
WM_KILLFOCUS and WM_SETFOCUS are messages that your DlgProc will receive to inform you that focus has changes
you use the SetFocus function to change the focus between windows
if you invoke that function, you will receive the appropriate message if it alters the state of your window

I use that  a lot with the edit boxes examples that I did ,  how does the window know when it lost focus ... I can not visualize what that command is ....
in a window you have  mouse clicks commands .... what do you have for out side the window?

dedndave

Quotehow does the window know when it lost focus
it receives WM_KILLFOCUS   :P

for mouse clicks outside the window, like keypresses when you don't have focus, your window receives no message

what you are seeing may be related to the default button
or - it may become disabled

you can enable/disable buttons with SendDlgItemMessage
WM_ENABLE
WM_DISABLE

you can set the default button with SendMessage
DM_SETDEFID

sometimes, you may have to use BM_SETSTYLE to "turn off" the default state of a button

hfheatherfox07

How does it receive the WM_KILLFOCUS is it automatic when you click off the window? that would be nice ... I can just use that to change the button bmp

I looked at a few skinned examples in other languages and they seem to have a resource for that color ;
so the there is 3 of each , button over, button down, button up... except the close button has an extra one for out of focus


hfheatherfox07

Ah thanks !
it seems that BN_KILLFOCUS does that

BN_KILLFOCUS Notification Code

Sent when a button loses the keyboard focus. The button must have the BS_NOTIFY style to send this notification code.

The parent window of the button receives this notification code through the WM_COMMAND message.


I just have to make that happen  :bg

hfheatherfox07

Quote from: dedndave on September 02, 2011, 03:22:19 AM
Quotehow does the window know when it lost focus
it receives WM_KILLFOCUS   :P

for mouse clicks outside the window, like keypresses when you don't have focus, your window receives no message

what you are seeing may be related to the default button
or - it may become disabled

you can enable/disable buttons with SendDlgItemMessage
WM_ENABLE
WM_DISABLE

you can set the default button with SendMessage
DM_SETDEFID

sometimes, you may have to use BM_SETSTYLE to "turn off" the default state of a button

Since you brought it up .... How to you send the command  WS_DISABLED and WM_ENABLE also how do you send the command WS_GRAYED    .....

I  would love to know ... i realize now we use invoke EnableWindow .... but I saw an example of that in MASMv7 although the command WS_GRAYED is used for a menu item ... I can not get it sent to a button....


Oh, and here is that example with changing the button color with BN_KILLFOCUS and BN_SETFOCUS if any body wants it.... :U

Gunner

Everything you are asking is documented.  All you have to do is search msdn OR download the psdk.  You don't "send" WS_DISABLED,  WS = Window Style.  The docs say to enable/disable a window use EnableWindow.  You could use GetWindowLong to get the style bits for the window, change the WS_DISABLED bit, then call SetWindowLong with the new value... then you have to call SetWindowPos to make the changes.  You CAN send the Message WM_ENABLE with SendMessage to enable/disable windows, I would use EnableWindow since I think it does some house keeping in the background on internal structures...
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

here's a little tip for you...

instead of
.ELSEIF  uMsg == WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
and eax,0ffffh


you can
.ELSEIF  uMsg == WM_COMMAND
movzx eax,word ptr wParam
movzx edx,word ptr wParam+2


be careful to use the right instruction
for some things, like WM_MOUSEWHEEL, the value is a signed distance - then you would want MOVSX instead of MOVZX

QuoteWS_DISABLED and WM_ENABLE  also how do you send the command WS_GRAYED

WS_ prefixes are for window styles
WM_ prefixes are for window messages

anyways - i am not sure those messages are what we really want - they apply more to windows than buttons
to disable a pushbutton, you simply ignore the WM_COMMAND messages it sends
you could store a global variable to store the enable/disable state of the buttons,
then check that variable before processing messages received from the button

grayed elements are usually menu items
although, the regular close box may be grayed because it is actually a custom drawn system menu item

not sure how to gray out pushbutton text - haven't tried that, yet
it is easy with a checkbox or radio button

hfheatherfox07

Thank for the replies ..... I Googled it and I ran into a winasm thread entitled "How to send WS_DISABLED"   http://www.winasm.net/forum/index.php?showtopic=2749


I think that through me off.... well at least it was educational for me .... I am embarrassed :red to say that I use theses a lot but never realized that

WS_ prefixes are for window styles
WM_ prefixes are for window messages

:red :red


hfheatherfox07

Quote from: dedndave on September 04, 2011, 11:56:29 PM
fix your link   :bg


Thanks just did ...too many pages opened at once ...sorry  :red

boy my face is red a lot today

dedndave

well - if you can do it with EnableWindow, then sending WM_ENABLE should work, too

hfheatherfox07

Quote from: dedndave on September 05, 2011, 12:00:16 AM
well - if you can do it with EnableWindow, then sending WM_ENABLE or WM_DISABLE should work, too

What did you think of my example that I posted ? 

I think you may have been right after all .... I think what I am seeing is the effect of the button being disabled .when the window losses focus... I got it to work ....but with 3 states per each button,
like in the "aero glass" I don't see this being the solution.... :(