flat assembler
Message board for the users of flat assembler.

Index > Windows > Dialog Box Question

Author
Thread Post new topic Reply to topic
Zero



Joined: 02 Aug 2008
Posts: 16
Zero
I'm reviewing iczelion win32 tutorials, in particular tut #10 Dialog Box as main window and when I assemble it I get strange results. Below is an image showing what I get. As you can see, the menu is invisible and the entire window doesn't show correctly. I looked at the code but can't find whats wrong. Could someone take a look at the code and tell me whats wrong.

Image

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable
     hMain     dd   ?
     hInstance dd   ?

     wTitle    db   'Tutorial 10',0
     wClsName  db   'DLGCLASS',0

     wMsg      MSG
     wCls      WNDCLASS

     ;experiment variables
     expDlgName     db   'My Dialog',0
     expTxt         db   "Wow! I'm in an edit box now",0
     expBuffer:     times 513 db 0
     expHDlg        dd   ?

section '.code' code readable executable
     start:
          ; +---------------------------+
          ; | register the window class |
          ; +---------------------------+
          invoke    GetModuleHandle,NULL
                    mov  [hInstance],eax
          invoke    DialogBoxParam,[hInstance],31,NULL,dialog_procedure,NULL
          invoke    ExitProcess,0

          ; +----------------------+
          ; | the dialog procedure |
          ; +----------------------+
          proc dialog_procedure,hDlg,uMsg,wParam,lParam
               push ebx esi edi
               cmp  [uMsg],WM_COMMAND
               je   wmCOMMAND
               cmp  [uMsg],WM_CLOSE
               je   wmCLOSE
               cmp  [uMsg],WM_INITDIALOG
               je   wmINITDIALOG
               jmp  wmBYE

               wmINITDIALOG:
                    invoke    GetDlgItem,[hDlg],3000
                    invoke    SetFocus,eax
                              jmp  wmBYE
               wmCLOSE:
                    invoke    SendMessage,[hDlg],WM_COMMAND,3002,0
                              jmp  wmBYE

               wmCOMMAND:
                    cmp  [wParam],0xFFFF and 32000
                    je   wmCOMMAND_32000
                    cmp  [wParam],0xFFFF and 32001
                    je   wmCOMMAND_32001
                    cmp  [wParam],0xFFFF and 32002
                    je   wmCOMMAND_32002
                    cmp  [wParam],BN_CLICKED shl 16 or 3002
                    je   wmCOMMAND_3002
                    cmp  [wParam],BN_CLICKED shl 16 or 3001
                    je   wmCOMMAND_3001
                    jmp  wmBYE

                    wmCOMMAND_3002:     ;exit button
                         invoke    EndDialog,[hDlg],0
                                   jmp  wmBYE
                    wmCOMMAND_3001:     ;say hello button
                         invoke    SetDlgItemText,[hDlg],3000,expTxt
                                   jmp  wmBYE
                    wmCOMMAND_32000:    ;menu get text
                         invoke    GetDlgItemText,[hDlg],3000,expBuffer,512
                         invoke    MessageBox,NULL,expBuffer,expDlgName,MB_OK
                                   jmp  wmBYE
                    wmCOMMAND_32001:    ;clear text
                         invoke    SetDlgItemText,[hDlg],3000,NULL
                                   jmp  wmBYE
                    wmCOMMAND_32002:    ;exit
                         invoke    SendMessage,[hDlg],WM_COMMAND,3002,0
                                   jmp  wmBYE

               wmBYE:
                    pop  edi esi ebx
                    ret
          endp

section '.idata' import data readable writeable
     library   KERNEL32, 'KERNEL32.DLL',\
               USER32,   'USER32.DLL'

     import    KERNEL32,\
               GetModuleHandle,    'GetModuleHandleA',\
               ExitProcess,        'ExitProcess'


     import    USER32,\
               LoadCursor,         'LoadCursorA',\
               LoadIcon,           'LoadIconA',\
               DialogBoxParam,     'DialogBoxParamA',\
               GetDlgItem,         'GetDlgItem',\
               EndDialog,          'EndDialog',\
               SetFocus,           'SetFocus',\
               MessageBox,         'MessageBoxA',\
               SetDlgItemText,     'SetDlgItemTextA',\
               GetDlgItemText,     'GetDlgItemTextA',\
               SendMessage,        'SendMessageA',\
               PostQuitMessage,    'PostQuitMessage'

section '.rsrc' resource data readable
     directory RT_MENU,appMenu,\
               RT_DIALOG,appDialog

     resource  appMenu,\
               30,LANG_NEUTRAL,menuMain
     resource  appDialog,\
               31,LANG_NEUTRAL,dlgMain

     menu menuMain
          menuitem  'Test Controls',0,MFR_POPUP + MFR_END
          menuitem       'Get Text',32000,MFT_STRING
          menuitem       'Clear Text',32001,MFT_STRING
                         menuseparator
          menuitem       'Exit',32002,MFR_END

     dialog dlgMain,'Our First Dialog Box',10,10,205,60,\
          DS_CENTER + WS_CAPTION + WS_MINIMIZEBOX + WS_SYSMENU + WS_VISIBLE + WS_OVERLAPPED + DS_MODALFRAME + DS_3DLOOK,30
          dialogitem     'EDIT','',3000,15,17,111,13,ES_AUTOHSCROLL + ES_LEFT + WS_BORDER + WS_VISIBLE + WS_TABSTOP
          dialogitem     'BUTTON','Say Hello',3001,141,10,52,13,BS_DEFPUSHBUTTON + WS_VISIBLE + WS_TABSTOP
          dialogitem     'BUTTON','E&xit',3002,141,26,52,13,WS_VISIBLE + WS_TABSTOP
     enddialog

    
Post 12 Aug 2008, 03:37
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 03:24; edited 1 time in total
Post 12 Aug 2008, 04:01
View user's profile Send private message Reply with quote
Zero



Joined: 02 Aug 2008
Posts: 16
Zero
hmmm....I assembled your code and I can now see the dialog box window, however the menu is still missing. Any ideas?

Also, do I have to return true when using both CreateDialogParam and DialogBoxParam?

thanks for your prompt help yardman
Post 12 Aug 2008, 04:14
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 03:24; edited 1 time in total
Post 12 Aug 2008, 04:54
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 03:24; edited 1 time in total
Post 12 Aug 2008, 05:13
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3043
Location: vpcmipstrm
bitRAKE
Also want to make hDlg the parent of the message box - otherwise it displays under the dialog.
Code:
invoke MessageBox,[hDlg],expBuffer,expDlgName,MB_OK    


Description:
Download
Filename: dialog.zip
Filesize: 1.57 KB
Downloaded: 46 Time(s)


_________________
¯\(°_o)/¯ unlicense.org
Post 13 Aug 2008, 02:40
View user's profile Send private message Visit poster's website Reply with quote
Zero



Joined: 02 Aug 2008
Posts: 16
Zero
thanks bitrake and yardman. I was wondering why the message box was displaying below the main window and [hDlg] solved it! Smile

Also, you modified it and included:

Code:
invoke    GetMenu,[hDlg]
invoke    DestroyMenu,eax    


Is it necessary to use DestroyMenu everytime LoadMenu is used, i.e. are they always used as pairs? Because I assembled it without those two lines of code, and it works ok.
Post 13 Aug 2008, 07:34
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3043
Location: vpcmipstrm
bitRAKE

_________________
¯\(°_o)/¯ unlicense.org
Post 14 Aug 2008, 01:29
View user's profile Send private message Visit poster's website 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.