Results 1 to 19 of 19

Thread: CommonDialog in VC++

  1. #1

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    I have this piece of code and Juz wandering why my OpenDialog won't show up?

    Code:
    					OPENFILENAME ofn;       // common dialog box structure
    					char szFile[260];       // buffer for file name
    	
    					// Initialize OPENFILENAME
    					ZeroMemory(&ofn, sizeof(OPENFILENAME));
    					ofn.lStructSize = sizeof(OPENFILENAME);
    					ofn.hwndOwner = hWnd;
    					ofn.lpstrFile = szFile;
    					ofn.nMaxFile = sizeof(szFile);
    					ofn.lpstrFilter = "MiniGIS map (*.map)\0 *.map\0";
    					ofn.nFilterIndex = 1;
    					ofn.lpstrFileTitle = NULL;
    					ofn.nMaxFileTitle = 0;
    					ofn.lpstrInitialDir = NULL;
    					ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; 
    
    					// Display the Open dialog box. 
    					if (GetOpenFileName(&ofn)==TRUE)
    					{
    						MessageBox(hWnd,"User was click the cancel button","Test",MB_OK);
    					}
    					else
    					{	
    						MessageBox(hWnd,ofn.lpstrFile,ofn.lpstrFile,MB_OK); 
    					} 
    
    					break;
    But same method in VB, it does work perfectly.

    [code]

  2. #2
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Your code worked for me. You might want to be sure your hWnd is actually there when you call this function and not 0x00000000. You also might want to set through your program and see if it has a problem with one of your calls in that function.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  3. #3
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Also you want to add:

    Code:
    char szFile[260];
    strcpy(szFile, "");
    To clear out your file name buffer.

    And Change:
    Code:
    // Display the Open dialog box. 
    					if (!GetOpenFileName(&ofn))
    					{
    						MessageBox(hWnd,"User was click the cancel button","Test",MB_OK);
    					}
    					else
    					{	
    						MessageBox(hWnd,ofn.lpstrFile,ofn.lpstrFile,MB_OK); 
    					}
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Well I think you have to include commctrl.lib and commctrl.h ?
    and use InnitCommonControlsEx api?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    That's for the common controls, not the common dialogs [sic].
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  6. #6
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    ahh sometimes I think I'm silly

    maybe it's the beer.. I heard common, so my brain automaticly thought about common controls
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Hehe
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    I did included the commdlg.h in my cpp file and linked the commdlg32.lib in my settings as well.

    What I encounter is the GetOpenFileName(&ofn)==TRUE always return a TRUE.

    Also, I run this under Win2K Pro platform. Will this cause any error.

    Mean while I also, load the color dialog box and it work greate. Juz wandering what the Open File Dialog.

    Code:
    	CHOOSECOLOR cc;                 // common dialog box structure 
    	static COLORREF acrCustClr[16]; // array of custom colors 
    	HBRUSH hbrush;                  // brush handle
    
    	// Initialize CHOOSECOLOR 
    	ZeroMemory(&cc, sizeof(CHOOSECOLOR));
    	cc.lStructSize = sizeof(CHOOSECOLOR);
    	cc.hwndOwner = hWnd;
    	cc.lpCustColors = (LPDWORD) acrCustClr;
    	cc.rgbResult = Color;
    	cc.Flags = CC_FULLOPEN | CC_RGBINIT;
    
    	if (ChooseColor(&cc)==TRUE) 
    	{
    		hbrush = CreateSolidBrush(cc.rgbResult);
    		Color = cc.rgbResult; 
    		/*
    		char	colorcode[16];
    		memset(colorcode,0,16);
    		sprintf(colorcode,"%s%ld", "User have selected color code ", cc.rgbResult);
    		MessageBox(hWnd,colorcode,"Choose Color", MB_OK);
    		*/
    		
    		//Refresh the Map
    		RefreshMap();
    	}
    	else
    	{
    		//MessageBox(hWnd,"User cancel the selection","Choose Color", MB_OK);
    	}					
    
    	break;
    Technocrat, thanks for your advice and I'll try it out and back to you later

  9. #9
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    It should always return TRUE unless cancel or the X is pressed. I got it to work fine with

    Code:
    if(GetOpenFileName(&ofn))    //True
    if(!GetOpenFileName(&ofn))  //False
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  10. #10

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Technocrat, you mean your Open Dialog was show on the screen?

  11. #11
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Originally posted by Technocrat
    Your code worked for me.
    If you want you can zip your project and post it and I will take a look at it.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  12. #12

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Technocrat, enclose is my sample project. Please click the File menu and look for the Open for Open File Dialog and Color for Open Color dialog.

    Thanks fr your time to look into my code )
    Attached Files Attached Files

  13. #13
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    No problem.

    Ok all you need to do is add this line:

    Code:
    char szFile[260];       // buffer for file name
    strcpy(szFile,"");
    And I would change to
    Code:
    if (!GetOpenFileName(&ofn))
    					{
    						MessageBox(hWnd,"User was click the cancel button","Test",MB_OK);
    					}
    					else
    					{	
    						MessageBox(hWnd,ofn.lpstrFile,ofn.lpstrFile,MB_OK); 
    					}
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  14. #14

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Wow... thanks Technocrat, it work perfectly and that what I wish to do too.

    Juz wanna to know why there must do the strcpy first?
    Code:
        strcpy(szFile,"");
    regasrds,
    Chris.C

  15. #15
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Clears out your buffer. With Win2000 for some reason, I dont know, if that is not cleared out it doesn't work. With Win98 it worked, it was just full of NULL chars, and was messy.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  16. #16

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    So, can I juz use the memset to fill it up will all NULL value?

    Yet, it is not stated in MSDN too

  17. #17
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    Umm I guess you could if you wanted to. But I would think that strcpy would be overall a little bit faster. But either way will get you the same thing.

    I noticed that with any of the MSDN examples I saw that it did not show NULL the buffer before hand. I dunno why.
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  18. #18

    Thread Starter
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Technocrat, but anyway, thanks a lot for your help that make my open file dialog work as what I wish )

  19. #19
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    No problem, I know what its like when you can get stuff to work right. Always glad to help when I can
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width