如何在不创建按钮变量的情况下更改mfc中按钮的形状 [英] How to change the shape of button in mfc without creating a variable of button

查看:73
本文介绍了如何在不创建按钮变量的情况下更改mfc中按钮的形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不创建按钮变量的情况下更改按钮的形状。



我尝试了什么:



我在onDraw上尝试了以下代码,

I want to change the shape of button without creating button variable.

What I have tried:

I tried the below code on onDraw ,

CDC* pDC = GetDlgItem(IDC_SAMPLE_BUTTON)->GetDC();
int nX1 = 0;
int nX2 = 100;
int nY1 = 0;
int nY2 = 100;
m_point = new POINT();
m_point->x = 100;
m_point->y = 100;
pDC->RoundRect(nX1, nY1, nX2, nY2, m_point->x, m_point->y);





,但它继续覆盖,我在onpaint上使用相同的代码,它不起作用。请帮助我。



but it goes on overwriting, i used the same code on onpaint and it does not work. Please help me.

推荐答案

按钮之类的所有GUI控件都只是自己处理绘图的窗口。因此,当重新绘制控件时会在控件区域上绘制某些内容,这会在几个条件下发生。



常见的解决方案是使用所有者绘制派生类这需要在对话框类中使用成员变量来将资源项链接到派生类。



如果你不想使用上面的方法,你可以处理 WM_DRAWITEM消息(Windows) [ ^ ]。当按钮具有所有者绘制样式集时,该消息将被发送到父窗口。
All GUI controls like buttons are just windows which handle the drawing on their own. So drawing something on the area of the control will be overwritten when the control is redrawn which happens upon several conditions.

The common solution is deriving a class using owner-draw which requires the usage of a member variable in the dialog class to link the resource item to your derived class.

If you don't want to use the above method, you can handle the WM_DRAWITEM message (Windows)[^] in your dialog containing the button. When the button has the owner draw style set, the message will be send to the parent window.


这篇关于如何在不创建按钮变量的情况下更改mfc中按钮的形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆