标题:最近学习win32汇编,遇到问题了,uu们帮忙看下。
只看楼主
guokaile0529
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-10-3
结帖率:66.67%
已结贴  问题点数:0 回复次数:8 
最近学习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
搜索更多相关主题的帖子: 学习 option model 
2011-10-03 16:14
guokaile0529
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-10-3
得分:0 
高手帮帮忙啊。好吧,附上我的工程文件。
tp.rar (48.73 KB)

高手帮我看下。跪谢啊!
2011-10-03 18:36
shweei
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2011-7-27
得分:10 
必须删除才行
invoke    Shell_NotifyIcon,NIM_DELETE,addr tuopan_jg

结构中还是用建立时候的参数就行

[ 本帖最后由 shweei 于 2011-10-3 20:08 编辑 ]
2011-10-03 20:05
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
得分:10 
invoke DestroyMenu,popmenu
invoke Shell_NotifyIcon,NIM_DELETE,addr @stNote

改成这样就好了 你要删除创建的那个目录

简单么 不简单 我这里 XP sp3 弹优盘的那个图标就不能自己消失 是微软写Shell的人出错了 可能罢。。
2011-10-03 20:23
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
得分:0 
顺便 发工程很好 反正我能编译看看怎么改 方便 要是只发代码

还有 你代码风格不行啊。。。。
2011-10-03 20:24
guokaile0529
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-10-3
得分:0 
回复 3楼 shweei
大虾,能说明白点不?
是这样写吗?
invoke    Shell_NotifyIcon,NIM_DELETE,addr @stNote
我就是这样删除的,可是不行啊。

2011-10-03 21:09
guokaile0529
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-10-3
得分:0 
回复 5楼 zklhp
版猪,虽然我还没有调试出来,但还是谢谢你。
2011-10-03 21:28
guokaile0529
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-10-3
得分:0 
多谢高手帮忙,程序已经改好了。。。见下面红色字体。
.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    @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

    MOV eax,uMsg
    .if eax==WM_SIZE
        .IF wParam==SIZE_MINIMIZED
原先红色代码是在这里,改到上面之后就可以了。
                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

[ 本帖最后由 guokaile0529 于 2011-10-4 10:27 编辑 ]
2011-10-04 10:26
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
得分:0 
我的改法也不对啊 呵呵 不过能解决就好了
2011-10-04 22:08



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-351522-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.152270 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved