In the last FASM tutorial I add a simple ComboBox without items.
In this tutorial I will add two items and one button to show the output of selected ComboBox.
The source code is similar with the source code from the last tutorial.
I commented the source code rows for a good image of development steps:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | ;---- free-tutorials.org - FASM - tutorials ;---- december 2021 format PE GUI 4.0 entry start ; include files I need include 'INCLUDE\WIN32A.INC' ;data area for set all you need to run it section '.data' data readable writeable ItemComboBox dd ? IDC_PARAM = 1000 IDC_BTN_GET = 1005 IDD_TEST_DIALOGS = 102 IDC_COMBOBOX_1 = 1000 buf db 50 dup (?) ; this set to .code area section '.code' code readable executable ; this start the program start: invoke GetModuleHandle,0 invoke DialogBoxParam,eax,IDD_TEST_DIALOGS,HWND_DESKTOP,DialogProc,0 invoke ExitProcess,0 proc DialogProc uses ebx esi edi,hwnddlg,msg,wparam,lparam cmp [msg],WM_COMMAND je .wmcommand cmp [msg],WM_INITDIALOG je .wminitdialog cmp [msg],WM_CLOSE je .wmclose jmp .quit ; if combobox is selected by WM_COMMAND .wmcommand: cmp [wparam], BN_CLICKED shl 16 + IDC_BTN_GET je .get ; go to quit jmp .quit ; run selected area by combobox .get: invoke GetDlgItemText,[hwnddlg],IDC_PARAM,buf,256 invoke MessageBox,NULL,buf,NULL,MB_OK jmp .quit ; start build the combobox .wminitdialog: invoke GetDlgItem,[hwnddlg],IDC_PARAM ; load eax register with mov [ItemComboBox],eax ; add a string to ComboBox with CB_ADDSTRING invoke SendMessage,[ItemComboBox],CB_ADDSTRING,NULL,szInitText1 invoke SendMessage,[ItemComboBox],CB_ADDSTRING,NULL,szInitText2 ; this will quit jmp .quit .wmclose: invoke EndDialog,[hwnddlg],0 ; default quit .quit: xor eax,eax ret endp ; section for load all for window and GUI section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'include\api\kernel32.inc' include 'include\api\user32.inc' ; section text for create items text strings section '.text' readable writeable szInitText1 db "Text set 1.",0 szInitText2 db "Text set 2.",0 ; build the resources for main window 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_PARAM,10,10,140,48,WS_VISIBLE+WS_VSCROLL+CBS_DROPDOWNLIST dialogitem 'Button',"GET ITEM",IDC_BTN_GET,10,50,140,12,BS_PUSHBUTTON+WS_VISIBLE enddialog |
This file is on main folder fasm and is named MyComboBox001.fasm.
I run all with this commands:
1 2 3 4 5 | C:\fasmw17328>FASM.EXE MyComboBox001.fasm flat assembler version 1.73.28 (1048576 kilobytes memory) 5 passes, 3072 bytes. C:\fasmw17328>MyComboBox001.exe |
This is result of these commands:
I don’t customize this example, but can be done.
For example, you can see the title of the message is Error, or the window is not set on the center of the screen.