| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 956 人关注过本帖
标题:win32汇编加载菜单出现问题求解释
取消只看楼主 加入收藏
yu305053463
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-10-11
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
win32汇编加载菜单出现问题求解释
.386
            .model  flat,stdcall
              option  casemap:none
include        windows.inc
include           user32.inc
include        kernel32.inc
include        gdi32.inc
includelib     user32.lib
includelib     kernel32.lib
includelib     gdi32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>图标定义>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
     ICO_MAIN           equ     1000h        ;图标
     IDM_MAIN            equ     2000h        ;菜单
     IDA_MAIN            equ      2000h        ;加速键
     IDM_OPEN         equ     4101h
     IDM_OPTION         equ     4102h
     IDM_EXIT         equ     4103h
     IDM_SETFONT         equ     4201h
     IDM_SETCOLOR     equ     4202h
     IDM_INACT         equ     4203h
     IDM_GRAY         equ     4204h
     IDM_BIG             equ     4205h
     IDM_SMALL         equ     4206h
     IDM_LIST         equ     4207h
     IDM_DETAIL         equ     4208h
     IDM_TOOLBAR         equ     4209h
     IDM_TOOLBARTEXT     equ     4210h
     IDM_INPUTBAR     equ     4211h
     IDM_STATUSBAR     equ     4212h
     IDM_HELP         equ     4301h
     IDM_ABOUT         equ     4302h
;>>>>>>>>>>>>>>>>>>>>>>代码段>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
        .data?
    hInstance      dd  ?
    hWinMain       dd  ?
    hMenu           dd  ?
    hSubMenu       dd  ?
        .const
    szCaptionMain  db    'Menu',0
    szClassName    db    'Menu Example',0
    szMenuHelp     db    '帮助主题(&H)',0
    szMenuAbout       db     '关于本程序(&A)',0
    szCaption      db    '菜单选项',0
    szFormat       db    '您选择了菜单:%08x',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        .code
    _DisplayMenuItem  proc   _dwCommandID
                      LOCAL  @szBuffer[256]:byte
                pushad
                invoke    wsprintf,addr @szBuffer,addr szFormat,_dwCommandID
                invoke    MessageBox,hWinMain,addr @szBuffer,\
                        offset  szCaption,MB_OK
                popad
                ret
        _DisplayMenuItem endp
    _Quit        proc
        
                invoke    DestroyWindow,hWinMain
                invoke  PostQuitMessage,NULL
               
        ret

    _Quit endp
    _ProcWinMain proc     uses  ebx edi esi,hWnd,uMsg,wParam,lParam
                 LOCAL    @stPos:POINT
                 LOCAL    @hSysMenu
                 mov      eax,uMsg
                .if  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_HELP,offset szMenuHelp                    
                    invoke  AppendMenu,@hSysMenu,0,IDM_ABOUT,offset szMenuAbout
;>>>>>>>>>>>>>>>>>>>>>>>>>>处理菜单及加速键消息>>>>>>>>>>>>>>>>>>>>>>>>>
                .elseif eax==WM_COMMAND
                    invoke    _DisplayMenuItem,wParam        
                    ;在处理WM_COMMAND消息前
                    ;将wParam的值通过一个对话框显示出来,
                    ;读者可以与资源脚本文件中的定义的名利ID值对比一下
                    ;在正常使用的程序中可以去掉这一句
                    mov        eax,wParam
                    movzx    eax,ax
                    .if    eax==IDM_EXIT
                        call    _Quit
                    .elseif eax>=IDM_TOOLBAR && eax<=IDM_STATUSBAR                        
                             mov        ebx,eax
                            invoke    GetMenuState,hMenu,ebx,MF_BYCOMMAND
                            .if    eax==MF_CHECKED
                                mov        eax,MF_UNCHECKED
                            .else
                                mov        eax,MF_CHECKED
                            .endif   
                            invoke    CheckMenuItem,hMenu,ebx,eax
                    .elseif    eax>=IDM_BIG && eax<=IDM_DETAIL
                            invoke  CheckMenuRadioItem,hMenu,IDM_BIG,\
                            IDM_DETAIL,eax,MF_BYCOMMAND
                    .endif
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>处理系统菜单消息>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
                .elseif eax == WM_SYSCOMMAND
                            mov        eax,wParam
                            movzx    eax,ax            ;将指令扩展到32位
                    .if        eax == IDM_HELP||eax == IDM_ABOUT
                    
                            invoke    _DisplayMenuItem,wParam
                    .else    invoke    DefWindowProc,hWnd,uMsg,wParam,lParam
                            ret
                    .endif        
                    
                    
;>>>>>>>>>>>>>>>>>>>>>>>>单击鼠标右键时弹出一个POPUP菜单>>>>>>>>>>>>>>>>>
                .elseif    eax == WM_RBUTTONDOWN
                            invoke  GetCursorPos,addr @stPos
                            invoke    TrackPopupMenu,hSubMenu,TPM_LEFTALIGN,\
                                    @stPos.x,@stPos.y,NULL,hWnd,NULL
                .elseif eax == WM_CLOSE
                            call    _Quit
                .elseif
                            invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
                            ret
                .endif
               
                xor        eax,eax
                ret
    _ProcWinMain endp
                 
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    _WinMain   proc
        
                LOCAL   @stWndClass:WNDCLASSEX
                LOCAL   @stMsg:MSG
                LOCAL   @hAccelerator
                invoke  GetModuleHandle,NULL
                mov     hInstance,eax
                invoke  LoadMenu,hInstance,IDM_MAIN
                mov        hMenu,eax
                invoke  LoadAccelerators,hInstance,IDA_MAIN
                mov        @hAccelerator,eax  
                invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
                invoke LoadIcon,hInstance,ICO_MAIN
                ;invoke LoadCursor,0,IDC_ARROW
                mov    @stWndClass.hIcon,eax
                mov       @stWndClass.hIconSm,eax
                push   hInstance
                pop       @stWndClass.hInstance
                mov    @stWndClass.cbSize,sizeof WNDCLASSEX
                mov    @stWndClass.style,CS_VREDRAW or CS_HREDRAW
                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_OVERLAPPEDWINDOW,100,100,600,400,\
                                    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
源代码如上,代码除了个别变量的名字,其余均照罗云彬书上来的,但是一直出现
源窗口.asm(84) : error A2008: syntax error : invoke 报错的那句我已经在上面加红标注了
    我尝试把那句话的.else 去掉程序正常运行,但是仅仅是显示窗口,没有任何菜单,也无法做最大化等操作,我常识将上级的if语句去掉,程序正常运行,但是就是一个可最大最小化的对话框,没有任何菜单!

这个问题我试着做了很多尝试,花了一整天时间,均未奏效,请大神指点迷津,万分感谢。倘若小弟错误很菜,请原谅,小弟初学者,也尝试了很多种方法,不敢轻易提问!谢谢各路大神
搜索更多相关主题的帖子: option 
2013-10-11 17:53
yu305053463
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-10-11
收藏
得分:0 
  等待大神降临!多谢 多谢
2013-10-11 17:54
yu305053463
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-10-11
收藏
得分:0 
回复 3楼 Explorerlxz
谢谢,确实这个问题。但是我从各个地方下手,但是真不知道原来ELSE 需要换行。以前其他的高级语言我是习惯性换号,这个由于初学,我就对着书本抄的。多谢 多谢!!
2013-10-11 19:43
yu305053463
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-10-11
收藏
得分:0 
回复 4楼 Explorerlxz
我今天下载了一份,有些代码是没有的!不过基本都齐了。谢谢你的回答。我会继续学习的
2013-10-11 19:44
yu305053463
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-10-11
收藏
得分:0 
回复 3楼 Explorerlxz
程序是没有报错了,只是运行的结果不像书中的图片,有菜单栏。只要运行的仍然是一个简单的窗口,也无右键功能!
2013-10-11 19:47
yu305053463
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2013-10-11
收藏
得分:0 
回复 8楼 Explorerlxz
万分感谢!我有点浮躁,谢谢你的一针见血!我会认真看的
2013-10-11 19:59
快速回复:win32汇编加载菜单出现问题求解释
数据加载中...
 
   



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

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