?? lion-tutorial11.htm
字號:
<b> hInst,NULL</b>
<br>
<b> mov hwnd,eax</b> <br>
<b> invoke ShowWindow, hwnd,SW_SHOWNORMAL</b> <br>
<b> invoke UpdateWindow, hwnd</b> <br>
<b> .WHILE TRUE</b> <br>
<b> invoke GetMessage, ADDR msg,NULL,0,0</b>
<br>
<b> .BREAK .IF (!eax)</b> <br>
<b> invoke TranslateMessage, ADDR
msg</b> <br>
<b> invoke DispatchMessage, ADDR msg</b>
<br>
<b> .ENDW</b> <br>
<b> mov eax,msg.wParam</b> <br>
<b> ret</b> <br>
<b>WinMain endp</b>
<p><b>WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM</b> <br>
<b> .IF 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 ax==IDM_OPEN</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> 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> mov
ofn.lpstrTitle, OFFSET OurTitle</b> <br>
<b> invoke
GetOpenFileName, ADDR ofn</b> <br>
<b> .if eax==TRUE</b>
<br>
<b>
invoke lstrcat,offset OutputString,OFFSET FullPathName</b> <br>
<b>
invoke lstrcat,offset OutputString,ofn.lpstrFile</b> <br>
<b>
invoke lstrcat,offset OutputString,offset CrLf</b> <br>
<b>
invoke lstrcat,offset OutputString,offset FullName</b> <br>
<b>
mov eax,ofn.lpstrFile</b> <br>
<b>
push ebx</b> <br>
<b>
xor ebx,ebx</b> <br>
<b>
mov bx,ofn.nFileOffset</b> <br>
<b>
add eax,ebx</b> <br>
<b>
pop ebx</b> <br>
<b>
invoke lstrcat,offset OutputString,eax</b> <br>
<b>
invoke lstrcat,offset OutputString,offset CrLf</b> <br>
<b>
invoke lstrcat,offset OutputString,offset ExtensionName</b> <br>
<b>
mov eax,ofn.lpstrFile</b> <br>
<b>
push ebx</b> <br>
<b>
xor ebx,ebx</b> <br>
<b>
mov bx,ofn.nFileExtension</b> <br>
<b>
add eax,ebx</b> <br>
<b>
pop ebx</b> <br>
<b>
invoke lstrcat,offset OutputString,eax</b> <br>
<b>
invoke MessageBox,hWnd,OFFSET OutputString,ADDR AppName,MB_OK</b> <br>
<b>
invoke RtlZeroMemory,offset OutputString,OUTPUTSIZE</b> <br>
<b> .endif</b>
<br>
<b> .else</b> <br>
<b> invoke
DestroyWindow, hWnd</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> <br>
<hr width="100%">
<h3> Analysis:</h3>
<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>
<p>We fill in the routine members of ofn structures.
<p><b> mov
ofn.lpstrFilter, OFFSET FilterString</b>
<p>This FilterString is the filename filter that we specify as follows:
<blockquote><b>FilterString db "All Files",0,"*.*",0</b> <br>
<b>
db "Text Files",0,"*.txt",0,0</b></blockquote>
Note that All four strings are zero terminated. The first string is the description
of the following string. The actual pattern is the even number string, in this
case, "*.*" and "*.txt". Actually we can specify any pattern we want here. We
MUST put an extra zero after the last pattern string to denote the end of the
filter string. Don't forget this else your dialog box will behave strangely.
<p><b> mov
ofn.lpstrFile, OFFSET buffer</b> <br>
<b> mov
ofn.nMaxFile,MAXSIZE</b>
<p>We specify where the dialog box will put the filename that the user selects.
Note that we must specify its size in nMaxFile member. We can later extract
the filename from this buffer.
<p><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>
<p>Flags specifies the characteristics of the dialog box. <br>
OFN_FILEMUSTEXIST and OFN_PATHMUSTEXIST flags demand that the filename
and path that the user types in the filename edit control MUST exist. <br>
OFN_LONGNAMES flag tells the dialog box to show long filenames. <br>
OFN_EXPLORER flag specifies that the appearance of the dialog box must be explorer-like.
<br>
OFN_HIDEREADONLY flag hides the read-only checkbox on the dialog box. <br>
There are many more flags that you can use. Consult your Win32 API reference.
<p><b> mov
ofn.lpstrTitle, OFFSET OurTitle</b>
<p>Specify the title of the dialog box.
<p><b> invoke
GetOpenFileName, ADDR ofn</b>
<p>Call the GetOpenFileName function. Passing the pointer to the ofn structure
as its parameter. <br>
At this time, the open file dialog box is displayed on the screen. The function
will not return until the user selects a file to open or presses the cancel
button or closes the dialog box. <br>
It 'll return the value TRUE in eax if the user selects a file to open. It returns
FALSE otherwise.
<p><b> .if eax==TRUE</b>
<br>
<b>
invoke lstrcat,offset OutputString,OFFSET FullPathName</b> <br>
<b>
invoke lstrcat,offset OutputString,ofn.lpstrFile</b> <br>
<b>
invoke lstrcat,offset OutputString,offset CrLf</b> <br>
<b>
invoke lstrcat,offset OutputString,offset FullName</b>
<p>In case the user selects a file to open, we prepare an output string to be
displayed in a message box. We allocate a block of memory in OutputString variable
and then we use an API function, lstrcat, to concatenate the strings together.
In order to put the strings into several lines, we must separate each line with
a carriage return-line feed pair.
<p><b>
mov eax,ofn.lpstrFile</b> <br>
<b>
push ebx</b> <br>
<b>
xor ebx,ebx</b> <br>
<b>
mov bx,ofn.nFileOffset</b> <br>
<b>
add eax,ebx</b> <br>
<b>
pop ebx</b> <br>
<b>
invoke lstrcat,offset OutputString,eax</b>
<p>The above lines require some explanation. nFileOffset contains the index into
the ofn.lpstrFile. But you cannot add them together directly since nFileOffset
is a WORD-sized variable and lpstrFile is a DWORD-sized one. So I have to put
the value of nFileOffset into the low word of ebx and add it to the value of
lpstrFile.
<p><b>
invoke MessageBox,hWnd,OFFSET OutputString,ADDR AppName,MB_OK</b>
<p>We display the string in a message box.
<p><b>
invoke RtlZerolMemory,offset OutputString,OUTPUTSIZE</b>
<p>We must *clear* the OutputString before we can fill in another string. So we
use RtlZeroMemory function to do the job. <br>
<strong><br>
</strong>
<hr size="1">
<div align="center"> This article come from Iczelion's asm page, Welcom to <a href="http://asm.yeah.net">http://asm.yeah.net</a></div>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -