Use BCB to change the form system menu

Source: Internet
Author: User
I wrote an article two years ago to fill the facade. ---------------------- Use BCB to change the form system menu

(Author: mikespook | Release Date: | views: 133)

Keywords: BCB, system menu, message ing table
When we use some software, we will find that the system menus of these software are not standard, there may be a few fewer, there may be several more, or the default system menus have become completely invisible. Figure 1 shows a standard system menu. Figure 2 shows the modified system menu. Next I will use this example to briefly introduce how to modify the system menu.
Figure 1 Figure 2

Create a new application ). Name the main form "frm_main ". Add the following code to the tfrm_main: formcreate () function:

Void _ fastcall tfrm_main: formcreate (tobject * sender)
{
Hmenu system_menu = getsystemmenu (handle, false); // obtain the handle of the System menu of the form.
Deletemenu (system_menu, 4, mf_byposition); // Delete the first item of the System Menu
Appendmenu (system_menu, mf_string, id_about_menu, "about (& A)"); // Add a "about" menu item
Modifymenu (system_menu, 0, mf_string, id_null_menu, "null"); // modify the menu item and change the separator to "null"
}

The preceding four API functions are getsystemmenu (), deletemenu (), appendmenu (), and modifymenu (). For detailed usage, refer to the msdn or win32sdk. HLP help file (which is included in the BCB installation disk ).
Now let's run it. Press F9 to run the program and call out the system menu. As we expected, the system menu has been modified successfully. Is that all done? Click the newly added menu item and try again. Nothing happens. This is because we have not processed the message by clicking this menu item. Fortunately, the powerful BCB left us a backdoor that allows us to intercept Windows messages.
Next we will continue our procedure. Add a message ing table to the end of the tfrm_main class definition in the frmmain. h header file:

Begin_message_map
Message_handler (wm_syscommand, tmessage, sysmenuonclick)
End_message_map (tform)

Wm_syscommand is the message to be intercepted. When we intercept the wm_syscommand message, it is processed by the sysmenuonclick () function.

In the tfrm_main class definition, add

PRIVATE:
Void _ fastcall sysmenuonclick (tmessage & message );

Add the content of the message processing function to the main form file frmmain. cpp. For example, click the menu item to bring up the "about" dialog box:

Void _ fastcall tfrm_main: sysmenuonclick (tmessage & message)
{
// Determine which menu item is clicked for the wm_syscommand message
Switch (message. wparam ){
Case id_about_menu:
Application-> messageboxa ("Author: mikespook 2002.5.24", "about", mb_ OK );
Break;
Case id_null_menu:
Application-> messageboxa ("You clicked the" null "menu", "NOTE", mb_ OK );
Break;
Default:
Break;
}
// Let the message continue to be transmitted. Without this sentence, the message will be completely intercepted, resulting in a program error.
Tform: Dispatch (& message );
}

Now let's try again. Is everything okay? I believe you have a general understanding of modifying the system menu. Use your imagination to make full use of the System menu.

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.