Thread: Open dialog box issue

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    42

    Open dialog box issue

    Hi,

    i am using the GetOpenFileName and "OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_PATHMUSTEXIST" flags to enable the User to select a file of any type, but when i try to open a file with URL extension the dialog box hangs up( not responding ) !!

    Can you tell me please, how can i fix this issue?

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Jun 2008
    Location
    tampa
    Posts
    2
    Could you post a code snippet? It would be helpful to see how your OPEFILENAME struct is set up.

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    Code:
    		char szFile[512] = { "\0" };
    		OPENFILENAME ofn;
    
    		ZeroMemory( &ofn, sizeof( OPENFILENAME ) );
    
    		ofn.lStructSize		= sizeof( OPENFILENAME );
    		ofn.Flags		= OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON | OFN_PATHMUSTEXIST ;//| OFN_NODEREFERENCELINKS
    		ofn.lpstrFilter		= "*.*";
    		ofn.lpstrTitle		= _("Select a File");
    		ofn.lpstrFile		= (LPSTR)szFile;
    		ofn.nMaxFile		= sizeof( szFile );
    		ofn.lCustData		= (DWORD)NULL;
    		ofn.lpstrFileTitle	= NULL;
    		ofn.nMaxFileTitle	= NULL;
    
    		if ( GetOpenFileName( &ofn ) )
    		{
    			szSelectedFile->Append( ofn.lpstrFile );
    		}

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Been a while but IIRC...

    The strings must be NULL terminated and the filter has a special format (check MSDN) and has to be double null terminated.

    If the create fails call GetLastError() and check what went wrong.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    Quote Originally Posted by novacain View Post
    and has to be double null terminated.
    Now it works correctly
    Thanks for help.


    But i have another problem :
    I have created a shortcut by right-clicking the Dial-up connection under "Network Connections" and then selected "Create Shortcut" from the context menu. After that i have renamed the shortcut on the Desktop to Dailup.lnk

    I can open the shortcut using the previous Dialog Box but when i try after that to launch it with ShellExecuteEx i get the following error :
    The parameter is incorrect.
    In a messagebox.

    Do you have any idea why i am getting this error?
    Code:
    	SHELLEXECUTEINFO	sei;
    	ZeroMemory( &sei, sizeof( sei ) );
    	
    	sei.cbSize		= sizeof ( SHELLEXECUTEINFO );
    	sei.lpFile		= ofn.lpstrFile;
    	sei.lpVerb		= _T("open"); 
    	sei.fMask		= SEE_MASK_NOCLOSEPROCESS | SEE_MASK_NOZONECHECKS;
    	sei.nShow		= SW_SHOWNORMAL;
    
    	CoInitializeEx( NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE ); // Incase that "COM single-threaded apartment (STA) type" is needed
    
            ShellExecuteEx( &sei );

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Try setting the verb to NULL.

    As you are trying to launch a shortcut (.lnk file) the OS should then search the reg for the correct association and run the required process/application based on the target of the shortcut.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    42
    Thanks, it worked flawlessly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dialog box problem keeps haunting me
    By Bleech in forum Windows Programming
    Replies: 2
    Last Post: 08-23-2006, 01:12 AM
  2. Command to open the 'Open Dialog Box' found in most programs.
    By OmegaFirebolt in forum Windows Programming
    Replies: 5
    Last Post: 03-16-2003, 08:58 PM
  3. edit control in dialog box problems
    By Bajanine in forum Windows Programming
    Replies: 11
    Last Post: 11-11-2002, 06:55 PM
  4. Resize Dialog Box via Code :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 10-27-2002, 11:00 PM
  5. Dialog Box & Property Sheet :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 01:33 PM