Implement label control for folder styles in Excel and Visual C + + (iii)

Source: Internet
Author: User
Tags knowledge base

Implement label control for folder styles in Excel and Visual C + +

In the first and second sections of this article, we describe the design idea, creation process and working principle of Cfoldertabctrl Label control, and analyze the thinking and key skills of integrating Cfoldertabctrl with MFC frame structure through a utility program. The primary purpose of Cfoldertabctrl is to emulate the UI features of the label control pages in Excel and Visual C + + applications. In this part we will further enhance and improve the simulation effect and reusability of Cfoldertabctrl label control. This includes creating multiple tab pages and increasing the number of arrow buttons that allow the tabs to scroll around, each of which is a small triangle pointing to the left and right.

We will take the "VC Knowledge Base Online Magazine" in the 15th issue of an article on the image display of the source code as an example, the Cfoldertabctrl implementation of the Label control function applied to the image display program. The original program is an MFC program that uses a C + + class (CPicture) to encapsulate the ipicture low-level COM interface provided by the Windows system, enabling us to easily display various format image files, including *.gif, *.jpg, *.bmp, and dibs files. The specific details of the image display are not discussed in this article, please refer to the article-"Display jpg/gif Image in MFC program".

First, let's look at how to implement the arrow buttons? My basic idea is to create the button as a Cfoldertabctrl window and place the label on the right side of the button. As shown in Figure one:

Figure 13 tabs in a program

To implement this button, I created a new class, Cfolderbutton. Its class is a custom button class that has a drawitem function that is responsible for drawing buttons instead of using bitmap buttons. I chose to draw the right triangle with the GDI class, so I don't have to worry about the edge display caused by scaling. Cfolderbutton::D Rawitem can draw triangles to fit the size of the button. The button is represented in the gray state with a 3D shadow color, but when the button is pressed, the pixel substitution method represents the button state. Cfolderbutton also handles mouse messages to implement two proprietary features, usually when the button does not respond to a double-click, but this button handles the double-click mouse event, which causes the label to scroll through two pages. That is, double-clicking is equivalent to two clicks. Here is the implementation code:

void CFolderButton::OnLButtonDblClk (UINT nFlags, CPoint pt) {
  SendMessage(WM_LBUTTONDOWN,   nFlags,   MAKELONG(pt.x,pt.y));
}

Another feature is that the user presses the button, and the label scrolls until the label's port. The way to implement this feature is to use a timer, and when the timer is activated, Cfolderbutton sends a WM_COMMAND message to its parent window as if the button had been pressed down.void CFolderButton::OnTimer(UINT nIDEvent) {
  GetParent()->SendMessage(WM_COMMAND, GetDlgCtrlID());
}

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.