|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 Μiss^依然 于 2013-5-6 22:43 编辑
;------------------------------------------------------------------------------------------------------------------------------------------------
;程序作者:fox
;开发日期:2013-5-2
;功能描述:这是我个人的应用程序模板
;注意事项:
;更新历史:
;-------------------------------------------------------------------------------------------------------------------------------------------------
.586
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
include kernel32.inc
include comdlg32.inc
includelib user32.lib
includelib kernel32.lib
includelib comdlg32.lib
;Res\menu.mnu
IDR_MENU equ 10000
IDM_FILE equ 10001
IDM_FILE_OPEN equ 10002
IDM_FILE_SAVE equ 10003
IDM_SPACE equ 10005
IDM_FILE_EXIT equ 10004
IDM_EDIT equ 10006
IDM_EDIT_UNDO equ 10007
IDM_EDIT_REDO equ 10008
IDM_SPACE1 equ 10009
IDM_EDIT_CUT equ 10010
IDM_EDIT_COPY equ 10011
IDM_EDIT_PASTE equ 10012
IDM_HELP equ 10013
IDM_HELP_ABOUAT equ 10014
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
.data
ClassName db "MainWinClass",0 ;窗口名
AppName db "Main Window",0 ;应用程序标题命名
Exitname db "edit",0
aboutmsg db "这是个人开发的第一个WIN32程序",0 ;帮助的信息
;调用公共对话框所必须的数据
szfile db "Files(*.txt)",0,"*.txt",0,"All Files(*.*)",0,"*.*",0,0
szdef db "txt",0
szerror db "打开错误",0
hfile db MAX_PATH dup (?) ;文件路径
lpbuffer db 1024 dup(?)
szreadbuffer db 1024 dup(?)
.data?
hInstance HINSTANCE ? ;应用程序句柄
CommandLine LPSTR ? ;程序命令行参数字符串指针
hedit dword ? ;文本框句柄
hfile1 dword ? ;文件句柄
truefile dword ?
;公共对话框传回的文件名
.const
APP_ICON equ 1100
.code
; ---------------------------------------------------------------------------
;程序入口点
start:
invoke GetModuleHandle, NULL ;为程序生成一个实例句柄
mov hInstance,eax
invoke GetCommandLine ;为程序获取一个命令行参数
mov CommandLine,eax
;调用windows主函数
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_BTNFACE+1 ;创建窗口背景的颜色
mov wc.lpszMenuName,IDR_MENU ;为这个窗口建立一个主菜单
mov wc.lpszClassName,OFFSET ClassName ;窗口类的名称
invoke LoadIcon,NULL,APP_ICON ;为此窗口建立一个图标
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW ;指定窗口光标的属性
mov wc.hCursor,eax
;向WINDOWS注册一个窗口
invoke RegisterClassEx, addr wc
;创建一个窗口,然后把窗口句柄赋值给hWnd变量
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,SW_SHOWNORMAL
;刷新一个窗口
invoke UpdateWindow, hwnd
;进入了一个处理消息的循环
.WHILE TRUE
;获取一条消息放进msg结构变量里
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 windrect:RECT
LOCAL hide:dword
LOCAL white:dword
LOCAL ofn : OPENFILENAME
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke LoadIcon,hInstance,APP_ICON
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset Exitname,NULL,WS_MAXIMIZE or WS_HSCROLL or WS_VSCROLL or \
WS_CHILDWINDOW or WS_VISIBLE or ES_AUTOHSCROLL or ES_AUTOVSCROLL or ES_MULTILINE ,0,0,300,300,hWnd,NULL,hInstance,NULL
mov hedit,eax
.elseif uMsg==WM_SIZE
invoke GetClientRect,hWnd,addr windrect
mov eax,windrect.right
sub eax,windrect.left
mov white,eax
mov eax,windrect.bottom
sub eax,windrect.top
mov hide,eax
invoke MoveWindow,hedit,0,0,white,hide,TRUE
.elseif uMsg==WM_COMMAND
mov eax,wParam
.if eax==IDM_FILE_EXIT
;退出程序
invoke DestroyWindow,hWnd
invoke PostQuitMessage,NULL
.elseif ax==IDM_EDIT_UNDO
;撤销操作
invoke SendMessage,hedit,EM_UNDO,0,0
.elseif ax==IDM_EDIT_REDO
;恢复上次操作
invoke SendMessage,hedit,EM_REDO,0,0
.elseif ax==IDM_EDIT_CUT
;剪切
invoke SendMessage,hedit,WM_CUT,0,0
.elseif ax==IDM_EDIT_COPY
;复制
invoke SendMessage,hedit,WM_COPY,0,0
.elseif ax==IDM_EDIT_PASTE
;黏贴
invoke SendMessage,hedit,WM_PASTE,0,0
.elseif ax==IDM_HELP_ABOUAT
;帮助
invoke MessageBox,hWnd,offset aboutmsg,NULL,MB_OK or MB_ICONHAND
.elseif ax==IDM_FILE_OPEN ;打开文件
;初始化openfilename结构
invoke RtlZeroMemory,addr ofn,sizeof ofn
mov ofn.lStructSize,sizeof ofn
push hWnd
pop ofn.hwndOwner
mov ofn.lpstrFilter,offset szfile
mov ofn.lpstrFile,offset hfile
mov ofn.nMaxFile,MAX_PATH
mov ofn.lpstrDefExt,offset szdef
mov ofn.Flags,OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST
;获取选择的文本句柄
invoke GetOpenFileName,addr ofn
invoke MessageBox,hWnd,offset hfile,NULL,MB_OK
invoke CreateFile,offset hfile,GENERIC_READ ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
mov hfile1,eax
.if eax==INVALID_HANDLE_VALUE
invoke MessageBox,hWnd,offset szerror,NULL,MB_OK
ret
.endif
invoke ReadFile,hfile1,offset lpbuffer,offset szreadbuffer,offset truefile,NULL
invoke MessageBox,hedit,offset lpbuffer,NULL,MB_OK
INVOKE SendMessage,hedit,WM_CLEAR,0,0
invoke SetWindowText,hedit,offset lpbuffer
.elseif ax==IDM_FILE_SAVE ;保存文件
;保存文件
invoke RtlZeroMemory,addr ofn,sizeof ofn
mov ofn.lStructSize,sizeof ofn
push hWnd
pop ofn.hwndOwner
mov ofn.lpstrFilter,offset szfile
mov ofn.lpstrFile,offset hfile
mov ofn.nMaxFile,MAX_PATH
mov ofn.lpstrDefExt,offset szdef
mov ofn.Flags,OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST
;获取选择的文本句柄
invoke GetSaveFileName,addr ofn
.if eax
invoke MessageBox,hWnd,offset hfile,NULL,MB_OK
.endif
.endif
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
end start
|
|