Создание меню без файла описания ресурсов на основе функции LoadMenuIndirect
Рефераты >> Программирование и компьютеры >> Создание меню без файла описания ресурсов на основе функции LoadMenuIndirect

r" >Программа.

p386

jumps

model flat,STDCALL

include win32.inc ;файл описания структур и констант

L equ <LARGE>

IDM_QUIT equ 100

IDM_ABOUT equ 101

MF_ENABLED equ 0

MF_POPUP equ 1h

;Функции Win32 API, используемые программой

extrn BeginPaint:PROC

extrn CreateWindowExA:PROC

extrn DefWindowProcA:PROC

extrn DispatchMessageA:PROC

extrn EndPaint:PROC

extrn ExitProcess:PROC

extrn GetMessageA:PROC

extrn GetModuleHandleA:PROC

extrn LoadCursorA:PROC

extrn LoadIconA:PROC

extrn RegisterClassA:PROC

extrn PostQuitMessage:PROC

extrn ShowWindow:PROC

extrn TranslateMessage:PROC

extrn UpdateWindow:PROC

extrn LoadMenuIndirectA:PROC

extrn MessageBoxA:PROC

.data

newhwnd dd 0

lppaint PAINTSTRUCT <?>

msg MSGSTRUCT <?>

wc WNDCLASS <?>

hInst dd 0

fl dw 0

szTitleName db 'Это наше окно',0

szClassName db 'ASMCLASS32',0

szHello db 'Привет!',0

szAppName db 'Сообщение',0

hMenu dd 0

align 4

MenuTemplate dw 1,0 ;Заголовок меню. 1 - признак

;структуры для функции Windows95

align 4

dd 0 ;тип пункта

dd 0,MF_ENABLED,0;IDM_ABOUT ;

dw 81h

dw '&','M','e','n','u','1',0

align 4

dd 0,0,0,IDM_QUIT

dw 0

dw 'E','&','x','i','t',0,0

align 4

dd 0,0,IDM_ABOUT

dw 0

dw '&','Q','u','i','t','1',0

align 4

dd 0,0,0;IDM_QUIT

dw 81h ;Признак вспл. меню

dw 'Q','u','i','t','2',0,0,0

align 4

dd 0,0,IDM_ABOUT

dw 0

dw 'Q','u','i','t','3',0,0

align 4

dd 0,0,IDM_QUIT

dw 80h

dw 'E','&','x','i','t',0,0

.code

start:

push L 0

call GetModuleHandleA

mov [hInst], eax

;инициализация структуры WndClass

mov [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS

mov [wc.clsLpfnWndProc], offset WndProc

mov [wc.clsCbClsExtra], 0

mov [wc.clsCbWndExtra], 0

mov eax, [hInst]

mov [wc.clsHInstance], eax

push L IDI_APPLICATION

push L 0

call LoadIconA

mov [wc.clsHIcon], eax

push L IDC_ARROW

push L 0

call LoadCursorA

mov [wc.clsHCursor], eax

mov [wc.clsHbrBackground], COLOR_WINDOW + 1

mov dword ptr [wc.clsLpszMenuName],0

mov dword ptr [wc.clsLpszClassName], offset szClassName

push offset wc

call RegisterClassA

push offset MenuTemplate

call LoadMenuIndirectA

mov [hMenu],eax

push L 0 ; lpParam

push [hInst] ; hInstance

push [hMenu] ; menu

push L 0 ; parent hwnd

push L CW_USEDEFAULT ; height

push L CW_USEDEFAULT ; width

push L CW_USEDEFAULT ; y

push L CW_USEDEFAULT ; x

push L WS_OVERLAPPEDWINDOW ; Style

push offset szTitleName ; Title string

push offset szClassName ; Class name

push L 0 ; extra style

call CreateWindowExA

mov [newhwnd], eax

push L SW_SHOWNORMAL

push [newhwnd]

call ShowWindow

push [newhwnd]

call UpdateWindow

msg_loop:

push L 0

push L 0

push L 0

push offset msg

call GetMessageA

cmp ax, 0

je end_loop

push offset msg

call TranslateMessage

push offset msg

call DispatchMessageA

jmp msg_loop

end_loop:

push [msg.msWPARAM]

call ExitProcess

; we never get to here

;----Оконная процедура----

WndProc proc uses ebx edi esi, hwnd:DWORD, wmsg:DWORD,\

wparam:DWORD, lparam:DWORD

LOCAL hDC:DWORD

cmp [wmsg], WM_DESTROY

je wmdestroy

cmp [wmsg], WM_SIZE

je wmsize

cmp [wmsg], WM_CREATE

je wmcreate

cmp [wmsg],WM_PAINT

je wmpaint

;**************************************

cmp [wmsg],WM_COMMAND

je wmcommand

;**************************************

jmp defwndproc

wmcommand:

mov eax,lparam

cmp ax,0

jne m1

mov eax,wparam

cmp ax,IDM_ABOUT

jne m2

call MessageBoxA,0,offset szHello,offset szAppName,MB_OK

jmp m1

m2: cmp ax,IDM_QUIT

jne m1

push 0

call PostQuitMessage

m1: mov eax,0

jmp finish

wmcreate:

mov eax, 0

jmp finish

defwndproc:

push [lparam]

push [wparam]

push [wmsg]

push [hwnd]

call DefWindowProcA

jmp finish

wmdestroy:

push L 0

call PostQuitMessage

mov eax, 0

jmp finish

wmsize:

mov eax, 0

jmp finish

wmpaint:

push offset lppaint

push [hwnd]

call BeginPaint

mov [hDC],eax

push offset lppaint

push [hwnd]

call EndPaint

mov eax,0

jmp finish

finish:

ret

WndProc endp

;---------------------------------

public WndProc

end start


Страница: