flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Combobox Problem

Author
Thread Post new topic Reply to topic
Force



Joined: 12 Jun 2012
Posts: 29
I cant add items to combobox

can anybody help me ?

thanks

Code:

format PE GUI 4.0
entry start

include 'd:\fasm\include\win32a.inc'

section '.data' data readable writeable
hInstance dd ?
hCombobox01 dd ?
IDC_PARAM = 1000
item1 db ' ',0
item2 db 'Fasm',0
item3 db 'Masm',0
section '.code' code readable executable

start:
invoke GetModuleHandle,0
mov [hInstance],eax
invoke DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
invoke ExitProcess,0

proc DialogProc hwnddlg,msg,wparam,lparam
push ebx esi edi
mov eax,[msg]
cmp eax,WM_COMMAND
je wmcommand
cmp eax,WM_INITDIALOG
je wminitdialog
cmp eax,WM_CLOSE
je wmclose

xor eax,eax
jmp finish
wmcommand:
.ext:

jmp processed


wminitdialog:
invoke  GetDlgItem,[hwnddlg],IDC_PARAM
 mov [hCombobox01],eax
invoke SendMessage,[hCombobox01],CB_SETITEMDATA,0,item2

invoke SendMessage,[hCombobox01],CB_ADDSTRING,NULL,item3 

jmp processed
wmclose:
invoke EndDialog,[hwnddlg],0

processed:
mov eax,1
finish:
pop edi esi ebx
ret
endp

section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL'


include 'd:\fasm\include\api\kernel32.inc'
include 'd:\fasm\include\api\user32.inc'


section '.rsrc' resource data readable

directory RT_DIALOG,dialogs

resource dialogs,\
37,LANG_ENGLISH+SUBLANG_DEFAULT,main

dialog main,\
'COMBOBOX',10,10,213,147,WS_MINIMIZEBOX+WS_VISIBLE+WS_POPUP+WS_CAPTION+WS_SYSMENU+DS_CENTER+DS_MODALFRAME
dialogitem 'EDIT',"",IDC_PARAM,12,70,100,17,WS_VISIBLE+WS_VSCROLL 

enddialog

    
Post 10 Nov 2012, 00:11
View user's profile Send private message Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
seriously, you should indent your code properly..

Also, there is no Combobox in your code. You're creating a window named "COMBOBOX" with an edit-child-window (a simple textbox).

In order to get a combobox, change 'edit' to 'combobox' to create a child-window of the class 'combobox' and use CB_ADDSTRING to add an item. You also need to increase its height to be able to see the items in the combobox's lower box (or its context menu if you've specified CBS_DROPDOWNLIST), like:

Code:
dialogitem 'combobox',"",IDC_PARAM,20,70,100,48,WS_VISIBLE+WS_VSCROLL+CBS_DROPDOWNLIST    
Post 10 Nov 2012, 01:55
View user's profile Send private message Reply with quote
Force



Joined: 12 Jun 2012
Posts: 29
Thanks yoshimitsu

I know i was confused in this code Smile


It is working code " SET ITEM and GET ITEM "

Code:

format PE GUI 4.0
entry start

include 'd:\fasm\include\win32a.inc'

section '.data' data readable writeable

hInstance     dd ?
hCombobox01   dd ?
IDC_PARAM   = 1000
IDC_BTN_GET = 1005

item1 db 'Fasm',0
item2 db 'Masm',0

buf db 50 dup (?)

section '.code' code readable executable

start:
invoke GetModuleHandle,0
mov [hInstance],eax
invoke DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
invoke ExitProcess,0

proc DialogProc uses ebx esi edi,hwnddlg,msg,wparam,lparam

mov eax,[msg]
cmp eax,WM_COMMAND
je wmcommand
cmp eax,WM_INITDIALOG
je wminitdialog
cmp eax,WM_CLOSE
je wmclose


jmp finish
wmcommand:
cmp [wparam], BN_CLICKED shl 16 + IDC_BTN_GET
je .GET
jmp finish

.GET:

invoke GetDlgItemText,[hwnddlg],IDC_PARAM,buf,256
invoke MessageBox,NULL,buf,NULL,MB_OK
jmp finish

wminitdialog:
invoke  GetDlgItem,[hwnddlg],IDC_PARAM
 mov [hCombobox01],eax
invoke SendMessage,[hCombobox01],CB_ADDSTRING,NULL,item1
invoke SendMessage,[hCombobox01],CB_ADDSTRING,NULL,item2 

jmp finish
wmclose:
invoke EndDialog,[hwnddlg],0


finish:
xor eax,eax
ret
endp

section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL'


include 'd:\fasm\include\api\kernel32.inc'
include 'd:\fasm\include\api\user32.inc'


section '.rsrc' resource data readable

directory RT_DIALOG,dialogs

resource dialogs,\
37,LANG_ENGLISH+SUBLANG_DEFAULT,main

dialog main,\
'COMBOBOX',10,10,213,147,WS_MINIMIZEBOX+WS_VISIBLE+WS_POPUP+WS_CAPTION+WS_SYSMENU+DS_CENTER+DS_MODALFRAME
dialogitem 'combobox',"",IDC_PARAM,50,40,100,48,WS_VISIBLE+WS_VSCROLL+CBS_DROPDOWNLIST
dialogitem 'BUTTON',"GET ITEM",IDC_BTN_GET,60,60,75,12,BS_PUSHBUTTON+WS_VISIBLE
enddialog




    
Post 10 Nov 2012, 12:20
View user's profile Send private message Reply with quote
catafest



Joined: 05 Aug 2010
Posts: 104
good example.
theoretically you can create any gui, then implement on events ...
here is an example without events but written in another way (fasm has some features):
Code:
format PE GUI 4.0

 entry start

 include 'win32a.inc'

 IDD_TEST_DIALOGS = 102
 IDC_COMBOBOX_1 = 1000

 section '.code' code readable executable

  start:

    invoke GetModuleHandle,0
    invoke DialogBoxParam,eax,IDD_TEST_DIALOGS,0,DialogProc,0

  exit:

    invoke  ExitProcess,0 

proc DialogProc uses esi edi ebx,hwnddlg,msg,wparam,lparam

  cmp [msg],WM_INITDIALOG
  je .wminitdialog

  cmp [msg],WM_CLOSE
  je .wmclose

  xor eax,eax
  jmp .quit

  .wminitdialog:

    invoke SetDlgItemText,[hwnddlg],IDC_COMBOBOX_1,szInitText

    jmp .done

  .wmclose:

    invoke EndDialog,[hwnddlg],0

  .done:

    mov eax,1

  .quit:

  ret       

endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'

  import kernel,\
         GetModuleHandle,'GetModuleHandleA',\
         ExitProcess,'ExitProcess'

  import user,\
         DialogBoxParam,'DialogBoxParamA',\ 
         SetDlgItemText,'SetDlgItemTextA',\
         EndDialog,'EndDialog'

section '.text' readable writeable

  szInitText db "Text set by WM_INITDIALOG.",0

section '.rc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,IDD_TEST_DIALOGS,LANG_ENGLISH+SUBLANG_DEFAULT,mod_exp_dialog

  dialog mod_exp_dialog,\
  'FASM - Dialogs Examples - combobox',0,0,160,160,\
  DS_MODALFRAME+WS_MINIMIZEBOX+WS_POPUP+WS_VISIBLE+WS_CAPTION+WS_SYSMENU,\
  0,0,"Lucida Console",11

  dialogitem 'COMBOBOX',IDC_COMBOBOX_1,-1,10,10,140,12,BS_GROUPBOX+WS_VISIBLE+WS_VSCROLL,0

  enddialog     
Post 14 Feb 2018, 10:01
View user's profile Send private message Visit poster's website Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.