Solved

customising cFileDialog

Posted on 1998-09-18
3
298 Views
Last Modified: 2013-11-19
I want to customise a CFileDialog so that I can change the
appearance of the listbox containing the files. I want to make it look like in MS Word so that files can be displayed
either in a list with horizontal scrolling or with default
vertical scrolling. How can I access and change the dialog
controls?
0
Comment
Question by:elazabi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
bobbym earned 100 total points
ID: 1322264
Well you cannot make the standart dialog box look the one in Word because we are simply not talking about the same dialogs but yes you can customize the standart one. All you need to do is make some changes in the OPENFILENAME structure. In the code below I use the standard dialog box to view only the directories. I change the template and attach a hook. You can get the template for the dialog box from FILEOPEN.DLG in Vc\include. Once you get that template you can insert it in your resource file and edit as it suits you. With the hook procedure you can modify the behaviour. Here is the code :

BOOL bDirectory;
CString Directory;
UINT APIENTRY MyHook(HWND hdlg, UINT uiMsg, WPARAM wParam,      LPARAM lParam)
{
      switch (uiMsg)
      {
      case WM_COMMAND:
            if (wParam == IDOK)
            {
                  // Close the dialog box
                  HWND hWndPath;
                  CString Path;
                  hWndPath = GetDlgItem(hdlg, stc1);
                  ASSERT(hWndPath);
                  int nLen = ::GetWindowTextLength(hWndPath);
                  ::GetWindowText(hWndPath, Path.GetBufferSetLength(nLen), nLen+1);
                  Path.ReleaseBuffer();
                  PostMessage(hdlg,  WM_COMMAND, IDABORT, 0L);
                  Directory = Path;
                  bDirectory = TRUE;
                  return TRUE;
            }
      default:
            return FALSE;
      }
}

void CTempFileOptDlg::OnBrowse()
{
      OPENFILENAME ofn;
    /* Get the system directory name, and store in szDirName. */
    // Initialize the OPENFILENAME
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = m_hWnd;
    ofn.hInstance = AfxGetInstanceHandle();
    ofn.lpstrFilter = NULL;
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter = 0;
    ofn.nFilterIndex = 0;
    ofn.lpstrFile = NULL;
    ofn.nMaxFile = 0;
    ofn.lpstrFileTitle = NULL;
    ofn.nMaxFileTitle = 0;
    ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle = NULL;
    ofn.Flags = 0;
    ofn.Flags |= OFN_ENABLETEMPLATE | OFN_ENABLEHOOK;
    ofn.nFileOffset = 0;
    ofn.nFileExtension = 0;
    ofn.lpstrDefExt = NULL;
    ofn.lCustData = NULL;
    ofn.lpfnHook = MakeProcInstance(MyHook, NULL);
    ofn.lpTemplateName = MAKEINTRESOURCE(IDD_BROWSEDIR_DLG);      
      // show the browse dir dialog. It will return FALSE always       
      bDirectory = FALSE;
      ::GetOpenFileName( &ofn);
      if (bDirectory)
      {
            UpdateData();
            m_Directory      = Directory;
            UpdateData(FALSE);
      }

Hope that helped :)
0
 

Author Comment

by:elazabi
ID: 1322265
actually I want to change the style of the  file listing ListBox to multicolumn and
I'm using Visual C++ 1.5 because my app runs on win 3.11. I managed to access the
list control by calling "GetDlgItem(lst1)" but I did not find any feature to change the style
to multicolumn. Any idea how to cahnge dialog control styles on run-time?
0
 

Expert Comment

by:bobbym
ID: 1322266
Well you may try the GetWindowLong and SetWindowLong to change the window style.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question