forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Icons in menus, centering captions
Goto page Previous  1, 2
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
jalih



Joined: 30 Jul 2012
Posts: 196

PostPosted: Sun Jun 16, 2013 5:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Mon Jun 17, 2013 7:04 am    Post subject: Reply with quote

Thanks for this Jalih. It is very helpful.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Mon Jun 17, 2013 8:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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