SMDLL + SMLIB (static code in SMSS.EXE)
[reactos.git] / rosapps / winfile / worker.c
1 /*
2 * ReactOS winfile
3 *
4 * worker.c
5 *
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
24 #include <windows.h>
25 #include <commctrl.h>
26 #include <stdlib.h>
27 #include <malloc.h>
28 #include <memory.h>
29 #include <tchar.h>
30 #include <process.h>
31 #include <stdio.h>
32
33 #include <windowsx.h>
34 #include <process.h>
35 #include <assert.h>
36 #define ASSERT assert
37
38 #include "main.h"
39 #include "worker.h"
40 #include "drivebar.h"
41
42
43 ////////////////////////////////////////////////////////////////////////////////
44 // Global Variables:
45 //
46
47 static HANDLE hMonitorThreadEvent = NULL; // When this event becomes signaled then we run the monitor thread
48
49 void MonitorThreadProc(void *lpParameter);
50
51 ////////////////////////////////////////////////////////////////////////////////
52 // Local module support methods
53 //
54
55
56 LRESULT CALLBACK MoveDialogWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
57 {
58 HWND hLicenseEditWnd;
59 TCHAR strLicense[0x1000];
60
61 switch (message) {
62 case WM_INITDIALOG:
63 hLicenseEditWnd = GetDlgItem(hDlg, IDC_LICENSE_EDIT);
64 LoadString(hInst, IDS_LICENSE, strLicense, 0x1000);
65 SetWindowText(hLicenseEditWnd, strLicense);
66 return TRUE;
67 case WM_COMMAND:
68 if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) {
69 EndDialog(hDlg, LOWORD(wParam));
70 return TRUE;
71 }
72 break;
73 }
74 return 0;
75 }
76
77 void StartWorkerThread(HWND hWnd)
78 {
79 DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)MoveDialogWndProc);
80 }
81
82 ////////////////////////////////////////////////////////////////////////////////
83
84 void MonitorThreadProc(void *lpParameter)
85 {
86 // ULONG OldProcessorUsage = 0;
87 // ULONG OldProcessCount = 0;
88 HWND hWnd = (HWND)lpParameter;
89
90 // Create the event
91 hMonitorThreadEvent = CreateEvent(NULL, TRUE, TRUE, _T("Winfile Monitor Event"));
92
93 // If we couldn't create the event then exit the thread
94 if (!hMonitorThreadEvent)
95 return;
96
97 while (1) {
98 DWORD dwWaitVal;
99
100 // Wait on the event
101 dwWaitVal = WaitForSingleObject(hMonitorThreadEvent, INFINITE);
102
103 // If the wait failed then the event object must have been
104 // closed and the task manager is exiting so exit this thread
105 if (dwWaitVal == WAIT_FAILED) {
106 // CloseHandle(hMonitorThreadEvent); // Should we close the event object handle or not ???
107 // hMonitorThreadEvent = NULL; // if we do then check what happens when main thread tries to delete it also....
108 return;
109 }
110
111 if (dwWaitVal == WAIT_OBJECT_0) {
112 // Reset our event
113 ResetEvent(hMonitorThreadEvent);
114
115
116 ConfigureDriveBar(Globals.hDriveBar);
117
118 #if 0
119 TCHAR text[260];
120 if ((ULONG)SendMessage(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0) != PerfDataGetProcessCount())
121 SendMessage(hProcessPageListCtrl, LVM_SETITEMCOUNT, PerfDataGetProcessCount(), /*LVSICF_NOINVALIDATEALL|*/LVSICF_NOSCROLL);
122 if (IsWindowVisible(hProcessPage))
123 InvalidateRect(hProcessPageListCtrl, NULL, FALSE);
124 if (OldProcessorUsage != PerfDataGetProcessorUsage()) {
125 OldProcessorUsage = PerfDataGetProcessorUsage();
126 wsprintf(text, _T("CPU Usage: %3d%%"), OldProcessorUsage);
127 SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
128 }
129 if (OldProcessCount != PerfDataGetProcessCount()) {
130 OldProcessCount = PerfDataGetProcessCount();
131 wsprintf(text, _T("Processes: %d"), OldProcessCount);
132 SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
133 }
134 #endif
135 }
136 }
137 }
138
139 BOOL CreateMonitorThread(HWND hWnd)
140 {
141 _beginthread(MonitorThreadProc, 0, hWnd);
142 return TRUE;
143 }
144
145 void SignalMonitorEvent(void)
146 {
147 SetEvent(hMonitorThreadEvent);
148 }
149
150 BOOL DestryMonitorThread(void)
151 {
152 CloseHandle(hMonitorThreadEvent);
153 hMonitorThreadEvent = NULL;
154 return TRUE;
155 }
156