Krzysztof Mossakowski
Windows Programming
2006 - Tasks
Resources, dialog boxes, controls
Sample task
Owner-draw menu
Demonstration
Create application with 2 menu items:
'Modify menu' - opens
modeless
dialog box with options to add and remove menu items:
textbox (edit control) for menu item's string
'Browse' button - opens standard dialog box for choosing icon file
selected icon preview
'Append' button - if string and icon are specified appends new menu item to the 'Test' menu
'Remove the last' button - removes the last menu item from 'Test' menu
'Close' button - closes the dialog box
'Test'
owner draw menu items with icons (as in the demonstration)
icons scaled to size 16 x 16
width and height of menu items dependend on the length of the string and system font used for menus
4 predefined menu items with icons taken from the system: error, exclamation, information, question
after choosing any item from 'Test' menu message box with the string from this menu item should be displayed
Hints:
GetMenu(), GetSubMenu(), AppendMenu(), DeleteMenu(), GetMenuItemInfo(), MF_OWNERDRAW
WM_MEASUREITEM, WM_DRAWITEM
GetTextExtentPoint32(), SystemParametersInfo(SPI_GETNONCLIENTMETRICS)
LoadIcon(), LoadImage()
DrawIconEx()
GetOpenFileName(), #include "commdlg.h"
Points:
owner draw menu
scaled icon - 1.0
string with proper alignment - 1.0
checking string's width - 0.5
using system menu font for measuring - 1.0
selection rectangle - 0.5
4 predefined items with icons from the system - 1.0
message box with menu item's string after choosing it - 0.5
dialog box for menu modifications
modeless dialog box - 0.5
textbox for the string - 0.5
buttons - 0.5
standard file dialog (with filter for .ico files) - 1.0
icon preview - 0.5
appending menu item - 0.5
removing the last menu item - 1.0