Page 1 of 1

Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 10:16
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

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 10:59
by Mex
Found another solution, but this code has a nasty GDI leak.
http://www.vbforums.com/attachment.php? ... 1156934327

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 11:02
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

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 11:05
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

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 12:47
by TiKu
I did only read over the code, but could not find any obvious GDI leak.

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 15:05
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.

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 16:28
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

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 16:39
by Mex
Thank you!

Maybe you know any other good solution how to change menu font or just increase font size ?

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 17:09
by TiKu
No, owner-drawing the items is the way to go.

Re: Toolbar as Menubar and fonts

Posted: 05 Oct 2013, 17:17
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