码迷,mamicode.com
首页 > Windows程序 > 详细

Windows下的窗口程序

时间:2015-10-18 19:55:52      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

再进一步、

 

.386
.model flat,stdcall
option casemap:none
include        Windows.inc
include        user32.inc
includelib    user32.lib
include        kernel32.inc
includelib    kernel32.lib


WinMain proto :DWORD ,:DWORD,:DWORD,:DWORD    ;WinMain 函数原型定义

.DATA
ClassName    db    "SimpleWinClass",0
AppName        db    "My First Window",0

.DATA?                            ;没有初始化的数据
hInstance    HINSTANCE    ?
CommandLine    LPSTR        ?            ;字符串指针变量

.CODE
start:
;-----------------------------------------------------------------------------------------------------------
;得到应用程序的句柄
invoke    GetModuleHandle,NULL
mov        hInstance,eax

;-----------------------------------------------------------------------------------------------------------
;得到命令行参数
invoke    GetCommandLine
mov        CommandLine,eax

;调用WinMain函数
invoke    WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
;-----------------------------------------------------------------------------------------------------------
;退出该应用程序

invoke    ExitProcess,eax


;-----------------------------------------------------------------------------------------------------------
WinMain    proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
;-----------------------------------------------------------------------------------------------------------
;注册窗口类
mov     wc.cbSize,SIZEOF WNDCLASSEX
mov        wc.style,CS_HREDRAW or CS_VREDRAW
mov        wc.lpfnWndProc,OFFSET    WndProc                ;指定窗口的回调函数
mov        wc.cbClsExtra,NULL
mov     wc.cbWndExtra,NULL
push    hInstance
pop        wc.hInstance                                ;保存窗口的实例句柄
mov     wc.hbrBackground,COLOR_WINDOW+1                ;窗口的背景颜色
mov     wc.lpszMenuName,NULL
mov        wc.lpszClassName,OFFSET ClassName        
invoke    LoadIcon,NULL,IDI_APPLICATION
mov        wc.hIcon,eax
mov        wc.hIconSm,eax
invoke    LoadCursor,NULL,IDC_ARROW
mov        wc.hCursor,eax
invoke    RegisterClassEx,addr wc

;-----------------------------------------------------------------------------------------------------------
;创建窗口对象

invoke    CreateWindowEx,NULL,            ADDR ClassName,            ADDR AppName,            WS_OVERLAPPEDWINDOW,            CW_USEDEFAULT,            CW_USEDEFAULT,            CW_USEDEFAULT,            CW_USEDEFAULT,            NULL,            NULL,            hInst,            NULL
mov        hwnd,eax
;-----------------------------------------------------------------------------------------------------------
;显示窗口
invoke    ShowWindow,hwnd,CmdShow

;-----------------------------------------------------------------------------------------------------------
;刷新窗口客户区
invoke UpdateWindow,hwnd
;-----------------------------------------------------------------------------------------------------------
;进入获取窗口消息的循环
 .WHILE TRUE
     invoke GetMessage,ADDR msg,NULL,0,0
     .BREAK .IF (!eax)
     invoke TranslateMessage,ADDR msg
     invoke DispatchMessage,ADDR     msg
 .endw
mov        eax,msg.wParam
ret
WinMain endp

;-----------------------------------------------------------------------------------------------------------
;窗口回调函数
WndProc    proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
;关闭消息--退出处理
.IF uMsg==WM_DESTROY
    invoke  PostQuitMessage,NULL
.ELSE
    invoke  DefWindowProc,hWnd,uMsg,wParam,lParam
    ret
.endif
xor eax,eax
ret        
WndProc endp

    
end start    

 

Windows下的窗口程序

标签:

原文地址:http://www.cnblogs.com/icqw/p/4889995.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!