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

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

@TOC


正文

对话框完全显示后,马上执行一个按钮的事件 (一),新建一个基于对话框的工程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 }


  • [原文链接]()
  • 注:知识搬运,供学习交流使用,侵联删!