Dear Forum,
I've been playing with ComboBox and discovered a little problem and
wondered if you could help me. A copy of the code I'm using appears below.
I have numbered the lines for ease of explanation.
1;DlgProc PROC hWnd:HWND,iMsg:DWORD,wParam:WPARAM, lParam:LPARAM
2;LOCAL hCmb : DWORD
3; .if iMsg==WM_INITDIALOG
4; invoke GetDlgItem,hWnd,IDC_EDIT
5; invoke SetFocus,eax
6;
7; invoke GetDlgItem, hWnd, IDC_COMBO
8; mov hCmb,eax
9; invoke SendMessage,hCmb, CB_ADDSTRING, 0, offset szStr1
10;
11;
12; .elseif iMsg==WM_CLOSE
13; invoke EndDialog,hWnd,NULL
14; .elseif iMsg==WM_COMMAND
15; mov eax,wParam
16; mov edx,eax
17; shr edx,16
18; .if dx==BN_CLICKED
19; .if eax==IDC_EXIT
20; invoke SendMessage,hWnd,WM_CLOSE,NULL,NULL
21; .elseif eax==IDC_BUTTON
22; invoke SetDlgItemText,hWnd,IDC_EDIT,ADDR TestString
23;
24; invoke SendDlgItemMessage, hWnd,IDC_COMBO,CB_GETCURSEL,0,0
25; ;invoke SendMessage,hCmb, CB_GETCURSEL,0,0 ;**This line will not work
26; ;invoke SendMessage,hCmb, CB_ADDSTRING, 0, offset szStr1;**This line will not work
27;
28; .endif
29; .endif
30; .else
31; mov eax,FALSE
32; ret
33; .endif
34; mov eax,TRUE
35; ret
36;DlgProc endp
When I use SendMessage as in line 9 I can load strings into the Combo.
Next I tried to use SendMessage to get the current selection, as in line 25 but
it returned "0" no matter which position I selected in the Combo.
Then for a test I tried to use the SendMessage in line 26. This is identical
to line 9. It works at line 9 but not at line 26.
I eventually used SendDlgItemMessage as in line 24 and it worked beautifully.
Why is this so?
Any advice would be greatly appreciated.
Regards, seaview and HAPPY NEW YEAR TO ALL
hCmb should not be a local variable :naughty: It will be lost after WM_INITDIALOG
I would also suggest that in line 20, you use PostMessage instead of SendMessage with the WM-CLOSE message.
The former simply puts the message in the message queue and continues immediately with the next instruction without any waiting, thus completing the processing of the current message before re-entering your DlgProc. The latter waits until the message is effectively processed before continuing with the next instruction.