📄 lion-tutorial12.htm
字号:
<b>; Initialize the members of OPENFILENAME
structure</b> <br>
<b>;==============================================</b> <br>
<b> mov ofn.lStructSize,SIZEOF ofn</b>
<br>
<b> push hWnd</b> <br>
<b> pop ofn.hWndOwner</b> <br>
<b> push hInstance</b> <br>
<b> pop ofn.hInstance</b> <br>
<b> mov ofn.lpstrFilter, OFFSET
FilterString</b> <br>
<b> mov ofn.lpstrFile, OFFSET
buffer</b> <br>
<b> mov ofn.nMaxFile,MAXSIZE</b>
<br>
<b> .ELSEIF uMsg==WM_SIZE</b> <br>
<b> mov eax,lParam</b> <br>
<b> mov edx,eax</b> <br>
<b> shr edx,16</b> <br>
<b> and eax,0ffffh</b> <br>
<b> invoke MoveWindow,hwndEdit,0,0,eax,edx,TRUE</b>
<br>
<b> .ELSEIF uMsg==WM_DESTROY</b> <br>
<b> invoke PostQuitMessage,NULL</b>
<br>
<b> .ELSEIF uMsg==WM_COMMAND</b> <br>
<b> mov eax,wParam</b> <br>
<b> .if lParam==0</b> <br>
<b> .if ax==IDM_OPEN</b>
<br>
<b>
mov ofn.Flags, OFN_FILEMUSTEXIST or \</b> <br>
<b>
OFN_PATHMUSTEXIST or OFN_LONGNAMES or\</b> <br>
<b>
OFN_EXPLORER or OFN_HIDEREADONLY</b> <br>
<b>
invoke GetOpenFileName, ADDR ofn</b> <br>
<b>
.if eax==TRUE</b> <br>
<b>
invoke CreateFile,ADDR buffer,\</b> <br>
<b>
GENERIC_READ or GENERIC_WRITE ,\</b> <br>
<b>
FILE_SHARE_READ or FILE_SHARE_WRITE,\</b> <br>
<b>
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\</b> <br>
<b>
NULL</b> <br>
<b>
mov hFile,eax</b> <br>
<b>
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE</b> <br>
<b>
mov hMemory,eax</b> <br>
<b>
invoke GlobalLock,hMemory</b> <br>
<b>
mov pMemory,eax</b> <br>
<b>
invoke ReadFile,hFile,pMemory,MEMSIZE-1,ADDR SizeReadWrite,NULL</b> <br>
<b>
invoke SendMessage,hwndEdit,WM_SETTEXT,NULL,pMemory</b> <br>
<b>
invoke CloseHandle,hFile</b> <br>
<b>
invoke GlobalUnlock,pMemory</b> <br>
<b>
invoke GlobalFree,hMemory</b> <br>
<b>
.endif</b> <br>
<b>
invoke SetFocus,hwndEdit</b> <br>
<b> .elseif
ax==IDM_SAVE</b> <br>
<b>
mov ofn.Flags,OFN_LONGNAMES or\</b> <br>
<b>
OFN_EXPLORER or OFN_HIDEREADONLY</b> <br>
<b>
invoke GetSaveFileName, ADDR ofn</b> <br>
<b>
.if eax==TRUE</b> <br>
<b>
invoke CreateFile,ADDR buffer,\</b> <br>
<b>
GENERIC_READ or GENERIC_WRITE ,\</b> <br>
<b>
FILE_SHARE_READ or FILE_SHARE_WRITE,\</b> <br>
<b>
NULL,CREATE_NEW,FILE_ATTRIBUTE_ARCHIVE,\</b> <br>
<b>
NULL</b> <br>
<b>
mov hFile,eax</b> <br>
<b>
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,MEMSIZE</b> <br>
<b>
mov hMemory,eax</b> <br>
<b>
invoke GlobalLock,hMemory</b> <br>
<b>
mov pMemory,eax</b> <br>
<b>
invoke SendMessage,hwndEdit,WM_GETTEXT,MEMSIZE-1,pMemory</b> <br>
<b>
invoke WriteFile,hFile,pMemory,eax,ADDR SizeReadWrite,NULL</b> <br>
<b>
invoke CloseHandle,hFile</b> <br>
<b>
invoke GlobalUnlock,pMemory</b> <br>
<b>
invoke GlobalFree,hMemory</b> <br>
<b>
.endif</b> <br>
<b>
invoke SetFocus,hwndEdit</b> <br>
<b>
.else</b> <br>
<b>
invoke DestroyWindow, hWnd</b> <br>
<b>
.endif</b> <br>
<b> .endif</b>
<br>
<b> .ELSE</b> <br>
<b> invoke
DefWindowProc,hWnd,uMsg,wParam,lParam</b> <br>
<b> ret</b>
<br>
<b>.ENDIF</b> <br>
<b>xor eax,eax</b> <br>
<b>ret</b> <br>
<b>WndProc endp</b> <br>
<b>end start</b>
<p>
<hr width="100%">
<h3> <b>Analysis:</b></h3>
<b> invoke CreateWindowEx,NULL,ADDR
EditClass,NULL,\</b> <br>
<b>
WS_VISIBLE or WS_CHILD or ES_LEFT or ES_MULTILINE or\</b> <br>
<b>
ES_AUTOHSCROLL or ES_AUTOVSCROLL,0,\</b> <br>
<b>
0,0,0,hWnd,EditID,\</b> <br>
<b>
hInstance,NULL</b> <br>
<b> mov hwndEdit,eax</b>
<p>In WM_CREATE section, we create an edit control. Note that the parameters that
specify x, y, width,height of the control are all zeroes since we will resize
the control later to cover the whole client area of the parent window. <br>
Note that in this case, we don't have to call ShowWindow to make the edit control
appear on the screen because we include WS_VISIBLE style. You can use this trick
in the parent window too.
<p><b>;==============================================</b> <br>
<b>; Initialize the members of OPENFILENAME
structure</b> <br>
<b>;==============================================</b> <br>
<b> mov ofn.lStructSize,SIZEOF ofn</b>
<br>
<b> push hWnd</b> <br>
<b> pop ofn.hWndOwner</b> <br>
<b> push hInstance</b> <br>
<b> pop ofn.hInstance</b> <br>
<b> mov ofn.lpstrFilter, OFFSET
FilterString</b> <br>
<b> mov ofn.lpstrFile, OFFSET
buffer</b> <br>
<b> mov ofn.nMaxFile,MAXSIZE</b>
<p>After creating the edit control, we take this time to initialize the members
of ofn. Because we want to reuse ofn in the save as dialog box too, we fill
in only the *common* members that're used by both GetOpenFileName and GetSaveFileName.
<br>
WM_CREATE section is a great place to do once-only initialization.
<p><b> .ELSEIF uMsg==WM_SIZE</b> <br>
<b> mov eax,lParam</b> <br>
<b> mov edx,eax</b> <br>
<b> shr edx,16</b> <br>
<b> and eax,0ffffh</b> <br>
<b> invoke MoveWindow,hwndEdit,0,0,eax,edx,TRUE</b>
<p>We receive WM_SIZE messages when the size of the client area of our main window
changes. We also receive it when the window is first created. In order to be
able to receive this message, the window class styles must include CS_VREDRAW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -