Preliminary study on new elements of OpenFileName

zhaozj2021-02-17  50

Starting from Windows Me, Windows 2000, the OpenFileName structure for getopenfilename () and getSaveFileName () functions adds three new elements. Let's take a look at:

Type OPENFILENAME lStructSize As Long hWndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String '#if (_WIN32_WINNT> = 0x0500) pvReserved As Long dwReserved As Long FlagsEx As Long' #endif // (_WIN32_WINNT> = 0x0500) End Type

About new elements pvreserved, dwreserved is not difficult to see is reserved, may have not completed the relevant functionality when Windows Me, Windows 2000 is released, so ... However, the FlagSex element is a parameter OFN_EX_NOPLACESBAR (1). Set this bit tag to close the shortcut bar left on the Windows 2000 (or Windows Me) "Open File" dialog. This shortcut can save five shortcuts to specify their own shortcuts by modifying the registry. As for how to modify, not our topic today, so do not discuss it. However, in actual use, I found a question: the program using this new structure cannot be run on Windows 98/95 / NT4. The reason may be to set up a new three members when setting LSTRUCTSIZE, causing the structure length to increase 12 bytes, and the old version of COMDLG32.dll cannot be identified, misunderstanding the structural length error. The final result is "Open File" and "Save File" dialog box that cannot be displayed.

In view of this problem, we use the following ideas to resolve: Use the getVersionex () function to detect the Windows version, if not Windows Me, Windows 2000, then subtract 12 bytes after the length of the OpenFileName structure is used, and then assign the value to lstructsize. In this way, the version of COMDLG32.DLL will ignore the new three elements. Practice, prove that this method is feasible.

Of course, we also consider that possible Windows 95/98 / NT4 has a new version of COMDLG32.DLL due to certain software installation, which can be used to use new features. So the best way is to detect the version of the comdlg32.dll itself, and then determine whether the length of the OpenFileName structure is to ignore the length of the new three elements.

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

New Post(0)