Tutorials to .com

Tutorials to .com » Database » Foxpro » Visual FoxPro to use the Common Dialogs control

Visual FoxPro to use the Common Dialogs control

Print View , by: iSee ,Total views: 49 ,Word Count: 2395 ,Date: Sat, 18 Apr 2009 Time: 7:39 AM

Common Dialogs Control III

If you used foxpro GETFILE () and PUTFILE () function. How much you might be a bit sorry for them:

  • There is no way to change the title of the dialog box.
  • PUTFILE () function is always asked whether users would like to cover pre-existing documents.
  • The use of two functions. The specified path must exist, otherwise an error message will appear.

In order to obtain greater flexibility. You need to use vfp 5 at the same time as the Common Dialogs control release (in the \ WINDOWS \ system directory of COMDLG32.OCX). The control referred to as "Common dialogs" because it can display a document. Color. Fonts, and Print dialog box. All of these VFP dialog box provides the same functionality than the greater flexibility. For example. When VFP use GETFONT () and GETCOLOR () function. Impossible to control all your things, such as non-TrueType font is available or users can customize the color. Common Dialog fonts and colors in the dialog box there is such a feature.

Because of time constraints. In this chapter we only focus on the file dialog. If you want to know on the colors, fonts, and Print dialog box for more information. Please refer to the help of ActiveX control files. Common Dialogs control attention does not appear in the Help file directory page. However, control can be selected after pressing the F1 key, or in helping in the search index "Common Dialog" to find them.

Common Dialogs five methods of control, they do not have parameters:

  • ShowOpen () show the open file dialog box;
  • ShowSave () display dialog box to save the file;
  • ShowPrinter () show the printer dialog box;
  • ShowFont () show the font dialog box;
  • ShowColor () show the color dialog box.

In this chapter, we use only the first two methods.

The following is the most commonly used documents Common Dialogs control the properties dialog box (some attributes are also used fonts, colors, and the printer dialog box); other attributes of the use of less information, see their help files:

  • CancelError: If you want to cancel when the user selects to generate an error (error No. 1429), set the attribute. T.. Error in control methods and to deal with moderate to capture the error. This is necessary because of the VFP in a similar function to return a special value (usually a space) to specify the user to choose to cancel, but they will not return the value of the dialog box.
  • DefaultExt: If the user does not enter the extension, the extension is automatically added to the file name entered by the user back.
  • DialogTitle: the title of dialog window.
  • FileName: the initial value for the file name, add the contents of it from the dialog box to return to the user input value. If not allowed to select multiple documents, or that allow users to select only a file, FileName file contains a complete selection of the path and file name. If you select multiple documents and allow the user to choose more than one file, FileName selected before the list of files containing a separator to separate with the selected document, the selected file path (multiple files to separate between the separator, However, without the path). In Windows 95 and NT 4 in the separator is a CHR (0), in Windows NT 3.51 in the separator is a space. For example, if the user data from the VFP directory of the sample chose the three tables, FileName may be the contents of C: \ VFP5 \ SAMPLES \ DATA <separator> CUSTOMER.DBF <separator> ORDERS.DBF <separator> ORDITEMS. DBF ". on the decomposition of the path and FileName for a different file name, see SFFileDialog category SetProperties () method (described later).
  • FileTitle: if not allowed to select multiple files and return to the selected document does not contain the path name. Otherwise, the return value is empty.
  • Filter: acceptable documentation. Filter has two parts: the user see that (for example, "database file") and these documents describe the extension (such as "*. DBC"). Description and description of a vertical bar (|) separate. Separated by a number of vertical lines can be used to provide more than one filter. For example, "database file | *. DBC | Table | *. DBF | All documents | *.*"。
  • FilterIndex: use the default filter. Filter the first attribute is 1.
  • Flags: The properties dialog box to control the appearance and behavior. The value can be used see below.
  • HelpFile: dialog box when the user clicks the help button in the Help file using the name.
  • HelpCommand: The attribute set is the most commonly used (see the other settings to help control file) 0x1 (use HelpContextID), 0x101 (using keywords), or 0x105 (using some keywords). Note: 0x symbols, is a new feature VFP 5 to specify a hexadecimal value.
  • HelpContext: When the value of HelpCommand set to 0x1, it is necessary to display the Help file in the theme of HelpContextID.
  • HelpKey: When the value of HelpCommand set to 0x101 or 0x105, it is necessary to look in the Help file keywords.
  • InitDir: dialog box to display the initial directory.

Note that to help the other two attributes, Path and Drive, but they do not exist.

Flags attribute of the action and VFP's MESSAGEBOX () is similar to the DialogBoxType parameters; can you need to add value to a number of different combinations of its appearance and behavior. Unfortunately, even if the flag for the various types of dialog box has the same meaning, but it may have different values.

For example, show the help button is the flag for the color dialog box for the File Dialog 0x8 is 0x10.

Because all of the settings dialog box rather mysterious, I created a file called that contains the COMMDLG.H used to define all the constants of different values. Flags to set control properties, simple to add the group you want to set a value to.

For example, to show the help button and the cover warning, it can be set:


The following is the most common Flags option (see the other help files):

  • Allow Multiple File Selection (0x200; cnFILEDLG_MULTIPLE in COMMDLG.H file): Allow to select multiple files. If the switch opens, the dialog box appearance and in general quite different from Windows 95 dialog box, unless you also add a 0x80000 (cnFILEDLG_EXPLORER) of the Flags; attention to help document the value is wrong 0x8000.
  • Prompt if File Doesn't Exist (0x2000; cnFILEDLG_PROMPTNEW): prompts the user to create a document that does not yet exist at present. If this option is open, you do not need to open "Path Must Exist" and "File Must Exist" signs, because they are automatically set ( "Path Must Exist" and open the "File Must Exist" off). The Save dialog box not being used for signs.
  • File Must Exist (0x1000; cnFILEDLG_FILEEXIST): If the user enters the file name does not exist, display an error message. If this option open, "Path Must Exist" symbol automatically open. The Save dialog box not being used for signs.
  • Path Must Exist (0x800; cnFILEDLG_PATHEXIST): If the user enters the path does not exist, display an error message. VFP's GETFILE () and PUTFILE () function of the switch is open forever, and this may be why you have to choose Common Dialogs control the reasons why.
  • Hide Read Only (0x4; cnFILEDLG_HIDERO): Hidden dialog box in the "Read Only" checkbox.
  • Help Button (0x10; cnFILEDLG_SHOWHELP): Help in the dialog box button.
  • Overwrite Prompt (0x2; cnFILEDLG_OVERWRITE): If the user enters a file name already exists, indicating a "coverage of the document" Information. The logo for the Save dialog box only. VFP's PUTFILE () function is always to maintain the switch to open, this may be why you should choose Common Dialogs control of another reason.
  • share Aware (0x4000; cnFILEDLG_SHAREAWARE): allows the user to select an application has been open to other documents.
  • Don't Change Directory (0x8; impermanence definition): File dialog box will do something you may not want to do: If the user chose a different directory the current directory in the dialog box to withdraw from, the directory will become the current directory. This setting can avoid the situation.

Common Dialogs derived

Common Dialogs control to make it easier to use, I created an abstract of the control sub-class called SFCommonDialog (in the source code Library ACTIVEX.VCX). SFCommonDialog with two new custom attributes: lShowHelpButton (set it. T. to show the help button) and lCancelled (If the user cancels the dialog box, set it. T.). There is also a new method of self-definition (SetFlags) to set some properties, so that we can see whether the user chose the Cancel dialog box. LCancelled settings for custom properties. T. When, Error method to deal with the situation the user choose to cancel (CancelError automatically set to. T. so the user can choose to cancel, the trigger an error).

I also created a SFCommonDialog the SFFileDialog called sub-categories, for specific file dialog. COMMDLG.H include file SFFileDialog use. It has a number of custom attributes for the Flags property for the provision of different options, so you do not have to remember what settings for what constant. These attributes, by default are set to. F., they are lAllowMultiple, lFileMustExist, lOverWritePrompt, lPathMustExist, lPromptNew, lShareAware and lShowReadOnly. Another custom attributes, cPath, set to the user to choose the file name in the path. cOldCurrDir is a protected custom attributes for the dialog box before calling for the preservation of the current directory. An array of custom attributes, aFiles, to save the user to choose to save the file name (no path). Since the definition of the two methods OpenFile () and SaveFile () to display the appropriate dialog box. The two method calls SaveDirectory () and RestoreDirectory () custom method to save and restore the current directory, SetFlags () mentioned previously set custom attributes to the Flags property is set to appropriate value, SetProperties () properly set up cPath, lCancelled and aFiles attributes.

Well, now we have created it, SFFileDialog What are the advantages? As long as I need to allow users to select a file, I use it. Because of its appearance and behavior to me than PUTFILE () or GETFILE () more control. For example, assume that your application has a function to import. If the user has three documents to import, you call PUTFILE () or GETFILE () three times right? When they can select multiple files and an import function so that a one-time processing, your application is even more obvious and easy to use, especially in dealing with more time-consuming, this advantage becomes more apparent.

Note here how to use the control. From the project manager to drag and drop an object SFFileDialog form. SFFileDialog is a non-visual control, so it will not appear at runtime in the form (if it displays a dialog box for the object is a non-visual category was very surprised to hear the dialog box to remember the method in control has not been called before not shown). By the need to control the various attributes. For example, to allow users to select multiple files, settings lAllowMultiple attribute. T., form the relevant button on the Click () method will be called SFFileDialog object OpenFile () method to display a dialog box to open the file. From the OpenFile () to return, it will check the property to determine lCancelled users are in the dialog box by pressing the Cancel button. If not, the code will be used aFiles (contains selected files) and cPath (include file where the directory name) to import file attributes. Looks like the code shown below:

with Thisform.oFileDialog. OpenFile () if not. lCancelled for lnI = 1 to alen (. aFiles) lcFile =. cPath +. aFiles [lnI] Thisform.ImportFile (lcFile) next lnI endif endwith

COMMDLG source code form is a dialog box open and save. It includes a SFFileDialog object, and form many ControlSource object attribute with the object. You can set up different signs and other property and click the "test" button in the dialog box to see the effect of the appearance and behavior.

Other Notes

VFP's GETFILE () and PUTFILE () function there are some Common Dialogs do not have control functions:

  • Can specify the file name appears next to the text to replace the default "File name". However, as specified in the text to show a very short (only 10 characters), so it does not matter much.
  • GETFILE () allows you to specify next to the button to open a message and specify whether to display a "new" or "no" button.
  • As I mentioned earlier, when the dialog box, select the cancellation, GETFILE () and PUTFILE () returns an empty file name. You can set up CancelError attribute. T. to deal with such situations and to capture No. 1429 error (typically FileTitle attribute set and FileName is empty).

FoxPro Tutorial Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.