Thread: CFileDialog Initial Dir

  1. #1
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128

    CFileDialog Initial Dir

    Hi, I want to open an open file dialog, I can manage it fine, the thing I am having the problem with is telling it a different default directory.

    I have created a structure of OPENFILENAME and am setting the lpstrInitialDir to the path I want to start at, but when I pass it to the CFileDialog constructor it errors saying:

    cannot convert parameter 4 from 'struct tagOFNA' to 'unsigned long.

    I have read and re-read and I don;t know what to do, this is all before DoModal() is called.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Post the call to CFileDialog constructor. One possible solution is pointer. Pass in the address of the structure.

    Kuphryn

  3. #3
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Hi Kuphryn, thanks.

    I tried passing the addrtess but it has teh same error.

    Here is my call:

    defdir.lpstrInitialDir = m_jobdir;

    CFileDialog findcpr(true, ".cpr", NULL, defdir, "cpr files (*.cpr)||All Files (*.*)||");

    I have just had another look and it may be the fact I am asking it to equal a CString, rather than a pointer to a character array.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  4. #4
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    I just tried passing it a pointer to a char array and it has the same error when using the constructor.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  5. #5
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Can anyone see what I am doing wrong?
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  6. #6
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    I had just been reading the documentation wrong.

    I was trying to pass it an OPENFILENAME structure in the place it wanted a DWORD to modify the look of the dialog box.

    Instead I needed to edit the m_ofn structure that is a member of the CFileDialog class, like this.

    Code:
        CFileDialog findcpr(true, ".cpr", NULL, NULL, "cpr files (*.cpr)||All Files (*.*)||");
        findcpr.m_ofn.lpstrInitialDir = m_jobdir;
        findcpr.DoModal();
    and there you have it the initial directory is what I want it to be.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error opening files in a different dir
    By Ozzie in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2008, 06:55 AM
  2. Replies: 12
    Last Post: 04-25-2007, 02:48 PM
  3. My first game
    By homeyg in forum Game Programming
    Replies: 20
    Last Post: 12-22-2004, 05:25 PM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM