-
GetOpenFileName()
I have a button (ID_LOADTEXTURE) in a window, and when the button is clicked, I would like to have an open file dialog pop up. I have the following code in the window proc... can someone tell me where I went wrong? (the open dialog doesn't open)
Code:
LRESULT CALLBACK WindowProcedure(HWND hWindow, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
char filename[64];
char fn[256];
char filefilter[]="Bitmaps\0*.bmp\0DDS files\0*.dds\0GIF files
\0*.gif\0JPEGs\0*.jpg\0PNG files\0*.png\0TGA files\0*.tga\0\0\0";
OPENFILENAME fname;
switch (uMessage)
{
case WM_COMMAND:
switch (LOWORD(wparam))
{
/*...*/
case ID_LOADTEXTURE:
fname.lStructSize=sizeof(OPENFILENAME);
fname.hwndOwner=hWindow;
fname.lpstrFilter=filefilter;
fname.nFilterIndex = 1;
fname.lpstrFile = fn;
fname.nMaxFile = sizeof(fn);
fname.lpstrFileTitle = filename;
fname.nMaxFileTitle = sizeof(filename)-1;
fname.Flags = OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
fname.lpstrCustomFilter = NULL;
fname.lpstrInitialDir = NULL;
fname.lpstrTitle = NULL;
fname.lpstrDefExt = NULL;
fname.lCustData = 0;
if(!GetOpenFileName(&fname))
break;
/*...*/
Thanks
-
Are you, by any chance, using bcc5.5 cmd line tools on win98/NT?
If you are, please read this first.
-
-
>>MSVC 6 / Win XP<<
Ah, well - worth a try. ;)
What does CommDlgExtendedError return?
edit: Sorry, i'm not using windows just now so can't test your code myself. :(
-
It returns 12290... I'll edit this post as soon as I figure out which error code that is. I haven't had time for the if statements yet.
edit:
FNERR_INVALIDFILENAME
-
Try strcpy (or lstrcpy) an empty string into your 'fn' variable prior to using it.
I have a vague recollection that the open/save common dialog doesn't like anything other than a valid string passed as that (fname.lpstrFile) parameter (I don't think NULL works either).
-
char fn[256]=""; did it :) Thanks.