From d123e0ce94bf90b2adb0a4000930eb467e293226 Mon Sep 17 00:00:00 2001 From: sje Date: Wed, 1 Nov 2006 14:48:34 +0000 Subject: git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@16 4f64403b-2f21-0410-a795-97e2b3489a10 --- updater/progress_dialog.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 updater/progress_dialog.cpp (limited to 'updater/progress_dialog.cpp') diff --git a/updater/progress_dialog.cpp b/updater/progress_dialog.cpp new file mode 100644 index 0000000..bdcb922 --- /dev/null +++ b/updater/progress_dialog.cpp @@ -0,0 +1,140 @@ +#include "common.h" +#include "progress_dialog.h" + +#define ID_PROGTIMER 101 + +// message loop messages +#define WMU_NEWPROGRESSWINDOW (WM_USER + 0x200) +#define WMU_KILLPROGRESSWINDOW (WM_USER + 0x201) + +HWND hwndProgress = 0; +//DWORD dwProgressThreadId = 0; +unsigned int dwProgressThreadId = 0; +HANDLE hProgSyncEvent = 0; + +BOOL CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + switch ( msg ) { + case WM_INITDIALOG: + TranslateDialogDefault( hwndDlg ); + SetWindowLong(hwndDlg, GWL_USERDATA, 0); + // these change icons for all system dialogs! + //SetClassLong(hwndDlg, GCL_HICON, (LONG)hIconCheck); + //SetClassLong(hwndDlg, GCL_HICONSM, (LONG)hIconCheck); + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIconCheck); + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIconCheck); + + SAVEWINDOWPOS swp; + swp.hwnd=hwndDlg; swp.hContact=0; swp.szModule=MODULE; swp.szNamePrefix="ProgressWindow"; + CallService(MS_UTILS_RESTOREWINDOWPOSITION, RWPF_NOSIZE | RWPF_NOACTIVATE, (LPARAM)&swp); + + PostMessage(hwndDlg, WMU_SETPROGRESS, 0, 0); + return FALSE; + case WM_TIMER: + if(wParam == ID_PROGTIMER) { + TCHAR text[512]; + GetDlgItemText(hwndDlg, IDC_PROGMSG, text, 512); + int len = _tcslen(text); + int pos = (int)GetWindowLong(hwndDlg, GWL_USERDATA); + if(len >= 3 && len < 511) { + pos = (pos + 1) % 4; + if(pos == 0) + text[len - 3] = 0; + else + _tcscat(text, _T(".")); + SetDlgItemText(hwndDlg, IDC_PROGMSG, text); + SetWindowLong(hwndDlg, GWL_USERDATA, pos); + } + return TRUE; + } + break; + case WMU_SETMESSAGE: + KillTimer(hwndDlg, ID_PROGTIMER); + SetDlgItemText(hwndDlg, IDC_PROGMSG, (TCHAR *)wParam); + SetWindowLong(hwndDlg, GWL_USERDATA, 0); + SetTimer(hwndDlg, ID_PROGTIMER, (WPARAM)500, 0); + return TRUE; + case WMU_SETPROGRESS: + SendDlgItemMessage(hwndDlg, IDC_PROGRESS, PBM_SETPOS, wParam, 0); + { + TCHAR buff[512]; + + _stprintf(buff, TranslateT("Progress - %d%%"), wParam); + SetWindowText(hwndDlg, buff); + } + return TRUE; + + case WM_COMMAND: + return TRUE; // disable esc, enter, etc + + case WM_CLOSE: + PostThreadMessage(dwProgressThreadId, WMU_KILLPROGRESSWINDOW, 0, 0); + break; + + case WM_DESTROY: + KillTimer(hwndDlg, ID_PROGTIMER); + Utils_SaveWindowPosition(hwndDlg,0,MODULE,"ProgressWindow"); + break; + } + return FALSE; +} + +//DWORD CALLBACK ProgressWindowThread(LPVOID param) { +unsigned int CALLBACK ProgressWindowThread(void *param) { + CallService(MS_SYSTEM_THREAD_PUSH, 0, 0); + + 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; + } + } + + if(hwndProgress) DestroyWindow(hwndProgress); + hwndProgress = 0; + + CallService(MS_SYSTEM_THREAD_POP, 0, 0); + return 0; +} + +void MakeProgressWindowThread() { + hProgSyncEvent = CreateEvent(0, 0, 0, 0); + CloseHandle((HANDLE)_beginthreadex(0, 0, ProgressWindowThread, hProgSyncEvent, 0, &dwProgressThreadId)); + WaitForSingleObject(hProgSyncEvent, INFINITE); +} + + +void KillProgressWindowThread() { + PostThreadMessage(dwProgressThreadId, WM_QUIT, 0, 0); + CloseHandle(hProgSyncEvent); +} + +void CreateProgressWindow() { + ResetEvent(hProgSyncEvent); + PostThreadMessage(dwProgressThreadId, WMU_NEWPROGRESSWINDOW, 0, 0); + WaitForSingleObject(hProgSyncEvent, INFINITE); +} + +void ProgressWindowDone() { + PostThreadMessage(dwProgressThreadId, WMU_KILLPROGRESSWINDOW, 0, 0); +} -- cgit v1.2.3