Open/Save Dialog with BC++ 6.0

This is a discussion on Open/Save Dialog with BC++ 6.0 within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to get the Common Open/Save dialogs to come up but they won't display no matter what I try, ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    81

    Open/Save Dialog with BC++ 6.0

    I'm trying to get the Common Open/Save dialogs to come up but they won't display no matter what I try, I'm using Borland C++ Builder 6.0 and i've tryed just about all the examples with getopenfilename on this forum and msdn site I could find. Nothing works.
    Code:
      case ID_FILE_LOAD:
      {
          char FileName[MAX_PATH];
          OPENFILENAME ofn;
          ZeroMemory(&ofn, sizeof(ofn));
          ofn.lStructSize = sizeof(ofn);
          ofn.hwndOwner = hwnd;
          ofn.lpstrFile = FileName;
          ofn.lpstrFile[0] = '\0';
          ofn.nMaxFile = sizeof(FileName);
          ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
          ofn.nFilterIndex = 1;
          ofn.lpstrFileTitle = NULL;
          ofn.nMaxFileTitle = 0;
          ofn.lpstrInitialDir = NULL;
          ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
          GetOpenFileName(&ofn);
     } break;
    Last edited by ColdFire; 08-25-2003 at 05:55 PM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    ofn.lpstrFile = FileName;
    ofn.lpstrFile[0] = '\0';
    ofn.nMaxFile = sizeof(FileName);
    What you do here is point lpstrFile to FileName, then set the first charater of FileName to NULL, then calculating the length of FileName which will be 0 (cause you made it into a NULL string). The function call to GetOpenFileName() will fail since the buffer is too small to hold any data.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    And you should use strlen, not sizeof.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    I restored my working copy from my backups, this is what i used when I was using Borland C++ builder 5.02 and it worked fine, since i switched to Borland C++ builder 6 it compiles fine but does nothing, the problem i'm having now.
    Code:
          char FileName[MAX_PATH];
          OPENFILENAME ofn;
          ZeroMemory(&ofn, sizeof(ofn));
          static TCHAR Filter[]       =     "HTML (*.html)\0*.html\0"
              			   "SHTML (*.shtml)\0*.shtml\0"
                                     	   "HTM (*.htm)\0*.htm\0"
                                     	   "All Files (*.*)\0*.*\0";
          ofn.lStructSize 			= strlen(ofn);
          ofn.hwndOwner		      	= hwnd;
          ofn.lpstrFilter			= Filter;
          ofn.lpstrFile		      	= FileName;
          ofn.nMaxFile		      	= sizeof(FileName);
          ofn.Flags			= 0;
          ofn.lpstrDefExt			= "html";
          GetOpenFileName(&ofn);

  5. #5
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>sizeof(FileName);
    Use the MAX_PATH variable.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    just tryed that, still doesn't work.

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    How did you manage to compile that?

    ofn.lStructSize = strlen(ofn);

    You can't calulate the size of the structire using strlen(). Use sizeof(). I'm amazed it compiled for you...

    Apart for that, it compiles fine and works for me.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Since you are using Borland C++ Builder, why not use one of the pre-built classes ?

    Eg:

    Code:
       TOpenDialog *myDlg = new TOpenDialog (Form1);
       if (myDlg->Execute()) 
          // User pressed "Open"
       else
          // User pressed "Cancel"

    Will do exactly what you want. Form1 is just the name of the form you want the dialog associated with.

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    I'm not using a form, is there any way to still use that?

  10. #10
    Registered User
    Join Date
    Jun 2003
    Posts
    245
    Yes, just make the owner NULL, as there's no owner form to associate with...

    Code:
     TOpenDialog *myDlg = new TOpenDialog (NULL);
       if (myDlg->Execute()) 
          // User pressed "Open"
       else
          // User pressed "Cancel"
    If you press F1 in the borland IDE on TOpenDialog, then you'll get all the properties and methods of the class so you can fully customise it to your liking.

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  3. Visual C++ 6.0 Sliders in Dialog Boxes
    By The Letter J in forum C++ Programming
    Replies: 24
    Last Post: 12-30-2004, 11:00 AM
  4. How to modify file open/save dialog?
    By _Elixia_ in forum Windows Programming
    Replies: 3
    Last Post: 07-05-2003, 11:41 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21