Popup menu with nice title

<!-- 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 foundCTMenu 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, useCTitleMenu 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.



转自:http://www.codeproject.com/Articles/1787/Popup-menu-with-nice-title

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值