Menu Button control Icon

Menu Button control

A menu button control. Ownerdrawn button painting.

Menu Button controlOverview

This is a Menu Button control. Menu Button controls are not rocket-science, but this control is also a demonstration on how to draw an ownerdrawn button in both Windows 98 and Windows XP.
The control displays itself as a regular button, except that it has a Glyph (a Little arrow) on the right signalling that it displays something when you click it. All it does is to display a popup menu. The popup menu is custom drawn because I wanted to be able to add colourful icons to it. The button is also ownerdrawn because it needs to Paint the dropdown-glyph on the right.
The problem with ownerdrawn buttons is that on Windows XP and greater we need to paint it with the current theme. Before Windows XP it was simply a matter of using the BS_OWNERDRAWN style. Unfortunately this also meant that we had to repaint the entire button exterior as well. Since a button always behaved the same, we could use the DrawFrameControl() API to do much of the drawing.
Along came Windows XP and changed all that. The DrawFrameControl() no longer works and we'll have to dip into the Theme API to get the job done. Well, not quite... because the old Windows Common Controls ListView and TreeView introduced a new ownerdraw method: the NM_CUSTOMDRAW notifications. And in Windows XP the Button control inherits this behaviour too (as well as supporting the old WM_DRAWITEM-range of messages).
The trick to drawing an ownerdraw button under Windows XP is not to draw the button at all.
The Button sends WM_NOTIFY / NM_CUSTOMDRAW notifications to the parent. If we wanted to drastically change the look of the button, we would start to custom paint here but since we just want to add an icon and some visual decorations, we'll answer the notification with the CDRF_NOTIFYPOSTPAINT code. This instructs Windows to paint the button entirely. When done, Windows calls us again with NM_CUSTOMDRAW and allows us to paint on top of the button image.

NEW

Fixed some bugs.

Menu Button controlInformation

Version
1.0
Date
12.22.08
License
Free
Language
English
File Size
5KB
Developer
Category
Operating Systems
Windows XP, 98
System Requirements
No additional system requirements.
GMail Drive Icon
GMail Drive allows you to use Gmail as a storage medium.
Free
BVRDE Icon
BVRDE is an Integrated Development Environment (IDE) for C and C++.
Free
RTF Script Editor Icon
A RTF based editor with syntax highlighting.
Free
ASMIL Icon
ASM to IL compiler
Free
CPathMonitor Icon
Uses the FindFirstChangeNotification Win32 API to detect changes in a file path.
Free
Console Screen class Icon
The class wraps the Win32 Console API.
Free
Database wrappers Class Icon
A set of classes wrapping the ODBC and OLE DB database APIs.
Free
Cool Tabs Icon
Includes DevStudio 6 and VisualStudio.NET folder tabs.
Free
More
Sublime Text (64-Bit) Icon
Create and edit commands, text files, macros, and regular expressions.
Demo
6-bit Binary Compression Icon
This is a fast 6-bit compression routine
Free
NetBeans IDE Icon
Fully-featured Java IDE written completely in Java, with many modules available.
Free
ArgoUML Icon
ArgoUML is the leading open source UML modeling tool.
Free
PE Viewer Icon
Tool to view/edit Windows Portable Executable files.
Free
Hex Workshop Icon
Hex edit, cut, copy, paste, insert, fill, and delete binary data.
Demo
Notepad++ (64-bit) Icon
Take full advantage of highly executable, multi-language, simultaneous text and source code editing.
Free
Hex Editor Neo Icon
Binary Data and File Data Editing Software Utility. Hex Editor Download
Trial
More