MFC-接收按钮单击消息失败
MFC- receiving Button-Click-Message failed
我在基于MFC对话框的应用程序中创建了一个新对话框。新对话框包含5个控制按钮。
下面的事情发生了,我不明白为什么?
- 单击按钮X。(结果ok,发送了OnBnClicked消息)
- 单击应用程序的任何位置,但不要单击对话框。(从对话框中删除焦点)
- 再次单击按钮X(失败,未发送OnBnClicked消息)。但如果我点击对话框中的任何其他按钮(结果ok,发送OnBnClicked消息)
当我这样做的时候:
- 单击对话框区域可以再次设置对话框的焦点
- 再次单击按钮X。(结果ok,发送OnBnClicked消息)
**只有当我想再次点击按钮X时,我才需要执行步骤3!为什么?我认为它与SetFocus()有关,但我不确定是怎么回事。
按钮IDC是:IDC_BACK_MEDIA_PRESS_BUTTON 1180IDC_TOOLS_LEFT_RIGHT 1024IDC_MEDIA_FOREWARD_BUTTON 1103IDC_MEDIA_BACKWARD_BUTTON 1104IDC_TOOLS_HOOD_BUTTON 2346
对话框属性为:
IDD_TOOLS_DIALOG对话框0、0、51、218样式DS_SETFONT|DS_MODALFRAME|DS_FIXEDSYS|WS_POPUP|WS_VISIBLE|WS_ception|WS_SYSMENU标题"工具"FONT 8,"MS Shell Dlg",400,0,0x1开始PUSHBUTTON"媒体和向前",IDC_Media_Foreward_BUTTON,7,79,37,36,BS_MULTILINEPUSHBUTTON"&Media&BackWard",IDC_Media_BackWard_BUTTON,7,43,37,36,BS_MULTILINEPUSHBUTTON"后退媒体按压",IDC_Back_Media_Press_BUTTON,7127,37,36,BS_MULTILINE | NOT WS_VISIBLEPUSHBUTTON"发动机罩",IDC_TOOLS_OOD_BUTTON,7,7,37,36按钮"左-右",IDC_TOOLS_Left_Right,7175,37,36结束
我尝试过不同的风格,比如,工具窗口,重叠,弹出。这种情况在所有情况下都会发生。
谢谢你的帮助。
.h
class CToolsDlg : public CBDialog
{
DECLARE_DYNAMIC(CToolsDlg)
public:
CToolsDlg(CWnd* pParent = NULL); // standard constructor
virtual ~CToolsDlg();
CToolTipCtrl m_ToolsTips;
// Dialog Data
enum { IDD = IDD_TOOLS_DIALOG };
protected:
virtual void OnCancel();
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
CMFCButton m_HoodButton;
CMFCButton m_MediaForewardButton;
CMFCButton m_MediaBackwardButton;
CMFCButton m_LeftRightButton;
virtual BOOL OnInitDialog();
virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnBnClickedCancel();
afx_msg void OnBnClickedToolsHoodButton();
afx_msg void OnBnClickedMediaForewardButton();
afx_msg void OnBnClickedMediaBackwardButton();
afx_msg void OnBnClickedLeftRightButton();
afx_msg void OnBnClickedBackMediaPressButton();
};
.cpp
IMPLEMENT_DYNAMIC(CToolsDlg, CBDialog)
CToolsDlg::CToolsDlg(CWnd* pParent /*=NULL*/)
: CBDialog(CToolsDlg::IDD, pParent)
{
}
CToolsDlg::~CToolsDlg()
{
}
void CToolsDlg::DoDataExchange(CDataExchange* pDX)
{
CBDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TOOLS_HOOD_BUTTON, m_HoodButton);
DDX_Control(pDX, IDC_MEDIA_FOREWARD_BUTTON, m_MediaForewardButton);
DDX_Control(pDX, IDC_MEDIA_BACKWARD_BUTTON, m_MediaBackwardButton);
DDX_Control(pDX, IDC_TOOLS_LEFT_RIGHT, m_LeftRightButton);
}
BEGIN_MESSAGE_MAP(CToolsDlg, CBDialog)
ON_WM_CLOSE()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_TOOLS_HOOD_BUTTON, &CToolsDlg::OnBnClickedToolsHoodButton)
ON_BN_CLICKED(IDC_MEDIA_FOREWARD_BUTTON, &CToolsDlg::OnBnClickedMediaForewardButton)
ON_BN_CLICKED(IDC_MEDIA_BACKWARD_BUTTON, &CToolsDlg::OnBnClickedMediaBackwardButton)
ON_BN_CLICKED(IDC_TOOLS_LEFT_RIGHT, &CToolsDlg::OnBnClickedLeftRightButton)
ON_BN_CLICKED(IDC_BACK_MEDIA_PRESS_BUTTON, &CToolsDlg::OnBnClickedBackMediaPressButton)
END_MESSAGE_MAP()
// CToolsDlg message handlers
BOOL CToolsDlg::OnInitDialog()
{
CBDialog::OnInitDialog();
// Window position
//////////////////////////////////////////////////////////////////////////
CMainFrame* mf = (CMainFrame*)AfxGetMainWnd();
RECT MFwinRect;
RECT ThiswinRect;
CWnd* fv = mf->m_wndSplitter.GetView( mf->m_wndSplitter.GetCurrentViewIndex(0,0) );
fv->GetWindowRect(&MFwinRect);
GetWindowRect(&ThiswinRect);
MoveWindow(
MFwinRect.right - (ThiswinRect.right - ThiswinRect.left) - 14, // X
MFwinRect.top + 14, // Y
(ThiswinRect.right - ThiswinRect.left), // nWidth
(ThiswinRect.bottom - ThiswinRect.top) ); // nHeight
// Set controls state
//////////////////////////////////////////////////////////////////////////
m_ToolsTips.Create(this);
m_ToolsTips.AddTool(&m_HoodButton, TOOLTIP_HOOD_BUTTON);
m_ToolsTips.AddTool(&m_MediaForewardButton, TOOLTIP_MEDIA_FOREWARD_BUTTON);
m_ToolsTips.AddTool(&m_MediaBackwardButton, TOOLTIP_MEDIA_BACKWARD_BUTTON);
m_ToolsTips.AddTool(&m_LeftRightButton, TOOLTIP_LEFT_RIGHT_BUTTON);
m_ToolsTips.SetDelayTime(1000);
m_ToolsTips.Activate(BARAK_PREFS->m_Params.m_bShowToolTips);
// Main timer loop (no need for now)
// SetTimer( 1, 1000, NULL );
return TRUE;
}
BOOL CToolsDlg::PreTranslateMessage(MSG* pMsg)
{
m_ToolsTips.RelayEvent(pMsg);
return CBDialog::PreTranslateMessage(pMsg);
}
void CToolsDlg::OnCancel()
{
// When closing the window, destroy it and not only hide (its a floating window).
DestroyWindow();
}
void CToolsDlg::OnTimer(UINT_PTR nIDEvent)
{
CBDialog::OnTimer(nIDEvent);
}
void CToolsDlg::OnBnClickedToolsHoodButton()
{
...
}
void CToolsDlg::OnBnClickedMediaForewardButton()
{
...
}
void CToolsDlg::OnBnClickedMediaBackwardButton()
{
...
}
void CToolsDlg::OnBnClickedLeftRightButton()
{
...
}
void CToolsDlg::OnBnClickedBackMediaPressButton()
{
...
}
我看到您正在用对话框内容填充视图。你把注意力放在对话上了吗?我认为这种神秘的行为只发生在对话框中的第一次鼠标点击时(然后对话框获得焦点)。我只是猜测:)
- 自定义预期失败的完整错误消息(boost::spirit::x3)
- boost::p rogram_options - 验证失败时,显示用户在错误消息中输入的值
- 为什么我的GLSL着色器失败汇编而没有错误消息
- 使用分位数函数提升断言失败的消息
- 由于管道破裂,提升 asio 发送消息失败
- git_clone错误消息断言失败:git_atomic_get(&git__n_inits) > 0
- 使用预编译标头时,海湾合作委员会在没有消息中失败
- 读取功能失败时的成功消息
- 构建失败 - 错误消息翻译
- 使用 CppUnit 和 TFS2015 时"断言失败"消息不完整
- IWICImagingFactory::CreateDecoderFromStream()失败,错误消息消息没有帮助
- MFC-接收按钮单击消息失败
- 如何在C++中读取系统调用失败时显示的故障日志消息
- MFC窗口工具栏创建失败,没有错误消息
- 顶点着色器编译失败,但信息日志中没有消息
- make find_package(OpenGL REQUIRED)失败,没有任何错误消息
- 调试断言失败消息
- 使模板函数编译失败,并返回错误消息
- Google Mock:如何配置自定义消息来解释匹配失败
- 使用模板检查结构体中的字段,启用函数if,并在失败时给出一个漂亮的错误消息