"pDoc->SetTitle" problem
-
er.. How do I use that code? I've tried replacing it with the old one but the title bar stays the same as the original.
Aint wrote:
How do I use that code?
Why you cant use of it?
WhiteSky
-
Aint wrote:
How do I use that code?
Why you cant use of it?
WhiteSky
-
Hello. I have created a CFormView based program and have added another CFormView class. I have tried to use this: pDoc->SetTitle("First View") for the first view and pDoc->SetTitle("Second View") for the second view. When file->open, the first view appear with the title "AppName - [First View]" but when I clicked on the menu for the second view, the first view title changed to "AppName - [Second View:1]". How can I make the title of the first view unchanged when the second view is opened? Thanks.
Hi, this is because you have maybe used my answer about the child window (if not, more or less the same that I had). The fact is that you are opening more views from the same document, and the MFC puts automatically the ":1", ":2"... to differenciate them. You can avoid it by overriding CChildFrame::OnPreCreateWindow (CREATESTRUCT& cs) If you re-read (or read for first time :P) the answers I wrote you in your message about the Child Window... You will find a line in the code with pDoc->m_szNewFrame there is where I save the string of the new title to the new window, and the new frame takes the title from that string.
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
Hi, this is because you have maybe used my answer about the child window (if not, more or less the same that I had). The fact is that you are opening more views from the same document, and the MFC puts automatically the ":1", ":2"... to differenciate them. You can avoid it by overriding CChildFrame::OnPreCreateWindow (CREATESTRUCT& cs) If you re-read (or read for first time :P) the answers I wrote you in your message about the Child Window... You will find a line in the code with pDoc->m_szNewFrame there is where I save the string of the new title to the new window, and the new frame takes the title from that string.
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
Hello. I have created a CFormView based program and have added another CFormView class. I have tried to use this: pDoc->SetTitle("First View") for the first view and pDoc->SetTitle("Second View") for the second view. When file->open, the first view appear with the title "AppName - [First View]" but when I clicked on the menu for the second view, the first view title changed to "AppName - [Second View:1]". How can I make the title of the first view unchanged when the second view is opened? Thanks.
Hi, I tried to reproduce your issue. I used MDI, two CFormView Derived class and added to doc template and in its OnInitialUpdate I set GetDocument()->SetTitle("First View") and second view. But I can't reproduce issue ,even i didn't get suffix index 1,2.... In MDI each view has its own document instance right. Would I like to know your setup, did you add multiple views to same doc, and where did you used pDoc->SetTitle(); Best Regards
-
Hi, I tried to reproduce your issue. I used MDI, two CFormView Derived class and added to doc template and in its OnInitialUpdate I set GetDocument()->SetTitle("First View") and second view. But I can't reproduce issue ,even i didn't get suffix index 1,2.... In MDI each view has its own document instance right. Would I like to know your setup, did you add multiple views to same doc, and where did you used pDoc->SetTitle(); Best Regards
-
yes. multiple views to the same doc. used pDoc->SetTitle() at OnInitialUpdate() of both views. thanks.
Hi, I reproduced your issue, you are setting the text for the same document instance by pDoc->SetTitle(), this will affect the same string object. Hence the last string you updated "SECONDVIEW" is the only document title, this is updated to all the views hence the FIRSTVIEW is changed to SECONDVIEW:1; The frame title of the views are updated by CFrameWnd/CMDIChildWnd::OnUpdateFrameTitle() we have advanced override for it. override your frame windows OnUpdateFrameTitle() and do the following this will set the frame title and overrides the default behaviour.
CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle) { CString szTitle = m_strTitle;// frame's title /* if you need the suffix index do this*/ if (m_nWindow > 0) // it is views index 1, 2 ... { szTitle.AppendFormat(_T("%d"), m_nWindow); } SetWindowText(szTitle); // set the caption }
then on your view's OnInitialUpdate() do the followingGetParentFrame()->SetTitle(_T("SECONDVIEW")); // your required string
this will set the views frame title which we use at the OnUpdateFrameTitle override rather thanpDoc->SetTitle(_T("SECONDVIEW")); // no need
this works verified Best Regards May be the same thing will be done by another way. -- modified at 5:50 Friday 1st June, 2007 -
Hello. I have created a CFormView based program and have added another CFormView class. I have tried to use this: pDoc->SetTitle("First View") for the first view and pDoc->SetTitle("Second View") for the second view. When file->open, the first view appear with the title "AppName - [First View]" but when I clicked on the menu for the second view, the first view title changed to "AppName - [Second View:1]". How can I make the title of the first view unchanged when the second view is opened? Thanks.
Hi another time... I'm not going to copy the whole code another time, so open (in a new window) this link: http://www.codeproject.com/script/comments/forums.asp?msg=2029429&forumid=1647&ForumID=1647&XtraIDs=1647&author=Nelek&sd=21%20Feb%202007&ed=22%20May%202007&stype=1&Page=3#xx2029429xx[^] Now the explanations about every socket of code. First: Declare the pDocTemplate. I used it to have a different Menu to the new Views added, and to have the possibility to use the implementation of MFC about the views of the Document (GetFirstViewPosition and so on). I think this is clear, isn't it? Second: CreateOrActivateNewFrame These function has to be implemented in CMainFrm.cpp (and declared in the CMainFrm.h of course). What it makes is to look for kinds of the pDocTemplate that I give as first parameter and check out the second parameter (the name of the element of my project that owns the view) to know if a new frame has to be created or is already created and only need to set it active on the front. Third: PreCreateWindow This function is a MFC message already implemented in CChildFrm if you used the assistant... If not... no problem, make it by yourself is a standard MFC message. In this function what I make is to check if it is the MAIN (CScrollView) view or one secondary view (If the document doesn't exist and the m_szNewFrame has nothing in it... is the main one, otherwise a secondary). If it is the main, I leave the default configuration. If it is a secondary (CFormView) I check which of the three different types is, modify the size of the frame and FOR ALL secondary... I set the title of the new frame with cs.lpszName = pDoc->m_szNewFrameName; AND NOT using pDoc->SetTitle () (this only works for the main frame and all the descendents at the same time, not for a independant secondary frame). Fourth: Using it In my project I have 3 type of objects visibles in the view. When I make a double click I check if the click was in one of the already placed elements. If there is a match... then I take the name of the element, set the pDoc->m_szNe
-
hi. Ive tried but I have an error for this part: CMDIChildWnd* pMDIActive = MDIGetActive(); 'MDIGetActive' : undeclared identifier. Is there any header that I need to include?
It is supposed to work without problems. Are you including the "stdafx.h"? Did you use the assistant to create the project? or did u implement all by yourself?
Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
-
Hi, I reproduced your issue, you are setting the text for the same document instance by pDoc->SetTitle(), this will affect the same string object. Hence the last string you updated "SECONDVIEW" is the only document title, this is updated to all the views hence the FIRSTVIEW is changed to SECONDVIEW:1; The frame title of the views are updated by CFrameWnd/CMDIChildWnd::OnUpdateFrameTitle() we have advanced override for it. override your frame windows OnUpdateFrameTitle() and do the following this will set the frame title and overrides the default behaviour.
CChildFrame::OnUpdateFrameTitle(BOOL bAddToTitle) { CString szTitle = m_strTitle;// frame's title /* if you need the suffix index do this*/ if (m_nWindow > 0) // it is views index 1, 2 ... { szTitle.AppendFormat(_T("%d"), m_nWindow); } SetWindowText(szTitle); // set the caption }
then on your view's OnInitialUpdate() do the followingGetParentFrame()->SetTitle(_T("SECONDVIEW")); // your required string
this will set the views frame title which we use at the OnUpdateFrameTitle override rather thanpDoc->SetTitle(_T("SECONDVIEW")); // no need
this works verified Best Regards May be the same thing will be done by another way. -- modified at 5:50 Friday 1st June, 2007