When I am using this api I obviously have to specify the number of bytes I want to be read, now my question is how can I specify the size of the buffer just read in? For example:
invoke GetDlgItemText, hCombo, 1003, lpDropDown, sizeof lpDropDown
However as I expected that results in a crash.
Edit:
Any reason why this does not work properly? lpDropDown seems to stay empty:
invoke GetDlgItemText, hCombo, 1003, offset lpDropDown, 20
This:
invoke GetDlgItemText, hCombo, 1003, offset lpDropDown, 20
Should be this:
invoke GetDlgItemText, hCombo, 1003, addr lpDropDown, 20
You'll have to use addr instead of offset when using invoke.
dev_zero,
Who told you that? You were mislead. Want me to post some working code?
Paul
Nilrem
How about posting that part of your code where you declare the lpDropDown and describe the 1003 for your combo.
Raymond
Why? I mean it works, the items are there on the drop-down menu, but upon retrieving the selection (from the drop-down menu) made it doesn't work.
Ok, here goes:
.data
lpDropDown dd 128 dup(?)
nDropDown dd 20
.const
IDD_DIALOG1 equ 101
IDC_IDCBTN1 equ 1001
IDC_BTN_ABOUT equ 1002
IDC_DROP equ 1003
.code
DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL cbi:COMBOBOXEXITEM
LOCAL buffer[256]:BYTE
LOCAL mValue:DWORD
mov eax,uMsg
;call FillMyCombo
.if (eax==WM_INITDIALOG)
;/* Combobox setup */
invoke GetDlgItem,hWin,1003
mov hCombo,eax
;/* Fill it up] */
invoke FillMyCombo
invoke UpdateWindow,hWnd
.elseif (eax==WM_COMMAND)
mov eax,wParam
.if (eax==1001) ; button pressed
invoke GetDlgItemText, hCombo, 1003, offset lpDropDown, nDropDown
invoke MessageBox,NULL,lpDropDown,lpDropDown,NULL
mov eax, offset lpDropDown
mov ecx, offset String1
.if eax==ecx
call RegistryProc
.else
;mov ecx, offset org_val
;mov edx, offset new_val
;push ecx; Save the values for later
;push edx
call SearchProc
.endif
.elseif (eax==1002) ; About button
invoke MessageBox, NULL, ADDR MsgBoxTextAbout, ADDR MsgBoxCaption, MB_OK
.endif
.endif
invoke GetDlgItemText, hCombo, 1003, offset lpDropDown, nDropDown
Change hCombo to hWin.
And don't forget to use GetLastError, it will usually tell you exactly what the error was.
You should rename lpDropDown to szDropDown. That will stop you getting confused.
The reason for asking to post the whole code is to get a better picture of what your asking!
Why it is not working is the call Get and SetDlgItemText:
Should be
invoke GetDlgItemText, hDlg, 1003, offset lpDropDown, sizeof lpDropDown
invoke MessageBox,hDlg,offset lpDropDown,offset lpDropDown,NULL
:U
Peter
Thanks guys. What was wrong with SetDlgItemText? I'm asking because it is working as expected for me. I use hDlg because that is the dialog window not the control? I'll try the suggestions when I get home. Really appreciate the help and explanations.
Nilrem,
Ignore the SetDlgItem Text bit, it escaped into my message in the confusion over your choice of variables.
As you probably know, there is no CB_GETTEXT so whenever I've used a ComboBox I use the CB_GETCURSEL message.
Anyway, if you need a ComboBox skeleton just ask...
Peter.
I can seriously use CB_GETCURSEL to get what is selected in the drop-down menu? If so which is more efficient, using that or getdlgitemtext? Can you pm me your skeleton please, it's probably better then mine (though it does work as I want it to). Once again, thanks.
Quote from: pbrennick on February 22, 2005, 01:21:26 AM
dev_zero,
Who told you that? You were mislead. Want me to post some working code?
Paul
Sorry my bad, when I see the source code now. I see that it was not an local variable.