flat assembler
Message board for the users of flat assembler.
Index
> Windows > converting Iczelion's-Tut10 part1 to FASM Goto page 1, 2 Next |
Author |
|
mns 22 Dec 2019, 08:51
I am tring to convert Iczelion's-Tut10 part1 to FASM(using dialog box template as a class template ,register with RegisterClassEx call).Although I managed to open a dialogbox with menu, menu items not working (well only 'Exit' item should work), and the close button( in upper right) not working. File is attached with this.Could someone please help?
|
|||||||||||
22 Dec 2019, 08:51 |
|
mns 22 Dec 2019, 17:07
Walter thank you for your kind reply.but your post shows how to create a dialogbox with
"DialogBoxParam" and calling dialog box procedure for handling messages.I want to create dialogbox with "CreateDialogParam" and handling messages with window procedure.(registering dialog box template as a class template). Actually there are posts in this message board which shows the Iczelion's tutorials in FASM, but they shows only the way you posted. |
|||
22 Dec 2019, 17:07 |
|
mns 23 Dec 2019, 09:07
Come on guys please help me....?
it seems dialogbox created here dosen't made from the registered template. Code: format PE GUI 4.0 entry start include 'WIN32Ax.inc' ;include 'rcWin32.inc' ;a custom inc file ;-------------------------------------------------------------- IDR_MAINMENU = 2000 IDR_DIALOG = 2001 IDC_EDIT = 5000 IDB_BUTTON = 4000 IDM_HELLO = 1000 IDM_CLEAR = 1001 IDM_GETTEXT = 1002 IDM_EXIT = 1003 IDM_EDIT = 1004 ;-------------------------------------------------------------- ;///////////////////////////////////////////////////////////////////////////////////////////////////// section '.data' data readable writeable ;======================================================================================================== MenuName = IDR_MAINMENU DlgsName db 'MNSdlgName',0 DlgClassName = IDR_DIALOG EditName db 'EDIT',0 ButtonClassName db 'BUTTON',0 ButtonText db 'my button',0 ErrTxt1 db 'Registering window class Failed',0 ErrTxt2 db 'Fail to create a window using DlgClassName',0 ErrTxt3 db 'Error in the message loop of the window',0 ErrMsgBoxCaption db 'Program Error',0 TestString db 'Hello edit',0 text2 db 'menu',0 buffer rb 520 msg MSG wc WNDCLASSEX cmdLine dd ? hInst dd ? hwndDlg dd ? hwndEdit dd ? hwndButton dd ? ;====================================================================================================== ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;////////////////////////////////////////////////////////// ;///////////////////////////////////////////////////////////////////////////////////////////////////// section '.code' code readable executable ;===================================================================================================== start: invoke GetModuleHandle,0 mov [hInst],eax invoke GetCommandLine mov [cmdLine],eax stdcall WinMain,[hInst],NULL,[cmdLine],SW_SHOWDEFAULT invoke ExitProcess,eax ;-----------------------WinMain Procedure------------------------------------------------------------- proc WinMain hInstance:DWORD,hPrvinstance:DWORD,commandLine:DWORD,cmdshow:DWORD ;----declare window struct---------------------------- push [hInst] pop [wc.hInstance] mov [wc.cbSize], sizeof.WNDCLASSEX mov [wc.style], 0 mov [wc.lpfnWndProc],WindowProc xor eax,eax mov [wc.cbClsExtra],eax mov [wc.cbWndExtra],DLGWINDOWEXTRA ;***** this needed mov [wc.hbrBackground], COLOR_BTNFACE+1 mov [wc.lpszMenuName],MenuName mov [wc.lpszClassName],DlgClassName invoke LoadIcon, NULL, IDI_APPLICATION mov [wc.hIcon], eax mov [wc.hIconSm], eax invoke LoadCursor, NULL, IDC_ARROW mov [wc.hCursor], eax ;----Registering window class---------- invoke RegisterClassEx, wc or eax,eax jz err1;end_loop ;-----Create modeless dialogbox--------- invoke CreateDialogParam,[hInst],DlgClassName,NULL,0,0 mov [hwndDlg],eax or eax,eax jz err2;end_loop ;-----Show window---------------------- invoke ShowWindow, [hwndDlg],SW_SHOWNORMAL ;-----Update window--------------------- invoke UpdateWindow, [hwndDlg] ;-----Set focus on dialog item------------- invoke GetDlgItem,[hwndDlg],IDC_EDIT ;return the control's window handle in eax from control id invoke SetFocus,eax ;jmp end_loop ;-----message loop---------------------- msg_loop: invoke GetMessage,msg,NULL,0,0 cmp eax,0 je end_loop jb err3 invoke IsDialogMessage, [hwndDlg],msg or eax,eax jnz msg_loop invoke TranslateMessage,msg invoke DispatchMessage,msg jmp msg_loop err1: invoke MessageBox, 0,ErrTxt1,ErrMsgBoxCaption, MB_OK jmp end_loop err2: invoke MessageBox, 0,ErrTxt2,ErrMsgBoxCaption, MB_OK jmp end_loop err3: invoke MessageBox, 0,ErrTxt3,ErrMsgBoxCaption, MB_OK jmp end_loop end_loop: mov eax,[msg.wParam] ret endp ;---------------------------------------------------------------------------------------------------------- ;------------------------------------window procedure------------------------------------------------------ proc WindowProc hwnd:DWORD,umsg:DWORD,wParam:DWORD,lparam:DWORD push ebx esi edi cmp [umsg],WM_CLOSE je ..endProgrm cmp [umsg],WM_DESTROY je .wmdestroy cmp [umsg],WM_COMMAND je .Commands .defwndproc: invoke DefWindowProc,[hwnd],[umsg],[wParam],[lparam] jmp .finish .Commands: xor eax,eax mov eax,[lparam] cmp eax,0 jne ..chldCntrl mov eax,[wParam] cmp ax,IDM_EXIT je ..endProgrm ;cmp ax,IDM_HELLO ;je ..wrtStrg ;cmp ax,IDM_CLEAR ;je ..clrStr ;cmp ax,IDM_GETTEXT ;je ..getText jmp .finish ..wrtStrg: ;invoke SetWindowText,[hwndEdit],TestString jmp .finish ..clrStr: ;invoke SetWindowText,[hwndEdit],0 jmp .finish ..getText: ;invoke GetWindowText,[hwndEdit],buffer,512 ;invoke MessageBox,NULL,buffer,AppName,MB_OK jmp .finish ..chldCntrl: mov eax,[wParam] cmp ax,IDB_BUTTON jne .finish shr eax,16 cmp ax,BN_CLICKED jne ..endProgrm ;invoke SendMessage,[hwnd],WM_COMMAND,IDM_GETTEXT,0 jmp .finish ..endProgrm: invoke DestroyWindow,[hwnd] .wmdestroy: invoke PostQuitMessage,0 xor eax,eax .finish: pop edi esi ebx ret endp ;--------------------------------------------------------------------------------------------------------- ;========================================================================================================== ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;////////////////////////////////////////////////////////// ;////////////////////////////////////////////////////////////////////////////////////////////////////// section '.idata' import data readable ;======================================================================================================= library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api/kernel32.inc' include 'api/USER32.inc' ;======================================================================================================= ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;////////////////////////////////////////////////////////////////////////////////////////////////////// section '.rsrc' resource data readable ;======================================================================================================= directory RT_DIALOG,dialogs,\ RT_MENU,menus resource dialogs,IDR_DIALOG,LANG_ENGLISH+SUBLANG_DEFAULT,mydialogbox dialog mydialogbox,'dialogBox',70,70,190,175,WS_CAPTION+WS_SYSMENU+DS_MODALFRAME+WS_VISIBLE,,IDR_MAINMENU,'Times New Roman',10 dialogitem 'EDIT','',IDC_EDIT,10,50,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL dialogitem 'BUTTON','open',IDB_BUTTON,50,10,52,13,WS_VISIBLE+WS_TABSTOP ;dialogitem 'BUTTON','OK',IDOK,10,10,45,15,WS_VISIBLE+WS_TABSTOP enddialog resource menus,IDR_MAINMENU,LANG_ENGLISH+SUBLANG_DEFAULT,mainMenu menu mainMenu ;{ menuitem '&File',0,MFR_POPUP ;{ menuitem '&Hello',IDM_HELLO menuitem '&Clear',IDM_CLEAR menuseparator menuitem 'E&xit',IDM_EXIT,MFR_END ;} menuitem '&Edit',IDM_EDIT,MFR_END ;} ;======================================================================================================= ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ |
|||
23 Dec 2019, 09:07 |
|
Walter 23 Dec 2019, 13:19
In CreateDialogParam, is it intentional that DlgProc callback paramater is 0?
|
|||
23 Dec 2019, 13:19 |
|
mns 23 Dec 2019, 14:15
yes.I think, so that windows procedure can handle messages.
link to Iczelion's tutorial 10 - http://www.interq.or.jp/chubu/r6/masm32/tute/tute010.html (please see the first example) |
|||
23 Dec 2019, 14:15 |
|
Walter 23 Dec 2019, 15:32
More examples.
https://wasm.in/threads/uroki-iczeliona-ot-sulaiman-chang-na-dialekte-fasm.31759/ In particular, tut_10c which nulls the DlgProc and uses WndProc to handle messages. |
|||
23 Dec 2019, 15:32 |
|
mns 23 Dec 2019, 17:54
Thank you very much.Actually I have seen it and tried to understand the problem of my code compaired to it, but no luck.
|
|||
23 Dec 2019, 17:54 |
|
mns 25 Dec 2019, 17:59
Walter when I was experimenting with the code in your link, I have encountered a strange thing which may also be the cause of the problem I have been having. The asm file in that example(tut_10c.asm) compiled with the .res file(tut_10c.res which contain dialogbox and menu resource) using fasm, menu and buttons of the resulted exe file worked properly(both are attached with this as zip file-->tut_10c.zip). but when the asm file modified(modifd_tut_10c.asm) to have dialogbox and menu resorces instead of using .res file resulting exe file from FASM not working as expected.(menu and buttons not working) see the modifiedTut10.zip attached with this.
|
|||||||||||||||||||||
25 Dec 2019, 17:59 |
|
Walter 25 Dec 2019, 23:03
mns,
Interesting. Might have been the problem all along. Your menus were there but did not respond. I'll give you an idea to work with here. But I may not be much help. I disassembled the resource sections from your modified version: and from the orginal version. The difference that I find most important is the "CLASS" statement. That is in the orginal version produced by a resource compiler. Here is more detail about the "CLASS" statement: https://docs.microsoft.com/en-us/windows/win32/menurc/class-statement That would explain not having callbacks for menu items (?)? I have never had to use that statement and with fasm, I don't believe you can. From the fasm manual: Code: The dialogitem has eight required parameters and one optional. First parameter should be the quoted string containing the class name for the item. Second parameter can be either the quoted string containing text for the item, or resource identifier in case when the contents of item has to be defined by some additional resource (like the item of STATIC class with the SS_BITMAP style). The third parameter is the identifier for the item, used to identify the item by the API functions. Next four parameters specify the horizontal, vertical coordinates, the width and height of the item respectively. The eighth parameter specifies the style for the item, and the optional ninth specifies the extended style flags. No mention for optional resource statement options. It is an optional resource statement that probably is just not used often. Wish I could have helped more, but maybe someone else can jump in here. |
|||
25 Dec 2019, 23:03 |
|
ProMiNick 26 Dec 2019, 05:01
That wasn`t problem for fasm for a long time (resurces macros already customized by me)
use this dialog macros: Code: macro dlgdefprop prop:''& { local ..done ..done = $ match any =, more,prop \{ du prop,0 \} if $ = ..done if prop eqtype '' if prop eq '' dw 0 else du prop,0 end if else if ~prop dw 0 else dw -1,prop end if end if end if } macro dlgdefchild class:''& { local ..done,tmpclass ..done = $ match any =, more,class \{ du class,0 \} if $ = ..done if class eqtype '' if class eq 'BUTTON' dw -1, 80h else if class eq 'EDIT' dw -1, 81h else if class eq 'STATIC' dw -1, 82h else if class eq 'LISTBOX' dw -1, 83h else if class eq 'SCROLLBAR' dw -1, 84h else if class eq 'COMBOBOX' dw -1, 85h else if class eq '' dw 0 else du class,0 end if else if (class and 1Fh) =10 | (class and 1Fh) =16 | (class-(class and 80h))>18h | class<0 .err unsupported classID = class end if dw -1,class end if end if } macro dialog label,class,title,x,y,cx,cy,style:0,exstyle:0,menu,fontname,fontsize:0 { local data,size,items label dd RVA data,size,0,0 data dd style,exstyle dw items,x,y,cx,cy dlgdefprop menu dlgdefprop class dlgdefprop title if style and DS_SETFONT if fontname eq du 8,'MS Sans Serif',0 else du fontsize,fontname,0 end if end if align 4 dialog_size equ size = $ - data dialog_items equ items = dialog_items_counter dialog_items_counter = 0 macro dlgitmxtrdata \{ local fin store word (fin-$) at $-2 macro enddlgitmxtrdata \\{ fin = $ \\} \} macro enddialog \{ dialog_items dialog_size purge dlgitmxtrdata,enddialog,enddlgitmxtrdata \} } ANSl_CHARSET = 0 DEFAULT_CHARSET = 1 SYMBOL_CHARSET = 2 MAC_CHARSET = 77 SHIFTJIS_CHARSET = 128 HANGEUL_CHARSET = 129 HANGUL_CHARSET = 129 JOHAB_CHARSET = 130 GB2312_CHARSET = 134 CHINESEBIG5_CHARSET = 136 GREEK_CHARSEO = 161 TURKISH_CHARSET = 162 VIETNAMESE_CHARSET = 163 HEBREW_CHARSET = 177 ARABIC_CHARSET = 178 BALTIC_CHARSET = 186 THAI_CHARSET = 222 EASTEUROPE_CHARSET = 238 RUSSIAN_CHARSET = 204 OEM_CHARSET = 255 macro dialogex label,class,title,x,y,cx,cy,style:0,exstyle:0,menu,helpID:0,fontname,fontsize:0,fontweight:0,italic:0,charset:1 { local data,size,items label dd RVA data,size,0,0 align 16 data dw 1,0FFFFh dd helpID dd exstyle,style dw items,x,y,cx,cy dlgdefprop menu dlgdefprop class dlgdefprop title ;fontweight=0..1000; 0=default=400; bold = 700 if style and DS_SETFONT ;or DS_SHELLFONT=DS_SETFONT or DS_FIXEDSYS if fontname eq dw 8,400 db italic, charset du 'MS Sans Serif',0 else dw fontsize,fontweight db italic, charset du fontname,0 end if end if align 4 dialog_size equ size = $ - data dialog_items equ items = dialog_items_counter dialog_items_counter = 0 macro dlgitmxtrdata \{ local fin store word (fin-$) at $-2 macro enddlgitmxtrdata \\{ fin = $ \\} \} macro enddialog \{ dialog_items dialog_size purge dlgitmxtrdata,enddialog,enddlgitmxtrdata \} } macro dialogitem class,title,id,x,y,cx,cy,style:0,exstyle:0 { align 4 dd style or WS_CHILD,exstyle dw x,y,cx,cy,id dlgdefchild class dlgdefprop title dw 0 dialog_items_counter = dialog_items_counter + 1 } macro dialogitemex class,title,id,x,y,cx,cy,style:0,exstyle:0,helpID:0 { align 4 dd helpID,exstyle,style or WS_CHILD dw x,y,cx,cy dd id ; against dialogitem here ID has dword size dlgdefchild class dlgdefprop title dw 0 dialog_items_counter = dialog_items_counter + 1 } I don`t find practical applience (to some improvements) at the moment I designed them but thou did. |
|||
26 Dec 2019, 05:01 |
|
mns 26 Dec 2019, 05:46
Thank you very much Walter and ProMiNick for your kind responses. (also when I opened modified exe file with ResEdit It gives a error regarding menu statement in dialogbox resource dosen't refer to a menu.I attached the screen shot.)
I will follow your leads to correct my problem(and learn something.)Thank you again.
|
||||||||||
26 Dec 2019, 05:46 |
|
mns 26 Dec 2019, 08:28
ProMiNick I don't have much knowladege about Macro . But I copied your macro definitions and replaced every thing named dialog in "resource.inc"( in FASM \include\MACRO folder)with it.Then in my file added lable of the class name of the dialog resource(zero ended string) just after the lable of the dialog box.And tried to compile.But FASM giving a error
"Error: value out of range" instruction: dw-1,ClassName Have I done it wrong?
|
|||||||||||
26 Dec 2019, 08:28 |
|
ProMiNick 26 Dec 2019, 10:03
I guess
Code: dialog DIALOGEXS,'DLGCLASS',"Iczelion Tutorial #10c: CreateDialogParam+WndProc+Class",10, 10, 230, 60,DS_CENTER+WS_CAPTION+WS_MINIMIZEBOX+WS_SYSMENU+WS_VISIBLE+WS_OVERLAPPED+DS_MODALFRAME+DS_3DLOOK,,IDC_MENU,'Times New Roman',10 not Code: dialog DIALOGEXS,ClassName,"Iczelion Tutorial #10c: CreateDialogParam+WndProc+Class",10, 10, 230, 60,DS_CENTER+WS_CAPTION+WS_MINIMIZEBOX+WS_SYSMENU+WS_VISIBLE+WS_OVERLAPPED+DS_MODALFRAME+DS_3DLOOK,,IDC_MENU,'Times New Roman',10 |
|||
26 Dec 2019, 10:03 |
|
mns 26 Dec 2019, 10:26
yes I have done both ways.
The error I posted was from the second one dialog DIALOGEXS,ClassName,"Iczelion Tutorial #10c: CreateDialogParam+WndProc+Class",10, 10, 230, 60,DS_CENTER+WS_CAPTION+WS_MINIMIZEBOX+WS_SYSMENU+WS_VISIBLE+WS_OVERLAPPED+DS_MODALFRAME+DS_3DLOOK,,IDC_MENU,'Times New Roman',10 The first one compiled without error. But the resulted exe dosen't showed a messagebox.So I have changed the asm file to show error message if "CreateDialogParam" failed. and the resulting exe suggest it failed in creating dialogbox. (please see the attached file)
|
|||||||||||
26 Dec 2019, 10:26 |
|
ProMiNick 26 Dec 2019, 11:58
left only compare binaries and found out what thours example produce wrong.
|
|||
26 Dec 2019, 11:58 |
|
Mikl___ 26 Dec 2019, 13:11
Code: ┌─────────────────────────┬───────┬────────┬───────┐ │ │DlgProc│ DlgProc│WndProc│ │ │ │+WndProc│ +Class│ ├─────────────────────────┼───────┼────────┼───────┤ │DialogBoxParam │ 10a│ 10b│ 10c│ ├───────-─────────────────┼───────┼────────┼───────┤ │CreateDialogParam │ 10d│ 10e│ 10f│ ├──────────────-──────────┼───────┼────────┼───────┤ │DialogBoxIndirectParam │ 10g│ 10i│ 10k│ ├─────────────────────────┼───────┼────────┼───────┤ │CreateDialogIndirectParam│ 10h│ 10j│ 10l│ └─────────────────────────┴───────┴-───────┴───────┘ There are twelve ways to create dialogs It’s unfortunate that the forum engine does not support table creation |
|||
26 Dec 2019, 13:11 |
|
mns 27 Dec 2019, 14:34
Thank you Mikl___ .But (no disrespect) it won't address my problem(I think).MY problem is to create dialogbox with FASM syntax+CreateDialogParam+wind procedure+dialogbox template(class) defined in same asm file(as "section '.rsrc' resource") not in .res file .
|
|||
27 Dec 2019, 14:34 |
|
Mikl___ 27 Dec 2019, 15:53
Hi, mns!
Iczelion showed two ways to create dialogs. I show that there are 12 such methods. You will find asm- and rc-files on the link. The transition from masm to fasm dialect is quite simple. I think that you will succeed. Only I did not understand why "no disrespect"? What have I done wrong? |
|||
27 Dec 2019, 15:53 |
|
mns 27 Dec 2019, 17:25
Mikl___
No. it means that, please don't think I am disrespecting you by saying "It won't address my problem". Yes your link show 12 ways to create a dialogbox in masm. But the problem I was facing is converting CreateDialogParam+wndproc+class to FASM.Especially when dialogbox resource(with menu) in '.rsrc' resource section (not in a seperate .res or .rc file) Attached file in my first post (win32p15.ASM) I managed to convert it to FASM and resulting exe produced a dialogbox with menu and button but menu or button didn't worked. |
|||
27 Dec 2019, 17:25 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.