flat assembler
Message board for the users of flat assembler.

Index > Windows > Dialog

Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
How to create a simple dialog with a button using resources and how to use events on mouse clicking the button? (please give the most simple example...)

Thanks
Post 27 Apr 2004, 20:37
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
ozzy, download the fasmw gui package - theres an excellent example in there:

Code:

; DialogBox example

format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

ID_OK              = 101
ID_CANCEL      = 102
ID_CAPTION     = 201
ID_MESSAGE     = 202
ID_ICONERROR           = 301
ID_ICONINFORMATION = 302
ID_ICONQUESTION    = 303
ID_ICONWARNING         = 304
ID_TOPMOST     = 401

section '.data' data readable writeable

  flags dd ?
  caption rb 40h
  message rb 100h

section '.code' code readable executable

  start:

    invoke  GetModuleHandle,0
   invoke  DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
     or      eax,eax
     jz      exit
        invoke  MessageBox,HWND_DESKTOP,message,caption,[flags]
  exit:
      invoke  ExitProcess,0

proc DialogProc,hwnddlg,msg,wparam,lparam
      push    ebx esi edi
 cmp     [msg],WM_INITDIALOG
 je      wminitdialog
        cmp     [msg],WM_COMMAND
    je      wmcommand
   cmp     [msg],WM_CLOSE
      je      wmclose
     xor     eax,eax
     jmp     finish
  wminitdialog:
       invoke  CheckRadioButton,[hwnddlg],ID_ICONERROR,ID_ICONWARNING,ID_ICONINFORMATION
   jmp     processed
  wmcommand:
       cmp     [wparam],BN_CLICKED shl 16 + ID_CANCEL
      je      wmclose
     cmp     [wparam],BN_CLICKED shl 16 + ID_OK
  jne     processed
   invoke  GetDlgItemText,[hwnddlg],ID_CAPTION,caption,40h
     invoke  GetDlgItemText,[hwnddlg],ID_MESSAGE,message,100h
    mov     [flags],MB_OK
       invoke  IsDlgButtonChecked,[hwnddlg],ID_ICONERROR
   cmp     eax,BST_CHECKED
     jne     iconerror_ok
        or      [flags],MB_ICONERROR
      iconerror_ok:
     invoke  IsDlgButtonChecked,[hwnddlg],ID_ICONINFORMATION
     cmp     eax,BST_CHECKED
     jne     iconinformation_ok
  or      [flags],MB_ICONINFORMATION
      iconinformation_ok:
 invoke  IsDlgButtonChecked,[hwnddlg],ID_ICONQUESTION
        cmp     eax,BST_CHECKED
     jne     iconquestion_ok
     or      [flags],MB_ICONQUESTION
      iconquestion_ok:
       invoke  IsDlgButtonChecked,[hwnddlg],ID_ICONWARNING
 cmp     eax,BST_CHECKED
     jne     iconwarning_ok
      or      [flags],MB_ICONWARNING
      iconwarning_ok:
 invoke  IsDlgButtonChecked,[hwnddlg],ID_TOPMOST
     cmp     eax,BST_CHECKED
     jne     topmost_ok
  or      [flags],MB_TOPMOST
      topmost_ok:
 invoke  EndDialog,[hwnddlg],1
       jmp     processed
  wmclose:
 invoke  EndDialog,[hwnddlg],0
  processed:
   mov     eax,1
  finish:
      pop     edi esi ebx
 return
endp

section '.idata' import data readable writeable

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

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

  import user,\
         DialogBoxParam,'DialogBoxParamA',\
       CheckRadioButton,'CheckRadioButton',\
    GetDlgItemText,'GetDlgItemTextA',\
       IsDlgButtonChecked,'IsDlgButtonChecked',\
        MessageBox,'MessageBoxA',\
       EndDialog,'EndDialog'

section '.rsrc' resource data readable

  directory RT_DIALOG,dialogs

  resource dialogs,\
     37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration

  dialog demonstration,'Create message box',70,70,190,175,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
    dialogitem 'STATIC','&Caption:',-1,10,10,70,8,WS_VISIBLE
    dialogitem 'EDIT','',ID_CAPTION,10,20,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP
    dialogitem 'STATIC','&Message:',-1,10,40,70,8,WS_VISIBLE
    dialogitem 'EDIT','',ID_MESSAGE,10,50,170,13,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL
    dialogitem 'BUTTON','&Icon',-1,10,70,80,70,WS_VISIBLE+BS_GROUPBOX
    dialogitem 'BUTTON','&Error',ID_ICONERROR,20,82,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON+WS_TABSTOP+WS_GROUP
    dialogitem 'BUTTON','I&nformation',ID_ICONINFORMATION,20,95,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON
    dialogitem 'BUTTON','&Question',ID_ICONQUESTION,20,108,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON
    dialogitem 'BUTTON','&Warning',ID_ICONWARNING,20,121,60,13,WS_VISIBLE+BS_AUTORADIOBUTTON
    dialogitem 'BUTTON','&Style',-1,100,70,80,70,WS_VISIBLE+BS_GROUPBOX
    dialogitem 'BUTTON','&Top most',ID_TOPMOST,110,82,60,13,WS_VISIBLE+WS_TABSTOP+BS_AUTOCHECKBOX
    dialogitem 'BUTTON','OK',ID_OK,85,150,45,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
    dialogitem 'BUTTON','C&ancel',ID_CANCEL,135,150,45,15,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
  enddialog
    
Post 28 Apr 2004, 04:03
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
I have Fasmw, but this example looks too much confusing to me, I can't understand the ".idata" part and the ".rsrc" part too.... Sad
Post 28 Apr 2004, 23:18
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
just sections that organize the code in memory. 'idata' is api imports your program will use. just like in visual basic you would do

Code:
Private Declare Function FindWindow lib "user32" Alias "FindWindowA" (szclass as string, szcaption as string") as long
    


you do the same in fasm; otherwise windows will have no idea what you mean when calling the api function. the '.rsrc' section is where you defines your resources, like menus and dialogs. fasm has macros to do this in that syntax used in the code, or optionally you can use a resource compiler and create a .res file. again an example of using an external res file is here:

http://board.flatassembler.net/topic.php?t=1399&highlight=resource+file
Post 29 Apr 2004, 03:46
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
But where can I download a resource compiler, and could you post a complete and simple example of how to display a dialog with a button on it and how to handle the clicks on the button?

Thanks
Post 29 Apr 2004, 19:28
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
most good resource compilers cost money, like http://www.sicomponents.com/rbldr.html there are some freeware ones out there, youd have to search around.

that dialog example may seem a bit confusing, but it does exactly what youre describing. it creates a dialog with some radio/option buttons, static labels, text boxes, and command buttons (yes i come from a vb background Smile )

the example creates a msgbox depending on the options you select, and the text/caption you write.

the code begins by calling DialogBoxParam, which loads the dialog created in the '.rsrc' section. messages sent by windows (mouse clicks, keystrokes, etc) are sent to the DialogProc procedure. the procedure checks to see which message is sent, and performs an action accordingly. when a button is clicked, windows sends a WM_COMMAND message to the DialogProc procedure, which then checks to see which of the 2 buttons was pressed. if cancel was pressed, the program exits. if ok was pressed the program then determines which radio button was pressed, grabs the text from the 2 edit fields, and creates the message box.
Post 01 May 2004, 04:54
View user's profile Send private message Reply with quote
coconut



Joined: 02 Apr 2004
Posts: 326
Location: usa
coconut
ozzy check out http://board.flatassembler.net/topic.php?t=1521 this example, it uses a dialog and handles some messages
Post 02 May 2004, 21:50
View user's profile Send private message 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 YouTube, Twitter.

Website powered by rwasa.