Two problems in the MDI window

zhaozj2021-02-08  218

1. The cause of Winmdi.cpp141 line errors in the MDI program:

The menu that is generally made through the wizard is as follows: (menu one)

File-> New

-> EXIT

View-> Toolbar

-> status bar

Help-> About XXX ...

This can be run:

Now change the upper menu to the following: (Menu 2)

File-> New

-> EXIT

View-> Toolbar

-> status bar

Help-> About XXX ...

TEST1 -> (where is set to not pop up menu)

TEST2 -> (where is set to not pop up menu)

Now you run again, an exception interrupt will occur (as shown below)

After analyzing the source code of the MFC, as follows:

134: int @ = pmenu-> getMenuItemcount () - 2; 135: 136: // if this assert fails, your menu bar does not follow the Guidelines137: // so you will have to override this function and call createclient138: // ApproPriately or Use The MFC V2 MDI FunctionAlity.139: assert (IMenu> = 0); 140: Pmenu = Pmenu-> GetSubmenu (IMENU); 141: Assert (pmenu! = null);

In the 134 line, the program is to calculate the number of main menus in the current menu bar, and subtract 2 in 139 lines, the program determines whether the count is greater than or equal to 0 in 140 lines, the program acquires a main menu, that is, 134 lines The calculation is obtained in 141 lines, and whether the program determines whether it is successful.

Press the menu of the upper side, this program is a menu that acquires (total menu-2), ie (3-2) = 1, the menu starts from 0, so the result is the VIEW menu, and this menu is Plus, and have a menu item.

If you press on the menu on the upper side, the program is acquired (5-2) = 3, that is, get the menu of Test1, and this menu is not popped, there is no menu item.

After experiment, this acquired menu must be popped and has a menu item. Either an abnormal interrupt occurs.

2. Is the menu item added in the MDI to always be ash?

I added a Tools-> Option menu item in the MDI program menu, but this menu is always gray, not available. There is no reason for the source program of tracking MFC.

In an accidental opportunity, I found that the items available in the menu have been mapped. So I handed a message mapping about the OPTION item, and the menu item became available.

转载请注明原文地址:https://www.9cbs.com/read-3419.html

New Post(0)