Create a bitmap menu

zhaozj2021-02-11  202

Creating a Bitchart menu In the usual program, the menu always exists in text, sometimes it is very monotonous. If you can add bitmap graphics in the menu, you will greatly increase the user's use interest. This article describes how to make menu options using a bitmap. Creating a bitmap menu - Creating a bitmap menu is actually very simple, it requires some menus functions and bitmap functions that use the Windows Application Programming Interface (API), you need to include these functions in your application In the standard module, please refer to the sample program. Proceed as follows:

Use the function getSubmenu to extract the handle of the submenu item and create a compatible device environment description table by using the function createCompatibleDC; in a loop process, by using the CreateCompablebitMap function, the selectObject function, and the Bitblt function, each menu item will be used. The bitmap is selected into a compatible device environment; draws a true bitmap menu option through the ModifyMenu function; use the deletedc function to release the device environment so that other programs can be used. ---- Extracting a bitmap can have a variety of ways, set up four graphics box controls on the form in this program, using them to load 4 preset icons to use the source file of the menu option bitmap Of course, you can also use other methods, such as using the LoadPicture function to load a bitmap from the disk. Sample program

Start a new project in Visual Basic, build FORM1 with the default method. Create a new module, build Module1.bas with the default approach. The following constants and added to the declaration statement Module1.Bas module: Option ExplicitDeclare Function GetMenu Lib "user32" (ByVal hwnd As Long) As LongDeclare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As LongDeclare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As LongDeclare Function ModifyMenu Lib "user32" Alias ​​"ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As LongDeclare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As LongDeclare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As LongDeclare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As LongDeclare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As LongDeclare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, BYVAL NHEIGHT AS long, byval hsrcdcas long, byval Val xsrc as long, byval ysrc asse line Add 4 graphics box controls on Form1, set their Name properties to Picture1, set their index properties to 0, 1, 2, 3, set their AutoRedRew properties to True, set their AutoSize property settings To TURE, and set their Visable property to false. Set the Picture property of the above four graphics box controls to Face1.ico, Face2.ico, Face3.ico, Face4.ico. Add the first menu item on Form1, set it to "[& F] file", and the name is set to Mnufile.

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

New Post(0)