Code: Select all
void CMsgBox::MessageBox(CString sMsg, CString sCaption, UINT nSleep,
UINT nFlags, bool bAutoClose)
{
// Save the caption, for finding this
// message box window later
m_Caption = sCaption;
// If auto close selected then, start the timer.
if(bAutoClose)
SetTimer(100, nSleep, NULL);
// Show the message box
CWnd::MessageBox(sMsg, sCaption, nFlags);
}
Code: Select all
void CMsgBox::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
BOOL bRetVal = false;
// Find the message box window
CWnd* pWnd = FindWindow(NULL, m_Caption);
if(pWnd != NULL)
{
// Send close command to the message box window
::PostMessage(pWnd->m_hWnd, WM_CLOSE, 0, 0);
}
// Kill the timer
KillTimer(100);
CWnd::OnTimer(nIDEvent);
}
Code: Select all
void CMsgBox::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
BOOL bRetVal = false;
// Find the message box window
CWnd* pWnd = FindWindow(NULL, m_Caption);
if(pWnd != NULL)
{
// Send close command to the message box window
// ::PostMessage(pWnd->m_hWnd, WM_CLOSE, 0, 0);
CWnd* pOK = pWnd->GetDlgItem(IDOK);
HWND hWndOK = pOK->m_hWnd; // <-- Access violation
PostMessage(WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), (LPARAM)hWndOK);
}
// Kill the timer
KillTimer(100);
CWnd::OnTimer(nIDEvent);
}
Code: Select all
HWND hWndOK = pOK->m_hWnd; <-- Access violation