|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
jalih
Joined: 30 Jul 2012 Posts: 196
|
Posted: Sun Jun 16, 2013 5:26 pm Post subject: |
|
|
My menu icon implementation ended up using three functions. One function for setting up the icon for menu item and two functions to be passed for window message handler.
Code: |
func SetMenuIcon(HWND hwnd, uint uItem, BOOL fByPosition, int wID), BOOL
HMENU hMenu = GetMenu(hwnd)
MENUITEMINFO mii
mii.cbSize = len(MENUITEMINFO)
mii.fMask = MIIM_BITMAP | MIIM_ID
mii.hbmpItem = HBMMENU_CALLBACK
mii.wID = wID ' Use this ID as link to icon resource when drawing
return SetMenuItemInfo(hMenu, uItem, fByPosition, &mii)
endf
func ON_WM_MEASUREITEM(pointer pmis),int
' Make sure there is a room for the icon in menu field.
settype pmis, MEASUREITEMSTRUCT
if #pmis <> NULL OR #pmis.CtlType = ODT_MENU
#pmis.ItemWidth += 4
if #pmis.ItemHeight < 16 then #pmis.ItemHeight = 16
endif
return TRUE
endf
func ON_WM_DRAWITEM(pointer pdis),int
settype pdis, DRAWITEMSTRUCT
if #pdis = NULL OR #pdis.CtlType <> ODT_MENU then return S_OK
CIcon *myIcon = new CIcon
myIcon->LoadFromResource(#pdis.itemID + 0)
HICON hIcon = myIcon->Detach()
IF hIcon = NULL then return S_OK
DrawIconEx(#pdis.hDC,#pdis.rcItem.left - 16,#pdis.rcItem.top + (#pdis.rcItem.bottom - #pdis.rcItem.top - 16) / 2, hIcon, 16, 16, 0, NULL, DI_NORMAL)
delete myIcon
return TRUE
endf
|
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7927 Location: Salford, UK
|
Posted: Mon Jun 17, 2013 7:04 am Post subject: |
|
|
Thanks for this Jalih. It is very helpful. |
|
Back to top |
|
|
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Mon Jun 17, 2013 8:49 am Post subject: |
|
|
I'm designing icons already! Fortunately, MSDN points out that "deciding to use menu icons doesn't mean that you must have icons for all your menu items. In fact, icons have better effect if they are reserved for only the most important menu items." and so there aren't hundreds to do!
Eddie |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|