Can anyone please show me how to use GetOpenFileName() ?
Thanks.
Printable View
Can anyone please show me how to use GetOpenFileName() ?
Thanks.
STFWQuote:
Originally posted by Devil Panther
Can anyone please show me how to use GetOpenFileName() ?
Thanks.
EDIT: As Eibro says. Code removed as it's copyrighted.
the example does not work, it doesn't even show the dialog box.
I have a feeling it's your code, and not the examples code. Are you checking the return values of all your calls? If you want another example, check www.sunlightd.com (It's the Windows tutorial, bitmap loading section)
I've placed the code so it will be used when a button is pressed, and changed the hwnd to my handle and everything, but it doesn't show the dialog...
Please wait while I attempt to use my telepathic powers to read the code off of your PC...
Or, if you don't want to wait as long, post some code.
Code:OPENFILENAME ofn;
char filename[256]={0};
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hDlg;
ofn.lpstrFilter = "Bitmap Files (*.bmp)\0*.bmp\0All Files (*.*\0*.*\0\0";
ofn.lpstrFile = filename;
ofn.nMaxFile = 256;
ofn.lpstrTitle = "Browse";
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
GetOpenFileName(&ofn);
From The Forgers Win32 API Tutorial
http://www.winprog.org/tutorial/
- SeanCode:OPENFILENAME ofn;
char szFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
if(GetOpenFileName(&ofn))
{
// Do something usefull with the filename stored in szFileName
}
*shrug* works fine for me. The only potential problem I can see is hDlg. Ensure that it's a valid window handle.
A stab in the dark, have you called InitCommonControls() somewhere?
here is the exact code:
hDlg is the handle of that dialog, I'm calling the GetOpenFileName() from...Code:// in the WM_COMMAND
case IDD_SETLOG_BROWSE:
{
OPENFILENAME ofn;
char szFileName[100] = "";
InitCommonControls();
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
ofn.hwndOwner = hDlg;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
ofn.lpstrFile = szFileName;
ofn.nMaxFile = 100;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.lpstrDefExt = "txt";
if(GetOpenFileName(&ofn))
{
MessageBox (NULL, "Message" , " ", 0);
}
}
break;
And I am calling InitCommonControls().
Just... one more thing, I'm using borland C++ 5.5 compiler. And C, not C++, I don't know, I'm just shooting in the dark as well
http://www.winprog.org/tutorial/
I've checked out their example code for GetOpenFileName()
I downloaded it (app_two) and tried to use FILE->OPEN, but nothing happened... maybe it's the windows?
With the last code you posted, did it put up the messagge box, i.e. is the call to GetOpenFileName() returning TRUE?
it returns false... and as I said, it doesn't even show the dialog...