Re: Digest for EUforum at topica.com, issue 6349
>
> Subject: Re: Picture menus
>
>
> posted by: Pete Stoner <stoner.pete at gmail.com>
>
> CChris wrote:
> >
> > Pete Stoner wrote:
> > >
> > > Hi y'all,
> > > I have an Win32lib application with a hidden window which just presents a
> > > popup
> > > menu, this is all working fine but I want to improve the look of the menu
> > > by
> > > adding icons so it is a picture menu. The only library I could find to do
> > > this
> > > is xControls (version 1 - the PicMenu isn't in version 2 - I guess this
> > > could
> > > be why!
) by Greg Haberek. This looks good but one of the menu items
> > > opens
> > > a window and if any of the menu options use PicMenu I get a win32lib error
> > > (version
> > > 0.60.6) - code 425, "Held resource owner is not the actual owner".
> > >
> > > Does anyone know of a fix for this or is there another library I can use
> > > to
> > > generate the picture menu?
> > >
> > > Regards PeteS
> >
> > You may wait for my mod'ed version of win32lib to be open to beta testers,
> > it will do that job right. This could take like 10-15 days, allowing for
> > more testing. Alternatively, you can try wrapping SetMenuItemInfo() in the
> > Win32 API and use this to set checked and unchecked marks to the same bitmap
> >
> > (your own). I'll post or email the details if you are in a hurry and wish
> > to try this approach. The API isn't very tricky really.
> >
> > HTH
> > CChris
>
> Thanks, I would like try wrapping the API myself, but the ways things are
> at the moment I doubt if I would have the time to figure it all out from
> scratch, so if you do have any info on it then I'll be glad for the
> help.. Otherwise I'll wait for your win32lib enhancements..
>
> PeteS
>
>
The SetMenuItemBitmaps function associates the specified bitmap with a
menu item. Whether the menu item is checked or unchecked, Windows
displays the appropriate bitmap next to the menu item.
BOOL SetMenuItemBitmaps(
HMENU hmenu, // handle of menu
UINT uItem, // menu item to receive new bitmaps
UINT fuFlags, // menu item flags
HBITMAP hbmUnchecked, // handle of unchecked bitmap
HBITMAP hbmChecked // handle of checked bitmap
);
So you need to first access this function:
constant
xSetMenuItemBitmaps=registerw32Function(user32,"SetMenuItemBitmaps",
{C_ULONG,C_ULONG,C_INT,C_POINTER,C_POINTER},C_INT)
The input parameters are:
hmenu
Identifies the menu containing the item to receive new check mark
bitmaps.
uItem
Specifies the menu item to be changed, as determined by the fuFlags
parameter.
fuFlags
Specifies how the uItem parameter is interpreted. The fuFlags parameter
must be one of the following values:
MF_BYCOMMAND
Indicates that uItem gives the identifier of the menu item. If neither
MF_BYCOMMAND nor
MF_BYPOSITION is specified, MF_BYCOMMAND is the default flag.
MF_BYPOSITION
Indicates that uItem gives the zero-based relative position of the
menu item.
hbmUnchecked
Handle of the bitmap displayed when the menu item is not checked.
hbmChecked
Handle of the bitmap displayed when the menu item is checked.
Return Value
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error
information, call GetLastError.
Remarks
If either the hbmUnchecked or hbmChecked parameter is NULL, Windows
displays nothing next to the menu item for the corresponding check
state. If both parameters are NULL, Windows displays the default check
mark bitmap when the item is checked and removes the bitmap when the
item is not checked. If both parameters are equal but not NULL, the same
bitmap will display whether the menu item is checked or not.
When the menu is destroyed, these bitmaps are not destroyed; it is up to
the application to destroy them.
Use GetsystemMetrics with the CXMENUCHECK and CYMENUCHECK values to
retrieve the right bitmap dimensions.
(adapted from M$ docs).
So, you'd set marks for the 3rd menu item like this:
if not w32Func(xSetMenuItemBitmaps,{
getHandle(myMenu),
2, -- 0-based for 3rd item
MF_BYPOSITION,
hUnchecked,
hChecked
}) then
warnErr("Couldn't set the check marks for that item")
end if
You probably got the bitmaps handles from loadBitmapFromFile() or
anything similar.
HTH
CChris
CChris
--
cchris005 at fastmail.fm
--
http://www.fastmail.fm - Does exactly what it says on the tin
|
Not Categorized, Please Help
|
|