程序无法显示图标,求助!
本帖最后由 H云淡风清 于 2014-8-31 12:10 编辑win32汇编写的一个程序,在程序里注册窗口类时设置了图标,在外面文件的图标可以显示,但是程序左上角无法显示图标,求大神看看啥问题。
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
IDR_MAIN equ 1000h ;菜单
ICO_MAIN equ 2000h ;图标
IDM_XINJIAN equ 3000h ;菜单项“新建”
IDM_DAKAI equ 3001h ;菜单项“打开”
IDM_GUANBI equ 3002h ;菜单项“关闭”
IDM_BAOCUN equ 3003h ;菜单项“保存”
IDM_TUICHU equ 3004h ;菜单项“退出”
IDM_GUANYU equ 3005h ;菜单项“关于”
.data?
hInstance dd ?
hWinMain dd ?
hEmnu dd ? ;菜单句柄
hSubEmnu dd ? ;右键菜单句柄
szHC db 32 dup(?) ;缓冲区
.const
szCaption db 'Message',0
szWndClass db 'MyClass',0
szText db '暂不支持 “%s”呢',0
szText1 db '新建',0
szText2 db '打开',0
szText3 db '关闭',0
szText4 db '保存',0
szText5 db '这个可以有',0
szHelpText db 'BY: H.Z.J E-mail: hInstance@126.com ',0
.code
_procWinMain proc uses ebx esi edi,hWnd,uMsg,wParam,lParam ;窗口过程
local @stPos : POINT
mov eax,uMsg
.if eax == WM_CLOSE
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
.elseif eax == WM_CREATE
invoke GetSubMenu,hEmnu,0
mov hSubEmnu,eax
.elseif eax == WM_COMMAND ;处理菜单
mov eax,wParam
movzx eax,ax
push eax
.if eax >= IDM_XINJIAN && eax <= IDM_BAOCUN ;菜单项被选择时添加标记
mov ebx,eax
invoke GetMenuState,hEmnu,ebx,MF_BYCOMMAND
.if eax == MF_CHECKED
mov eax,MF_UNCHECKED
.else
mov eax,MF_CHECKED
.endif
invoke CheckMenuItem,hEmnu,ebx,eax
.endif
pop eax
;处理各个菜单项
.if eax == IDM_XINJIAN
invoke wsprintf,addr szHC,addr szText,addr szText1
invoke MessageBox,NULL,offset szHC,offset szCaption,MB_OK
.elseif eax == IDM_DAKAI
invoke wsprintf,addr szHC,addr szText,addr szText2
invoke MessageBox,NULL,offset szHC,offset szCaption,MB_OK
.elseif eax == IDM_GUANBI
invoke wsprintf,addr szHC,addr szText,addr szText3
invoke MessageBox,NULL,offset szHC,offset szCaption,MB_OK
.elseif eax == IDM_BAOCUN
invoke wsprintf,addr szHC,addr szText,addr szText4
invoke MessageBox,NULL,offset szHC,offset szCaption,MB_OK
.elseif eax == IDM_TUICHU
invoke MessageBox,NULL,offset szText5,offset szCaption,MB_OK
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
.elseif eax == IDM_GUANYU
invoke MessageBox,NULL,offset szHelpText,offset szCaption,MB_OK
.endif
.elseif eax == WM_RBUTTONDOWN ;右键弹出菜单
invoke GetCursorPos,addr @stPos
invoke TrackPopupMenu,hSubEmnu,TPM_LEFTALIGN,@stPos.x,@stPos.y,NULL,hWnd,NULL
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
_procWinMain endp
_WinMain proc
local @stClass : WNDCLASSEX
local @stuMsg : MSG
;获取窗口句柄
invoke GetModuleHandle,NULL
mov hInstance,eax
;获取菜单句柄
invoke LoadMenu,hInstance,IDR_MAIN
mov hEmnu,eax
invoke RtlZeroMemory,addr @stClass,sizeof @stClass
;注册窗口类
invoke LoadCursor,0,IDC_ARROW
mov @stClass.hCursor,eax
invoke LoadIcon,0,ICO_MAIN
mov @stClass.hIcon,eax
mov @stClass.hIconSm,eax
push hInstance
pop @stClass.hInstance
mov @stClass.cbSize,sizeof WNDCLASSEX
mov @stClass.style,CS_VREDRAW or CS_HREDRAW
mov @stClass.lpfnWndProc,offset _procWinMain
mov @stClass.hbrBackground,COLOR_WINDOW + 1
mov @stClass.lpszClassName,offset szWndClass
invoke RegisterClassEx,addr @stClass
;建立窗口
invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,offset szWndClass,offset szCaption,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,600,400,NULL,hEmnu,hInstance,NULL
mov hWinMain,eax
;显示窗口
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
;消息循环
.while TRUE
invoke GetMessage,addr @stuMsg,NULL,NULL,0
.break .if eax == 0
invoke TranslateMessage,addr @stuMsg
invoke DispatchMessage,addr @stuMsg
.endw
ret
_WinMain endp
start:
call _WinMain
invoke ExitProcess,NULL
end start 强烈支持楼主ing…… 第 119 行“invoke LoadIcon,0,ICO_MAIN”,应该改成“invoke LoadIcon,hInstance,ICO_MAIN”
页:
[1]