www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - GetOpenFileName

reply Scrappy <Scrappy_member pathlink.com> writes:
I need to get the file to open though the common Open File dialog box, so I have
the following with my headers:
#pragma comment(lib, "comdlg32")
Then theres a function called from WM_COMMAND in WndProc like this: 
if(LOWORD(wParam)==1003) { openExistingFile(hwnd); }
And the function looks like this:
int openExistingFile(HWND hwnd) {
OPENFILENAME ofn;

ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hInstance = hMainInstance;
ofn.hwndOwner = hwnd;
ofn.Flags = OFN_FILEMUSTEXIST; 
if(GetOpenFileName(&ofn)) { return 1; };

return 0;
}
hwnd is of course the hwnd parameter for WndProc, and hMainInstance is the
hIstance with which the main window was created.  It all compiles fine, but when
I select the appropriate item from the menu the programme closes.  There are no
error messages or such.  Any suggestions?
Jan 02 2004
next sibling parent reply Jan Knepper <jan smartsoft.us> writes:
Scrappy wrote:

 I need to get the file to open though the common Open File dialog box, so I
have
 the following with my headers:
 #pragma comment(lib, "comdlg32")
 Then theres a function called from WM_COMMAND in WndProc like this: 
 if(LOWORD(wParam)==1003) { openExistingFile(hwnd); }
 And the function looks like this:
 int openExistingFile(HWND hwnd) {
 OPENFILENAME ofn;
memset ( &ofn, 0, sizeof ( ofn ) ); // Might solve the problem.
 
 ofn.lStructSize = sizeof(OPENFILENAME);
 ofn.hInstance = hMainInstance;
 ofn.hwndOwner = hwnd;
 ofn.Flags = OFN_FILEMUSTEXIST; 
 if(GetOpenFileName(&ofn)) { return 1; };
 
 return 0;
 }
 hwnd is of course the hwnd parameter for WndProc, and hMainInstance is the
 hIstance with which the main window was created.  It all compiles fine, but
when
 I select the appropriate item from the menu the programme closes.  There are no
 error messages or such.  Any suggestions?
-- ManiaC++ Jan Knepper
Jan 02 2004
parent Scrappy <Scrappy_member pathlink.com> writes:
It works fine now! Thanks for ur help

In article <bt413l$2mtq$3 digitaldaemon.com>, Jan Knepper says...
Scrappy wrote:

 I need to get the file to open though the common Open File dialog box, so I
have
 the following with my headers:
 #pragma comment(lib, "comdlg32")
 Then theres a function called from WM_COMMAND in WndProc like this: 
 if(LOWORD(wParam)==1003) { openExistingFile(hwnd); }
 And the function looks like this:
 int openExistingFile(HWND hwnd) {
 OPENFILENAME ofn;
memset ( &ofn, 0, sizeof ( ofn ) ); // Might solve the problem.
 
 ofn.lStructSize = sizeof(OPENFILENAME);
 ofn.hInstance = hMainInstance;
 ofn.hwndOwner = hwnd;
 ofn.Flags = OFN_FILEMUSTEXIST; 
 if(GetOpenFileName(&ofn)) { return 1; };
 
 return 0;
 }
 hwnd is of course the hwnd parameter for WndProc, and hMainInstance is the
 hIstance with which the main window was created.  It all compiles fine, but
when
 I select the appropriate item from the menu the programme closes.  There are no
 error messages or such.  Any suggestions?
-- ManiaC++ Jan Knepper
Jan 02 2004
prev sibling parent ucampi newlogic.fr writes:
if(GetOpenFileName(&ofn)) { return 1; };
maybe you should do something more than a return otherwise it is normal that it does nothing
Apr 15 2004