Solved

customising cFileDialog

Posted on 1998-09-18
3
300 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

726 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