首页
社区
课程
招聘
[求助]win32汇编新手小问题
2012-8-6 17:54 3779

[求助]win32汇编新手小问题

2012-8-6 17:54
3779
开始看罗云彬的《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
----------------------------------------------------------------------------------------------------------------------------------------------
.const
szWndClass db 'Win32 Window',0
szCaptionText db 'Made by lilin',0
szText        db         'Hello world!',0

.data?
hInstance        dd        ?
hWinMain        dd         ?
-----------------------------------------------------------------------------------------------------------------------------------------------
.code
_WinMainProc        proc        uses ebx esi edi,hWnd,uMsg,wParam,lParam
        local @sthDc
        local @stPs:PAINTSTRUCT
        local @stRect:RECT
        local @stCaptionText:DWORD
        local @stText:DWORD
       
        mov eax,uMsg
       
        .if eax==WM_CLOSE
                invoke DestroyWindow,hWinMain
                invoke PostQuitMessage,NULL
        ;.elseif eax==WM_CHAR
               
        .elseif eax==WM_LBUTTONDOWN
                invoke MessageBox,hWinMain,addr @stText,addr @stCaptionText,MB_OK
        .elseif        eax==WM_PAINT
                invoke BeginPaint,hWnd,addr @stPs
                mov @sthDc,eax
               
                invoke GetClientRect,hWnd,addr @stRect
                invoke DrawText,@sthDc,addr szText,-1,addr @stRect,DT_SINGLELINE or DT_CENTER or DT_VCENTER
                invoke EndPaint,hWnd,addr @stPs
        .else
                invoke DefWindowProc,hWnd,uMsg,wParam,lParam
                ret
        .endif
        xor eax,eax
        ret
       
_WinMainProc        endp
------------------------------------------------------------------------------------------------------------------------------------------
_WinMain         proc
        local        @stWndClass:WNDCLASSEX
        local        @stMsg:MSG
       
        invoke GetModuleHandle,0
        mov hInstance,eax
       
        invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
       
        push hInstance
        pop @stWndClass.hInstance
       
        invoke LoadCursor,0,IDC_ARROW
        mov @stWndClass.hCursor,eax
       
        invoke LoadIcon,0,IDI_APPLICATION
        mov @stWndClass.hIcon,eax
       
        mov @stWndClass.cbSize,sizeof WNDCLASSEX
        mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
        mov @stWndClass.hbrBackground,COLOR_WINDOW+1
        mov @stWndClass.lpszClassName,offset szWndClass
        mov @stWndClass.lpfnWndProc,offset _WinMainProc
        invoke RegisterClass,addr @stWndClass
       
        invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
                                                                                        offset szWndClass,\
                                                                                        offset szCaptionText,\
                                                                                        WS_OVERLAPPEDWINDOW,\
                                                                                        100,100,400,600,\
                                                                                        0,0,hInstance,0
        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
------------------------------------------------------------------------------------------------------------------------------------------
start:
        invoke _WinMain
        invoke ExitProcess,0
end start

阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

收藏
点赞0
打赏
分享
最新回复 (5)
雪    币: 9
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
天涯路 2012-8-6 20:43
2
0
是我没写注释么?还是什么原因啊,大家都不发言的?
雪    币: 31
活跃值: (43)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
邋遢鬼 2012-8-6 21:13
3
0
_WinMainProc  proc  uses ebx esi edi,hWnd,uMsg,wParam,lParam
我记得是这样的:
_WinMainProc  proc  uses ebx esi edi hWnd,uMsg,wParam,lParam
其它倒没发现什么问题。
雪    币: 60
活跃值: (25)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
fy风云 1 2012-8-6 21:59
4
0
invoke RegisterClass, addr @stWndClass改成invoke RegisterClassEx,addr @stWndClass, 另外invoke MessageBox,hWinMain,addr @stText,addr @stCaptionText,MB_OK其中@stText是szText吧,其他的没看,刚开始看也没看出来,用od调了下,发现showwindow的窗体句柄竟然为NULL...一直往上看,终于找打了。。。
雪    币: 78
活跃值: (85)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
baixinye 1 2012-8-6 22:16
5
0
大哥~你用WNDCLASSEX结构,却是用RegisterClass函数
雪    币: 9
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
天涯路 2012-8-6 22:28
6
0
多谢了,原来是这样啊。因为在window.inc 中好像没有关于CreateWindow的声明,只好改为用WndClassEx,没想到RegisterClass没改好!呵呵!
游客
登录 | 注册 方可回帖
返回