Thread: GetOpenFileName()

  1. #1
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916

    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
    Last edited by confuted; 08-06-2003 at 11:32 AM.
    Away.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Are you, by any chance, using bcc5.5 cmd line tools on win98/NT?

    If you are, please read this first.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    MSVC 6 / Win XP
    Away.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>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.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    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
    Last edited by confuted; 08-06-2003 at 01:50 PM.
    Away.

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    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).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    char fn[256]=""; did it Thanks.
    Away.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GetOpenFileName not working...
    By manugarciac in forum Windows Programming
    Replies: 6
    Last Post: 04-24-2007, 10:50 PM
  2. GetOpenFileName function for dir's?
    By willc0de4food in forum Windows Programming
    Replies: 3
    Last Post: 04-15-2006, 12:54 AM
  3. Major Problems with GetSaveFileName() and GetOpenFileName()
    By CodeHacker in forum Windows Programming
    Replies: 8
    Last Post: 07-12-2004, 11:05 AM
  4. Troubles with GetOpenFileName()
    By lyx in forum Windows Programming
    Replies: 13
    Last Post: 10-28-2003, 09:47 PM
  5. GetOpenFileName() won't show
    By harryP in forum Windows Programming
    Replies: 1
    Last Post: 10-20-2003, 04:47 PM