飘云阁

 找回密码
 加入我们

QQ登录

只需一步,快速开始

查看: 1849|回复: 0

[ASM] 新手 学习 win32汇编 创建一个窗口

[复制链接]
  • TA的每日心情
    开心
    半小时前
  • 签到天数: 1046 天

    [LV.10]以坛为家III

    发表于 2016-7-14 23:21:15 | 显示全部楼层 |阅读模式
                    .386                       
                    .model        flat,stdcall
                    option        casemap:none
    ;==============================================================
    ;Include包含文件
    ;==============================================================
    include                windows.inc
    include                user32.inc
    includelib        user32.lib
    include                kernel32.inc
    includelib        kernel32.lib
    include                gdi32.inc
    includelib        gdi32.lib
    ;=============================================================
                    .data?
    hInstance        dd        ?
    hWinMain        dd        ?
    ;=============================================================
                    .const
    szClassName        db        'My Class',0
    szCaption        db        '我的窗口',0
    ;=======================程序过程处理==========================
                    .code
    _ProcWinMain        proc        uses ebx edi esi hWnd,uMsg,wParam,lParam
                    mov        eax,uMsg
    ;=============================================================
                    .if        eax == WM_CLOSE
                            invoke DestroyWindow,hWinMain
                            invoke PostQuitMessage,NULL
    ;======================不处理消息让系统处理====================
                    .else       
                            invoke DefWindowProc,hWnd,uMsg,wParam,lParam
                            ret
                    .endif
                    xor        eax,eax
                    ret
    _ProcWinMain        endp
    ;==============================================================

    _WinMain        proc
    ;=================注册窗口类===================================
                    local        @stWndClass:WNDCLASSEX
                    local        @stMsg:MSG
                    invoke        RtlZeroMemory,addr @stWndClass,sizeof WNDCLASSEX
                    invoke        GetModuleHandle,NULL
                    mov        hInstance,eax
                    push        hInstance
                    pop        @stWndClass.hInstance
                    mov        @stWndClass.cbSize,sizeof WNDCLASSEX
                    mov        @stWndClass.lpszClassName,offset szClassName
                    mov        @stWndClass.lpfnWndProc,offset _ProcWinMain
                    invoke        RegisterClassEx,addr @stWndClass
    ;==============================创建显示窗口=======================
                    invoke        CreateWindowEx,0,offset szClassName,\
                            offset szCaption,WS_OVERLAPPEDWINDOW,\
                            100,100,600,400,NULL,NULL,hInstance,NULL
                    mov        hWinMain,eax
                    invoke        ShowWindow,hWinMain,SW_SHOWNORMAL
    ;===============================消息循环==========================
                    .while        TRUE
                            invoke        GetMessage,addr @stMsg,0,0,0
                            .break        .if eax == 0
                            invoke        TranslateMessage,addr @stMsg
                            invoke        DispatchMessage,addr @stMsg
                    .endw
                    ret
    _WinMain        endp
    ;========================程序开始===================================
    start:
                    call        _WinMain
                    invoke        ExitProcess,NULL
                    end        start

    PYG19周年生日快乐!
    您需要登录后才可以回帖 登录 | 加入我们

    本版积分规则

    快速回复 返回顶部 返回列表