.386
        .model flat, stdcall
        option casemap :none   ; case sensitive
include        windows.inc
include        user32.inc
include        kernel32.inc
include        comctl32.inc
include        comdlg32.inc
include        gdi32.inc
includelib    user32.lib
includelib    kernel32.lib
includelib    comctl32.lib
includelib    comdlg32.lib
includelib    gdi32.lib
IDM_EXIT    equ        4001
IDB_MYBITMAP equ 100
        .data?
hInstance    dd        ?
hWinMain    dd        ?
hMenu        dd        ?
szBuffer    db    256 dup    (?)
        .data
szClassName    db    "Windows Template",0
szCaptionMain    db    '窗口模板',0
        .code
start:
        call    _WinMain
        invoke    ExitProcess,NULL
_WinMain    proc
        local    @stWcMain:WNDCLASSEX
        local    @stMsg:MSG
        invoke    InitCommonControls
        invoke    GetModuleHandle,NULL
        mov    hInstance,eax
    ;    invoke    LoadIcon,hInstance,IDI_MAIN
    ;    mov    hIcon,eax
    ;    invoke    LoadMenu,hInstance,IDM_MAIN
    ;    mov    hMenu,eax
;*************** 注册窗口类 *****************************************
        invoke    LoadCursor,0,IDC_ARROW
        mov    @stWcMain.hCursor,eax
        mov    @stWcMain.cbSize,sizeof WNDCLASSEX
        mov    @stWcMain.hIconSm,0
        mov    @stWcMain.style,CS_HREDRAW or CS_VREDRAW
        mov    @stWcMain.lpfnWndProc,offset WndMainProc
        mov    @stWcMain.cbClsExtra,0
        mov    @stWcMain.cbWndExtra,0
        mov    eax,hInstance
        mov    @stWcMain.hInstance,eax
        mov    @stWcMain.hIcon,0
        mov    @stWcMain.hbrBackground,COLOR_WINDOW + 1
        mov    @stWcMain.lpszClassName,offset szClassName
        mov    @stWcMain.lpszMenuName,0
        invoke    RegisterClassEx,addr @stWcMain
        
;*************** 建立输出窗口 ***************************************
        invoke    CreateWindowEx,WS_EX_CLIENTEDGE,\
            offset szClassName,offset szCaptionMain,\
            WS_OVERLAPPEDWINDOW OR WS_VSCROLL OR WS_HSCROLL,\
            0,0,550,300,\
            NULL,hMenu,hInstance,NULL
        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
_DrawMyBitMap   proc hdc:DWORD
    
    LOCAL mdc:DWORD;
    LOCAL hobj:DWORD;
    LOCAL hold:DWORD;
    LOCAL src:DWORD;
    
    
    invoke CreateCompatibleDC,hdc;
    mov mdc,eax;
    
    
    invoke LoadBitmap,hInstance,IDB_MYBITMAP;
    mov hobj,eax;
    
    
    invoke SelectObject,mdc,hobj;
    mov hold,eax;
    
    invoke BitBlt,hdc,0,0,1024,768,mdc,0,0,SRCCOPY;
    
    
    invoke SelectObject,mdc,hold;
    
    mov src,eax;
    
    invoke DeleteObject,src;
    invoke DeleteDC,mdc;
    
    ret
_DrawMyBitMap endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WndMainProc    proc    uses ebx edi esi, \
        hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
        LOCAL hdc:DWORD;
        LOCAL lpaint:PAINTSTRUCT;
        mov    eax,uMsg
        .if    eax ==    WM_CREATE
            mov    eax,hWnd
            mov    hWinMain,eax
            call    _Init
;********************************************************************
        .elseif    eax ==    WM_COMMAND
           .if    lParam == 0
            mov    eax,wParam
            .if    ax == IDM_EXIT
                call    _Quit
            .endif
           .endif
;********************************************************************
        .elseif    eax ==    WM_CLOSE
            call    _Quit
        .elseif eax ==  WM_PAINT
            invoke BeginPaint,hWnd,addr lpaint;
            mov hdc,eax;
            invoke _DrawMyBitMap,hdc; 
            invoke EndPaint,hWnd,addr lpaint;
;********************************************************************
        .else
            invoke    DefWindowProc,hWnd,uMsg,wParam,lParam
            ret
        .endif
        xor    eax,eax
        ret
WndMainProc    endp
_Init        proc
        ;invoke    SendMessage,hWinMain,WM_SETICON,ICON_SMALL,hIcon
        ret
_Init        endp
;********************************************************************
_Quit        proc
        invoke    DestroyWindow,hWinMain
        invoke    PostQuitMessage,NULL
        ret
_Quit        endp
;********************************************************************
        end    start
	posted on 2010-06-24 22:35 
小果子 阅读(132) 
评论(0)  编辑 收藏 引用  所属分类: 
学习笔记