Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Static text to display long filenames with ellipses

0.00/5 (No votes)
15 Jan 2000 1  
Lightweight class for displaying long filespecs that may need to be truncated
  • Download demo project - 14 Kb
  • Download source files - 3 Kb
  • Sample Image - cstatic_filespec.gif

    The CStaticFilespec control is a lightweight class suitable for displaying long filespecs that may need to be truncated or compressed, in order to fit the size of the display. The image presents an example of what the control looks like when used in a dialog box.

    By default, CStaticFilespec supports 2 drawing styles: DT_END_ELLIPSIS and DT_PATH_ELLIPSIS. The former displays a truncated filespec with trailing ellipses while the latter adds embedded ellipses to a compressed filespec.

    Using CStaticFilespec in a dialog is quite simple:

    Include CStaticFilespec.h in your dialog class' header file.

    Add member variables of type CStaticFilespec for every static text control you want to subclass.

    Subclass the static text controls in your dialog's OnInitDialog() method and set the controls' style.

      m_wndStaticFileEnd.SubclassDlgItem (IDC_FILE_END, this);
    m_wndStaticFilePath.SubclassDlgItem (IDC_FILE_PATH, this);
    m_wndStaticFilePath.SetPath (TRUE);

    You can also use any other DT_ drawing style you like. For example, to draw right justified text that is vertically centered and has trailing ellipses, do:

      m_wndStaticText.SubclassDlgItem (IDC_STATIC_TEXT, this);
      m_wndStaticText.SetFormat (DT_RIGHT | DT_VCENTER);
      m_wndStaticText.SetWindowText ("d:\\There\\Is\\Always\\One\\More\\Bug.cpp");
    

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here