How to modify titles of C ++ documents

Source: Internet
Author: User
How to change the document title

I. Changes in the title of a Single-Document Interface (SDI) window
First, let's look at windows
Structure of the title bar of the SDI window. Detailed examples: Use
VC Appwizard creates a single-document project named "sdititle". After the project is created, compile and run the project. The title of the Main Window of the program is as follows:

Document title main window title
1. Document title change
The document title is controlled by the corresponding document classes in the project, so we can use
Settitle
() Function to change the document title.
For example, the function of modifying csdititledoc: onnewdocument () is:
Bool csdititledoc: onnewdocument ()
{
If (! Cdocument: onnewdocument ())
Return false;
Settitle ("document title ");
Return true;
}
To run the program, the document title is changed to "document title-sdititle" each time you select the "file" new option in the menu ".
2. Change the title of the Main Window
The title of the main window is the project file name by default. After the sdititle project generated by appwazied is executed, the title bar is in the form of "(document name )-
Sdititle ".
There are two methods to change the title of the main window:
Method 1: Use resourceview to open project resources and modify string
The value of idr_mainframe in table. The original "sdititle \ n \ Ntitle. Document \ Ntitle
Change document to "title change example \ n \ Ntitle. Document \ Ntitle
Document ". After this change, the form of the title bar of the main window is "(-Example of title change ".
Method 2: The specific change method is as follows:
Change the member function precreatewindow () of csdimainframe:
Bool cmainframe: precreatewindow (createstruct &
CS)
{
M_strtitle = "VC online programming network ";
Return cframewnd: precreatewindow (CS );
}
After this change, the title bar is in the form of "(-VC online programming network ".
Among the two change methods, the second method has a high priority. That is to say, after the m_strtitle value is changed, the value of idr_mainframe does not work.

2. Change the title of the window of the Multi-Document Interface (MDI) Type
  
In the MDI type window title, the order of the title of the main window and the document is different from that in the SDI type window. Create an Appwizard named
"Mdititle" Multi-document block type project. After the project is created, compile and run the project. The title of the main window is as follows: the title of the main window (currently open) Document

1. Document title change
The document title of the MDI window is also controlled by the corresponding document class. The change method is the same as that in the SDI window.
Similarly, to change the title, you only need to use the settitle () function in the corresponding document class to change the document label.
Question.
2. Change the title of the Main Window
  
The method for changing the title of the MDI type main window is similar to that of the SDI type window. You can change the title of the main window by changing the value of idr_mainframe or m_strtitle. Similarly, after the m_strtitle value is changed, the value of idr_mainframe does not work.

3. Change the subwindow title
By default, MFC automatically sets the subwindow title as the document title opened in the subwindow. However, the title of a subwindow is not the same as the title of the document opened by the subwindow title. We can do the following experiments:

(Use resourceview to open the resource and modify the string
The value of idr_mainframe in table is "VC online programming network", which changes the title of the main window to "VC online programming network ".
(Change the bool cmdititledoc: onnewdocument () function:
Bool cmdititledoc: onnewdocument ()
{
If (! Cdocument: onnewdocument ())
Return false;
Static int COUNT = 0;
Char message [10];
Wsprintf (message, "% S % d", "document", count );
Settitle (Message );
Count ++;
Return true;
}
Set the document title to "document 0" and "Document 1 "....
(R) change the cchildframe: precreatewindow () function:
Bool cchildframe: precreatewindow (createstruct &
CS)
{
CS. Style & = ~ (Long) fws_addtotitle;
Return response ichildwnd: precreatewindow (CS );
}
Change the window type. This step is required. The constant fws_addtotitle is in the file \ msdev \ MFC \ include
\ Afxwin. h.
(Add the oninitialupdate () function to the cmdititleview class:
Void cmdititleview: oninitialupdate ()
{
Cview: oninitialupdate ();
Getparent ()-> setwindowtext (getdocument ()-> gettitle () + "-VC window title example ");

} In this way, the title bar of the subwindow is in the form of "document name (-VC window title example ".

The modified program running effect is as follows: the above example can also be used as a reference to modify various headers of the MDI type window.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.