Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. PathCompactPath/PathSetDlgItemPath with owner-drawn static control?

PathCompactPath/PathSetDlgItemPath with owner-drawn static control?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicsdelphiquestioncareer
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sashoalm
    wrote on last edited by
    #1

    Hi, I have an owner-drawn static control that I use to display a file path. The file path often exceeds the width of the static control and the last directories and files are truncated. I know about PathSetDlgItemPath and PathCompactPath, but they don't work with this control because it is owner-drawn (the app is skinned). I've looked at PathCompactPath, but it requires a HDC parameter for reference, and the drawing is done with Gdiplus. The control draws itself in the OnPaint routine with this code:

    void CNiceLabel::OnPaint()
    {
    CPaintDC dc(this);

    CRect r;
    GetClientRect(&r);
    
    auto\_ptr<Graphics> g(Graphics::FromHDC(dc.m\_hDC));
    
    CStringW txt;
    GetWindowText(txt);
    Gdiplus::Font myFont(m\_FontName, (REAL) m\_FontSize, m\_FontStyle);
    StringFormat format;
    
    RectF rf;
    g->MeasureString(txt, txt.GetLength(), &myFont, PointF((REAL) r.left, (REAL) r.top), &rf);
    if (m\_bWordWrap)
    {
    	rf.Width = (REAL) r.Width();
    	rf.Height = (REAL) r.Height();
    }
    
    Color color;
    color.SetFromCOLORREF(m\_Color);
    SolidBrush whiteBrush(color);
    g->DrawString(txt, txt.GetLength(), &myFont, 
    	rf,	&format, &whiteBrush);
    
    g->Flush();
    

    }

    I thought about using g->GetHDC() to obtain a HDC for PathCompactPath to work with, but I probably need to select the font in it, and the font I use for drawing is a Gdiplus::Font, not CFont. And it can't be selected - it is passed to DrawString directly as a parameter. So I'm looking for a way to make PathCompactPath work with my control, or if someone can point me a function that does a similar job but has its source code published, that would be great.

    There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups