source: trunk/gsinstaller/copyProgress.cpp@ 1537

Last change on this file since 1537 was 1536, checked in by sjboddie, 24 years ago

Changes to get compiling on VC++ and gcc

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