-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppDialog.cpp
126 lines (108 loc) · 2.61 KB
/
AppDialog.cpp
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <windows.h>
#include "resource.h"
#include "AppDialog.h"
PVOID pResizeState = NULL;
// Constructor
CAppDialog::CAppDialog(HINSTANCE hInst)
{
m_hInst = hInst;
m_hWnd = NULL;
LoadString(hInst, IDS_APP_NAME, m_szAppName, STR_MAX);
}
BOOL CAppDialog::DialogProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return FALSE;
}
BOOL CAppDialog::OnInitDialog(WPARAM wParam, LPARAM lParam)
{
return TRUE;
}
BOOL CAppDialog::OnDrawItem(WPARAM wParam, LPDRAWITEMSTRUCT lParam)
{
return TRUE;
}
BOOL CAppDialog::OnCommand(WPARAM wId)
{
return TRUE;
}
BOOL CAppDialog::OnNotify(WPARAM wId, LPNMHDR nmhdr)
{
return TRUE;
}
void CAppDialog::MsgBox(UINT type, UINT id, ...)
{
va_list arglist;
TCHAR szFormat[80];
::LoadString(m_hInst, id, szFormat, sizeof(szFormat));
TCHAR szBuffer[256];
va_start(arglist, id );
wvsprintf(szBuffer, szFormat, arglist);
va_end(arglist);
MessageBox(m_hWnd, szBuffer, m_szAppName, type);
}
void CAppDialog::SleepYield(DWORD msec)
{
MSG msg;
::Sleep(msec);
if (PeekMessage(&msg, m_hWnd, 0L, 0L, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
void CAppDialog::OnClose()
{
::EndDialog(m_hWnd, IDOK);
}
BOOL CALLBACK AppDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CAppDialog* pDlg = (CAppDialog*) GetWindowLong(hDlg, GWL_USERDATA);
switch (uMsg)
{
case WM_INITDIALOG:
SetWindowLong(hDlg, GWL_USERDATA, lParam);
pDlg = (CAppDialog*) lParam;
pDlg->m_hWnd = hDlg;
return pDlg->OnInitDialog(wParam, lParam);
case WM_CLOSE:
pDlg->OnClose();
DestroyWindow(hDlg);
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
return pDlg->OnCommand(wParam);
case WM_NOTIFY:
return pDlg->OnNotify(wParam, (LPNMHDR) lParam);
case WM_DRAWITEM:
return pDlg->OnDrawItem(wParam, (LPDRAWITEMSTRUCT) lParam);
return pDlg->DialogProc(uMsg, wParam, lParam);
}
return FALSE;
}
BOOL CAppDialog::CreateDialogBox(LPCTSTR lpszResource, HWND hParent)
{
m_hWnd = CreateDialogParam(m_hInst, lpszResource, hParent, (DLGPROC)AppDialogProc, (LPARAM) this);
return m_hWnd != NULL;
}
int CAppDialog::Run(void)
{
int status;
MSG msg;
while ((status = GetMessage(&msg, 0, 0, 0)) != 0)
{
if (status == -1)
return -1;
if (!::IsDialogMessage(m_hWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
BOOL CAppDialog::ShowWindow(int nCmdShow)
{
return ::ShowWindow(m_hWnd, nCmdShow);
}