请帮忙:自定义单选按钮没有 BN_CLICKED(MFC、VC++6)
我派生了一个 CButton 类并创建了我自己的单选按钮控件。除了我无法让父对话框检测它何时单击单选按钮之外,一切都运行良好。
如果我调用 CButton::OnLButtonUp(),父对话框将检测单选按钮单击,但这样做的问题是框架也会绘制单选按钮。我不想这样做,因为我自己绘制单选按钮。
有人可以告诉我如何阻止 Windows/MFC 框架在这种情况下绘制控件吗?如果我不调用 CButton::OnLButtonUp() 那么是的,Windows/MFC 将不会绘制控件,但我的父对话框也不会收到 BN_CLICKED 通知。
我知道我可以将自定义消息发送回我的对话框,但我不希望这样 - 我希望与 BN_CLICKED 消息兼容。
正如您将在下面看到的,我还尝试将消息发布回所属对话框,但这也不起作用。
void CNCCheckBox::OnLButtonUp(UINT nFlags, CPoint point)
{
if( m_Owner )
m_Owner->PostMessage( BN_CLICKED, (WPARAM) IDC_RAD_1/*GetDlgCtrlID()*/, (LPARAM) this->m_hWnd );
//CButton::OnLButtonUp(nFlags,point); // Can't use this!!
}
I have derived a CButton class and created my own radion button control. Its all working nicely with the exception that I can't get the parent dialog to detect when the radio button it clicked.
The parent dialog will detect the radio button click if I call CButton::OnLButtonUp() but the problem in doing that is that the framework also draws the radio button as well. I don't want to do that as I am drawing the radio button myself.
Can somebody please tell me how to stop Windows/MFC framework from drawing the control in this case? If I don't call CButton::OnLButtonUp() then yeah, Windows/MFC won't draw the control but my parent dialog won't get a BN_CLICKED notification either.
I know I could send a custom message back to my dialog but I don't want that - I want compatability with the BN_CLICKED message.
As you will see below, I have also tried posting a message back to the owning dialog and this doesn't work either.
void CNCCheckBox::OnLButtonUp(UINT nFlags, CPoint point)
{
if( m_Owner )
m_Owner->PostMessage( BN_CLICKED, (WPARAM) IDC_RAD_1/*GetDlgCtrlID()*/, (LPARAM) this->m_hWnd );
//CButton::OnLButtonUp(nFlags,point); // Can't use this!!
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经解决了。我摆脱了 OnDrawItem() (AFX_MSG),并添加了 DrawItem (AFX_VIRTUAL)。另外,在 PreSubClassWindow() 中,我将按钮的样式修改为 BS_PUSHBUTTON,并且 BN_CLICKED 事件现在被发送到我的父对话框。
简而言之:
- 不要使用 OnPaint()
- 不要使用 OnDrawItem()
- 使用:
I've solved it. I got rid of OnDrawItem() (AFX_MSG), and added DrawItem (AFX_VIRTUAL) instead. Also, in PreSubClassWindow() I modify the style to the button is treated as a BS_PUSHBUTTON and BN_CLICKED events are now being sent to my parent dialog.
So in short:
- Don't use OnPaint()
- Don't use OnDrawItem()
- Use: