Click here to Skip to main content
13,202,262 members (61,343 online)
Click here to Skip to main content
Add your own
alternative version


30 bookmarked
Posted 15 Jan 2000

Static text to display long filenames with ellipses

, 15 Jan 2000
Rate this:
Please Sign up or sign in to vote.
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

    <!-- Article Starts -->

    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);<br>
      m_wndStaticFilePath.SubclassDlgItem (IDC_FILE_PATH, this);<br>
      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");


    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


    About the Author

    Ravi Bhavnani
    Technical Lead
    Canada Canada
    Ravi Bhavnani is an ardent fan of Microsoft technologies who loves building Windows apps, especially PIMs, system utilities, and things that go bump on the Internet. During his career, Ravi has developed expert systems, desktop imaging apps, marketing automation software, EDA tools, a platform to help people find, analyze and understand information, trading software for institutional investors and advanced data visualization solutions. He currently works for a company that provides enterprise workforce management solutions to large clients.

    His interests include the .NET framework, reasoning systems, financial analysis and algorithmic trading, NLP, HCI and UI design. Ravi holds a BS in Physics and Math and an MS in Computer Science and was a Microsoft MVP (C++ and C# in 2006 and 2007). He is also the co-inventor of 3 patents on software security and generating data visualization dashboards. His claim to fame is that he crafted CodeProject's "joke" forum post icon.

    Ravi's biggest fear is that one day he might actually get a life, although the chances of that happening seem extremely remote.

    You may also be interested in...

    Comments and Discussions

    GeneralMy vote of 5 Pin
    CIDev24-Sep-10 5:08
    memberCIDev24-Sep-10 5:08 
    GeneralError Compiling in VS2005 Pin
    ldsdbomber12-Jan-09 0:02
    memberldsdbomber12-Jan-09 0:02 
    AnswerRe: Error Compiling in VS2005 Pin
    Ravi Bhavnani12-Jan-09 2:50
    memberRavi Bhavnani12-Jan-09 2:50 
    GeneralRe: Error Compiling in VS2005 Pin
    ldsdbomber28-Jan-09 0:49
    memberldsdbomber28-Jan-09 0:49 
    GeneralRe: Error Compiling in VS2005 Pin
    ldsdbomber28-Jan-09 0:52
    memberldsdbomber28-Jan-09 0:52 
    GeneralRe: Error Compiling in VS2005 Pin
    ldsdbomber28-Jan-09 0:54
    memberldsdbomber28-Jan-09 0:54 
    GeneralRe: Error Compiling in VS2005 Pin
    Ravi Bhavnani28-Jan-09 1:38
    memberRavi Bhavnani28-Jan-09 1:38 
    GeneralRe: Error Compiling in VS2005 Pin
    JPhelps1-Nov-14 5:45
    memberJPhelps1-Nov-14 5:45 
    GeneralRe: Error Compiling in VS2005 Pin
    Ravi Bhavnani1-Nov-14 5:47
    professionalRavi Bhavnani1-Nov-14 5:47 
    GeneralRe: Error Compiling in VS2005 Pin
    JPhelps1-Nov-14 7:33
    memberJPhelps1-Nov-14 7:33 
    Questiona simple program on EMP Pin
    sireeshakolluri7-Apr-08 21:52
    membersireeshakolluri7-Apr-08 21:52 
    GeneralRe: a simple program on EMP Pin
    Ravi Bhavnani8-Apr-08 2:55
    memberRavi Bhavnani8-Apr-08 2:55 
    GeneralFlickering Pin
    rrrado11-Jun-03 1:29
    memberrrrado11-Jun-03 1:29 
    GeneralRe: Flickering Pin
    Ravi Bhavnani11-Jun-03 1:38
    memberRavi Bhavnani11-Jun-03 1:38 
    Questionhave a bug, how to do? Pin
    use_id8-Aug-02 1:36
    memberuse_id8-Aug-02 1:36 
    AnswerRe: have a bug, how to do? Pin
    Ravi Bhavnani8-Aug-02 2:24
    memberRavi Bhavnani8-Aug-02 2:24 
    GeneralShowing MDI Child window Maximized Pin
    Konrad Rotuski30-Apr-02 3:30
    memberKonrad Rotuski30-Apr-02 3:30 
    GeneralAPI Functions Pin
    Armen Hakobyan29-Apr-02 22:22
    memberArmen Hakobyan29-Apr-02 22:22 
    GeneralRe: API Functions Pin
    Ravi Bhavnani30-Apr-02 3:16
    memberRavi Bhavnani30-Apr-02 3:16 
    GeneralRe: API Functions Pin
    DavidCrow1-Dec-04 8:55
    memberDavidCrow1-Dec-04 8:55 
    GeneralRe: API Functions Pin
    Ravi Bhavnani1-Dec-04 16:37
    memberRavi Bhavnani1-Dec-04 16:37 
    GeneralBugFix: Disabled text incorrectly shown as enabled Pin
    Ravi Bhavnani10-Dec-01 17:37
    memberRavi Bhavnani10-Dec-01 17:37 
    GeneralAPI Function Pin
    Anonymous8-Feb-01 14:13
    memberAnonymous8-Feb-01 14:13 
    GeneralRe: API Function Pin
    Balkrishna Talele13-Apr-04 23:49
    memberBalkrishna Talele13-Apr-04 23:49 
    GeneralI can't get this up a running my way... Pin
    webguy6-Jul-00 9:48
    susswebguy6-Jul-00 9:48 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    Permalink | Advertise | Privacy | Terms of Use | Mobile
    Web04 | 2.8.171020.1 | Last Updated 16 Jan 2000
    Article Copyright 2000 by Ravi Bhavnani
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid