CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2002
    Location
    Bangalore
    Posts
    135

    Make CFileDialog fixed to one Folder

    Hi Gurus,

    Is it possible to make the CFileDialog fixed to one directory. The user should not be able to change the directory by any button. It only shows the content of the m_ofn.lpstrInitialDir.

    Any suggestions guys. One more idea is to build a Dialog which does the similar thing but i want to reuse the class and not build something new.

    thanks in advance

    cheers
    sumits
    ---------------------------------------------------------------------------------
    Live as if U would Die tommorow and Learn as if U will Live Forever...
    Live Life the Fullest!!!
    ----------------------------------------------------------------------------------

  2. #2
    Join Date
    Feb 2002
    Posts
    3,788
    maybe the following flag will help?
    OFN_NOCHANGEDIR
    Restores the current directory to its original value if the user changed the directory while searching for files.

  3. #3
    Join Date
    Nov 2002
    Location
    Bangalore
    Posts
    135

    No Pal

    Hi myth,

    I have already tried that. that only allows the CFileDialog to come back to initialDirectory after a DoModal is performed. Its about the saving the global path. which will not be changed by this file dialog.

    Any more ways guys...

    thanks myth for the prompt reply.

    regards
    sumits
    ---------------------------------------------------------------------------------
    Live as if U would Die tommorow and Learn as if U will Live Forever...
    Live Life the Fullest!!!
    ----------------------------------------------------------------------------------

  4. #4
    Join Date
    Sep 2003
    Location
    San Diego
    Posts
    190
    Two things you could try:
    1. Handle the OnFolderChange message (WM_NOTIFY CDN_FOLDERCHANGE message.). this one would be kinda rough... (behavior wise)

    2. Use the OFN_ENABLETEMPLATE flag in the OPENFILENAME structure and pass your own dialog template. I've never done this so can't guarantee it will work.


    If all else fails, write your own dialog!

  5. #5
    Join Date
    Apr 2000
    Location
    Romania, Cluj-Napoca
    Posts
    57
    I did some tests. I thought that indeed handling the message WM_NOTIFY CDN_FOLDERCHANGE then u can make changes. I derived a class from the CFileDialog called CMyFileDialog, and there I override the OnFolderChange() function. I inserted a single line in it:
    Code:
    strcpy(this->m_ofn.lpstrFile,"C:\\TEMP");
    , where
    C:\TEMP is the folder that u want to be fixed. It is not working properly, because u can change the folders however. The best idea is still the one of building your own file open dialog box, OR, in the hook function that u can provide (see parameter lpfnHook of the OPENFILENAME structure), u have to handle all the messages sent by the dialog controls (list,buttons etc.,), and modify their behaviour.

    RATE ME OR HATE ME

  6. #6
    Join Date
    Nov 2002
    Location
    Bangalore
    Posts
    135

    Umm.. i know of those

    Hi thanks
    I know of those but the message handler only returns it after folder has been changed.
    I want to access the private member of the CFileDialog.. which may contain the ListBox File path.

    something like that. .am not sure..

    thanks
    sumits
    ---------------------------------------------------------------------------------
    Live as if U would Die tommorow and Learn as if U will Live Forever...
    Live Life the Fullest!!!
    ----------------------------------------------------------------------------------

  7. #7
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

  8. #8
    Join Date
    Nov 2002
    Location
    Bangalore
    Posts
    135

    Thanks

    Hi kirants...

    Thanks for the solution but probably i will not be able to use that. I think it is better to make a dialog with similar feature and read all File content with the right filter. In that i will not allow it to move up the folder.

    But the solution is really interesting. The problem i have is that it is a not a fool proof solution. It should not fail in any place.

    thanks a lot for the help

    regards
    sumits
    Last edited by sumits; December 16th, 2003 at 11:55 PM.
    ---------------------------------------------------------------------------------
    Live as if U would Die tommorow and Learn as if U will Live Forever...
    Live Life the Fullest!!!
    ----------------------------------------------------------------------------------

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

Featured