Re: String width
From: Scott McPhillips [MVP] (scottmcp_at_mvps.org.nothere)
Date: 03/25/04
- Next message: Jase: "Re: Q: Member variable problem"
- Previous message: prg: "Launching wordpad from a dialog box"
- In reply to: James Ryan: "Re: String width"
- Next in thread: James Ryan: "Re: String width"
- Reply: James Ryan: "Re: String width"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 24 Mar 2004 21:39:08 -0500
James Ryan wrote:
> Well I suppose the solution is to create one! For some reason I didn't
> think this was possible...
>
> However, this seems to work:
>
> void CMainFrame::OnUpdateUI(CCmdUI pCmdUI)
> {
> switch(pCmdUI->m_nID)
> {
> case ID_INDICATOR_ITEM_COUNT:
> {
> CString cs("Some text");
> pCmdUI->SetText(cs);
>
> int index =
> m_wndStatusBar.CommandToIndex(ID_INDICATOR_ITEM_COUNT);
> if (index > -1)
> {
> UINT id;
> UINT style;
> int width;
> m_wndStatusBar.GetPaneInfo(index, id, style, width);
>
> try
> {
> CClientDC dc(&m_wndStatusBar);
> width = dc.GetTextExtent(cs).cx;
> }
> catch(CResourceException)
> {
> // Oh well
> }
>
> m_wndStatusBar.SetPaneInfo(index, id, style, width);
> }
>
>
> }
> break;
>
> }
>
> Any comments on creating a device context here? I always thought they were
> limited to OnDraw() and OnPaint()
>
> James
You have the right idea here, but maybe in the wrong place. All of this
is executed several times per second (that's the way OnUpdateUI works).
It would probably make more sense to do this operation only when the
text changes. SetPaneInfo doesn't normally have anything to do with
OnUpdateUI.
-- Scott McPhillips [VC++ MVP]
- Next message: Jase: "Re: Q: Member variable problem"
- Previous message: prg: "Launching wordpad from a dialog box"
- In reply to: James Ryan: "Re: String width"
- Next in thread: James Ryan: "Re: String width"
- Reply: James Ryan: "Re: String width"
- Messages sorted by: [ date ] [ thread ]