最近学习win32汇编,遇到问题了,uu们帮忙看下。
当我打开程序最小化后,右键单击图标关闭程序,最小化图标不消失。让鼠标光标经过一下托盘图标,图标才消失。想了好久,也上网查了,不知道为什么?本人菜鸟,希望高手帮忙。谢谢。
“下面是tp.asm”源码:
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include gdi32.inc
includelib gdi32.lib
include shell32.inc
includelib shell32.lib
INCLUDE rsrc.inc
WM_SHELLNOTIFY equ WM_USER+5
.data?
hInstance dd ?
hWinMain dd ?
hMenu dd ?
popmenu dd ?
.const
open db '打开' ,0
exit db '退出',0
about db '关于',0
szClassName db 'myclass',0
szCaptionMain db 'shell_notifyicon',0
szText db 'Hello shell_nontifyicon',0
.code
_Quit proc
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
ret
_Quit endp
_WinMain proc
local @stWndClass:WNDCLASSEX
local @stMsg:MSG
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke LoadMenu,hInstance,IDM_MAIN
mov hMenu,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
invoke LoadIcon,hInstance,ICO_MAIN
mov @stWndClass.hIcon,eax
mov @stWndClass.hIconSm,eax
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof WNDCLASSEX
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW+1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,\
offset szCaptionMain,\
WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,\
100,100,400,300,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 TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret
_WinMain endp
_ProcWinMain proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
LOCAL @pt:POINT
LOCAL @stNote:NOTIFYICONDATA
MOV eax,uMsg
.if eax==WM_SIZE
.IF wParam==SIZE_MINIMIZED
mov @stNote.cbSize,sizeof NOTIFYICONDATA
push hWnd
pop @stNote.hwnd
mov @stNote.uID,ICO_MAIN
mov @stNote.uFlags,NIF_ICON OR NIF_MESSAGE OR NIF_TIP
mov @stNote.uCallbackMessage,WM_SHELLNOTIFY
invoke LoadIcon,hInstance,ICO_MAIN
mov @stNote.hIcon,eax
invoke lstrcpy,addr @stNote.szTip,addr szText
invoke ShowWindow,hWnd,SW_HIDE
invoke Shell_NotifyIcon,NIM_ADD,addr @stNote
.endif
.elseif eax==WM_CLOSE
invoke Shell_NotifyIcon,NIM_DELETE,addr @stNote
call _Quit
.elseif eax==WM_CREATE
invoke CreatePopupMenu
mov popmenu,eax
invoke AppendMenu,popmenu,MF_STRING,IDM_OPEN,addr open
invoke AppendMenu,popmenu,MF_STRING,IDM_ABOUT,addr about
invoke AppendMenu,popmenu,MF_STRING,IDM_EXIT,addr exit
.elseif eax==WM_SHELLNOTIFY
.if wParam==ICO_MAIN
.if lParam==WM_RBUTTONDOWN
invoke GetCursorPos,addr @pt
invoke SetForegroundWindow,hWnd
invoke TrackPopupMenu,popmenu,TPM_LEFTALIGN,@pt.x,@pt.y,NULL,hWnd,NULL
invoke PostMessage,hWnd,WM_NULL,0,0
.elseif lParam==WM_LBUTTONDBLCLK
invoke SendMessage,hWnd,WM_COMMAND,IDM_OPEN,0
invoke Shell_NotifyIcon,NIM_DELETE,addr @stNote
.endif
.endif
.elseif eax==WM_COMMAND
mov eax,wParam
movzx eax,ax
.if eax==IDM_EXIT
invoke Shell_NotifyIcon,NIM_DELETE,addr @stNote
call _Quit
.elseif eax==IDM_ABOUT
invoke MessageBox,hWinMain,offset szText,offset szCaptionMain,MB_OK OR MB_ICONINFORMATION
.elseif eax==IDM_OPEN
invoke Shell_NotifyIcon,NIM_DELETE,addr @stNote
invoke ShowWindow,hWnd,SW_SHOWNORMAL
.endif
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
_ProcWinMain endp
start:
call _WinMain
invoke ExitProcess,NULL
end start