Click here to Skip to main content
Click here to Skip to main content

Popup menu with nice title

By , 2 Apr 2002
Rate this:
Please Sign up or sign in to vote.
<!-- Download Links --> <!-- Article image -->

Sample Image - TitleMenu.jpg

<!-- Add the rest of your HTML here -->

Introduction

I wanted to put a title on top of some popup menus, but I didn't like to use DISABLED|STRING as flags for a menu-item, as this doesn't prevent the mouse-over selection, and doesn't look nice. So I checked around and found CTMenu by Per Fikse on Code Guru, which I then build upon, to get what I wanted.

CTitleMenu is pretty simple to use. Include the source-files in your project, and where you use CMenu, use CTitleMenu instead. And don't forget to #include "TitleMenu.h" ofcourse.

Functions:

void AddMenuTitle(LPCTSTR lpszTitle);
This puts a MenuItem on first menu position, with the caption lpszTitle. If you don't use this, the menu will look just like a normal menu.
void SetColor(long cl) {clLeft=cl;};
This sets the background color, or left-side color in a gradient background.
Default: Standard Windows Active Caption color
void SetGradientColor(long cl);
This sets the right-side color in a gradient background. If this color is the same as the set background color, obviously no gradient will be drawn either.

NOTE: I'm loading the GradientFill function dynamically from msimg32.dll. If this load fails, for whatever reason, no gradient fill will be performed, but no crash should occur either.

Default: Standard Windows Gradient Active Caption color

void SetTextColor(long cl);
This sets the text color of the title.
Default: Standard Windows Captiontext color
void SetEdge(bool shown,UINT remove=0,UINT add=0);
This sets the visibility and style of the edge around the title. For an overview of the flag values, see ::DrawEdge help.
Default: no border (shown=false), and style BDR_SUNKENINNER
long GetColor();
long GetGradientColor();
long GetTextColor();
long GetEdge();
These functions will get you the current values.

Example:

CTitleMenu menu1;
menu1.CreatePopupMenu();
menu1.AddMenuTitle("Power Channels");
menu1.AppendMenu(MF_STRING | MF_ENABLED | MF_CHECKED, 20, "Right Peltier");
menu1.AppendMenu(MF_STRING | MF_ENABLED | MF_CHECKED, 20, "Left Peltier");
...

I haven't tested this very thoroughly, but the code isn't that complex. I didn't encounter any problems with it, so far. There is enough that could be improved upon, like bitmap background, it's own gradient-function, and more, but then I would have to write a much bigger article. ^_^

Still, if you'd like to see a feature in it, or have expanded upon it yourself, leave a reply.

History

3 Apr 2002 - updated downloads.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Arthur Westerman

Netherlands Netherlands
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 PinmemberDurga Prasad Dhulipudi19-Oct-09 19:02 
GeneralLeaking dc PinmvpHans Dietrich25-Jul-08 22:36 
Generalit's cool Pinmemberyysdsyl12-Jun-07 6:13 
GeneralHaving trouble importing project Pinmemberadonisv14-Nov-05 10:49 
I'm getting the following errors..
 
:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(65) : error C2065: '_Module' : undeclared identifier
c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(2912) : error C2228: left of '.GetModuleInstance' must have class/struct/union type
c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(2974) : error C2228: left of '.GetModuleInstance' must have class/struct/union type
TitleMenu.cpp
c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(65) : error C2065: '_Module' : undeclared identifier
c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(2912) : error C2228: left of '.GetModuleInstance' must have class/struct/union type
c:\program files\microsoft visual studio\vc98\atl\include\atlwin.h(2974) : error C2228: left of '.GetModuleInstance' must have class/struct/union type
Error executing cl.exe.
Creating browse info file...
 
lesson3.exe - 6 error(s), 0 warning(s)
 
I'm trying to get this to work with an open gl project.
 
Normality is a weakness...
GeneralInsert a control in a popup menu. PinmemberNegrume4-Nov-04 6:11 
GeneralIf the title is too long... PinmemberDaniel132422-Mar-04 6:28 
GeneralNeeded bit of code for my implementation PinmemberMike Gaskey21-Apr-02 8:48 
GeneralNice UI feature PinmemberAnonymous3-Apr-02 23:32 
QuestionWhat if you don't have msimg32.dll ... try this PinmemberBrian D Pearson23-Mar-02 6:02 
AnswerRe: What if you don't have msimg32.dll ... try this PinmemberArthur Westerman29-Mar-02 0:36 
GeneralRe: What if you don't have msimg32.dll ... try this Pinmemberronhash3-Apr-02 22:30 
GeneralRe: What if you don't have msimg32.dll ... try this PinmemberPaul Selormey14-Oct-02 18:17 
Generalforgot to add this ... Pinmembershanthu20-Mar-02 12:26 
GeneralThanks a lot and I added this PopUp feature Pinmembershanthu20-Mar-02 12:21 
GeneralRe: Thanks a lot and I added this PopUp feature PinmemberAtlantys4-Apr-02 8:17 
GeneralRe: Thanks a lot and I added this PopUp feature PinmemberAnonymous4-Apr-02 10:57 
Generalproblem.. Pinmemberwebcreator14-Feb-02 3:46 
GeneralRe: problem.. PinmemberArthur Westerman15-Feb-02 12:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 3 Apr 2002
Article Copyright 2002 by Arthur Westerman
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid