| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 669 人关注过本帖
标题:有点感想,也有点问题
只看楼主 加入收藏
chengiant
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-3-13
收藏
 问题点数:0 回复次数:4 
有点感想,也有点问题

今天搞了一天,终于完成一个程序,请大家看看,也有点问题,请大家指教:
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comdlg32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\comdlg32.lib
winmain proto :HINSTANCE
wndproc proto :HWND,:DWORD,:DWORD,:DWORD
.const
IDM_SAVE EQU 1001
IDM_OPEN EQU 1010
MAXSIZE EQU 260
MEMSIZE EQU 65535
EditID equ 1
.data
editclass db"EDIT",0
classname db "win32"
appname db "TEXT EDIT"
ofn OPENFILENAME <?>
filterstring db "All Files",0,"*.*",0
db "Text Files",0,"*.txt",0,0
buffer db MAXSIZE dup(0)
msg MSG <?>
wc WNDCLASSEX <?>
menuname db "ams",0
.data?
hInstance DWORD ?
cmdline DWORD ?
hWnd HWND ?
hEdit HWND ?
hMem HANDLE ?
pMem DWORD ?
hFile HANDLE ?
read DWORD ?
write DWORD ?
.code
;========================================================================================第一步骤
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke GetCommandLine
mov cmdline,eax
invoke winmain,hInstance
invoke ExitProcess,eax
;======================================================================================第二步骤
winmain proc hInst:HINSTANCE
mov wc.cbSize,sizeof wc ;50
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.hIcon,NULL
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszClassName,offset classname
mov wc.lpszMenuName,offset menuname
mov wc.hIconSm,NULL
invoke RegisterClassEx,addr wc ;63
invoke CreateWindowEx,WS_EX_CLIENTEDGE,addr classname,addr appname,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,\
320,300,NULL,NULL,hInstance,NULL
mov hWnd,eax
;invoke LoadMenu,hWnd,600 原来的菜单ID是600
;invoke SetMenu,hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
startloop:
invoke GetMessage,addr msg,NULL,0,0
.IF eax==0
jmp asd
.endif
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
jmp startloop
asd:
mov eax,msg.wParam
ret
winmain endp
;======================================================================================第三步骤
wndproc proc hWind:HWND,umsg:DWORD,wParam:DWORD,lParam:DWORD
.if umsg==WM_CREATE
invoke CreateWindowEx,NULL,addr editclass,NULL,WS_VISIBLE or WS_CHILD or ES_LEFT or ES_MULTILINE or\
ES_AUTOHSCROLL or ES_AUTOVSCROLL,0,0,0,0,hWind,EditID,hInstance,NULL
mov hEdit,eax
invoke SetFocus,hEdit
mov ofn.lStructSize,sizeof ofn
push hWnd
pop ofn.hWndOwner
push hInstance
pop ofn.hInstance
mov ofn.lpstrFilter,offset filterstring
mov ofn.lpstrFile,offset buffer
mov ofn.nMaxFile,MAXSIZE
.elseif umsg==WM_SIZE
mov eax,lParam
mov edx,eax
shr edx,16
and eax,0ffffh
sub edx,20
invoke MoveWindow,hEdit,0,0,EAX,EDX,TRUE
.elseif umsg==WM_DESTROY
invoke PostQuitMessage,NULL ;106
.elseif umsg==WM_COMMAND
mov eax,wParam
.if lParam==0 ;110
;============================================================
.if eax==IDM_OPEN
mov ofn.Flags,OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or\
OFN_HIDEREADONLY
invoke GetOpenFileName,addr ofn
.if eax==TRUE
invoke CreateFile,addr buffer,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE ;117
mov hMem,eax
invoke GlobalLock,hMem
mov pMem,eax
invoke ReadFile,hFile,pMem,MEMSIZE-1,addr read,NULL
invoke SendMessage,hEdit,WM_SETTEXT,NULL,pMem
invoke CloseHandle,hFile
invoke GlobalUnlock,pMem
invoke GlobalFree,hMem
.endif
invoke SetFocus,hEdit
;=======================================================
.elseif eax==IDM_SAVE
mov ofn.Flags,OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
invoke GetSaveFileName,addr ofn
.if eax==TRUE
invoke CreateFile,addr buffer,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,CREATE_NEW,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMem,eax
invoke GlobalLock,hMem
mov pMem,eax
invoke SendMessage,hEdit,WM_GETTEXT,MEMSIZE-1,pMem ;140
invoke WriteFile,hFile,pMem,eax,addr write,NULL
invoke CloseHandle,hFile
invoke GlobalUnlock,pMem ;145
invoke GlobalFree,hMem
.endif
invoke SetFocus,hEdit
;=====================
.else
invoke DestroyWindow,hWind
.endif
.endif
.else
invoke DefWindowProc,hWind,umsg,wParam,lParam
ret
.endif
xor eax,eax
ret
wndproc endp
end start ;162

RC 文件:
ams MENUEX MOVEABLE IMPURE LOADONCALL DISCARDABLE ; 原来菜单名为600
BEGIN
POPUP "&File", , , 0
BEGIN
MENUITEM "&Open", 1010
MENUITEM "&SAVE",1001
END

END
但用红字部分代码时却不能正成菜单,不知为嘛???

搜索更多相关主题的帖子: 感想 
2006-03-15 20:17
wy_5203345
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2006-2-6
收藏
得分:0 
invoke LoadMenu,hWnd,600使用有问题
将其改为invoke LoadMenu,hInst,offset menuname就可正常
同时mov wc.lpszMenuName,offset menuname可以删除

2006-03-22 12:21
wy_5203345
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2006-2-6
收藏
得分:0 
这种方法也可以

hHandle dd ?;在Data?中加入



invoke LoadMenu,hInst,offset menuname
mov hHandle,eax
invoke CreateWindowEx,WS_EX_CLIENTEDGE,addr classname,addr appname,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,\
320,300,NULL,hHandle,hInstance,NULL

2006-03-22 12:28
wy_5203345
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2006-2-6
收藏
得分:0 
能详细解释一下这段代码吗?谢谢
wndproc proc hWind:HWND,umsg:DWORD,wParam:DWORD,lParam:DWORD
.if umsg==WM_CREATE
invoke CreateWindowEx,NULL,addr editclass,NULL,WS_VISIBLE or WS_CHILD or ES_LEFT or ES_MULTILINE or\
ES_AUTOHSCROLL or ES_AUTOVSCROLL,0,0,0,0,hWind,EditID,hInstance,NULL
mov hEdit,eax
invoke SetFocus,hEdit
mov ofn.lStructSize,sizeof ofn
push hWnd
pop ofn.hWndOwner
push hInstance
pop ofn.hInstance
mov ofn.lpstrFilter,offset filterstring
mov ofn.lpstrFile,offset buffer
mov ofn.nMaxFile,MAXSIZE
.elseif umsg==WM_SIZE
mov eax,lParam
mov edx,eax
shr edx,16
and eax,0ffffh
sub edx,20
invoke MoveWindow,hEdit,0,0,EAX,EDX,TRUE
.elseif umsg==WM_DESTROY
invoke PostQuitMessage,NULL ;106
.elseif umsg==WM_COMMAND
mov eax,wParam
.if lParam==0 ;110
;============================================================
.if eax==IDM_OPEN
mov ofn.Flags,OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or\
OFN_HIDEREADONLY
invoke GetOpenFileName,addr ofn
.if eax==TRUE
invoke CreateFile,addr buffer,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE ;117
mov hMem,eax
invoke GlobalLock,hMem
mov pMem,eax
invoke ReadFile,hFile,pMem,MEMSIZE-1,addr read,NULL
invoke SendMessage,hEdit,WM_SETTEXT,NULL,pMem
invoke CloseHandle,hFile
invoke GlobalUnlock,pMem
invoke GlobalFree,hMem
.endif
invoke SetFocus,hEdit
;=======================================================
.elseif eax==IDM_SAVE
mov ofn.Flags,OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
invoke GetSaveFileName,addr ofn
.if eax==TRUE
invoke CreateFile,addr buffer,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,CREATE_NEW,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFile,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE
mov hMem,eax
invoke GlobalLock,hMem
mov pMem,eax
invoke SendMessage,hEdit,WM_GETTEXT,MEMSIZE-1,pMem ;140
invoke WriteFile,hFile,pMem,eax,addr write,NULL
invoke CloseHandle,hFile
invoke GlobalUnlock,pMem ;145
invoke GlobalFree,hMem
.endif
invoke SetFocus,hEdit
;=====================
.else
invoke DestroyWindow,hWind
.endif
.endif
.else
invoke DefWindowProc,hWind,umsg,wParam,lParam
ret
.endif
xor eax,eax
ret
wndproc endp

2006-03-22 12:31
chengiant
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2006-3-13
收藏
得分:0 

;;;windproc 是窗口过程函数,其已在RegisterWndClassEx 的wc参数中定义
umsg 参数是系统传递的消息,如WM_CREATE,窗口创建时由系统发出此消息到该窗口过程,.
hWnd代表发生该事件的窗口句柄,wParam代表窗口中的控件的id,lParam,代表发生该事件的对象的坐标,高十六位为纵坐标,低十六位为横坐标
详情可参阅微软的MSDN

2006-03-25 22:43
快速回复:有点感想,也有点问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017115 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved