如何在派生类里设置控件的大小
我自己定义了一个CButton派生类CMyButton,同时在对话框里定义了一个CMyButton类型的按钮控件,现在给定了这个按钮的大小值,想让控件生成的时候自己根据这个值设置大小。
我知道在对话框里,可以用MoveWindow等进行大小的设置,但这样比较麻烦,最好是给CMyButton类一个值,让他自己生成的时候就弄好。
我试了半天,也不成功。。。在 PreCreateWindow()函数里控制一下,控件大小样子可以变了,但是当按钮的实际响应区域没有变,还是和原来一样。也就是说鼠标点击按钮原来多余的地方,也响应按钮的事件。按钮的响应区域和按钮控件大小没有同步。
这是什么原因呢?要想在派生类CMyButton里设置控件的大小,如何实现呢?
问题点数:20、回复次数:5Top
1 楼Snow_Ice11111(雪上加冰)回复于 2005-11-03 22:30:31 得分 0
CMyButton m_myButton;
m_myButton.Create(WS_VISIBLE|WS_TABSTOP, CRect(10, 150, 170, 370), this, 10000);
上面的代码不一定对,自己试下。Top
2 楼djfu(飞龙在天)回复于 2005-11-03 22:36:12 得分 0
用:SetWindowRgn(...)看看。
SetWindowRgn
The SetWindowRgn function sets the window region of a window. The window region determines the area within the window where the system permits drawing. The system does not display any portion of a window that lies outside of the window region
int SetWindowRgn(
HWND hWnd, // handle to window
HRGN hRgn, // handle to region
BOOL bRedraw // window redraw option
);
Parameters
hWnd
[in] Handle to the window whose window region is to be set.
hRgn
[in] Handle to a region. The function sets the window region of the window to this region.
If hRgn is NULL, the function sets the window region to NULL.
bRedraw
[in] Specifies whether the system redraws the window after setting the window region. If bRedraw is TRUE, the system does so; otherwise, it does not.
Typically, you set bRedraw to TRUE if the window is visible.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Windows NT/2000/XP: To get extended error information, call GetLastError.
Top
3 楼linsi(〆轻羽无痕♀)回复于 2005-11-04 10:17:10 得分 0
还是没有解决,哪位大侠帮忙 看看啊。。。
Top
4 楼linsi(〆轻羽无痕♀)回复于 2005-11-04 11:39:34 得分 0
接着顶。。。Top
5 楼djfu(飞龙在天)回复于 2005-11-04 12:37:51 得分 0
CRect rcDialog;
GetClientRect(rcDialog);
CRgn rgn;
rgn.CreateRectRgn(rcDialog.left, rcDialog.top,
rcDialog.Width() + rcDialog.left - 50,
rcDialog.Height() + rcDialog.top - 50);
SetWindowRgn(GetSafeHwnd(), (HRGN)rgn, TRUE);Top




