Solved

Change child window title in doc/view MDI.

Posted on 2001-08-03
8
235 Views
Last Modified: 2013-11-20
How can I change a child windows title to reflect an arbitrary number? i.e. Rotation Calibration: 99 Units.

0
Comment
Question by:sgraves66
8 Comments
 
LVL 2

Expert Comment

by:Lockias
Comment Utility
Assuming you have a pointer (or know how to get it) to the child window, simply call SetWindowText(sTitle).

~Lockias
0
 
LVL 1

Author Comment

by:sgraves66
Comment Utility
Ok. Actually, now I override CDocument::SetTitle(LPCTSTR lpszTitle). Doing this, how can I append the number of current document instanes to the title? I would like to reflect the number of units as the number of open documents. Originally, I wanted to set this to an arbitrary number and had forgotten SetWindowText() altogether, but I've changed how I wish to implement this.
0
 
LVL 2

Accepted Solution

by:
Lockias earned 75 total points
Comment Utility
I will assume you know the number of documents some how.  Then you just need to format a string the way you want it.  There are many ways to format strings, some arguably better than others, but I will show you one, because that gets into a whole other question.

-----------------------------
CString sTitle = pDoc->GetTitle();

CString sNewTitle;
sNewTitle.Format("%s - %d", sTitle, nDocCount);
pDoc->SetTitle(sNewTitle);

-----------------------------

Something like that.

~Lockias
0
 
LVL 1

Author Comment

by:sgraves66
Comment Utility
Well, I understand how to format the string output. I need to know how to calculate the number of open documents for a specific doc template. I suppose I will have to use a nested loop within my CWinApp derived class. Just thought there might be a way to quickly determine the value.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 12

Expert Comment

by:migel
Comment Utility
Hi!
you can ask docTemplate from document:
CDocTemplate* pTemplate = pDco->GetDocTemplate();
int nCount = 0;
POSITION pos = pTemplate->GetFirstDocPosition();
while (pos)
{
pTemplate->GetNextDoc(pos);
nCount++;
}
0
 
LVL 1

Author Comment

by:sgraves66
Comment Utility
Ok. I see, I would need to create a public member function in my CMultiDocTemplate-derived class to calculate the number of documents. i.e. UINT CMyMultiDocTemplate::NumDocs()
Then call pTemplate->NumDocs, correct?
0
 
LVL 1

Expert Comment

by:pkreddy
Comment Utility
hi,
 Its not necessary to derive a class form CDocTemplate to count no. of docs. You can use migels's code in any function of your CDocument derived class with slight modification.

I am writing a funtion for a CMyDocument derived class

int CMyDocument::GetNumDocuments()
{
  CDocTemplate* pTemplate = GetDocTemplate();
  int nCount = 0;
  POSITION pos = pTemplate->GetFirstDocPosition();
  while (pos)
  {
    pTemplate->GetNextDoc(pos);
    nCount++;
  }
  return nCount;
}

 and you can call it anywhere and display the no.

- PK
0
 
LVL 1

Author Comment

by:sgraves66
Comment Utility
Cool. I alreadly have a class derived from CMultiDocTemplate and have several different documents based upon this. I would have to write code for every CDocument-derived class to produce the count, so I think, in my situation, it would be more efficient to create a new class member function. Thx for all the help.

BTW - Both answers were correct, since I asked 2 questions. How should I allocate the points? I'll let you two decide.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now