i need to respond to a notification from my combobox when i press the return key. the problem is i havent found a way that works right. the code im attaching works somewhat but the only way is does work is when i hold down on the down arrow with my mouse button then press the return key. i need to get it where it works just by pressing the return key. here is the test code i use. its just a window with a combobox and i thought i would include it just in case you wanted to do some testing. you can cut and paste of download the source below. thanks.
.586

.model flat, stdcall
option casemap :none

include /masm32/include/windows.inc
include /masm32/include/kernel32.inc
include /masm32/include/user32.inc
includelib /masm32/lib/kernel32.lib
includelib /masm32/lib/user32.lib

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopXY PROTO :DWORD,:DWORD
sub_1 PROTO :DWORD,:DWORD,:DWORD,:DWORD

.data
ClassName db "Starting Template",0
CaptionText db "Testing for the Return key",0
ComboBoxClass db "combobox",0

.data?
hWnd HANDLE ?
hInstance HANDLE ?
hCombobox1 HANDLE ?
OldProc dd ?

.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
invoke ExitProcess,eax

; #######################################
WinMain proc hInst:DWORD, hPrevIns:DWORD, CmdLine:DWORD, CmdShow:DWORD

LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD

mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW + CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
mov eax, hInstance
mov wc.hInstance, eax
invoke LoadIcon, NULL,IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor, NULL,IDC_ARROW
mov wc.hCursor, eax
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName,OFFSET ClassName
invoke RegisterClassEx, addr wc

mov Wwd, 300
mov Wht, 200

invoke GetSystemMetrics,SM_CXSCREEN
invoke TopXY,Wwd,eax
mov Wtx, eax

invoke GetSystemMetrics,SM_CYSCREEN
invoke TopXY,Wht,eax
mov Wty, eax

invoke CreateWindowEx, NULL,
ADDR ClassName,
ADDR CaptionText,
WS_OVERLAPPEDWINDOW,
Wtx,Wty,Wwd,Wht,
NULL,
NULL,
hInst,
NULL
mov hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd

StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:

mov eax,msg.wParam
ret

WinMain endp

; ##############################

WndProc proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.IF uMsg == WM_CREATE
invoke CreateWindowEx, 0,
ADDR ComboBoxClass,
NULL,
WS_CHILD + WS_VISIBLE + CBS_DROPDOWN,
56,35,170,0,
hWin,
0,
hInstance,
0
mov hCombobox1,eax
invoke SetWindowLong,hCombobox1,GWL_WNDPROC,addr sub_1 ;sublcass the combobox
mov OldProc,eax

.ELSEIF uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
.ELSE
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret

WndProc endp


sub_1 Proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
;// dot he return key procesing here
.IF uMsg == WM_KEYDOWN
mov eax,wParam
.if eax == VK_RETURN
invoke MessageBox,0,0,0,0
.endif
xor eax,eax
ret

.ENDIF
invoke CallWindowProc,OldProc,hWin,uMsg,wParam,lParam
ret
sub_1 endp


; ###########################

TopXY proc wDim:DWORD, sDim:DWORD

shr sDim, 1
shr wDim, 1
mov eax, wDim
sub sDim, eax
mov eax,sDim
ret

TopXY endp

; #############################

end start
Posted on 2002-05-18 22:13:41 by smurf
I saw a microsoft example where tab
key messages were passed back
to the parent window from each child.

Handle the enter key at the parent
window.
Posted on 2002-05-18 22:26:33 by bdjames
hmm, if i process the wm_keydown message in the parent window (hWin) it only handles the return key if it has focus. any other control such as my combobox will have to process it seperately because the wm_keydown it posted to the window/control which has focus. am i wrong here?
Posted on 2002-05-18 23:06:41 by smurf
My only guess is that the edit part of the combobox is a subclass of the combobox control. Try checking the window handles with one of the spy utilities.
Posted on 2002-05-19 01:14:10 by grv575
i think that U can use MsgLoop to do this
   StartLoop:

invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
.If msg.hwnd == hCombobox1 && msg.message == WM_KEYDOWN && msg.wParam == VK_RETURN
invoke MessageBox,0,0,0,0
.EndIf
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:

but i can be wrong:grin:
:alright:
Posted on 2002-05-19 04:28:20 by NEMO
hmm...

Bypass the window proc and process
all window messages in the message
loop...
Posted on 2002-05-19 17:25:16 by bdjames
grv575: your right. the editbox is the child of the combobox. so i subclassed the combobox and then used the editbox handle i got from the GetComboBoxInfo api and then subclassed the editbox. when i did that i didnt receive one message from the editbox and im not sure why. it appears this should be the method to use but when i was searching for answers on the codeguru website many people were recomending to use the pretranslatemessage function which looks like basically the same as handling it in the message loop.

NEMO: i tried using your method and changed my main message loop accordingly but the only thing i could detect was the handle(msg.hwnd == hCombobox1) and no WM_KEYDOWN messages. wanna demonstrate a working example if you have time?

bdjames: you got a few minutes to modify my sample code to demonstrate a working example?
Posted on 2002-05-19 18:28:47 by smurf
It works, give me some time to clean the
code up.

<edit>
; invoke TranslateMessage, ADDR msg
; invoke DispatchMessage, ADDR msg
push msg.MSG.lParam
push msg.MSG.wParam
push msg.MSG.message
push msg.MSG.hwnd
call WndProc
</edit>
Posted on 2002-05-19 19:35:37 by bdjames
im sorry bdjames sometimes (most times) thinking isnt easy for me. here is the code im using now for my main loop:
   StartLoop:

invoke GetMessage,ADDR msg,0,0,0
cmp eax, 0
je ExitLoop
mov eax,msg.hwnd
.If eax == hCombobox1
.if msg.message == WM_KEYDOWN
invoke MessageBox,0,0,0,0
.endif
.endif
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
push msg.MSG.lParam
push msg.MSG.wParam
push msg.MSG.message
push msg.MSG.hwnd
call WndProc
jmp StartLoop
ExitLoop:
mov eax,msg.wParam
ret


what am i doing wrong?
:stupid:
Posted on 2002-05-20 00:05:21 by smurf
i've re-think it again and i know why it didn't work, i forgot 'bout Edit Box[/B/ which is in combobox. here's a working example:
Posted on 2002-05-20 05:49:09 by NEMO
thank you nemo it works great.
Posted on 2002-05-20 09:20:38 by smurf
Smurf, what I was trying to say is that
the message loop handles all the
messages for that thread.
Translate/Dispatch do little more than
call the correct wndproc. So I figure
it is possible to completely bypass these
two functions. This is taking nemo's
example to the end.

This should have a significant effect.

      .If msg.hwnd == Ebx && msg.message == WM_KEYDOWN && msg.wParam == VK_RETURN

invoke MessageBox, 0, ADDR CaptionText, ADDR CaptionText, 0

if you want to intercept the return
key for the entire thread ==>

.If msg.message == WM_KEYDOWN && msg.wParam == VK_RETURN
invoke MessageBox, 0, ADDR CaptionText, ADDR CaptionText, 0



I am going to work more on this later.
Posted on 2002-05-20 13:56:05 by bdjames
#include <windows.h>

#define MAIN_WINDOW_HEIGHT 400
#define MAIN_WINDOW_WIDTH 400

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){
switch(msg){
case WM_DESTROY:
PostQuitMessage(NULL);
return NULL;
default:
return DefWindowProc(hWnd,msg,wParam,lParam);
}
}

int main(){
WNDCLASSEX wc = {sizeof WNDCLASSEX,CS_HREDRAW|CS_VREDRAW,WndProc,NULL,NULL,NULL,NULL,NULL,(struct HBRUSH__ *)(COLOR_BTNFACE+1),NULL,"Bolder",NULL};
HWND hWnd;
MSG msg;
wc.hInstance = GetModuleHandle(NULL);
RegisterClassEx(&wc);
hWnd = CreateWindowEx(NULL, "Bolder", "Bolder", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, NULL, NULL, wc.hInstance, NULL);
ShowWindow(hWnd, SW_SHOWDEFAULT);
UpdateWindow(hWnd);
while(GetMessage(&msg,NULL,0,0)) WndProc(msg.hwnd,msg.message,msg.wParam,msg.lParam);
return msg.wParam;
}
Posted on 2002-05-20 17:38:51 by bdjames