LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

copy menubar item from one menu to another

Solved!
Go to solution

I have a menu created in my UIR file.  In the same UIR (or hypothetically another), I want to programmatically copy a menubar item to the other.

 

I'm not seeing a DuplicateMenuItem or similar function.  Am I missing something?  Surely there's a way to do this.

0 Kudos
Message 1 of 8
(2,673 Views)
Solution
Accepted by topic author ElectroLund

I don't see a function like that either.  The only way I can see to do it is to manually read the name and callback function pointer of the source item (GetMenuBarAttribute) and use them to create a new target item (NewMenuItem).

Message 2 of 8
(2,643 Views)

Yeah, that's what I'll just have to do in this case.  I hadn't thought of the reading the menu item label and callback.  That's a nice solution, as I can continue creating the menu in the UIR but copy in code.

 

Only thing I can't find is how to read the icon of a menu item in order to copy it. There doesn't appear to be an attribute for attached images, probably because the IDE immediately encodes the image bitmap into the UIR.  Bummer.

0 Kudos
Message 3 of 8
(2,632 Views)

Perhaps ATTR_ITEM_BITMAP?

0 Kudos
Message 4 of 8
(2,630 Views)

Hmm, I'm getting negative bitmap ID numbers when calling:

 

 

GetMenuBarAttribute(mainMenu, menuItem, ATTR_ITEM_BITMAP, &image);

Other attributes of this menu item work, such as both ATTR_CALLBACK_FUNCTION_POINTER and ATTR_ITEM_NAME. As such, when I copy all of these to my new destination menu, I get the name of the item, its callback function, but no image.

 

 

There's a whole section in the help manual called "Using Bitmap Objects" but nothing there references menus specifically.

0 Kudos
Message 5 of 8
(2,615 Views)

I haven't looked into why ATTR_ITEM_BITMAP doesn't work, but would calling LoadMenuBar on the new panel, followed by removing all the menu items that you don't need, be a feasible solution?

0 Kudos
Message 6 of 8
(2,579 Views)

That could work.  Give it a try.

0 Kudos
Message 7 of 8
(2,573 Views)

I finally got around to working on this again.  I found the solution to my bitmap problem.  It was even easier than I realized.

 

It turns out that when a new menu is created, by default the ATTR_SHOW_IMAGES is disabled. So enabling that before checking for existence of a source menu bitmap then will show in the destination.

 

2018-10-10 06_53_33-WinTestTaurus (Rev_ 1.0.0.0).png

 

 

0 Kudos
Message 8 of 8
(2,513 Views)