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

dedndave

WM_ENABLE
wParam...
Indicates whether the window has been enabled or disabled. This parameter is TRUE
if the window has been enabled or FALSE if the window has been disabled.

so, you can send the message with 1 of 3 functions
PostMessage
SendMessage
SendDlgItemMessage

for the first 2 functions, hWnd is the button handle
for the last one, hDlg is the dialog box handle, and nIDDlgItem is the button ID

for all of them...
Msg is WM_ENABLE
wParam is TRUE/FALSE
lParam is NULL

dedndave

now - as to making the self-made buttons look and act like the OS buttons   :P

if you really want something different for that, you can probably draw it like the OS does - as a custom-drawn menu
you are trying to make pushbuttons act like menu items, which they are not

hfheatherfox07

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

here is the code:

mov eax,uMsg
.if eax==WM_INITDIALOG
invoke GetDlgItem,hWin,1002
mov hBtn,eax

.elseif eax==WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
and eax,0FFFFh
.if edx==BN_CLICKED
.if eax==1001
invoke SetWindowText,hWin,offset NewCaption
.elseif eax==1002
invoke EnableWindow,hBtn,0
.elseif eax==1003
invoke EnableWindow,hBtn,1



hfheatherfox07

Quote from: dedndave on September 05, 2011, 12:07:30 AM
WM_ENABLE
wParam...
Indicates whether the window has been enabled or disabled. This parameter is TRUE
if the window has been enabled or FALSE if the window has been disabled.

so, you can send the message with 1 of 3 functions
PostMessage
SendMessage
SendDlgItemMessage

for the first 2 functions, hWnd is the button handle
for the last one, hDlg is the dialog box handle, and nIDDlgItem is the button ID

for all of them...
Msg is WM_ENABLE
wParam is TRUE/FALSE
lParam is NULL

Thank you !  :U
I was looking to learn more ways of doing things ...I will give this  a try when I get home tonight...

Since we are on this topic, just found the examples (not mine)
basics.zip has the buttons
basics2.zip has the the menu

but they use invoke EnableWindow

I was looking to learn what you just wrote  :U


dedndave

some additional info from EnableWindow documenation...

QuoteIf the window is being disabled, the system sends a WM_CANCELMODE message. If the enabled state of
a window is changing, the system sends a WM_ENABLE message after the WM_CANCELMODE message.
(These messages are sent before EnableWindow returns.) If a window is already disabled, its child
windows are implicitly disabled, although they are not sent a WM_ENABLE message.

in Community Content...

QuoteSome care is needed if using this to disable a dialog box control.  If the control had focus when it becomes disabled,
the focus might be stranded.  See http://blogs.msdn.com/b/oldnewthing/archive/2004/08/04/208005.aspx

dedndave

i was just playing with the one you named "bmp Button Grayed when not in focus"

i noticed that a regular close button behaves the same way   :P

hfheatherfox07

Quote from: dedndave on September 05, 2011, 02:00:01 AM
i was just playing with the one you named "bmp Button Grayed when not in focus"

i noticed that a regular close button behaves the same way   :P

can you upload it? not home right did not have the chance to mess around yet


hfheatherfox07

Thanks ....

Well that answers that than .....

I think you were right .... I was seeing the effect of the button being disabled and not a gray button skin.....

I think I will go that route  :U

hfheatherfox07

Quote from: dedndave on September 05, 2011, 12:07:30 AM
WM_ENABLE
wParam...
Indicates whether the window has been enabled or disabled. This parameter is TRUE
if the window has been enabled or FALSE if the window has been disabled.

so, you can send the message with 1 of 3 functions
PostMessage
SendMessage
SendDlgItemMessage

for the first 2 functions, hWnd is the button handle
for the last one, hDlg is the dialog box handle, and nIDDlgItem is the button ID

for all of them...
Msg is WM_ENABLE
wParam is TRUE/FALSE
lParam is NULL

I Finally got around to this.... ::)

This does not seem to work

dedndave

yah - it is more or less intended for windows - not buttons   :P

there are a few finer points to the code
for WM_COMMAND, wParam LOW WORD is the ID
also, use the IDC values as you have assigned them
it makes it easier to change values and to read the code
here are a few changes....
; Get the Button handle
        INVOKE  GetDlgItem,hWnd,IDC_BTN2
        mov     hBtn,eax
;
;
;

.ELSEIF uMsg == WM_COMMAND

        movzx   eax,word ptr wParam

.IF eax==IDC_BTN1 ; If BTN1 is pressed - Disable BTN2
invoke EnableWindow,hBtn,FALSE
.ENDIF

.IF eax==IDC_BTN3 ; If BTN3 is pressed - Enable BTN2
invoke EnableWindow,hBtn,TRUE
.ENDIF

.IF eax==IDC_CLOSE
INVOKE SendMessage,hWnd,WM_CLOSE,0,0
.ENDIF