CWnd* pWnd = AfxGetMainWnd(); pWnd->SendMessage(WM_CLOSE, 0, 0);
CButton* pBtn = (CButton*)GetDlgItem(IDC_MY_BUTTON); pBtn->SendMessage(BM_CLICK, 0, 0);In this example, the SendMessage function is used to send the BM_CLICK message to a button control with the identifier IDC_MY_BUTTON. This will cause the button to be clicked. Both examples use the MFC library in Visual Studio.