Displaying LONG filename on limited static control

This is a discussion on Displaying LONG filename on limited static control within the Windows Programming forums, part of the Platform Specific Boards category; I am writing a program and I'm on the file choosing part of it. I thought it a good idea ...

  1. #1
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584

    Displaying LONG filename on limited static control

    I am writing a program and I'm on the file choosing part of it. I thought it a good idea for the user to see what file and the path they are choosing via a static control. Well, of course a filename can be really long, so how do I display this long path+filename in this limited amount of static area. How do you make a static control's display (on a window, not a dialog) with wordwrap? That could always work. Thanks!

    Garfield
    1978 Silver Anniversary Corvette

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223
    just declare in the header


    in the .h file

    Code:
    CStatic txtFileName;
    
    
    in the .cpp file for the window
    
    #define ID_FILENAME 101
    
    ....::OnCreate(.....)
    {
          txtFileName.Create( sText,  dwStyle,  rect,  this,  ID_FILENAME );
    .....
    }
    
    ....::SetFileName( CString strFilename )
    {
         CDC* pdc = txtFileName.GetDC(); 
         CSize size = pdc->GetTextExtent( strFilename );
         CRect r;
          txtFileName.GetWindowRect( &r );
    
         int area1 = r.Width() * r.Height();
         int area2 = size.cx * size.cy;
         
         if( r.Width() < size.cx && area1 < area2 + size.cy )
         {
              //resize the window
               txtFileName.SetWindowPos(NULL, 0, 0, r.Height() + size.cy, SWP_NOMOVE | SWP_NOZORDER);
         }               
    
         txtFileName.SetWindowText( strFileName );
    }

    I have not tested the above code but with some fine tuning it will work....
    zMan

  3. #3
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Well, I can only go so far with the static control. Otherwise, it'll be off the client and you won't be able to see it anyway. I think the best thing to do is to use a wordwrap static, but I don't know how to. Thanks...

    Garfield
    1978 Silver Anniversary Corvette

  4. #4
    Registered User (TNT)'s Avatar
    Join Date
    Aug 2001
    Location
    UK
    Posts
    339
    Hey Garfield,

    Just wandering i dont know how to do wordwraps but couldnt you use a multi lined edit box, if you removed the borders and made it read only and colour it the same as the background of your prog, then it would look like a standard static control, and the text would word wrap as nessecery.

    Hope that helps,
    TNT
    TNT
    You Can Stop Me, But You Cant Stop Us All

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    As a suggestion: create an edit cntrl with the ES_READONLY style.
    You can then fit the cntrl to whatever size you choose within the client area of the parent wnd while the user can use keys like END, HOME, arrows etc to move around the text without being able to change it. It also has the advantage of having the std edit cntrl context menu if your user wants to copy the contents to the clipboard.

    edit: the background of the edit cntrl is set (I think) to COLOR_BTNFACE too instead of the more usual COLOR_WINDOW (see GetSysColor for more info).
    Last edited by Ken Fitlike; 01-30-2002 at 04:31 PM.

  6. #6
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Okay, I'll give the edit control suggestion a try. I'll also use ES_AUTOSCROLL (I think this is the constant) so when I set the window text, it should automatically go to the end (which is the most recent filename/dir), right? Thanks...

    Garfield
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. ADDING text to a STATIC control
    By Garfield in forum Windows Programming
    Replies: 2
    Last Post: 09-01-2003, 09:48 AM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 06:48 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21