如何用 win32 API 实现不规则形状的按钮?

aiyaya730 2011-10-10 01:43:14
如何实现不规则形状的按钮呢?


之前用 SetWindowRgn实现了不规则窗口,很简单

但是我现在把按钮的Proc设置成为了自定义的Proc

然后修改WM_CREATE消息,
使用SetWindowRgn设置按钮窗口的Rgn,却不管用。

我怕是消息不对,就把WM_CREATE改称 WM_LBUTTONDOWN试验一下
发现那个按钮点一下就显示得一片白了,不知道为什么!



要SDK的,不要MFC的
最好能给几个关键字,关键代码

恳求帮忙!谢谢!!
...全文
270 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuhuigong 2011-10-10
  • 打赏
  • 举报
回复
参照DirectUI的思想,图片,都是图片。。。
aiyaya730 2011-10-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 visualeleven 的回复:]
是因为子控件这个CS_PARENTDC属性的关系:
MSDN:
CS_PARENTDC Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style……
[/Quote]

谢谢!
刚才试了试,
不知道是自己汇编位运算有问题,还是还有其他的属性也对SetWindowRgn有影响,
暂时发现去掉 CS_PARENTDC之后,还是不能设置

但是试了试把字窗口控件的Style设置成和父窗口一致,就能实现功能,但是就已经不时按钮了

回头我再想想吧.
GetClassLong和SetClassLong,给了我很大启发。谢谢!

再挂挂看看有没有新的回复

明天没有回复就结贴
不二星空 2011-10-10
  • 打赏
  • 举报
回复
规则的做过。。不规则的还真不清楚。。。按钮就是的几个基本状态处理好就OK了
aiyaya730 2011-10-10
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 fangchao918628 的回复:]
这个应该得自绘按钮
[/Quote]

自绘按钮倒是知道
以前是在父窗口里处理WM_DRAWITEM

但是那样做的结果,按钮的图案是可以改变,可是还是矩形的。。
aiyaya730 2011-10-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 visualeleven 的回复:]
是因为子控件这个CS_PARENTDC属性的关系:
MSDN:
CS_PARENTDC Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style……
[/Quote]

多谢指教!以前还真不知道这个
fangchao918628 2011-10-10
  • 打赏
  • 举报
回复
这个应该得自绘按钮
Eleven 2011-10-10
  • 打赏
  • 举报
回复
是因为子控件这个CS_PARENTDC属性的关系:
MSDN:
CS_PARENTDC Sets the clipping rectangle of the child window to that of the parent window so that the child can draw on the parent. A window with the CS_PARENTDC style bit receives a regular device context from the system's cache of device contexts. It does not give the child the parent's device context or device context settings. Specifying CS_PARENTDC enhances an application's performance.

除非你子控件去掉这个CS_PARENTDC这个属性
DWORD style = GetClassLong(hWnd, GCL_STYLE);
SetClassLong(hWnd, GCL_STYLE, style & ~CS_PARENTDC);
HRGN hRgn = CreateEllipticRgn(0, 0, 100, 100);
SetWindowRgn(hWnd, hRgn, FALSE);
Eleven 2011-10-10
  • 打赏
  • 举报
回复
SetWindowRgn对子窗口不起作用

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧