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