diff options
author | George Hazan <george.hazan@gmail.com> | 2016-10-02 18:01:49 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-10-02 18:01:49 +0000 |
commit | c133d3f9924fa89912a3c576e0b2ddf4f8987100 (patch) | |
tree | 348b62da37cf72cab5bab9fa626b25602625b3ab | |
parent | ef8b008cdbe92cab970b3013c930c322ea3948b1 (diff) |
miranda restart dialog rewritten using ui utils
git-svn-id: http://svn.miranda-ng.org/main/trunk@17343 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | src/mir_app/src/miranda.cpp | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/src/mir_app/src/miranda.cpp b/src/mir_app/src/miranda.cpp index f09b54e83c..2557d9eac1 100644 --- a/src/mir_app/src/miranda.cpp +++ b/src/mir_app/src/miranda.cpp @@ -145,34 +145,56 @@ static int SystemShutdownProc(WPARAM, LPARAM) #define MIRANDA_PROCESS_WAIT_TIMEOUT 60000
#define MIRANDA_PROCESS_WAIT_RESOLUTION 1000
#define MIRANDA_PROCESS_WAIT_STEPS (MIRANDA_PROCESS_WAIT_TIMEOUT/MIRANDA_PROCESS_WAIT_RESOLUTION)
-static INT_PTR CALLBACK WaitForProcessDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+
+class CWaitRestartDlg : public CDlgBase
{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hwnd);
- SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
- SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_SETRANGE, 0, MAKELPARAM(0, MIRANDA_PROCESS_WAIT_STEPS));
- SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_SETSTEP, 1, 0);
- SetTimer(hwnd, 1, MIRANDA_PROCESS_WAIT_RESOLUTION, NULL);
- break;
-
- case WM_TIMER:
- if (SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_STEPIT, 0, 0) == MIRANDA_PROCESS_WAIT_STEPS)
- EndDialog(hwnd, 0);
- if (WaitForSingleObject((HANDLE)GetWindowLongPtr(hwnd, GWLP_USERDATA), 1) != WAIT_TIMEOUT) {
- SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_SETPOS, MIRANDA_PROCESS_WAIT_STEPS, 0);
- EndDialog(hwnd, 0);
- }
- break;
+ HANDLE m_hProcess;
+ CTimer m_timer;
+ CProgress m_progress;
+ CCtrlButton m_cancel;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDCANCEL) {
- SendDlgItemMessage(hwnd, IDC_PROGRESSBAR, PBM_SETPOS, MIRANDA_PROCESS_WAIT_STEPS, 0);
- EndDialog(hwnd, 1);
- }
- break;
+protected:
+ void OnInitDialog();
+
+ void Timer_OnEvent(CTimer*);
+
+ void Cancel_OnClick(CCtrlBase*);
+
+public:
+ CWaitRestartDlg(HANDLE hProcess);
+};
+
+CWaitRestartDlg::CWaitRestartDlg(HANDLE hProcess)
+ : CDlgBase(g_hInst, IDD_WAITRESTART), m_timer(this, 1),
+ m_progress(this, IDC_PROGRESSBAR), m_cancel(this, IDCANCEL)
+{
+ m_autoClose = 0;
+ m_hProcess = hProcess;
+ m_timer.OnEvent = Callback(this, &CWaitRestartDlg::Timer_OnEvent);
+ m_cancel.OnClick = Callback(this, &CWaitRestartDlg::Cancel_OnClick);
+}
+
+void CWaitRestartDlg::OnInitDialog()
+{
+ m_progress.SetRange(MIRANDA_PROCESS_WAIT_STEPS);
+ m_progress.SetStep(1);
+ m_timer.Start(MIRANDA_PROCESS_WAIT_RESOLUTION);
+}
+
+void CWaitRestartDlg::Timer_OnEvent(CTimer *timer)
+{
+ if (m_progress.Move() == MIRANDA_PROCESS_WAIT_STEPS)
+ EndModal(0);
+ if (WaitForSingleObject(m_hProcess, 1) != WAIT_TIMEOUT) {
+ m_progress.SetPosition(MIRANDA_PROCESS_WAIT_STEPS);
+ EndModal(0);
}
- return FALSE;
+}
+
+void CWaitRestartDlg::Cancel_OnClick(CCtrlBase*)
+{
+ m_progress.SetPosition(MIRANDA_PROCESS_WAIT_STEPS);
+ EndModal(1);
}
INT_PTR CheckRestart()
@@ -181,7 +203,7 @@ INT_PTR CheckRestart() if (tszPID) {
HANDLE hProcess = OpenProcess(SYNCHRONIZE, FALSE, _wtol(tszPID));
if (hProcess) {
- INT_PTR result = DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_WAITRESTART), NULL, WaitForProcessDlgProc, (LPARAM)hProcess);
+ INT_PTR result = dlg.DoModal();
CloseHandle(hProcess);
return result;
}
|