VC Learning Data Collection (19): Using General Dialog

xiaoxiao2021-03-06  41

Use general dialog

Some general dialogs are provided in the Windows system such as the file selection dialog, as shown in the figure, the color selection dialog is as shown in the figure, the font selection dialog is as shown. CFILEDIALOG, CCOLORDIALOG, CFONTDIALOG are used in MFC. Generally speaking, you don't need to derive new classes, because base classes have provided common functions. And after you create and wait for the dialog, you can get the options in the dialog box through the member function. Use CFileDialog file selection dialog box: a first object and configured to provide the appropriate parameters as constructor function prototype: CFileDialog :: CFileDialog (BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWND * PPARENTWND = NULL); the parameters are as follows:

BopenfileDialog Displays the open dialog for TRUE, which displays the save dialog file dialog for False. LPSZDefext Specifies the default file extension. LPSZFileName Specifies the default file name. DWFlags indicates some specific styles. LPSZFilter is the most important parameter that indicates that the file type and the corresponding extension are available. Parameter formats such as "Chart files (* .xlc) | * .xlc | Worksheet files (* .xls) | * .xls | data files (* .xlc; *. Xls) | * .xlc; * .xls | all FILES (*. *) | *. * || "; File Type Description and Extension Demanitions | Separation, the extension of the same type file can be used; split, each file type | Separate, end | | Indicate. PParentWnd is a parent window pointer. Creating a file dialog You can use Domodal (), you can use the following function to get the user selection after returns:

CString cfiledialog :: getPathname () Get full file name, including directory name and extension, such as: c: /test/test1.txt cstring cfiledialog :: getFileName () Get full file name, including extension, such as: test1.txt cstring CFiledialog :: getExtName () Get full file extensions, such as: txt cstring cfiledialog :: getFileTitle () Get full file name, excluding directory names and extensions, such as: test1 position cfiledialog :: getStartPosition () For multiple The status of the file gets the first file location. CString CFiledialog :: GetNextPathname (Position & Pos) Get the next file location for the case where multiple files is selected and return to the current file name. But you must have called Position CfileDialog :: getStartPosition () to get the original position variable. CCOLORDIALOG color selection dialog: First constructed an object by ccolordialog :: ccolordialog (ColorRef Clrinit = 0, DWORD * PPARETWND = NULL), where CLRINIT is initial colors. Call the colorRef ccolorDialog :: getColor () get the color value selected by calling ColorRef ccolordialog :: getColor () after returning. CFontDialog font selection using the dialog box: First, construct an object and provide the appropriate parameters as constructor function prototype: CFontDialog :: CFontDialog (LPLOGFONT lplfInitial = NULL, DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS, CDC * pdcPrinter = NULL, CWnd * pParentWnd = NULL); Constructs an object, where the parameter LPLFINITIAL points to a logfong structure (this structure is described with respect to 2.2 Output text in the window), if the parameter is set to NULL means that the initial font is not set. PDCPrinter points to a DC object representing the printer device environment. If the parameter is set, the selected font is used for the printer. PParentWnd is used to specify the parent window. By calling the Domodal () creation dialog, you can get the user selection by calling the following functions: Void cfontdialog :: getCurrentFont (LPLogFont LPLF); used to get the properties of the selected font. This function has a parameter that is a pointer to the LogFont structure, and the function writes the various properties of the selected font to this LogFont structure. CSTRING CFONTDIALOG :: getfacename () get the name of the selected font. INT cfontdialog :: getSize () Get the size of the selected font (in 10 pixels). ColorRef cfontialog :: getColor () gets the color of the selected font. Bool CFONTDIALOG :: IsstrikeOut () BOOL CFONTDIALOG :: Isunderline () BOOL CFONTDIALOG :: Isbold () BOOL CFONTDIALOG :: Isbold () BOOL CFONTDIALOG :: isbold () BOOL CFONTDIALOG :: isbold () BOOL CFONTDIALOG :: isbold () BOOL CFONTDIALOG :: ISITALIC () gets the other attribute of the selected font, whether there is a delete line, whether there is a loop, whether it is a bold, Whether it is a bevel.

Copyright 怡 洋

转载请注明原文地址:https://www.9cbs.com/read-78492.html

New Post(0)