I am trying to enable a disabled button in a another running process. I through this would be a simple matter of calling SendMessage with WM_ENABLE and the relevant flags and target window handle set. However, this doesn't seem to work.

I've been experimenting with the calc program, which has the hexadecimal 'A, B, C, D' buttons disabled when in decimal mode. I've used spy (from VC++) to monitor the messages sent and returned by these buttons. When calc is switched from decimal to hex mode it sends a WM_ENABLE message to each of these buttons and they then return some acnowledgement message and are then enabled. However, when I send EXACTLY the same message, the button returns the same acnowledgement message but DOESN'T enable itself !

Why does this happen ? Anyone have any ideas ?

Posted on 2003-01-05 16:08:02 by JustanotherLostSoul
look into EnableWindow api
Posted on 2003-01-05 16:47:27 by BubbaFate



EnumChildWindows --> EnumChildproc --> GetClassName or GetWindowText

For example :


call FindWindow,offset classname,0
call EnumChildWindows,eax, offset enumkids, hwnd

;*** EnumChild Proc ***
enumkids proc ehandle:dword, x:dword

call GetClassName,ehandle, offset buffer, 100

call GetWindowText,ehandle, offset buffer2, 100

call EnableWindow,ehandle, TRUE
mov eax,ehandle

enumkids endp
;*** ***

Posted on 2003-01-05 17:53:59 by CYDONIA
EnableWindow was just the API I was looking for.
Posted on 2003-01-06 15:05:27 by JustanotherLostSoul
Posted on 2003-01-07 14:42:50 by wicr0s0ft
this is another one of those internal windows features that im not 100% sure of, but here is my theory...

The real determining factor as to whether or not a window is disabled or not is the style property of the window... so to disable a window you gotta use SetWindowLong, GWL_STYLE, WS_DISABLED. The WM_ENABLE message is just a message that tells the window "Hey i just changed your window state to enabled/disabled... just lettin ya know". So pretty much all the EnableWindow api does is call SetWindowLong, then sends the WM_ENABLE message to the window... again i dont know this for sure...
Posted on 2003-01-07 15:26:26 by BubbaFate
Thanks, BubbaFate :)

Ok, I have read the API ref about those, and the EnableWindow does the job.

I still have a doubt about that one 'alternative' method':

The API states: LONG SetWindowLong(

HWND hWnd, // handle of window
int nIndex, // offset of value to set
LONG dwNewLong // new value

Specifies the zero-based offset to the value to be set. Valid values are in the range zero through the number of bytes of extra window memory, minus 4; for example, if you specified 12 or more bytes of extra memory, a value of 8 would be an index to the third 32-bit integer. To set any other value, specify one of the following values:

Value Action
GWL_EXSTYLE Sets a new extended window style.

So when we set the new style to WS_ENABLED or disabled, woudn't we lose all the other styles the window might have?
If this is correct, is there a way to 'OR' the current window style, with our desired one? (like get mem address and access directly)

Woud be nice if someone could confirm BubbaFate's theory... :alright:
Posted on 2003-01-08 14:40:32 by wicr0s0ft
well of course...

; Disable Window

invoke GetWindowLong, hwndWindow, GWL_STYLE
invoke SetWindowLong, hwndWindow, GWL_STYLE, eax
invoke SendMessage, hwndWindow, WM_ENABLE, FALSE, NULL

; Enable Window
invoke GetWindowLong, hwndWindow, GWL_STYLE
and eax, not WS_DISABLED
invoke SetWindowLong, hwndWindow, GWL_STYLE, eax
invoke SendMessage, hwndWindow, WM_ENABLE, TRUE, NULL

Posted on 2003-01-08 15:13:08 by BubbaFate