PathCompactPath/PathSetDlgItemPath with owner-drawn static control?
-
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