Repository navigation
Expand file tree
/
Copy pathMyMsgBox.cpp
More file actions
68 lines (60 loc) · 1.44 KB
/
Copy pathMyMsgBox.cpp
File metadata and controls
68 lines (60 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "stdafx.h"
#include "MyMsgBox.h"
IMPLEMENT_DYNAMIC(CMyMsgBox, CWnd)
CMyMsgBox::CMyMsgBox(CWnd* pParent)
{
m_hWndParent = pParent->GetSafeHwnd(); // can be NULL
m_autoclose = NULL;
m_count = 0;
}
BEGIN_MESSAGE_MAP(CMyMsgBox, CWnd)
ON_WM_TIMER()
ON_WM_CREATE()
ON_MESSAGE(WM_INITDIALOG, OnSubclassedInit)
END_MESSAGE_MAP()
int CMyMsgBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
AfxUnhookWindowCreate();
return CWnd::OnCreate(lpCreateStruct);
}
LRESULT CMyMsgBox::OnSubclassedInit(WPARAM wParam, LPARAM lParam)
{
LRESULT lRet = Default();
CWnd* pOk = GetDlgItem(IDCANCEL);
if ( NULL != pOk ) { pOk->EnableWindow(FALSE); }
SetTimer(100,2000,NULL);
return lRet;
}
void CMyMsgBox::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 100)
{
if (m_count>0) { m_count--; }
if (m_count == 0)
{
CWnd* pOk = GetDlgItem(IDCANCEL);
if ( NULL != pOk )
{
pOk->EnableWindow(TRUE);
pOk->SetFocus();
}
KillTimer(100);
if (m_autoclose) { PostMessage(WM_CLOSE); }
}
}
}
int CMyMsgBox::MessageBox(LPCTSTR lpszText,LPCTSTR lpTitle, int count, bool bclose,UINT uType)
{
m_autoclose = bclose;
m_count = count;
AfxHookWindowCreate(this);
return ::MessageBox(m_hWndParent, lpszText,lpTitle, uType);
}
LRESULT CMyMsgBox::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message==WM_COMMAND && m_count>0)
{
if(HIWORD(wParam)==BN_CLICKED) { return 0; }
}
return CWnd::DefWindowProc(message, wParam, lParam);
}