hwnd of a B+ menu

BlitzPlus Forums/BlitzPlus Programming/hwnd of a B+ menu

How do I get the hwnd of a Blitz+ menu?

I've tried
hwnd=GetMenu (QueryObject (win,1))

where:
win is the handle of my main window
GetMenu%(hwnd%):"GetMenu" in User32

GetMenu always returns zero.
Anyone know what I'm doing wrong? I'm trying to add bitmaps to my menus.

hi Cold Harbour.

try this, it works for me.

if you need the decls, and constants , let me now.

function to add bitmaps to your menus

Function AddBitmapMenuIcon(window,subindex,menuindex,bitmapfile$,width=16,height=16)

	; get hwnd handle to passed window.
	hwnd = QueryObject(window,1)
	
	; check if it has a parent.
	real_hwnd = apiGetParent(hwnd)
	If real_hwnd <> 0 Then
		hwnd = real_hwnd
	EndIf
	
	; get the windows menu and submenu.
	hMenu_pointer = apiGetMenu(hwnd) 
	hMenu_subitem_pointer = apiGetSubMenu(hMenu_pointer,subindex)
	
	; open bitmap image to use in the menu.
	loadiconimage = apiLoadImage(0,bitmapfile$,IMAGE_BITMAP,width,height,LR_LOADFROMFILE)
	
	; add the icon to the windows menu item.
	icon = apiSetMenuItemBitmaps(hMenu_subitem_pointer,menuindex,MF_BYPOSITION,loadiconimage,loadiconimage)
	
End Function


kev

Cheers Kev.
Can I see how you declared apiLoadImage please and also what you use as bitmapfile$.

Thanks again.

Alternatively, you can use this code to retrieve the real window handle:
Function WindowHandle%(window)
Return PeekL(window+164)
End Function


My icons make anything close to white transparent. I tried the LR_LOADTRANSPARENT (=32) flag, but it had no effect.

We also need a way to change the menuitem height, since the menus are too small to display a 16x16 icon.

@Cold Harbour

.lib "user32.dll"
apiLoadImage%(hinst%,lpszName$,uType%,cxDesired%,cyDesired%,fuLoad%):"LoadImageA"

bitmapfile$ is the name of the image file on disk to open.

@halo

try LR_DEFAULTSIZE im not sure yet about the LR_LOADTRANSPARENT flag, i look into it.

LR_DEFAULTSIZE is a default flag. You don't need to enter a width and height.

Kev, damn, left the A off the end of :"LoadImageA".

Yay it works. Thanks for your help!

@halo
the MENUITEMINFO struct might be the way to change the menuitem height, using MFT_OWNERDRAW and WM_MEASUREITEM/WM_DRAWITEM messages but under blitz+ i not sure about hooking these messages.

@Cold Harbour
no problems, checkout api viewer.
http://www.activevb.de/rubriken/apiviewer/index-apiviewereng.html