首页 > 其他分享 >对话框完全显示后,马上执行一个按钮的事件

对话框完全显示后,马上执行一个按钮的事件

时间:2022-10-05 11:36:15浏览次数:49  
标签:return 对话框 马上 OnInitDialog hButton 按钮 TRUE CDlgEventDlg


                                                                           何志丹 

对话框完全显示后,马上执行一个按钮的事件
(一),新建一个基于对话框的工程DlgEvent。
(二),增加一个按钮IDC_BUTTON1,并为其增加响应函数,代码如下:
void CDlgEventDlg::OnButton1()
{
AfxMessageBox("CDlgEventDlg::OnButton1");
}
(三),修改函数CDlgEventDlg::OnInitDialog,方法一代码如下:
BOOL CDlgEventDlg::OnInitDialog()
{
//...
ShowWindow(SW_NORMAL);
OnButton1();

return TRUE; // return TRUE unless you set the focus to a control
}
方法二代码如下:
BOOL CDlgEventDlg::OnInitDialog()
{
//...
HWND hButton = ::GetDlgItem(m_hWnd,IDC_BUTTON1);
::PostMessage(hButton,WM_LBUTTONDOWN,MK_LBUTTON,NULL);
::PostMessage(hButton,WM_LBUTTONUP,MK_LBUTTON,NULL);

return TRUE; // return TRUE unless you set the focus to a control
}

标签:return,对话框,马上,OnInitDialog,hButton,按钮,TRUE,CDlgEventDlg
From: https://blog.51cto.com/u_15724537/5732446

相关文章