Problem solving--MFC Ribbon response function disorder perform other functions

Source: Internet
Author: User

================================== Declaration ==================================

This article is original, reproduced in the text of the influential annotated author and source, and to ensure the integrity of the article.

Do not modify (including this statement) without the consent of the author, and reserve the right of legal investigation.

Do not use academic references without the consent of the author.

Do not use for commercial publication, commercial printing or commercial reference without the consent of the author. Can negotiate.

In order to ensure the correct contents, we suggest that we should read the original text.

This article link: http://www.cnblogs.com/wlsandwho/p/4388382.html

=======================================================================

win7+vs2010

Recently, in the MFC Ribbon button write function, accidentally added a new button and response function, found that the execution is another function!

=======================================================================

Let me try to reproduce and fix it.

=======================================================================

New MFC Program

The other uses the default settings.

Operating effect:

=======================================================================

The default ribbon:

=======================================================================

Here's what you'll start adding ribbon.

Add a category, default is Category 1, and by default there is a panel of 1. Add button Button1.

Here to see the attribute, found that the ID is actually id_button2. I don't know why, is it my vs problem? But I am also in another virtual machine environment.

=======================================================================

Rename Id_button2 to id_btn_t, and change the title to T. Add the function onbtnt.

void cmainframe::onbtnt (){// TODO: Add Command handler code in this 4 MessageBox (TEXT ("onbtnt")) ; 5}         

Run, normal.

=======================================================================

Back up the project.

=======================================================================

Add 1 new buttons and a separator. But the ID of the button is Id_button2 and the title is Button1.

I changed it to id_btn_wls. Change the title to WLS.

The same add function.

void cmainframe::onbtnwls (){// TODO: Add Command handler code 4 in MessageBox ("onbtnwls" )); 5}         

Run, success. There is no problem with the function response.

=======================================================================

It's starting to build!

=======================================================================

Change Id_btn_wls to Id_btn_tt.

Try right-clicking Add function and find "add Edit" button is available!

Incredibly can add, then add one.

void Cmainframe::onbtntt (){// TODO: Add Command handler code 4 in MessageBox ("onbtntt"  )); 5}         

Now compile the link to run the program and find that the click Is TT, but the response function is onbtntt!

=======================================================================

Watch Resource.h File

Discover the last two IDs are the same! Of course, it must be the same! Because just changed the ID name, and did not delete or add the ID, so MFC just added a macro to map to the corresponding control ID.

But since the second one is newly added, there is no mapping function, so right-click can add the upper function.

To verify this idea, take a look at the mapping macro in MainFrm.cpp.

I'm now going to change the order of the Code in the box.

The result of the execution is correct:

Now it seems that the code should be removed from this situation, i.e. the following code is removed:

#define ID_BTN_WLS                      32772
1 On_command (id_btn_wls, &cmainframe::onbtnwls)
void cmainframe::onbtnwls (){// TODO: Add Command handler code 4 in MessageBox ("onbtnwls" )); 5}         
void Onbtnwls ();

=======================================================================

You think this is over? It's not that simple!

Open the project you just backed up and recreate it once!

=======================================================================

Not to be continued.

Problem solving--MFC Ribbon response function disorder perform other functions

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.