Home > Back-end >  GetOpenFileName occasionally play file selection box, not the program card to death
GetOpenFileName occasionally play file selection box, not the program card to death

Time:11-22

As title, GetOpenFileName occasionally play file selection box, not the program card to death;
The code is as follows:
OPENFILENAME ofn={0};
ZeroMemory (& amp; Ofn, sizeof (ofn));

TCHAR strOpenFileNames [80 * MAX_PATH]={0};//used to receive the file name
TCHAR szPath [MAX_PATH];
TCHAR szFileName [80 * MAX_PATH];

Ofn. LStructSize=sizeof (OPENFILENAME);//structure size
Ofn. HwndOwner=GetForegroundWindow ();

Char type [MAX_PATH];
Memset (type, 0, sizeof (type));
String tmpType="File Type";
Memcpy (type, tmpType c_str (), tmpType. The length ());
Memcpy (type + tmpType. Length () + 1, fileType. C_str (), fileType. The length ());
Ofn. LpstrFilter=TEXT (" All the File \ 0 *. * \ 0 image
Files \ 0 *. JPG. *.jpg. *.jpeg; *. JPEG. *. BMP; *. BMP; *. PNG; *.png; *. Docx; *. XLSX; *. XLS; *.txt. *. PPT; *. The PPTX \ \ 0 0 ");//set the filter

Ofn. LpstrFile=strOpenFileNames;
Ofn. LpstrFile [0]='\ 0';
Ofn. NMaxFile=sizeof (strOpenFileNames);
Ofn. LpstrInitialDir=NULL;
Char buf [MAX_PATH]="file selection";
Ofn. LpstrTitle=TEXT (buf);//use the system default title can be left blank
Ofn. Flags=OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER |
OFN_ALLOWMULTISELECT;

If (GetOpenFileName (& amp; Ofn))//occasionally run to here, don't play the file selection box, the program card here
{}

CodePudding user response:

Top,
Table heavy

CodePudding user response:

Use the CFileDialog need? GetOpenFileName this function use it may not seem like a lot,

CodePudding user response:

GetOpenFileName
The GetOpenFileName function creates an Open common dialog box that lets The user specify The drive, directory, and The name of a file or set of files to Open.

BOOL GetOpenFileName (
LPOPENFILENAME lpofn//address of structure with initialization
//data
);

The Parameters
Lpofn
Pointer to an OPENFILENAME structure that contains information, informs the to initialize the dialog box. The When GetOpenFileName returns, this structure contains information about the user 's file selection.
The Return Values
If the user specifies a filename and on the OK button, the return value is nonzero. The buffer pointed to by the lpstrFile member of the OPENFILENAME structure contains the full path and filename specified by the user.

If the user cancels the or closes the Open dialog box or an error occurs, the return value is zero. To get extended error information, call the CommDlgExtendedError function, which can return one of the following values:

CDERR_FINDRESFAILURE CDERR_NOHINSTANCE
CDERR_INITIALIZATION CDERR_NOHOOK
CDERR_LOCKRESFAILURE CDERR_NOTEMPLATE
CDERR_LOADRESFAILURE CDERR_STRUCTSIZE
CDERR_LOADSTRFAILURE FNERR_BUFFERTOOSMALL
CDERR_MEMALLOCFAILURE FNERR_INVALIDFILENAME
CDERR_MEMLOCKFAILURE FNERR_SUBCLASSFAILURE


Few
Beginning with Windows 95 and Windows NT version 4.0, the default Open dialog box provides a user interface - the features that are similar to the Windows Explorer, You can dojo.provide an OFNHookProc hook procedure for an Explorer - style the Open dialog box. To enable the hook procedure, set the OFN_EXPLORER and OFN_ENABLEHOOK flags in the flags member of the OPENFILENAME structure and specify the address of the hook procedure in the lpfnHook member.

Windows 95 and Windows NT continue to support the old - style the Open dialog box for applications that want to maintain a user - interface consistent with the Windows or Windows NT 3.51 3.1 user - interface. To display the old - style the Open dialog box, enable the an OFNHookProcOldStyle hook procedure and ensure that the OFN_EXPLORER flag is not set.

To display a dialog box that allows the user To select a directory home a file, call theSHBrowseForFolder function.

Windows CE: Not all members of the OPENFILENAME structure are defined in the Windows CE. For information about the defined members, see the reference topic For OPENFILENAME structure.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: the Requires version 1.0 or later.
Header: Declared in commdlg. H.
The Import Library: Use comdlg32. Lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

See Also
Common Dialog Box Library the Overview, Common Dialog Box Functions provides, CommDlgExtendedError, GetSaveFileName, OFNHookProc, OFNHookProcOldStyle, OPENFILENAME, SHBrowseForFolder


CodePudding user response:

Pay attention to the ofn. HwndOwner=GetForegroundWindow ();
GetForegroundWindow is not necessarily your program window

CodePudding user response:

refer to the second floor light bamboo hat reply:
convert CFileDialog mine? GetOpenFileName this function use, it may not seem like a lot of


This is the method of MFC, I want to use the standard C/C + +

CodePudding user response:

reference 4 floor zgl7903 response:
note under ofn. HwndOwner=GetForegroundWindow ();
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related