Solved

customising cFileDialog

Posted on 1998-09-18
3
289 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
Comment Utility
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
Comment Utility
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
Comment Utility
Well you may try the GetWindowLong and SetWindowLong to change the window style.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Strange date stored 22 99
Turn a spreadsheet into a vba executable. 2 66
mapBully challenge 6 88
Change to event 1 72
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

763 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

7 Experts available now in Live!

Get 1:1 Help Now