📄 tut11.html
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Iczelion">
<meta name="GENERATOR" content="Mozilla/4.51 [en] (Win95; I) [Netscape]">
<title>Iczelion's Win32 Assembly Tutorial 10: More about Dialog Box</title>
</head>
<body text="#FFFFFF" bgcolor="#000000" link="#FFFF00" vlink="#C0C0C0" alink="#C0FFC0">
<center>
<h1>
<font face="Arial,Helvetica"><font color="#999900">Tutorial 11: More about
Dialog Box</font></font></h1></center>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>We will
learn more about dialog box in this tutorial. Specifically, we will explore
the topic of how to use dialog boxs as our input-output devices. If you
read the previous tutorial, this one will be a breeze since only a minor
modification is all that's needed to be able to use dialog boxes as adjuncts
to our main window. Also in this tutorial, we will learn how to use common
dialog boxes.</font></font></font><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<p><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Download
the dialog box examples <a href="files/tut11-1.zip">here</a> and <a href="files/tut11-2.zip">here</a>.
Download Common Dialog Box example
<a href="files/tut11-3.zip">here</a>.</font></font></font>
<h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=+0>Theory:</font></font></font></h3>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Very little
is to be said about how to use dialog boxes as input-output devices of
our program. Your program creates the main window as usual and when you
want to display the dialog box, just call CreateDialogParam or DialogBoxParam.
With DialogBoxParam call, you don't have to do anything more, just process
the messages in the dialog box procedure. With CreateDialogParam, you must
insert IsDialogMessage call in the message loop to let dialog box manager
handle the keyboard navigation in your dialog box for you. Since the two
cases are trivial, I'll not put the source code here. You can download
the examples and examine them yourself, <a href="files/tut11-1.zip">here</a>
and <a href="files/tut11-2.zip">here</a>.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Let's
go on to the common dialog boxes. Windows has prepared predefined dialog
boxes for use by your applications. These dialog boxes exist to provide
standardized user interface. They consist of file, print, color, font,
and search dialog boxes. You should use them as much as possible. The dialog
boxes reside in comdlg32.dll. In order to use them, you have to link to
comdlg32.lib. You create these dialog boxes by calling appropriate functions
in the common dialog library. For open file dialog, it is GetOpenFileName,
for save as dialog it is GetSaveFileName, for print dialog it is PrintDlg
and so on. Each one of these functions takes a pointer to a structure as
its parameter. You should look them up in Win32 API reference. In this
tutorial, I'll demonstrate how to create and use an open file dialog.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Below
is the function prototype of GetOpenFileName function:</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<blockquote><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>GetOpenFileName
proto lpofn:DWORD</font></font></font></b></blockquote>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>You can
see that it receives only one parameter, a pointer to an OPENFILENAME structure.
The return value TRUE means the user selected a file to open, it's FALSE
otherwise. We will look at OPENFILENAME structure next.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<blockquote><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>OPENFILENAME
STRUCT</font></font></font></b>
<blockquote><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lStructSize
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> hwndOwner
HWND ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> hInstance
HINSTANCE ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpstrFilter
LPCSTR ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpstrCustomFilter
LPSTR ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> nMaxCustFilter
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> nFilterIndex
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpstrFile
LPSTR ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> nMaxFile
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpstrFileTitle
LPSTR ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> nMaxFileTitle
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpstrInitialDir
LPCSTR ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpstrTitle
LPCSTR ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> Flags
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> nFileOffset
WORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> nFileExtension
WORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpstrDefExt
LPCSTR ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lCustData
LPARAM ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpfnHook
DWORD ?</font></font></font></b>
<br><b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1> lpTemplateName
LPCSTR ?</font></font></font></b></blockquote>
<b><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>OPENFILENAME
ENDS</font></font></font></b></blockquote>
<font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Let's
see the meaning of the frequently used members.</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1></font></font></font>
<center><table BORDER WIDTH="100%" >
<tr>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>lStructSize</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The
size of the OPENFILENAME structure , in bytes</font></font></font></td>
</tr>
<tr>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>hwndOwner</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The
window handle of the open file dialog box.</font></font></font></td>
</tr>
<tr>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>hInstance</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Instance
handle of the application that creates the open file dialog box</font></font></font></td>
</tr>
<tr>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>lpstrFilter</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>The
filter strings in the format of pairs of null terminated strings.
The first string in each pair is the description. The second string is
the filter pattern. for example:</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
FilterString db "All Files (*.*)",0, "*.*",0</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>
db "Text Files (*.txt)",0,"*.txt",0,0</font></font></font>
<br><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Note
that only the pattern in the second string in each pair is actually used
by Windows to filter out the files. Also noted that you have to put an
extra 0 at the end of the filter strings to denote the end of it.</font></font></font></td>
</tr>
<tr>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>nFilterIndex</font></font></font></td>
<td><font face="Arial,Helvetica"><font color="#CCCCCC"><font size=-1>Specify
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -