分类: Sybase
2008-04-21 13:24:06
******************************************************* 实用环境:pb6.5\pb70\pb80\pb90 功 能:位图菜单的制作 方 法:如下 ******************************************************* 第一步,首先要建立一个menu对象,命名为:m_bitmap。设计格式有 一个主菜单 File,下面有4个子菜单new\open\save\exit,如下: ----File----- -new -open -save -exit 第二步,找4个位图文件,放到exe所在的目录下,命名为:new.bmp\open.bmp\save.bmp\exit.bmp 第三步,编代码 主窗体w_main,窗体类型main,加入主菜单m_menu。 实例变量声明: //Win32常量 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 全局外部函数引入API: FUNCTION ulong LoadImageA(ulong hintance, string filename,uint utype,& int x,int y,uint fload) LIBRARY "USER32.DLL" FUNCTION boolean SetMenuItemBitmaps(ulong hmenu,uint upos,uint flags,& ulong handle_bm1,ulong handle_bm2) LIBRARY "USER32.DLL" FUNCTION int GetSystemMetrics( int nIndex ) LIBRARY "USER32.DLL" FUNCTION ulong GetMenuItemID(ulong hMenu,uint uItem) LIBRARY "USER32.DLL" FUNCTION int GetSubMenu(ulong hMenu,int pos) LIBRARY "USER32.DLL" FUNCTION ulong GetMenu(ulong hWindow) LIBRARY "USER32.DLL" FUNCTION boolean ModifyMenu(ulong hMnu, ulong uPosition, ulong uFlags, & ulong uIDNewItem, long lpNewI) alias for ModifyMenuA LIBRARY "USER32.DLL" open事件中: long ll_MainHandle long ll_SubMenuHandle integer li_MenuItemID long ll_X long ll_Y long ll_BitmapNew long ll_BitmapOpen long ll_BitmapSave long ll_BitmapExit //取得菜单句柄 ll_MainHandle = GetMenu(Handle(this)) //取得第一个菜单项的句柄 ll_SubMenuHandle = GetSubMenu(ll_MainHandle,0) //装入图像数据 ll_BitmapNew = LoadImageA(0,’new.bmp’,IMAGE_BITMAP,0,0,LR_LOADFROMFILE) ll_BitmapOpen = LoadImageA(0,’open.bmp’,IMAGE_BITMAP,0,0,LR_LOADFROMFILE) //取得第一个子菜单项的ID并修改菜单 li_MenuItemID = GetMenuItemID(ll_SubMenuHandle,0) ModifyMenu(ll_SubMenuHandle,li_MenuItemID,MF_BITMAP,li_MenuItemId,ll_BitmapNew) //取得第二个子菜单项的ID并修改菜单 li_MenuItemID = GetMenuItemID(ll_SubMenuHandle,1) ModifyMenu(ll_SubMenuHandle,li_MenuItemID,MF_BITMAP,li_MenuItemId,ll_BitmapOpen) //取得菜单缺省check-mark位图的尺寸 ll_x = GetSystemMetrics(SM_CXMENUCHECK) ll_y = GetSystemMetrics(SM_CYMENUCHECK) //按系统尺寸装入图像 ll_BitmapSave = LoadImageA(0,’save.bmp’, IMAGE_BITMAP ,ll_x,ll_y,LR_LOADFROMFILE) ll_BitmapExit = LoadImageA(0,’exit.bmp’, IMAGE_BITMAP ,ll_x,ll_y,LR_LOADFROMFILE) //设置菜单位图 SetMenuItemBitmaps(ll_SubMenuHandle,2,MF_BYPOSITION,ll_BitmapSave,ll_BitmapSave) SetMenuItemBitmaps(ll_SubMenuHandle,3,MF_BYPOSITION,ll_BitmapExit,ll_BitmapExit) |