Solved

customising cFileDialog

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
fizzArray  challenge 1 57
NotAlone Challenge 20 79
canBalance challenge 34 69
mapAB Challlenge 35 123
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

947 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now