Toolbar as Menubar and fonts

The place for threads about TimoSoft ToolBarControls.
Post Reply
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Toolbar as Menubar and fonts

Post by Mex »

Hi Timo!

Do You have any examples how to customize menu font and size?
I can change main menus font and size, but how about sub items?


Best Regards
Meelis
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Re: Toolbar as Menubar and fonts

Post by Mex »

Found another solution, but this code has a nasty GDI leak.
http://www.vbforums.com/attachment.php? ... 1156934327
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Toolbar as Menubar and fonts

Post by TiKu »

Well, the sub menus are popup menus (CreatePopupMenu) and Windows doesn't provide a way to customize the font of menu items. So the only way would be make the popup menus owner-drawn. I do this in the Office Style sample app. In this sample, I do not change the font of sub menu items, but I owner-draw them. Changing the font would be as simple as calling SelectObject(hDC, hFont) before drawing (don't forget to restore the old font after drawing).

Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Re: Toolbar as Menubar and fonts

Post by Mex »

TiKu wrote:Well, the sub menus are popup menus (CreatePopupMenu) and Windows doesn't provide a way to customize the font of menu items. So the only way would be make the popup menus owner-drawn. I do this in the Office Style sample app. In this sample, I do not change the font of sub menu items, but I owner-draw them. Changing the font would be as simple as calling SelectObject(hDC, hFont) before drawing (don't forget to restore the old font after drawing).

Regards
TiKu
Thnx, for thw answer.
If you have time, can you test and comment this code and GDI leak, please? :)
http://www.vbforums.com/attachment.php? ... 1156934327
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Toolbar as Menubar and fonts

Post by TiKu »

I did only read over the code, but could not find any obvious GDI leak.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Re: Toolbar as Menubar and fonts

Post by Mex »

OK is it normal - if you start the program there are (lets say) 200 GDI objects.
Click on first menu, GDI objects are now 206. Close menu. GDI objetcs 205. Open menu GDI objetcs 212 aso.
In my application after 10 min using there was over 1000 GDI objects and this only after clicking on menus :)

You can test it with this sample application
Open first menu and move mouse over menus, GDI objects are growing and growing.

It think the problem is with menu images, if you disable menu images/buttons then GDI obects are not growing.
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Toolbar as Menubar and fonts

Post by TiKu »

Well, after a deeper look, I can tell you that some parts of the code are really horrible:
  1. DrawEmbossed creates quite a few GDI objects but deletes none of them. This is the main problem.
  2. m_MenuFont is never deleted - should be done in Class_Terminate.
  3. GetDC is called twice without calling ReleaseDC.
  4. ImageList_GetIcon is called without destroying the icon (which is never used by the way).
  5. The code often calls GetSysColor and uses the result for calling CreateSolidBrush. What's wrong with GetSysColorBrush?
Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Re: Toolbar as Menubar and fonts

Post by Mex »

Thank you!

Maybe you know any other good solution how to change menu font or just increase font size ?
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: München
Contact:

Re: Toolbar as Menubar and fonts

Post by TiKu »

No, owner-drawing the items is the way to go.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Re: Toolbar as Menubar and fonts

Post by Mex »

OK improved the code and now all gdi objects are destroyed.
of course mu gdi, api skills are zero :D, but its working and gdi objects are not growing anymore :).

Thank you again!


Meelis
Post Reply