Solved

customising cFileDialog

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 99
notReplace  challenge 53 141
changeXy challenge 13 88
Path of Workbook 3 86
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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