我想问一下在下面的程序中为什么
invoke TrackPopupMenu,
hSubMenu ,TPM_LEFTALIGN,@stPos.x,@stPos.y,NULL,hWnd,NULL
和
invoke GetSubMenu,hMenu,1
mov
hSubMenu ,eax
这两句中的hSubMenu句柄要设为全局变量呢, 程序中红色部分,而不能用局部变量来替代呢,我感觉他只在子程序中运行啊.
.386
.Model Flat,StdCall
Option CaseMap:None
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;include
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include gdi32.inc
includelib gdi32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;equ等值定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
IDI_MYICON equ 4144d
IDA_MAIN equ 102d
IDR_MENUDEMO equ 101d
IDM_FILE_NEW equ 40002d
IDM_FILE_SAVE equ 40003d
IDM_FILE_SAVE_AS equ 40004d
IDM_APP_EXIT equ 40005d
IDM_EDIT_UNDO equ 40006d
IDM_EDIT_CUT equ 40007d
IDM_EDIT_COPY equ 40008d
IDM_EDIT_PASTE equ 40009d
IDM_EDIT_CLEAR equ 40010d
IDM_EDIT_CLEA equ 40011d
IDM_BKGND_WHITE equ 40012d
IDM_BKGND_LTGRAY equ 40013d
IDM_BKGND_GRAY equ 40014d
IDM_BKGND_DKGRAY equ 40015d
IDM_BKGND_BLACK equ 40016d
IDM_TIMER_START equ 40017d
IDM_TIMER_STOP equ 40018d
IDM_APP_HELP equ 40019d
IDM_APP_ABOUT equ 40020d
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;.data?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance dd ?
hWinMain dd ?
hMenu dd ?
hSubMenu dd ?
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;.data
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.const
szClassName db 'MyClass',0
szText db 'Win32 Assembly, Simple and powerful !',0
szCaptionMain db 'My first Window !',0
szFormat db '您选择了菜单命令:%08x',0
szMsgCaption db 'MENU ID',0
szMenuHelp db 'Help!',0
szMenuAbout db 'Menu about!',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
_DisplayMenuItem Proc _dwCommandID
local @szBuffer[256]:byte
pushad
invoke wsprintf,addr @szBuffer,addr szFormat,_dwCommandID
invoke MessageBox,hWinMain,addr @szBuffer,addr szMsgCaption,MB_OK
popad
ret
_DisplayMenuItem endp
;********************************************************************
_ProcWinMain proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
local @stPs:PAINTSTRUCT
local @stRect:RECT
local @hDc
local @hSysMenu
local @stPos:POINT
; local @hSubMenu
mov eax,uMsg
;********************************************************************
.if eax == WM_PAINT
invoke BeginPaint,hWnd,addr @stPs
mov @hDc,eax
invoke GetClientRect,hWnd,addr @stRect
invoke DrawText,@hDc,addr szText,-1,\
addr @stRect,\
DT_SINGLELINE or DT_CENTER or DT_VCENTER
invoke EndPaint,hWnd,addr @stPs
;********************************************************************
.elseif eax == WM_COMMAND
mov eax,wParam
movzx eax,ax
invoke _DisplayMenuItem,wParam
;********************************************************************
.elseif eax == WM_SYSCOMMAND
mov eax,wParam
movzx eax,ax
.if eax==IDM_APP_HELP || eax==IDM_APP_ABOUT
invoke _DisplayMenuItem,wParam
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
;********************************************************************
.elseif eax == WM_CLOSE
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
;********************************************************************
.elseif eax == WM_RBUTTONDOWN
invoke GetCursorPos,addr @stPos
invoke TrackPopupMenu,
hSubMenu ,TPM_LEFTALIGN,@stPos.x,@stPos.y,NULL,hWnd,NULL
;********************************************************************
.elseif eax == WM_CREATE
invoke GetSubMenu,hMenu,1
mov
hSubMenu ,eax
invoke GetSystemMenu,hWnd,FALSE
mov @hSysMenu,eax
invoke AppendMenu,@hSysMenu,MF_SEPARATOR,0,NULL
invoke AppendMenu,@hSysMenu,0,IDM_APP_HELP,offset szMenuHelp
invoke AppendMenu,@hSysMenu,0,IDM_APP_ABOUT,offset szMenuAbout
;********************************************************************
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
;********************************************************************
xor eax,eax
ret
_ProcWinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain proc
LOCAL @stWndClass:WNDCLASS
LOCAL @stMsg:MSG
local @hAccelerator
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;注册窗口类:
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
invoke LoadIcon,hInstance,IDI_MYICON
mov @stWndClass.hIcon,eax
; mov @stWndClass.cbSize,sizeof WNDCLASSEX
invoke LoadMenu,hInstance,IDR_MENUDEMO
mov hMenu,eax
invoke LoadAccelerators,hInstance,IDA_MAIN
mov @hAccelerator,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW+1
mov @stWndClass.lpszMenuName,NULL
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClass,addr @stWndClass
invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
offset szClassName,offset szCaptionMain,\
WS_OVERLAPPEDWINDOW,\
100,100,800,540,\
NULL,hMenu,hInstance,NULL
mov hWinMain,eax
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax==0
invoke TranslateAccelerator,hWinMain,@hAccelerator,addr @stMsg
.if eax==0
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endif
.endw
ret
_WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain
invoke ExitProcess,NULL
end start
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;.data
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课