5 #pragma warning(disable : 4244) // disable: conversion from 'LONG_PTR' to 'LONG', possible loss of data
6 #pragma warning(disable : 4312) // disable: conversion from 'LONG' to 'CUPDialog *' of greater size
7 #pragma warning(disable : 4996) // disable: 'wcsncpy' was declared deprecated
28 static const unsigned char dlg_145[] =
30 0xc8,0x08,0xc8,0x82,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0xbb,0x00,0x46,
31 0x00,0x00,0x00,0x00,0x00,0x44,0x00,0x69,0x00,0x61,0x00,0x6c,0x00,0x6f,0x00,0x67,
32 0x00,0x00,0x00,0x08,0x00,0x4d,0x00,0x53,0x00,0x20,0x00,0x53,0x00,0x68,0x00,0x65,
33 0x00,0x6c,0x00,0x6c,0x00,0x20,0x00,0x44,0x00,0x6c,0x00,0x67,0x00,0x00,0x00,0x00,
34 0x00,0x01,0x50,0x00,0x00,0x00,0x00,0x81,0x00,0x32,0x00,0x32,0x00,0x0e,0x00,0x02,
35 0x00,0xff,0xff,0x80,0x00,0x26,0x00,0x43,0x00,0x61,0x00,0x6e,0x00,0x63,0x00,0x65,
36 0x00,0x6c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x50,0x00,0x00,0x00,0x00,0x07,
37 0x00,0x19,0x00,0xac,0x00,0x0e,0x00,0xfa,0x03,0x6d,0x00,0x73,0x00,0x63,0x00,0x74,
38 0x00,0x6c,0x00,0x73,0x00,0x5f,0x00,0x70,0x00,0x72,0x00,0x6f,0x00,0x67,0x00,0x72,
39 0x00,0x65,0x00,0x73,0x00,0x73,0x00,0x33,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,
40 0x00,0x00,0x00,0x00,0x02,0x02,0x50,0x00,0x00,0x00,0x00,0x07,0x00,0x07,0x00,0xac,
41 0x00,0x08,0x00,0x02,0x04,0xff,0xff,0x82,0x00,0x53,0x00,0x74,0x00,0x61,0x00,0x74,
42 0x00,0x69,0x00,0x63,0x00,0x00,0x00,0x00,0x00
45 #define CUPDIALOG_TEXTBOX_ID (1026) //Static Control Id
46 #define CUPDIALOG_PROGRESSBAR_ID (1018) //ProgressBar Control Id
47 #define CUPDIALOG_CANCELBUTTON_ID (IDCANCEL) //Cancel Button Control Id
48 #define CUPDIALOG_TERMINATE_DELAY (500) //Amount of time to wait after signaling the termination, in MilliSeconds.
50 CUPDialog::CUPDialog(HWND hParentWnd,LP_CUPDIALOG_USERPROC lpUserProc,LPVOID lpUserProcParam,LPCTSTR lpszDlgTitle,
bool bAllowCancel)
54 m_hParentWnd = hParentWnd;
58 m_lpszTemplateName = NULL;
60 m_nStaticControlId = CUPDIALOG_TEXTBOX_ID;
62 m_nProgressBarControlId = CUPDIALOG_PROGRESSBAR_ID;
64 m_nCancelButtonId = CUPDIALOG_CANCELBUTTON_ID;
66 m_dwTerminateDelay = CUPDIALOG_TERMINATE_DELAY;
68 m_bAllowCancel = bAllowCancel;
70 m_ThreadData.pUserProcParam = lpUserProcParam;
72 m_ThreadData.m_lpUserProc = lpUserProc;
74 ZeroMemory(m_szDialogCaption,
sizeof(m_szDialogCaption));
76 _tcsncpy(m_szDialogCaption,lpszDlgTitle,(
sizeof(m_szDialogCaption)/
sizeof(m_szDialogCaption[0]))-1);
79 CUPDialog::~CUPDialog(
void)
84 void CUPDialog::Cleanup()
86 m_ThreadData.bTerminate =
true;
88 if(m_ThreadData.bAlive)
90 Sleep(m_dwTerminateDelay);
92 if(GetExitCodeThread(m_hThread,&dwExitCode) && dwExitCode == STILL_ACTIVE)
93 TerminateThread(m_hThread, IDCANCEL);
98 CloseHandle(m_hThread);
102 m_ThreadData.bAlive =
false;
103 m_ThreadData.bTerminate =
false;
104 m_ThreadData.hThreadWnd = NULL;
107 INT_PTR CUPDialog::DoModal()
111 if(m_lpszTemplateName == NULL)
112 return DialogBoxIndirectParam(NULL, (LPDLGTEMPLATE) dlg_145, m_hParentWnd, (DLGPROC) ProgressDlgProc, (LPARAM)
this);
114 return DialogBoxParam(m_hInst,m_lpszTemplateName,m_hParentWnd,ProgressDlgProc,(LPARAM)
this);
117 static DWORD WINAPI ThreadProc(LPVOID lpThreadParameter)
121 pThreadData->bAlive =
true;
123 INT_PTR nResult = IDCANCEL;
125 if(pThreadData->bTerminate ==
true)
126 goto TerminateThreadProc;
128 nResult = (
true == (*pThreadData->m_lpUserProc)((
CUPDUPDATA*)lpThreadParameter)) ? IDOK : IDCANCEL;
132 pThreadData->bAlive =
false;
134 if(pThreadData->bTerminate ==
false)
135 ::PostMessage(pThreadData->hThreadWnd,PROGRESSTHREADDATA::WM_PROGRESSTHREADCOMPLETED,MAKEWPARAM(nResult,0),0);
140 INT_PTR CALLBACK ProgressDlgProc(HWND hDlg,UINT Message,WPARAM wParam,LPARAM lParam)
142 BOOL bProcessed = FALSE;
151 SetWindowLongPtr(hDlg,GWL_USERDATA,(LONG_PTR)pProgressDialog);
153 if(pProgressDialog->m_bAllowCancel ==
false)
154 SendMessage(hDlg,PROGRESSTHREADDATA::WM_DISABLECONTROLS,wParam,lParam);
156 SendMessage(GetDlgItem(hDlg, pProgressDialog->m_nStaticControlId),WM_SETTEXT,0,(LPARAM)_T(
""));
158 SendMessage(GetDlgItem(hDlg, pProgressDialog->m_nProgressBarControlId),PBM_SETPOS,0,0);
160 SendMessage(hDlg,WM_SETTEXT,0,(LPARAM)pProgressDialog->m_szDialogCaption);
164 pProgressDialog->OnMessage(hDlg, Message, wParam, lParam, TRUE);
166 DWORD dwThreadId = 0;
168 pProgressDialog->m_hThread = CreateThread(NULL,NULL,ThreadProc,&pProgressDialog->m_ThreadData,0,&dwThreadId);
170 if(pProgressDialog->m_hThread == NULL) EndDialog(hDlg,IDABORT);
176 pProgressDialog = (
CUPDialog*)GetWindowLongPtr(hDlg,GWL_USERDATA);
178 if(pProgressDialog->m_nCancelButtonId == LOWORD(wParam))
180 SendMessage(hDlg,PROGRESSTHREADDATA::WM_CANCELPROGRESSTHREAD,0,0);
187 if(SC_CLOSE == wParam)
189 SendMessage(hDlg,PROGRESSTHREADDATA::WM_CANCELPROGRESSTHREAD,0,0);
194 case PROGRESSTHREADDATA::WM_DISABLECONTROLS:
196 pProgressDialog = (
CUPDialog*)GetWindowLongPtr(hDlg,GWL_USERDATA);
197 EnableMenuItem(GetSystemMenu(hDlg,
false),SC_CLOSE,MF_DISABLED|MF_GRAYED|MF_BYCOMMAND);
198 EnableWindow(GetDlgItem(hDlg, pProgressDialog->m_nCancelButtonId),
false);
202 case PROGRESSTHREADDATA::WM_ENABLECONTROLS:
204 pProgressDialog = (
CUPDialog*)GetWindowLongPtr(hDlg,GWL_USERDATA);
205 EnableMenuItem(GetSystemMenu(hDlg,
false),SC_CLOSE,MF_ENABLED|MF_BYCOMMAND);
206 EnableWindow(GetDlgItem(hDlg, pProgressDialog->m_nCancelButtonId),
true);
210 case PROGRESSTHREADDATA::WM_PROGRESSTHREADCOMPLETED:
212 EndDialog(hDlg, wParam);
216 case PROGRESSTHREADDATA::WM_PROGRESSTEXTUPDATE:
218 pProgressDialog = (
CUPDialog*)GetWindowLongPtr(hDlg,GWL_USERDATA);
219 SendMessage(GetDlgItem(hDlg, pProgressDialog->m_nStaticControlId),WM_SETTEXT,0,lParam);
223 case PROGRESSTHREADDATA::WM_PROGRESSBARUPDATE:
225 pProgressDialog = (
CUPDialog*)GetWindowLongPtr(hDlg,GWL_USERDATA);
226 SendMessage(GetDlgItem(hDlg, pProgressDialog->m_nProgressBarControlId),PBM_SETPOS,wParam,0);
230 case PROGRESSTHREADDATA::WM_CANCELPROGRESSTHREAD:
232 pProgressDialog = (
CUPDialog*)GetWindowLongPtr(hDlg,GWL_USERDATA);
235 pThreadData->bTerminate =
true;
236 SendMessage(GetDlgItem(hDlg, pProgressDialog->m_nStaticControlId),WM_SETTEXT,0,(LPARAM)(_T(
"Termination Initiated..")));
237 SendMessage(hDlg,PROGRESSTHREADDATA::WM_DISABLECONTROLS,wParam,lParam);
238 if(pThreadData->bAlive)
239 Sleep(pProgressDialog->m_dwTerminateDelay);
240 if(pThreadData->bAlive)
241 SendMessage(GetDlgItem(hDlg, pProgressDialog->m_nStaticControlId),WM_SETTEXT,0,(LPARAM)(_T(
"Termination Complete ..Shutting Down !!")));
242 if(pThreadData->bAlive)
243 Sleep(pProgressDialog->m_dwTerminateDelay);
244 EndDialog(hDlg, MAKEWPARAM(IDCANCEL,1));
251 if(pProgressDialog == NULL)
252 pProgressDialog = (
CUPDialog*)GetWindowLongPtr(hDlg,GWL_USERDATA);
254 if(pProgressDialog != NULL)
258 INT_PTR RetVal = pProgressDialog->OnMessage(hDlg, Message, wParam, lParam, bProcessed);
260 if(bProcessed == FALSE)
return RetVal;