Re: [Dev-C++] Create DialogBox on demand
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Bruno B. <bbe...@cl...> - 2001-08-06 21:38:00
|
Hi, The GetOpenFilename function is what your looking for. BOOL GetOpenFileName(OPENFILNAME lpofn) The GetOpenFileName function creates a system-defined dialog box that enables the user to select a file to open. Parameters lpofn Points to an OPENFILENAME structure that contains information used to initialize the dialog box. When GetOpenFileName returns, this structure contains information about the user's file selection. Return Value If the user selects a file to open, the return value is TRUE. It is FALSE if an error occurs, the user chooses the Cancel button, the user chooses the Close command on the System menu to close the dialog box, or the buffer identified by the lpstrFile member of the OPENFILENAME structure is too small to contai= n the string that specifies the selected file. The OPENFILENAME structure contains information the operating system uses to initialize the system-defined Open or Save As dialog box. After the user closes the dialog box, the system returns information about the user's selection in this structure. Members of OPENFILENAME structure: lStructSize Specifies the length, in bytes, of the structure. hwndOwner Identifies the window that owns the dialog box. This member can be any valid window handle, or it can be NULL if the dialog box has no owner. hInstance Identifies a data block that contains a dialog box template specified by the lpTemplateName member (if the Flags member is set to OFN_ENABLETEMPLATE). Identifies the memory object containing a dialog box template (if Flags i= s set to OFN_ENABLETEMPLATEHANDLE). If neither OFN_ENABLETEMPLATE nor OFN_ENABLETEMPLATEHANDLE is set, this member is ignored. lpstrFilter Points to a buffer containing pairs of null-terminated filter strings. Th= e first string in each pair describes a filter (for example, "Text Files"), and t= he second specifies the filter pattern (for example, "*.TXT"). Multiple filters can be specified for a single item by separating the filter pattern strings with a semicolon (for example, "*.TXT;*.DOC;*.BAK"). The last string in the buff= er must be terminated by two NULL characters. If this member is NULL, the dialog box will not display any filters. The filter strings are assumed to be in the proper order =BE the operating system does not change the order. lpstrCustomFilter Points to a buffer containing a pair of user-defined filter strings. The first string describes the filter, and the second specifies the filter pattern (for example "WinWord, *.docnn"). The buffer is terminated by two NULL characters. The operating system copies the strings to the buffer when the user close= s the dialog box. The system uses the strings to initialize the user-defined fi= le filter the next time the dialog box is created. If this member is NULL, t= he dialog box lists but does not save user-defined filter strings. Windows 95: If this member is NULL, the member is ignored. If this member is not NULL, the value of the nMaxCustFilter member is use= d to determine the length of the corresponding string. nMaxCustFilter Specifies the size, in bytes or characters, of the buffer identified by lpstrCustomFilter. This buffer should be at least 40 characters long. Thi= s member is ignored if lpstrCustomFilter is NULL or points to a NULL string. Windows 95: The value of nMaxcustFilter is used whenever lpstrCustomFilte= r is defined. nFilterIndex Specifies an index into the buffer pointed to by lpstrFilter. The system uses the index value to obtain a pair of strings to use as the initial filter description and filter pattern for the dialog box. The first pair of strings has an index value of 1. When the user closes the dialog box, the system copi= es the index of the selected filter strings into this location. If nFilterIndex = is zero, the custom filter is used. If nFilterIndex is zero and lpstrCustomFilter is NULL, the system uses the first filter in the buffer identified by lpstrFilter. If all three members are zero or NULL, the system does not u= se any filters and does not show any files in the file list control of the dialo= g box. lpstrFile Points to a buffer that contains a filename used to initialize the File Name edit control. The first character of this buffer must be NULL if initialization is not necessary. When the GetOpenFileName or GetSaveFileName function returns, this buffer contains the drive designator, path, filename, and extension = of the selected file. If the buffer is too small, the dialog box procedure copies the required size into this member. nMaxFile Windows NT: Specifies the size, in characters, of the buffer pointed to b= y lpstrFile. The GetOpenFileName and GetSaveFileName functions return FALSE if the buffer is too small to contain the file information. The buffer should be at least 256 characters long. This member is ignored if lpstrFile is NULL. Windows 95: Specifies the size in bytes or characters of the buffer point= ed to by lpstrFile. The buffer should be at least 260 charcters long. this memb= er is ignored if lpstrFile is NULL. lpstrFileTitle Points to a buffer that receives the title of the selected file. For Windows versions 3.0 and 3.1, this buffer receives the filename and extension without path information. The application should use this string to display the file title. If this member is NULL, the function does not copy the file title. nMaxFileTitle Specifies the maximum length of the string that can be copied into the lpstrFileTitle buffer. This member is ignored if lpstrFileTitle is NULL. lpstrInitialDir Points to a string that specifies the initial file directory. If this member is NULL, the system uses the current directory as the initial directory. lpstrTitle Points to a string to be placed in the title bar of the dialog box. If th= is member is NULL, the system uses the default title (that is, "Save As" or "Open"). Flags Specifies the dialog box creation flags. This member may be a combination of the following flags: Flag Meaning OFN_ALLOWMULTISELECT Specifies that the File Name list box allows multiple selections. (If the dialog box is created by using a private template, the definition of the File Na= me list box must contain the LBS_EXTENDEDSEL value.)Specifies that the File Name list box allows multiple selections. If the dialog box is created by using a private template, the definition of the File Name list box must contain the LBS_EXTENDEDSEL value.When this flag is set, the lpstrFile member points = to a buffer containing the path to the current directory and all filenames in the selection. The first filename is separated from the path by a space. Each subsequent filename is separated by one space from the preceding filename. Note that for the new Explorer-style dialogs (dialogs that have the OFN_EXPLOR= ER flag set), a single null character, \0, separates the filenames, and two null characters, \0\0, terminate the entire string. OFN_CREATEPROMPT Specifies that the dialog box function should ask whether the user wants = to create a file that does not currently exist. (This flag automatically use= s the OFN_PATHMUSTEXIST and OFN_FILEMUSTEXIST flags.) OFN_ENABLEHOOK Enables the hook function specified in the lpfnHook member. OFN_ENABLETEMPLATE Causes the operating system to create the dialog box by using the dialog box template identified by hInstance and lpTemplateName. OFN_ENABLETEMPLATEHANDLE Indicates that hInstance identifies a data block that contains a preloade= d dialog box template. The operating system ignores lpTemplateName if this flag is specified. OFN_EXPLORER Creates an Open or Save As dialog box that uses user-interface features similar to the Windows Explorer. OFN_EXTENSIONDIFFERENT Specifies that the user typed a filename extension that differs from the extension specified by lpstrDefExt. The function does not use this flag i= f lpstrDefExt is NULL. OFN_FILEMUSTEXIST Specifies that the user can type only names of existing files in the File Name entry field. If this flag is specified and the user enters an invalid nam= e, the dialog box procedure displays a warning in a message box. If this flag is specified, the OFN_PATHMUSTEXIST flag is also used. OFN_HIDEREADONLY Hides the Read Only check box. OFN_LONGNAMES Causes the Open or Save As dialog box to display long filenames. If this flag is not specified, the dialog box displays filenames in 8.3 format. This valu= e is ignored if OFN_EXPLORER is set. OFN_NOCHANGEDIR Restores the current directory to its original value if the user changed the directory while searching for files. OFN_NODEREFERENCELINKS Directs the dialog box to return the path and filename of the selected shortcut (.LNK) file. If this value is not given, the dialog box returns the path and filename of the file referenced by the shortcut. OFN_NOLONGNAMES Specifies that long filenames are not displayed in the File Name list box. This value is ignored if OFN_EXPLORER is set. OFN_NONETWORKBUTTON Hides and disables the Network button. OFN_NOREADONLYRETURN Specifies that the returned file does not have the Read Only check box checked and is not in a write-protected directory. OFN_NOTESTFILECREATE Specifies that the file is not created before the dialog box is closed. This flag should be specified if the application saves the file on a create-nonmodify network sharepoint. When an application specifies this flag, the library does not check for write protection, a full disk, an open drive door, or netwo= rk protection. Applications using this flag must perform file operations carefully, because a file cannot be reopened once it is closed. OFN_NOVALIDATE Specifies that the common dialog boxes allow invalid characters in the returned filename. Typically, the calling application uses a hook function that checks the filename by using the FILEOKSTRING message. If the text box in the ed= it control is empty or contains nothing but spaces, the lists of files and directories are updated. If the text box in the edit control contains anything else, nFileOffset and nFileExtension are set to values generated by parsi= ng the text. No default extension is added to the text, nor is text copied to th= e buffer specified by lpstrFileTitle. If the value specified by nFileOffset is less than zero, the filename is invalid. Otherwise, the filename is valid, and nFileExtension and nFileOffset can be used as if the OFN_NOVALIDATE flag had not been specified. OFN_OVERWRITEPROMPT Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file. OFN_PATHMUSTEXIST Specifies that the user can type only valid paths and filenames. If this flag is used and the user types an invalid path and filename in the File Name ent= ry field, the dialog box function displays a warning in a message box. OFN_READONLY Causes the Read Only check box to be checked initially when the dialog bo= x is created. This flag indicates the state of the Read Only check box when th= e dialog box is closed. OFN_SHAREAWARE Specifies that if a call to the OpenFile function fails because of a network sharing violation, the error is ignored and the dialog box returns the given filename. If this flag is not specified, the registered message for SHAREVISTRING is sent to the hook function with a pointer to a null-terminated string for the path and filename in the lParam parameter. OFN_SHOWHELP Causes the dialog box to show the Help button. The hwndOwner member must not be NULL if this option is specified. nFileOffset Specifies a zero-based offset from the beginning of the path to the filename in the string pointed to by lpstrFile. For example, if lpstrFile points to t= he following string, "c:\dir1\dir2\file.ext", this member contains the value 13. nFileExtension Specifies a zero-based offset from the beginning of the path to the filename extension in the string pointed to by lpstrFile. For example, if lpstrFil= e points to the following string, "c:\dir1\dir2\file.ext", this member contains the value 18. If the user did not type an extension and lpstrDefExt is NULL, this member specifies an offset to the terminating null character. If the user typed "." as the last character in the filename, this member specifies 0. lpstrDefExt Points to a buffer that contains the default extension. GetOpenFileName a= nd GetSaveFileName append this extension to the filename if the user fails t= o type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member = is NULL and the user fails to type an extension, no extension is appended. lCustData Specifies application-defined data that the operating system passes to th= e hook function identified by lpfnHook. The system passes the data in the lParam parameter of the WM_INITDIALOG message. lpfnHook Points to a hook function that processes messages intended for the dialog box. An application must specify the OFN_ENABLEHOOK flag in the Flags member t= o enable the function; otherwise, the operating system ignores this structu= re member. The hook function should return FALSE to pass a message to the standard dialog box procedure or TRUE to discard the message. If the hook function processes WM_CTLCOLOR* messages (such as WM_CTLCOLORDLG), the function must return a valid brush handle for painting the background of the dialog box or the corresponding control. lpTemplateName Points to a null-terminated string that names the dialog box template to = be substituted for the standard dialog box template. An application can use the MAKEINTRESOURCE macro for numbered dialog box resources. This member is only used if Fla= gs specifies the OFN_ENABLETEMPLATE flag; otherwise, this member is ignored. |