I have created a Dialog box within a resource editor and here is the lines for the combo box and list box
CONTROL "",IDC_LST1,"ListBox",WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LBS_NOINTEGRALHEIGHT
|LBS_HASSTRINGS|LBS_NOTIFY,243,91,78,59,WS_EX_CLIENTEDGE
CONTROL "",IDC_CBO1,"ComboBox",WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP
|CBS_DROPDOWN,174,156,141,15
Then within the WinProc(?) I call the following (INITDIALOG is WM_INIDIALOG i just changed it whilst messing around)
.IF uMsg==INITDIALOG
call SendDlgItemMessageA, hWnd, IDC_CBO1, CB_INSERTSTRING, -1, offset szSmall
szSmall is defined as szSmall db "abc",0
But when the program runs nothing apears in the combo box, or if i modify it to use the list box again nada.
I have tried:
1) calling InitCommonControls before the IF statement and after no joy.
2) I have tried getting the control ID by calling GetDlgItem, hWnd, IDC_CBO1 sticking 3) this into a variable and then calling SendDlgItemMessageA, variable, (as above) again fail
4) I have tried using SendMessage too all to no avail.
Also the main procedure returns true at the end.
I have had a google around and found an example of a combobox being used. Here is a snippet I found:
call SendDlgItemMessageA, handle, 1004, 143h, 00h, offset value11
call SendDlgItemMessageA, handle, 1004, 143h, 00h, offset value12
call SendDlgItemMessageA, handle, 1004, 143h, 00h, offset value13
call SendDlgItemMessageA, handle, 1004, 143h, 00h, offset value14
Nothing overly strange here compared to what I was calling. The guy that wrote above code has idc_cbo1 defined as 1004 (not sure what the 143h's are they dont appear to match any of the Combo box messages) therefore the only difference being I was setting wParam as -1 (append items to the end of the list) so I changed it to 0. stil no joy.
I have also tried CB_ADDSTRING, CB_INSERTSTRING.
I'm sure its something simple I'm missing or being over zealous, but again any help is thanked for in advance and most appreciated.
I have also run this through olly, and see abc being passed around. and If i check the return of senddlgitemmessagea it comes back as 0 showing eveything is ok, so i'm assuming I need to redraw the window? Owner redraw is set to no in the .rc file (well in the editor anyway) and I have tried calling update window, still no joy :(
CONTROL "",IDC_LST1,"ListBox",WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|LBS_NOINTEGRALHEIGHT
|LBS_HASSTRINGS|LBS_NOTIFY,243,91,78,59,WS_EX_CLIENTEDGE
CONTROL "",IDC_CBO1,"ComboBox",WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP
|CBS_DROPDOWN,174,156,141,15
Then within the WinProc(?) I call the following (INITDIALOG is WM_INIDIALOG i just changed it whilst messing around)
.IF uMsg==INITDIALOG
call SendDlgItemMessageA, hWnd, IDC_CBO1, CB_INSERTSTRING, -1, offset szSmall
szSmall is defined as szSmall db "abc",0
But when the program runs nothing apears in the combo box, or if i modify it to use the list box again nada.
I have tried:
1) calling InitCommonControls before the IF statement and after no joy.
2) I have tried getting the control ID by calling GetDlgItem, hWnd, IDC_CBO1 sticking 3) this into a variable and then calling SendDlgItemMessageA, variable, (as above) again fail
4) I have tried using SendMessage too all to no avail.
Also the main procedure returns true at the end.
I have had a google around and found an example of a combobox being used. Here is a snippet I found:
call SendDlgItemMessageA, handle, 1004, 143h, 00h, offset value11
call SendDlgItemMessageA, handle, 1004, 143h, 00h, offset value12
call SendDlgItemMessageA, handle, 1004, 143h, 00h, offset value13
call SendDlgItemMessageA, handle, 1004, 143h, 00h, offset value14
Nothing overly strange here compared to what I was calling. The guy that wrote above code has idc_cbo1 defined as 1004 (not sure what the 143h's are they dont appear to match any of the Combo box messages) therefore the only difference being I was setting wParam as -1 (append items to the end of the list) so I changed it to 0. stil no joy.
I have also tried CB_ADDSTRING, CB_INSERTSTRING.
I'm sure its something simple I'm missing or being over zealous, but again any help is thanked for in advance and most appreciated.
I have also run this through olly, and see abc being passed around. and If i check the return of senddlgitemmessagea it comes back as 0 showing eveything is ok, so i'm assuming I need to redraw the window? Owner redraw is set to no in the .rc file (well in the editor anyway) and I have tried calling update window, still no joy :(
Try using something like Microsoft's "Spy++" to make sure that all handles, IDs, etc. are the same as the ones you pass in your calls.
Hi, cheers, I havent tried Spy ++ (or used it before) ut i'll see if i can make it make any sense :D
Spy ++ didn't tell me too much just yet, but I did find a basic example that just puts a list box on the screen and when you click it it displays a messagebox on the screen saying which item you clicked.
Good.
I converted it from MASM32 to TASM changing invoke to to call and addr to offset etc, recompiled the resource file and run the proggie, again no win :(
So it would appear that I am missing something within TASM, this morning I will install masm32 and try the code in there and see what happens :D
Good.
I converted it from MASM32 to TASM changing invoke to to call and addr to offset etc, recompiled the resource file and run the proggie, again no win :(
So it would appear that I am missing something within TASM, this morning I will install masm32 and try the code in there and see what happens :D
After going wtf as my lazy ass attempt to change call to invoke by using find/replace which also replaced stdcall to stdinvoke and spewed errors all over the place I can confirm all my listbox tests run fine within masm32, looks like i'm missing something in tasm :/
if/when i find the error i'll post it in here
if/when i find the error i'll post it in here
The simplest way to add strings to a combo box is using SendMessage.
push StringToSend
push 0
push CB_ADDSTRING
push ComboBoxHandle
call SendMessage
I made an example in FASM which demonstrates how to add user-inputted strings, and hard-coded ones. It also shows how you (again using SendMessage), set the default item.
Note. To change the default combo box item its the third parameter of:
And is the index of the item (starting at zero)
push StringToSend
push 0
push CB_ADDSTRING
push ComboBoxHandle
call SendMessage
I made an example in FASM which demonstrates how to add user-inputted strings, and hard-coded ones. It also shows how you (again using SendMessage), set the default item.
format PE GUI
entry start
include '..\INCLUDE\Win32a.inc'
section '.data' data readable writeable
wCls WNDCLASS
wMsg MSG
cmbhWnd dd ?
cmbID equ 100
cmbClass db 'combobox',0
btnhWnd dd ?
btnID equ 101
btnClass db 'button',0
btnText db 'Add Item',0
edthWnd dd ?
edtID equ 102
edtClass db 'edit',0
edtText db 'Item to add',0
wndMain dd ?
szClassName db 'comboexample',0
szTitle db 'Combo Box Example',0
szItemA db 'Item A',0
szItemB db 'Item B',0
szBuffer db 512 dup 0
szError db 260 dup 0
section '.code' code readable executable
start:
push 0
call
mov ,eax
mov ,szClassName
mov ,WndProc
push 32512
push 0
call
mov ,eax
push 32512
push 0
call
mov ,eax
push wCls
call
cmp eax,0
je errGetError
push 0
push
push 0
push 0
push 200
push 300
push 16
push 16
push WS_OVERLAPPEDWINDOW
push szTitle
push
push 0
call
cmp eax,0
je errGetError
mov ,eax
push SW_SHOW
push eax
call
messageLoop:
push 0
push 0
push 0
push wMsg
call
or eax,eax
je codeEnd
push wMsg
call
push wMsg
call
jmp messageLoop
proc WndProc,hWnd,uMsg,wParam,lParam
cmp ,WM_DESTROY
je wmDestroy
cmp ,WM_CREATE
je wmCreate
cmp ,WM_COMMAND
je wmCommand
wmDefault:
push
push
push
push
call
jmp wmEnd
wmDestroy:
push 0
call
xor eax,eax
jmp wmEnd
wmCreate:
push 0
push
push cmbID
push
push 300
push 100
push 5
push 5
push WS_CHILD or WS_VISIBLE or CBS_DROPDOWNLIST
push 0
push cmbClass
push 0
call
cmp eax,0
je errGetError
mov ,eax
push 0
push
push edtID
push
push 25
push 135
push 30
push 5
push WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL
push 0
push edtClass
push WS_EX_CLIENTEDGE
call
cmp eax,0
je errGetError
mov ,eax
push 0
push
push btnID
push
push 25
push 100
push 30
push 150
push WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON
push btnText
push btnClass
push 0
call
cmp eax,0
je errGetError
mov ,eax
; Set edit box's text
push edtText
push
call
; Add a string to combo box
push szItemA
push 0
push CB_ADDSTRING
push
call
; Add another string
push szItemB
push 0
push CB_ADDSTRING
push
call
; Set the default item
push 0
push 0
push CB_SETCURSEL
push
call
jmp wmEnd
wmCommand:
mov eax,
cmp ax,btnID
jne wmEnd
shr ax,16
cmp ax,BN_CLICKED
jne wmEnd
; Get the edit box text
push 512
push szBuffer
push
call
cmp eax,0 ; Edit box empty?
je wmEnd
push szBuffer
push 0
push CB_ADDSTRING
push
call
push 0
push
call
wmEnd:
ret
endp
errGetError:
call
push 0
push 260
push szError
push 0
push eax
push 0
push 0x1000
call
push 0
push 0
push szError
push 0
call
codeEnd:
push 0
call
section '.idata' import readable
dd 0,0,0,RVA user_name ,RVA user_table
dd 0,0,0,RVA kernel_name ,RVA kernel_table
dd 0,0,0,0,0
kernel_table:
GetModuleHandle dd RVA _GetModuleHandle
FormatMessage dd RVA _FormatMessage
GetLastError dd RVA _GetLastError
ExitProcess dd RVA _ExitProcess
dd 0
user_table:
MessageBox dd RVA _MessageBox
CreateWindowEx dd RVA _CreateWindowEx
RegisterClass dd RVA _RegisterClass
DispatchMessage dd RVA _DispatchMessage
TranslateMessage dd RVA _TranslateMessage
DefWindowProc dd RVA _DefWindowProc
GetMessage dd RVA _GetMessage
LoadIcon dd RVA _LoadIcon
LoadCursor dd RVA _LoadCursor
PostQuitMessage dd RVA _PostQuitMessage
ShowWindow dd RVA _ShowWindow
SendMessage dd RVA _SendMessage
SetWindowText dd RVA _SetWindowText
GetWindowText dd RVA _GetWindowText
dd 0
user_name db 'USER32.DLL',0
kernel_name db 'KERNEL32.DLL',0
_GetModuleHandle dw 0
db 'GetModuleHandleA',0
_FormatMessage dw 0
db 'FormatMessageA',0
_GetLastError dw 0
db 'GetLastError',0
_ExitProcess dw 0
db 'ExitProcess',0
_MessageBox dw 0
db 'MessageBoxA',0
_CreateWindowEx dw 0
db 'CreateWindowExA',0
_RegisterClass dw 0
db 'RegisterClassA',0
_DispatchMessage dw 0
db 'DispatchMessageA',0
_TranslateMessage dw 0
db 'TranslateMessage',0
_DefWindowProc dw 0
db 'DefWindowProcA',0
_GetMessage dw 0
db 'GetMessageA',0
_LoadIcon dw 0
db 'LoadIconA',0
_LoadCursor dw 0
db 'LoadCursorA',0
_PostQuitMessage dw 0
db 'PostQuitMessage',0
_ShowWindow dw 0
db 'ShowWindow',0
_SendMessage dw 0
db 'SendMessageA',0
_SetWindowText dw 0
db 'SetWindowTextA',0
_GetWindowText dw 0
db 'GetWindowTextA',0
Note. To change the default combo box item its the third parameter of:
push 0
push 0
push CB_SETCURSEL
push
call
And is the index of the item (starting at zero)
ugh - push push push push push push push push call looks so ugly and makes your code harder to read.
Sure there are times where we can shave a few cycles by doing it, but I think most asm programmers prefer to use a less machinecode syntax.
Sorry for whining, I'll shut up now.
Sure there are times where we can shave a few cycles by doing it, but I think most asm programmers prefer to use a less machinecode syntax.
Sorry for whining, I'll shut up now.
:D I like pushes over invoke. Its all personal preference ain't it. I find pushes and calls easier to read that invokes in some cases though...
Problem Solved!!
It turns out the windows.inc file I had with my TASM distribution is messed up. After copying the LB_ADDSTRING etc bits from the MASM32 version everything works.
Sad Panda :(
It turns out the windows.inc file I had with my TASM distribution is messed up. After copying the LB_ADDSTRING etc bits from the MASM32 version everything works.
Sad Panda :(