@会网络的老鼠

涂飞平的博客空间

编程随记1 [原]

12 年前 0

;-------------------------------------------------------------------------------
; 2004-08-06 Sundytu tufeiping@vip.sina.com
; GuangZhou Guangdong China
;-------------------------------------------------------------------------------
.586
.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc

includelib user32.lib
includelib kernel32.lib
include sds.inc

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

;----------------------------------
; interface define
;----------------------------------
ProcPtr struct
AddFunc DWORD ?
SubFunc DWORD ?
MulFunc DWORD ?
DivFunc DWORD ?
ProcPtr ends

.data
ClassName db "Sundy_WinClass",0
AppName db "ASM Window",0
Files db "&File",0
Opens db "&Open",0
News db "&New",0
Exits db "&Exit",0
Cap db "Quest",0
Lab db "Will Exit Application,Are you sure?",0
Buttib db "BUTTON",0
ButtonCap db "Click Me",0
Tips db "Button be clicked!",0
Edit db "EDIT",0

.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
HEdit DWORD ?
Intf DWORD ?
.code

; -----------------------------------------------------------------------------------
; PELoader Entry ! RTL Code
;------------------------------------------------------------------------------------
start:
invoke GetModuleHandle, NULL
mov hInstance,eax

invoke GetCommandLine
mov CommandLine,eax
;---------------------------------------------------------------------------
; WinMain -- C Language Entry Function
;---------------------------------------------------------------------------
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
;---------------------------------------------------------------------------
;Return to PELoader And Clearnup Process Resource
;---------------------------------------------------------------------------
invoke ExitProcess,eax
; -----------------------------------------------------------------------------------
; PELoader Out
;------------------------------------------------------------------------------------
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_BTNFACE+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_CAPTION +WS_MINIMIZE+WS_SYSMENU+WS_VISIBLE,CW_USEDEFAULT,
CW_USEDEFAULT,300,200,NULL,NULL,
hInst,NULL
mov hwnd,eax

invoke ShowWindow, hwnd,SW_SHOWNORMAL
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
LOCAL HM:DWORD
LOCAL HMS: DWORD
LOCAL MR:DWORD
LOCAL MH:DWORD
LOCAL Buf:DWORD
LOCAL Len:DWORD
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,0
.ELSEIF uMsg==WM_CREATE
invoke CreateMenu
mov HMS,eax
invoke CreateMenu
mov HM,eax
invoke AppendMenu,HMS,MF_STRING,1000,ADDR News
invoke AppendMenu,HMS,MF_STRING,1001, ADDR Opens
invoke AppendMenu,HMS,MF_SEPARATOR,1002,NULL
invoke AppendMenu,HMS,MF_STRING,1003,ADDR Exits
invoke AppendMenu,HM,MF_POPUP,HMS,ADDR Files
invoke SetMenu,hWnd,HM
invoke CreateWindowEx,0,ADDR Buttib,ADDR ButtonCap,WS_CHILD+BS_DEFPUSHBUTTON+WS_VISIBLE,20,60,75,25,hWnd,1004,hInstance,0
invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR Edit,ADDR AppName,WS_CHILD+ES_MULTILINE+WS_BORDER+WS_VISIBLE+WS_VSCROLL,120,20,170,125,hWnd,1004,hInstance,0
invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR Edit,ADDR ButtonCap,WS_CHILD+ES_CENTER+WS_VISIBLE+WS_BORDER,20,20,90,22,hWnd,1005,hInstance,0
mov HEdit,eax
.ELSEIF uMsg==WM_COMMAND
.if wParam==1000
invoke MessageBox,hWnd,ADDR News,ADDR AppName,MB_OK
.elseif wParam==1001
invoke MessageBox,hWnd,ADDR Opens,ADDR AppName,MB_OK
.elseif wParam==1003
invoke MessageBox,hWnd,ADDR Lab,ADDR Cap,MB_YESNO+MB_ICONQUESTION
mov MR,eax
.if MR==IDYES
invoke PostQuitMessage,0
.endif
.elseif wParam==1004
invoke GetWindowTextLength,HEdit
mov Len,eax
invoke GlobalAlloc,GMEM_ZEROINIT, Len
mov Buf,eax
invoke GetWindowText,HEdit,Buf,Len+1
invoke MessageBox,hWnd,Buf,ADDR AppName,MB_OK
invoke GlobalFree,Buf
.endif
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF

xor eax,eax
ret
WndProc endp

end start

编写评论