Re: how to display full path instead of filename
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 12/31/04
- Previous message: Joseph M. Newcomer: "Re: output.c error in multithreaded program"
- Next in thread: Václav Jedlicka: "Re: how to display full path instead of filename"
- Reply: Václav Jedlicka: "Re: how to display full path instead of filename"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 31 Dec 2004 16:09:34 -0500
Why do you need a TCHAR variable? This is an invitation to disaster. Learn to use CString
for things like this!
CString Text;
if(pDocument == NULL)
text = m_strTitle;
else
{
CString title = pDocument->GetPathName();
if(title.IsEmpty())
{ /* not saved yet */
title = pDocument->GetTitle();
} /* not saved yet */
if(m_nWindow > 0)
{ /* has sequence number */
CString n;
n.Format(_T(".%d"), m_nWindow);
title += n;
} /* has sequence number */
SetWindowText(title);
}
The general assumption should be as soon as you write a TCHAR array in MFC, particularly
for purposes of forming a string, you have made a fundamental error in programming. Do
not use TCHAR arrays unless there is no other way to do it. And I don't want to hear
anything about "efficiency" coming into the discussion; the cost of activating a window is
so high that the cost of the CString managment is unmeasurable by comparison.
joe
On Thu, 30 Dec 2004 21:13:32 +0100, "Václav Jedlicka" <no@spam.please> wrote:
>Here is my solution:
>override in CChildFrame:
>
>
>//display full path instead of a filename only
>void CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle)
>{
> // update our parent window first
> GetMDIFrame()->OnUpdateFrameTitle(bAddToTitle);
>
> if ((GetStyle() & FWS_ADDTOTITLE) == 0)
> return; // leave child window alone!
>
> CDocument* pDocument = GetActiveDocument();
> if (bAddToTitle)
> {
> TCHAR szText[256+_MAX_PATH];
> if (pDocument == NULL)
> lstrcpy(szText, m_strTitle);
> else
> {
> CString ls_title = pDocument->GetPathName();
> if(ls_title.GetLength() == 0){//not saved yet
> ls_title = pDocument->GetTitle();
> }
> lstrcpy(szText, ls_title);
> }
> if (m_nWindow > 0)
> wsprintf(szText + lstrlen(szText), _T(":%d"), m_nWindow);
>
> // set title if changed, but don't remove completely
> SetWindowText(szText);
> }
>
>
>}
>
>I would prefer something more elegant but it works.
>
>Vaclav
>
>
>
>"Joseph M. Newcomer" <newcomer@flounder.com> píse v diskusním príspevku
>news:e787t0dg97k3fv1c86reo599kp0ho4n3l7@4ax.com...
>> When you create the window, remove the FWS_ADDTOTITLE style from the
>window style,
>> otherwise the MFC framework will keep replacing the value you
>SetWindowText with.
>> Typically you do this in PreCreateWindow, use &=~FWS_ADDTOTITLE on the cs
>style flags.
>> joe
>> On Tue, 28 Dec 2004 20:11:03 -0800, "Naren"
><Naren@discussions.microsoft.com> wrote:
>>
>> >hi
>> >first u get the full path of the file by using CFile::GetFilePath. it
>> >returns the full path of the file. then update the window title bar by
>using
>> >SetWindowText
>> >naren
>> >
>> >
>> >"Václav Jedlièka" wrote:
>> >
>> >> Hello
>> >>
>> >> In a MDI app, how can I display full path of the doc in the titlebar of
>the
>> >> window?
>> >>
>> >> Thanks
>> >>
>> >> Vaclav
>> >>
>> >>
>> >>
>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Previous message: Joseph M. Newcomer: "Re: output.c error in multithreaded program"
- Next in thread: Václav Jedlicka: "Re: how to display full path instead of filename"
- Reply: Václav Jedlicka: "Re: how to display full path instead of filename"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|