PB12.5带图标菜单自定义对象

1.新建自定义非可视对象, uo_supermenu。

   新建main类型窗口w_popmenu.

   新建菜单 m_popmenu。


2.uo_supermenu完整脚本:

forward
global type uo_supermenu from nonvisualobject
end type
type rect from structure within uo_supermenu
end type
end forward


type rect from structure
integer bottom
integer left
integer right
integer top
end type


global type uo_supermenu from nonvisualobject
end type
global uo_supermenu uo_supermenu


type prototypes
FUNCTION ulong GetMenu(ulong hwnd) LIBRARY "user32.dll"


FUNCTION ulong GetSubMenu(ulong hMenu,ulong nPos) LIBRARY "user32.dll"


FUNCTION ulong TrackPopupMenu(ulong hMenu,ulong wFlags,ulong x,ulong y,ulong nReserved,ulong hwnd,ref Rect lprc) LIBRARY "user32.dll"
end prototypes


type variables
ulong il_popmenu_window_hwnd
end variables


forward prototypes
public subroutine of_init ()
public subroutine of_show_popmenu (long xpos, long ypos)
public subroutine of_close ()
end prototypes


public subroutine of_init ();if isvalid(w_popmenu) then
close(w_popmenu)
end if
open(w_popmenu)


il_popmenu_window_hwnd = handle(w_popmenu)
end subroutine


public subroutine of_show_popmenu (long xpos, long ypos);ulong hmenu,hsubmenu,hwnd
integer li_x,li_y


RECT l_rect
l_rect.left = 0
l_rect.top = 0
l_rect.right = 0
l_rect.bottom = 0


hmenu = getmenu(il_popmenu_window_hwnd)
hsubmenu = getsubmenu(hmenu, 0)


li_x = xpos 
li_y = ypos 




TrackPopupMenu(hsubMenu, 2, li_x, li_y, 0, il_popmenu_window_hwnd, l_rect)
end subroutine


public subroutine of_close ();if isvalid(w_popmenu) then
close(w_popmenu)
end if
end subroutine


on uo_supermenu.create
call super::create
TriggerEvent( this, "constructor" )
end on


on uo_supermenu.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on


event destructor;if isvalid(w_popmenu) then
close(w_popmenu)
end if
end event

/

w_popmenu完整脚本:

forward
global type w_popmenu from window
end type
end forward


global type w_popmenu from window
integer width = 119
integer height = 252
boolean titlebar = true
string title = "Untitled"
string menuname = "m_popmenu"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
end type
global w_popmenu w_popmenu


type prototypes
FUNCTION ulong LoadImageW(ulong hintance, string filename,uint utype,int ix,int iy,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 int GetSubMenu(ulong hMenu,int pos) LIBRARY "USER32.DLL"


FUNCTION ulong GetMenu(ulong hWindow) LIBRARY "USER32.DLL"


end prototypes
type variables
//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


end variables


on w_popmenu.create
if this.MenuName = "m_popmenu" then this.MenuID = create m_popmenu
end on


on w_popmenu.destroy
if IsValid(MenuID) then destroy(MenuID)
end on


event open;
long ll_MainHandle
long ll_SubMenuHandle
long ll_X
long ll_Y
long ll_Bitmapcut
long ll_Bitmapcopy
long ll_Bitmappaste
long ll_Bitmapitl
long ll_bitmapcnt
long ll_bitmapunderline


this.visible = false




ll_MainHandle = GetMenu(Handle(this))




ll_SubMenuHandle = GetSubMenu(ll_MainHandle,0)




ll_x = GetSystemMetrics(SM_CXMENUCHECK) 
ll_y = GetSystemMetrics(SM_CYMENUCHECK) 




ll_Bitmapcut = LoadImageW(0,'cut.bmp',  IMAGE_BITMAP ,ll_x,ll_y,LR_LOADFROMFILE)
ll_Bitmapcopy = LoadImageW(0,'copy.bmp',  IMAGE_BITMAP ,ll_x,ll_y,LR_LOADFROMFILE)
ll_Bitmappaste = LoadImageW(0,'paste.bmp',  IMAGE_BITMAP ,ll_x,ll_y,LR_LOADFROMFILE)
ll_Bitmapitl = LoadImageW(0,'itl.bmp',  IMAGE_BITMAP ,ll_x,ll_y,LR_LOADFROMFILE)
ll_Bitmapcnt = LoadImageW(0,'big.bmp',  IMAGE_BITMAP ,ll_x,ll_y,LR_LOADFROMFILE)
ll_bitmapunderline = LoadImageW(0,'ul.bmp',  IMAGE_BITMAP ,ll_x,ll_y,LR_LOADFROMFILE)


SetMenuItemBitmaps(ll_SubMenuHandle,0,MF_BYPOSITION,ll_Bitmapcut,ll_Bitmapcut)
SetMenuItemBitmaps(ll_SubMenuHandle,1,MF_BYPOSITION,ll_Bitmapcopy,ll_Bitmapcopy)
SetMenuItemBitmaps(ll_SubMenuHandle,2,MF_BYPOSITION,ll_Bitmappaste,ll_Bitmappaste)
SetMenuItemBitmaps(ll_SubMenuHandle,4,MF_BYPOSITION,ll_Bitmapitl,ll_Bitmapitl)
SetMenuItemBitmaps(ll_SubMenuHandle,5,MF_BYPOSITION,ll_Bitmapcnt,ll_Bitmapcnt)
SetMenuItemBitmaps(ll_SubMenuHandle,6,MF_BYPOSITION,ll_Bitmapunderline,ll_Bitmapunderline)
end event
///

3.uo_supermenu 的方法:

of_init()
of_show_popmenu(long xpos, long ypos)    (这两个一起用, 在窗口或控件的rightbuttondown事件里用, 建立实例变量, 要注意销毁对象,不然程序退出后还在后台运行)


  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LoveLearnling

您的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值