Many excellent software displays a small picture on the left side of the Window menu, such as Word, which makes the operator feel very intuitive. For PowerBuilder, it has developed hundreds of simple and practical functions for applications, which are sufficient for general development applications and do not require extended functions. However, we often want to provide end users with features that PowerBuilder do not provide, such as this bitmap menu, when we need external functions.
An external function is a function written in another language and stored in a dynamic-link library (DLL). A DLL is a file that contains Windows code that can be executed. DLLs are dynamically loaded and linked at run time and can be shared by multiple applications. DLLs can be moved or fixed in memory, can be preloaded into or loaded by commands, or can be deleted or permanently mounted. The developer must define the external function before using it, and the external function is divided into two types according to the scope: global external function and local external function. The syntax for defining an external function in PowerBuilder is fairly straightforward, and two keywords are used when defining a function, depending on the return value: function (function) and subroutine (subroutine).
In PowerBuilder, we can also implement this functionality through Windows API functions, which enable many PowerBuilder functions that can be implemented with Windows API functions.
The following is an example of how to implement a bitmap menu through a Windows API function. In this example, suppose that after you create an Application object application, you create a menu object M_main and a Window object W_main respectively. In the Menu object M_main, there are the following menu items: File/new, File/open, File/save, File/exit, Edit/copy, Edit/cut, Edit/paste, and Edit/delete. In the Window object W_main, set its Title property to bitmap menu, and connect the menu "W_main" to the Window "W_main".
1 declare local external functions for window W_main first
FUNCTION ULONG Loadimagea (ULONG hintance, string filename,uint utype, int x,int y,uint fload) & LIBRARY "USER32. DLL "
This function realizes the function of loading the image data
FUNCTION boolean setmenuitembitmaps (ulong hmenu,uint upos,uint flags,&
ULONG Handle_bm1,ulong handle_bm2) LIBRARY "USER32. DLL "
This function sets the menu unit diagram
FUNCTION int getsystemmetrics (int nindex) LIBRARY "USER32. DLL "
This function gets the bitmap size of the menu
FUNCTION ULONG Getmenuitemid (ULONG hmenu,uint Uitem) LIBRARY "USER32. DLL "
This function gets the ID number of the menu item
FUNCTION int GetSubMenu (ULONG hmenu,int POS) LIBRARY "USER32. DLL "
This function gets the handle of the submenu item
FUNCTION ULONG GetMenu (ulong Hwindow) LIBRARY "USER32. DLL "
This function gets the menu item that is applied
FUNCTION boolean modifymenu (ULONG Hmnu, ulong uposition, ULONG uflags, &
ULONG Uidnewitem, Long Lpnewi) alias for Modifymenua LIBRARY "USER32. DLL "
This function is used to update a menu item
2 Second, the window W_main declare the instance variable
Win32 Constants
CONSTANT Integer image_bitmap = 0
CONSTANT Integer lr_loadfromfile = 16
CONSTANT Integer Sm_cxmenucheck = 71
CONSTANT Integer Sm_cymenucheck = 72
CONSTANT Integer Mf_bitmap = 4
CONSTANT Integer mf_byposition = 1024