flat assembler
Message board for the users of flat assembler.

Index > Windows > Saturday morning confusion...

Author
Thread Post new topic Reply to topic
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
Anyone have any ideas on how to add the menu items?

Quote:
handle: ;Sneaky or what?
use32
format PE gui 4.0

include '%fasminc%\win32ax.inc'

entry main

;CONSTANTS

IDC_EDIT equ 3000
IDC_BUTTON equ 3001
IDC_EXIT equ 3002
IDR_MENU1 equ 3003
IDM_GETTEXT equ 32000
IDM_CLEAR equ 32001
IDM_EXIT equ 32002

;NUMERICALS
;NOTE: Handle was removed and "The trick" is used
buffer du 512 dup (0)

;OTHER

DlgName du "MyDialog", 0
AppName du "The Dialog box", 0
TestString du "Rawr", 0


section '.code' readable writeable executable

main:

invoke DialogBoxParam, handle, 31, NULL,\ ;Handle to Parent
DlgProc, NULL ;Lparam value to pass with the init message.

invoke ExitProcess, 0 ;Kill program

proc DlgProc, hwnd, msg, wparam, lparam
;=====MAIN LADDER=====
cmp [msg], WM_INITDIALOG
je INITDIALOG
cmp [msg], WM_CLOSE
je CLOSE
cmp [msg], WM_COMMAND
je COMMAND
mov eax, 0 ;Not sure what the true and false is for...
ret
INITDIALOG:
invoke GetDlgItem, [hwnd], IDC_EDIT
invoke SetFocus, eax
jmp KILL
CLOSE:
invoke SendMessage, [hwnd], WM_COMMAND, IDM_EXIT, 0
jmp KILL
COMMAND:
;=====COMMAND LADDER=====
mov eax, [wparam]
cmp [lparam], 0
jne BUTTONS
cmp ax, IDM_GETTEXT
je GETTEXT
cmp ax, IDM_CLEAR
je CLEAR
cmp ax, IDM_EXIT
je EXIT
jmp KILL ;shouldn't hit this
GETTEXT:
invoke GetDlgItemText, [hwnd], IDC_EDIT, buffer, 512
invoke MessageBox, NULL, buffer, AppName, MB_OK
jmp KILL
CLEAR:
invoke SetDlgItemText, [hwnd], IDC_EDIT, NULL
jmp KILL
EXIT:
invoke EndDialog, [hwnd], NULL
jmp KILL
BUTTONS:
mov edx, [wparam]
shr edx, 16
cmp dx, BN_CLICKED
jne KILL
cmp ax, IDC_BUTTON
je BUTTON
cmp ax, IDC_EXIT
je EXIT
jmp KILL ;shouldn't hit this
BUTTON:
invoke SetDlgItemText, [hwnd], IDC_EDIT, TestString
KILL:
mov eax, 1
ret
endp


section '.idata' data readable writeable import

library kernel, 'kernel32.dll',\
user, 'user32.dll'

import kernel, ExitProcess, 'ExitProcess'

import user, DialogBoxParam, 'DialogBoxParamW',\
GetDlgItem, 'GetDlgItem',\
SetFocus, 'SetFocus',\
SendMessage, 'SendMessageW',\
GetDlgItemText, 'GetDlgItemTextW',\
MessageBox, 'MessageBoxW',\
SetDlgItemText, 'SetDlgItemTextW',\
EndDialog, 'EndDialog'

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 'E&xit',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


Also, note my sneaky way of getting a handle to the program.

EDIT: Fixed, missing parameter in the macro for the dialog box. =) Though i wouldn't mind some input on my handle trick... lol
Post 28 Apr 2007, 15:50
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.