[1397] | 1 | #include "copyProgress.h"
|
---|
| 2 |
|
---|
| 3 | #include <windows.h>
|
---|
| 4 | #include <commctrl.h>
|
---|
| 5 |
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 |
|
---|
| 8 | extern HINSTANCE app_instance;
|
---|
[1475] | 9 | extern gsInstall_getDesktopExt(int *x, int *y);
|
---|
[1397] | 10 |
|
---|
| 11 | LRESULT CALLBACK copyProgressBar_windowProc( HWND window, UINT message,
|
---|
| 12 | WPARAM wParam, LPARAM lParam)
|
---|
| 13 | { switch (message)
|
---|
| 14 | { case WM_CREATE:
|
---|
| 15 | { CREATESTRUCT *createStruct = (CREATESTRUCT *) lParam;
|
---|
| 16 | long *createParams;
|
---|
| 17 | copyProgressBar *progressBar;
|
---|
| 18 |
|
---|
| 19 | createParams = (long *) createStruct->lpCreateParams;
|
---|
| 20 |
|
---|
| 21 | SetWindowLong(window, GWL_USERDATA, createParams[0]);
|
---|
| 22 | progressBar = (copyProgressBar *) GetWindowLong(window, GWL_USERDATA);
|
---|
| 23 | if (progressBar == NULL)
|
---|
| 24 | { MessageBox(0, "A", "A", MB_OK);
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | CreateWindowEx( 0, "STATIC", (char *) createParams[1], WS_CHILD | WS_VISIBLE,
|
---|
| 28 | 10, 5, 180, 20, window, (HMENU) 0,
|
---|
| 29 | app_instance, NULL);
|
---|
| 30 |
|
---|
| 31 | }
|
---|
| 32 | break;
|
---|
| 33 |
|
---|
| 34 | default:
|
---|
| 35 | return(DefWindowProc(window, message, wParam, lParam));
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | return 0;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | void copyProgressBar::registerClass()
|
---|
| 42 | { static bool registered = false;
|
---|
| 43 |
|
---|
| 44 | if (registered == false)
|
---|
| 45 | { WNDCLASS classdef;
|
---|
| 46 |
|
---|
| 47 | classdef.style = 0;
|
---|
| 48 | classdef.lpfnWndProc = copyProgressBar_windowProc;
|
---|
| 49 | classdef.cbClsExtra = 0;
|
---|
| 50 | classdef.cbWndExtra = sizeof(copyProgressBar *) + sizeof(long);
|
---|
| 51 | classdef.hInstance = app_instance;
|
---|
| 52 | classdef.hIcon = 0;
|
---|
| 53 | classdef.hCursor = NULL;
|
---|
| 54 | classdef.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
|
---|
| 55 | classdef.lpszMenuName = NULL;
|
---|
| 56 | classdef.lpszClassName = "CopyProgressBar";
|
---|
| 57 | RegisterClass(&classdef);
|
---|
| 58 | registered = true;
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | copyProgressBar::copyProgressBar(unsigned long totalSize)
|
---|
| 63 | { this->total = totalSize;
|
---|
| 64 | this->copied = 0;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | copyProgressBar::copyProgressBar()
|
---|
| 68 | { this->total = 0;
|
---|
| 69 | this->copied = 0;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | void copyProgressBar::init(unsigned long totalSize)
|
---|
| 73 | { this->total = totalSize;
|
---|
| 74 | this->copied = 0;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | void copyProgressBar::done(unsigned long bytesDone)
|
---|
| 78 | { unsigned int percent;
|
---|
| 79 | this->copied += bytesDone;
|
---|
| 80 |
|
---|
| 81 | percent =(this->copied * 100 / this->total);
|
---|
| 82 |
|
---|
| 83 | SendMessage(this->progressBar, PBM_SETPOS, percent, 0L);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | void copyProgressBar::show()
|
---|
| 87 | { long params[2];
|
---|
[1475] | 88 | int sx, sy, dx, dy;
|
---|
[1397] | 89 |
|
---|
| 90 | params[0] = (long) this;
|
---|
| 91 | params[1] = (long) "Copying files....";
|
---|
| 92 | this->registerClass();
|
---|
[1475] | 93 |
|
---|
| 94 | gsInstall_getDesktopExt(&sx, &sy);
|
---|
| 95 |
|
---|
| 96 | dx = (sx - 200) >> 1;
|
---|
| 97 | dy = (sy - 80) >> 1;
|
---|
| 98 |
|
---|
| 99 | this->progressParent = CreateWindowEx( WS_EX_APPWINDOW, "CopyProgressBar",
|
---|
| 100 | "GreenStone Installer", WS_VISIBLE,
|
---|
| 101 | dx, dy, 200, 80,
|
---|
| 102 | 0, (HMENU) 0,
|
---|
| 103 | app_instance, (void *) params);
|
---|
[1397] | 104 | this->progressBar = CreateWindowEx(0, PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE,
|
---|
[1475] | 105 | 10, 30, 180, GetSystemMetrics(SM_CYVSCROLL),
|
---|
| 106 | this->progressParent, (HMENU) 0,
|
---|
[1397] | 107 | app_instance, NULL);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | void copyProgressBar::close()
|
---|
| 111 | { return;
|
---|
| 112 | ShowWindow(this->progressBar, SW_HIDE);
|
---|
| 113 | DestroyWindow(this->progressBar);
|
---|
| 114 |
|
---|
| 115 | ShowWindow(this->progressParent, SW_HIDE);
|
---|
| 116 | DestroyWindow(this->progressParent);
|
---|
| 117 | }
|
---|
| 118 |
|
---|