From cca5b3bf138052f870cc4f6596f7bf18172e1f62 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Wed, 10 Nov 2010 03:17:46 +0000 Subject: Removed unneeded constantly running thread Removed error messages if Miranda is terminated during update git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@552 4f64403b-2f21-0410-a795-97e2b3489a10 --- updater/progress_dialog.cpp | 98 ++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 63 deletions(-) (limited to 'updater/progress_dialog.cpp') diff --git a/updater/progress_dialog.cpp b/updater/progress_dialog.cpp index cbe7380..4d35bd0 100644 --- a/updater/progress_dialog.cpp +++ b/updater/progress_dialog.cpp @@ -3,18 +3,14 @@ #define ID_PROGTIMER 101 -// message loop messages -#define WMU_NEWPROGRESSWINDOW (WM_USER + 0x200) -#define WMU_KILLPROGRESSWINDOW (WM_USER + 0x201) +HWND hwndProgress; -HWND hwndProgress = 0; -unsigned int dwProgressThreadId = 0; -HANDLE hProgSyncEvent = 0; - -INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch ( msg ) { +INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch ( msg ) + { case WM_INITDIALOG: - TranslateDialogDefault( hwndDlg ); + TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIconEx(I_CHKUPD)); SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIconEx(I_CHKUPD, true)); @@ -25,14 +21,16 @@ INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l PostMessage(hwndDlg, WMU_SETPROGRESS, 0, 0); return FALSE; + case WM_TIMER: if(wParam == ID_PROGTIMER) { TCHAR text[512]; - GetDlgItemText(hwndDlg, IDC_PROGMSG, text, 512); + GetDlgItemText(hwndDlg, IDC_PROGMSG, text, SIZEOF(text)); size_t len = _tcslen(text); INT_PTR pos = (INT_PTR)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - if(len >= 3 && len < 511) { + if(len >= 3 && len < 511) + { pos = (pos + 1) % 4; if(pos == 0) text[len - 3] = 0; @@ -44,12 +42,14 @@ INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l return TRUE; } break; + case WMU_SETMESSAGE: KillTimer(hwndDlg, ID_PROGTIMER); SetDlgItemText(hwndDlg, IDC_PROGMSG, (TCHAR *)wParam); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - SetTimer(hwndDlg, ID_PROGTIMER, (WPARAM)500, 0); + SetTimer(hwndDlg, ID_PROGTIMER, 500, 0); return TRUE; + case WMU_SETPROGRESS: SendDlgItemMessage(hwndDlg, IDC_PROGRESS, PBM_SETPOS, wParam, 0); { @@ -64,7 +64,7 @@ INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l return TRUE; // disable esc, enter, etc case WM_CLOSE: - PostThreadMessage(dwProgressThreadId, WMU_KILLPROGRESSWINDOW, 0, 0); + PostMessage(hwndDlg, WM_QUIT, 0, 0); break; case WM_DESTROY: @@ -77,60 +77,32 @@ INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l return FALSE; } -//DWORD CALLBACK ProgressWindowThread(LPVOID param) { -unsigned int CALLBACK ProgressWindowThread(void *param) { - if(param) SetEvent((HANDLE)param); - - MSG hwndMsg = {0}; - while(GetMessage(&hwndMsg, 0, 0, 0) > 0 && !Miranda_Terminated()) { - switch(hwndMsg.message) { - case WMU_NEWPROGRESSWINDOW: - if(hwndProgress) DestroyWindow(hwndProgress); - hwndProgress = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROGRESS), 0, DlgProcProgress); - SetWindowPos(hwndProgress, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW); - //ShowWindow(hwndProgress, SW_SHOWNOACTIVATE); - UpdateWindow(hwndProgress); - if(param) SetEvent((HANDLE)param); - break; - case WMU_KILLPROGRESSWINDOW: - if(hwndProgress) { - DestroyWindow(hwndProgress); - hwndProgress = 0; - } - break; - default: - if(!IsDialogMessage(hwndProgress, &hwndMsg)) { - TranslateMessage(&hwndMsg); - DispatchMessage(&hwndMsg); - } - break; +void ProgressWindowThread(void *) +{ + hwndProgress = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PROGRESS), NULL, DlgProcProgress); + SetWindowPos(hwndProgress, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW); + UpdateWindow(hwndProgress); + + MSG hwndMsg; + while (GetMessage(&hwndMsg, NULL, 0, 0) > 0 && !Miranda_Terminated()) + { + if (!IsDialogMessage(hwndProgress, &hwndMsg)) + { + TranslateMessage(&hwndMsg); + DispatchMessage(&hwndMsg); } } - if(hwndProgress) DestroyWindow(hwndProgress); - hwndProgress = 0; - - return 0; -} - -void MakeProgressWindowThread() { - hProgSyncEvent = CreateEvent(0, 0, 0, 0); - CloseHandle(mir_forkthreadex(ProgressWindowThread, hProgSyncEvent, 0, &dwProgressThreadId)); - WaitForSingleObject(hProgSyncEvent, INFINITE); -} - - -void KillProgressWindowThread() { - PostThreadMessage(dwProgressThreadId, WM_QUIT, 0, 0); - CloseHandle(hProgSyncEvent); + if (hwndProgress) DestroyWindow(hwndProgress); + hwndProgress = NULL; } -void CreateProgressWindow() { - ResetEvent(hProgSyncEvent); - PostThreadMessage(dwProgressThreadId, WMU_NEWPROGRESSWINDOW, 0, 0); - WaitForSingleObject(hProgSyncEvent, INFINITE); +void CreateProgressWindow(void) +{ + mir_forkthread(ProgressWindowThread, NULL); } -void ProgressWindowDone() { - PostThreadMessage(dwProgressThreadId, WMU_KILLPROGRESSWINDOW, 0, 0); +void ProgressWindowDone(void) +{ + PostMessage(hwndProgress, WM_QUIT, 0, 0); } -- cgit v1.2.3