Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dialog Caption

Posted on 2002-07-30
7
Medium Priority
?
1,637 Views
Last Modified: 2013-11-20
A few things:

I do not want MFC to display the current filename in the Title bar of the main window, and I want to have the ability to change the caption at various runtime points... what do I need?

Also: How do I change the caption on a dialog box at runtime? Is it the same as for the main window?

thanks
jeff
0
Comment
Question by:jkelly061597
7 Comments
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 7188724
Hi,

For all ur questions, there is only one answer. Use the function SetWindowText(). If U want to set the title for the main window in an SDi/MDI, then use the mainframe pointer and call SetWindowText(...) specifying ur new title. And for dialog, use ur dialog pointer or from the dialog class call SetWindowText(...) function.

If u want to set the title bar initially itself, then for MainFrame, do it in OnCreate function before returning and for dialog, map OnInitDialog message map and call SetWindowText.

Try it out.
VinExpert
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7189276
... so far so good :) ...

To get the mainframe pointer from any location call the AfxGetMainWnd-function. It returns a CWnd*

Other than that, VinExpert has already answered your question.

.f
0
 
LVL 2

Expert Comment

by:SamratAshok
ID: 7189431
From your questions, I gather that you are using
Document-view architecture and most likely MDI!

In this case, you have to override functions in
CDocument; I don't remember the exact name, but is
something like GetTitle.

Even if you do suppress the name, it still leaves
that annoying separator "-" To suppress this, I tinkered
with CMainframe, I will dig up my old code and let you
know; I don't remember as of now.

If you cannot wait, then set break point on CDocument
override; debug it into MFC to figure out how it
peices name together and then break the chain.

For dialog boxes; you can call SetWindowText.

For views : Never call SetWindow text indiscriminately
without understanding which window you are calling for.
There is much more behind the screens then you can see
for a view.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jkelly061597
ID: 7218418
Samarat did you find the code?
0
 
LVL 2

Expert Comment

by:SamratAshok
ID: 7227934
jkelly

was too busy to check ee. Will be able to look and
let u know!

Sorry for delay!
0
 
LVL 2

Accepted Solution

by:
SamratAshok earned 300 total points
ID: 7228508
Hello jkelly

Finally, did the code dig up as promised. Found
couple of different methods exist where you can
control appearance of title. Listing them in
order of simplicity.

1) Override CDocument::SetTitle method

2) Override CMainFrame::PreCreateWindow

Add a line which looks like
cs.style &= ~FWS_ADDTOTITLE;

// This line changes window style settings that
// affect the title generation. play with them
// to see which override works the best.

3) Override CChildFrame::PreCreateWindow

This function is exactly identical to above
one needs same source code, but affects inner
child window behaviour.

Again experiment by setting both on, first only, second only or none permutations.

4) Edit resource string in  editor
Read documentation for further details
or look up source code for AfxExtractSubString
in winstr.cpp to see how it parses the string.

5) Last option. Override OnUpdateFrameTitle function
and code your requirements exactly.

override this function if and only if you absolutely must.
You will be preety much out and open with no MFC intervention regarding titles. You can actually copy
existing MFC source and then tweak it to make it work
for you.


Hope this helps

0
 

Author Comment

by:jkelly061597
ID: 7228813
Thnk you very much... I got it.

jeff
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

824 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