#include "copyProgress.h" #include #include #include extern HINSTANCE app_instance; extern void gsInstall_getDesktopExt(int *x, int *y); LRESULT CALLBACK copyProgressBar_windowProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { CREATESTRUCT *createStruct = (CREATESTRUCT *) lParam; long *createParams; copyProgressBar *progressBar; createParams = (long *) createStruct->lpCreateParams; SetWindowLong(window, GWL_USERDATA, createParams[0]); progressBar = (copyProgressBar *) GetWindowLong(window, GWL_USERDATA); if (progressBar == NULL) { MessageBox(0, "A", "A", MB_OK); } CreateWindowEx( 0, "STATIC", (char *) createParams[1], WS_CHILD | WS_VISIBLE, 10, 5, 180, 20, window, (HMENU) 0, app_instance, NULL); } break; default: return(DefWindowProc(window, message, wParam, lParam)); } return 0; } void copyProgressBar::registerClass() { static bool registered = false; if (registered == false) { WNDCLASS classdef; classdef.style = 0; classdef.lpfnWndProc = copyProgressBar_windowProc; classdef.cbClsExtra = 0; classdef.cbWndExtra = sizeof(copyProgressBar *) + sizeof(long); classdef.hInstance = app_instance; classdef.hIcon = 0; classdef.hCursor = NULL; classdef.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); classdef.lpszMenuName = NULL; classdef.lpszClassName = "CopyProgressBar"; RegisterClass(&classdef); registered = true; } } copyProgressBar::copyProgressBar(unsigned long totalSize) { this->total = totalSize; this->copied = 0; } copyProgressBar::copyProgressBar() { this->total = 0; this->copied = 0; } void copyProgressBar::init(unsigned long totalSize) { this->total = totalSize; this->copied = 0; } void copyProgressBar::done(unsigned long bytesDone) { unsigned int percent; this->copied += bytesDone; percent =(this->copied * 100 / this->total); SendMessage(this->progressBar, PBM_SETPOS, percent, 0L); } void copyProgressBar::show() { long params[2]; int sx, sy, dx, dy; params[0] = (long) this; params[1] = (long) "Copying files...."; this->registerClass(); gsInstall_getDesktopExt(&sx, &sy); dx = (sx - 200) >> 1; dy = (sy - 80) >> 1; this->progressParent = CreateWindowEx( WS_EX_APPWINDOW, "CopyProgressBar", "GreenStone Installer", WS_VISIBLE, dx, dy, 200, 80, 0, (HMENU) 0, app_instance, (void *) params); this->progressBar = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE, 10, 30, 180, GetSystemMetrics(SM_CYVSCROLL), this->progressParent, (HMENU) 0, app_instance, NULL); } void copyProgressBar::close() { return; ShowWindow(this->progressBar, SW_HIDE); DestroyWindow(this->progressBar); ShowWindow(this->progressParent, SW_HIDE); DestroyWindow(this->progressParent); }