source: trunk/dll/datamin.c@ 593

Last change on this file since 593 was 593, checked in by Gregg Young, 18 years ago

Changes to remove GetPString from window class names

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 26.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: datamin.c 593 2007-03-31 19:13:59Z gyoung $
5
6 Minimized data bar
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2006 Steven H. Levine
10
11 14 Sep 02 SHL Handle large partitions
12 16 Oct 02 SHL Handle large partitions better
13 23 May 05 SHL Use QWL_USER
14 23 May 05 SHL Avoid delays for inaccessible drives
15 25 May 05 SHL Use ULONGLONG and CommaFmtULL
16 06 Jun 05 SHL Drop unused code
17 22 Jul 06 SHL Check more run time errors
18 02 Jan 07 GKY Changed drive information string formating to accomodate 6 char FS names
19 07 Jan 07 GKY Move error strings etc. to string file
20 30 Mar 07 GKY Remove GetPString for window class names
21
22***********************************************************************/
23
24#define INCL_DOS
25#define INCL_DOSERRORS
26#define INCL_WIN
27#define INCL_GPI
28#define INCL_LONGLONG
29#include <os2.h>
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34#include <ctype.h>
35#include <limits.h>
36
37#include "fm3dll.h"
38#include "fm3dlg.h"
39#include "fm3str.h"
40#include "procstat.h"
41#include "datamin.h"
42
43#pragma data_seg(DATA2)
44
45static PSZ pszSrcFile = __FILE__;
46
47#pragma alloc_text(DATAMIN,DataDlgProc,MiniTimeProc)
48
49APIRET16 APIENTRY16 Dos16MemAvail(PULONG pulAvailMem);
50
51static volatile HEV G_hevDataMin = NULLHANDLE;
52static volatile HWND G_hwndSingle = NULLHANDLE;
53
54static VOID dataminThread(VOID * pv);
55
56long MINI_X = 208, MINI_Y = 16;
57
58//=== MiniTimeProc - time, swap and drive status mini windows procedure ===
59
60MRESULT EXPENTRY MiniTimeProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
61{
62 APIRET rc;
63
64 switch (msg) {
65 case WM_CREATE:
66 {
67 PVOID pv = xmalloc(sizeof(tDataMin), pszSrcFile, __LINE__);
68
69 WinSetWindowPtr(hwnd, QWL_DATAMIN_PTR, pv);
70 }
71 break;
72
73 case WM_BUTTON1CLICK:
74 {
75 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
76
77 if (id >= MINI_DRIVEA) {
78 if (G_hevDataMin != NULLHANDLE) {
79 G_hwndSingle = hwnd;
80 rc = DosPostEventSem(G_hevDataMin);
81 if (rc) {
82 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
83 GetPString(IDS_POSTSEMFAILED));
84 }
85 }
86 }
87 else if (id == MINI_TIME)
88 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_SETUP6, // Up time
89 MPVOID, MPVOID);
90 else if (id == MINI_PROC)
91 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
92 WM_SYSCOMMAND, MPFROM2SHORT(SC_TASKMANAGER, 0), MPVOID);
93 }
94 break;
95
96 case WM_BUTTON1DBLCLK:
97 {
98 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
99
100 if (id >= MINI_DRIVEA && !hwndMain) {
101 CHAR s[] = " :\\";
102
103 *s = (CHAR) (id - MINI_DRIVEA) + 'A';
104 OpenDirCnr((HWND) 0, HWND_DESKTOP, (HWND) 0, FALSE, s);
105 return MRFROMLONG(1L);
106 }
107 else if (id == MINI_TIME) {
108 OpenObject("<WP_CLOCK>",
109 (SHORT2FROMMP(mp2) & KC_SHIFT) ? Default : Settings, hwnd);
110 return MRFROMLONG(1L);
111 }
112
113#ifdef NEVER
114 else if (id == MINI_MEM) {
115 WinDlgBox(HWND_DESKTOP,
116 HWND_DESKTOP,
117 SysInfoDlgProc, FM3ModHandle, SYS_FRAME, NULL);
118 return MRFROMLONG(1L);
119 }
120#endif
121
122 else if (id == MINI_PROC || id == MINI_MEM) {
123 WinDlgBox(HWND_DESKTOP,
124 hwnd, KillDlgProc, FM3ModHandle, KILL_FRAME, NULL);
125 return MRFROMLONG(1L);
126 }
127 else if (id == MINI_SWAP && *SwapperDat) {
128
129 char s[5];
130
131 strncpy(s, SwapperDat, 4);
132 s[3] = 0;
133 WinDlgBox(HWND_DESKTOP,
134 hwndMain,
135 UndeleteDlgProc, FM3ModHandle, UNDEL_FRAME, MPFROMP(s));
136 return MRFROMLONG(1L);
137 }
138 }
139 break;
140
141 case WM_BUTTON1MOTIONSTART:
142 PostMsg(WinQueryWindow(hwnd, QW_PARENT),
143 UM_BUTTON1MOTIONSTART, MPVOID, MPVOID);
144 break;
145
146 case WM_CONTEXTMENU:
147 PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_CONTEXTMENU, MPVOID, MPVOID);
148 break;
149
150 case WM_PAINT:
151 {
152 MRESULT mr = 0;
153 USHORT id;
154
155 id = WinQueryWindowUShort(hwnd, QWS_ID);
156 if (id >= MINI_DRIVEA) {
157 HPS hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
158
159 if (hps) {
160 mr = WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
161 UM_PAINT, MPFROM2SHORT(id, 0), MPFROMLONG(hps));
162 WinEndPaint(hps);
163 return mr; // Bypass default paint
164 }
165 }
166 }
167 break;
168
169 case WM_DESTROY:
170 {
171 PVOID pv = WinQueryWindowPtr(hwnd, QWL_DATAMIN_PTR);
172
173 xfree(pv);
174 }
175 break;
176 }
177 return PFNWPStatic(hwnd, msg, mp1, mp2);
178
179} // MiniTimeProc
180
181//=== DataProc - databar client window procedure ===
182
183MRESULT EXPENTRY DataProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
184{
185 APIRET rc;
186
187 static ULONG counter;
188 static BOOL NoFloat, noqproc = FALSE, Positioned;
189 static HWND hwndMenu = (HWND) 0;
190
191 switch (msg) {
192 case WM_CREATE:
193 if (DataHwnd) {
194 WinSetWindowPos(DataHwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER | SWP_SHOW);
195 return MRFROMLONG(1L);
196 }
197 DataHwnd = WinQueryWindow(hwnd, QW_PARENT);
198 NoFloat = FALSE;
199 Positioned = FALSE;
200 SetPresParams(hwnd,
201 &RGBGREY, &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVTEXT));
202 {
203 int c;
204 long x = 3;
205 USHORT ids[] = { MINI_TIME, MINI_MEM, MINI_SWAP, MINI_PROC, 0 };
206 POINTL aptl[TXTBOX_COUNT];
207 HPS hps;
208
209 hps = WinGetPS(hwnd);
210 if (hps) {
211 GpiQueryTextBox(hps,
212 34,
213 " -=03:08:22 SMW 1998/08/02=- ",
214 TXTBOX_COUNT, aptl);
215 WinReleasePS(hps);
216 MINI_X = aptl[TXTBOX_TOPRIGHT].x + 6;
217 MINI_Y = aptl[TXTBOX_TOPRIGHT].y + 6;
218 }
219 for (c = 0; ids[c]; c++) {
220 if (!WinCreateWindow(hwnd,
221 WC_MINITIME,
222 NullStr,
223 SS_TEXT | DT_CENTER | DT_VCENTER | WS_VISIBLE,
224 x,
225 3,
226 MINI_X,
227 MINI_Y, hwnd, HWND_TOP, ids[c], NULL, NULL)) {
228 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__, IDS_WINCREATEWINDOW);
229 }
230 x += (MINI_X + 4);
231 }
232 }
233 if (!hwndMain) {
234 SWCNTRL swctl;
235
236 memset(&swctl, 0, sizeof(swctl));
237 swctl.hwnd = WinQueryWindow(hwnd, QW_PARENT);
238 swctl.uchVisibility = SWL_VISIBLE;
239 swctl.fbJump = (fDataToFore) ? SWL_NOTJUMPABLE : SWL_JUMPABLE;
240 swctl.bProgType = PROG_PM;
241 strcpy(swctl.szSwtitle, GetPString(IDS_DATABARTITLETEXT));
242 WinCreateSwitchEntry(WinQueryAnchorBlock(hwnd), &swctl);
243 }
244 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
245 return 0;
246
247 case WM_MENUEND:
248 NoFloat = FALSE;
249 if (hwndMenu == (HWND) mp2) {
250 WinDestroyWindow(hwndMenu);
251 hwndMenu = (HWND) 0;
252 }
253 break;
254
255 case UM_RESTORE:
256 WinSetWindowPtr(hwnd, QWL_USER, mp1);
257 return 0;
258
259 case UM_SETUP:
260 {
261 long x, y;
262 SWP swp, swpD;
263 int c;
264 ULONG size = sizeof(SWP);
265 ULONG numdrives = 0;
266 ULONG drivestyle = (DRIVE_REMOVABLE | DRIVE_INVALID |
267 DRIVE_IGNORE | DRIVE_ZIPSTREAM | DRIVE_NOSTATS);
268 ULONG ulDriveNum, ulDriveMap;
269
270 if (!fDataInclRemote)
271 drivestyle |= DRIVE_REMOTE || DRIVE_VIRTUAL || DRIVE_RAMDISK;
272 if (fDataShowDrives) {
273 DosError(FERR_DISABLEHARDERR);
274 DosQCurDisk(&ulDriveNum, &ulDriveMap);
275 x = 3;
276 y = MINI_Y + 4;
277 // Drive status windows
278 for (c = 2; c < 26; c++) {
279 if ((ulDriveMap & (1L << c)) && !(driveflags[c] & drivestyle)) {
280 if (!WinCreateWindow(hwnd,
281 WC_MINITIME,
282 NullStr,
283 SS_TEXT | DT_CENTER | DT_VCENTER |
284 WS_VISIBLE, x, y, MINI_X, MINI_Y, hwnd,
285 HWND_TOP, MINI_DRIVEA + c, NULL, NULL)) {
286 Win_Error2(hwnd, hwnd, pszSrcFile, __LINE__,
287 IDS_WINCREATEWINDOW);
288 }
289 numdrives++;
290 x += (MINI_X + 4);
291 if ((numdrives % 4) == 0) {
292 y += (MINI_Y + 4);
293 x = 3;
294 }
295 }
296 }
297 }
298 x = (MINI_X * 4) + 18;
299 y = (MINI_Y + 4) + ((numdrives / 4) * (MINI_Y + 4)) +
300 (((numdrives % 4) != 0) * (MINI_Y + 4));
301 if (!Positioned) {
302 if (PrfQueryProfileData(fmprof, appname, "DataMinPos", &swp, &size)) {
303 WinQueryWindowPos(HWND_DESKTOP, &swpD);
304 if (swp.x > swpD.cx - 16)
305 swp.x = swpD.cx - 16;
306 if (swp.y > swpD.cy - 16)
307 swp.y = swpD.cy - 16;
308 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
309 HWND_TOP,
310 swp.x,
311 swp.y,
312 x, y, SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER);
313 }
314 else
315 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
316 HWND_TOP,
317 0,
318 0,
319 x, y, SWP_SHOW | SWP_SIZE | SWP_MOVE | SWP_ZORDER);
320 Positioned = TRUE;
321 }
322 else
323 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
324 HWND_TOP,
325 0, 0, x, y, SWP_SHOW | SWP_SIZE | SWP_ZORDER);
326 WinShowWindow(WinQueryWindow(hwnd, QW_PARENT), TRUE);
327 if (numdrives) {
328 if (_beginthread(dataminThread, NULL, 32768, (PVOID) hwnd) == -1) {
329 Runtime_Error(pszSrcFile, __LINE__,
330 GetPString(IDS_COULDNTSTARTTHREADTEXT));
331 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
332 }
333 }
334 counter = 0;
335 PostMsg(hwnd, UM_TIMER, MPVOID, MPVOID);
336 }
337 return 0; // UM_SETUP
338
339 case WM_BUTTON1DBLCLK:
340 if (hwndMain)
341 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
342 break;
343
344 case UM_CONTEXTMENU:
345 case WM_CONTEXTMENU:
346 if (!hwndMenu)
347 hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, MINI_FRAME);
348 if (hwndMenu) {
349 WinCheckMenuItem(hwndMenu, MINI_FLOAT, fDataToFore);
350 WinCheckMenuItem(hwndMenu, MINI_SHOW, fDataShowDrives);
351 WinCheckMenuItem(hwndMenu, MINI_BORING, fDullMin);
352 WinCheckMenuItem(hwndMenu, MINI_INCLREMOTE, fDataInclRemote);
353 NoFloat = TRUE;
354 if (!PopupMenu(hwnd, hwnd, hwndMenu))
355 NoFloat = FALSE;
356 }
357 if (msg == UM_CONTEXTMENU)
358 return 0;
359 break;
360
361 case WM_BUTTON2DBLCLK:
362 if (!(SHORT2FROMMP(mp2) & KC_SHIFT)) {
363 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(MINI_FLOAT, 0), MPVOID);
364 break;
365 }
366 /* else intentional fallthru */
367 case WM_CHORD:
368 case WM_BUTTON3DBLCLK:
369 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(MINI_SHOW, 0), MPVOID);
370 break;
371
372 case UM_BUTTON1MOTIONSTART:
373 case WM_BUTTON1MOTIONSTART:
374 {
375 TRACKINFO TrackInfo;
376 SWP Position;
377
378 memset(&TrackInfo, 0, sizeof(TrackInfo));
379 TrackInfo.cxBorder = 1;
380 TrackInfo.cyBorder = 1;
381 TrackInfo.cxGrid = 1;
382 TrackInfo.cyGrid = 1;
383 TrackInfo.cxKeyboard = 8;
384 TrackInfo.cyKeyboard = 8;
385 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &Position);
386 TrackInfo.rclTrack.xLeft = Position.x;
387 TrackInfo.rclTrack.xRight = Position.x + Position.cx;
388 TrackInfo.rclTrack.yBottom = Position.y;
389 TrackInfo.rclTrack.yTop = Position.y + Position.cy;
390 WinQueryWindowPos(HWND_DESKTOP, &Position);
391 TrackInfo.rclBoundary.xLeft = Position.x;
392 TrackInfo.rclBoundary.xRight = Position.x + Position.cx;
393 TrackInfo.rclBoundary.yBottom = Position.y;
394 TrackInfo.rclBoundary.yTop = Position.y + Position.cy;
395 TrackInfo.ptlMinTrackSize.x = 0;
396 TrackInfo.ptlMinTrackSize.y = 0;
397 TrackInfo.ptlMaxTrackSize.x = Position.cx;
398 TrackInfo.ptlMaxTrackSize.y = Position.cy;
399 TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY;
400 if (WinTrackRect(HWND_DESKTOP, (HPS) 0, &TrackInfo)) {
401 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
402 HWND_TOP, TrackInfo.rclTrack.xLeft,
403 TrackInfo.rclTrack.yBottom, 0, 0, SWP_MOVE);
404 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
405 }
406 }
407 break;
408
409 case WM_HELP:
410 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_HELP, 0), MPVOID);
411 break;
412
413 case WM_COMMAND:
414 switch (SHORT1FROMMP(mp1)) {
415 case IDM_COMMANDLINE:
416 case IDM_DOSCOMMANDLINE:
417 case IDM_WINFULLSCREEN:
418 {
419 CHAR *env = GetCmdSpec(FALSE), path[CCHMAXPATH];
420 INT type = SEPARATE | WINDOWED;
421
422 *path = 0;
423 TopWindowName(hwnd, (HWND) 0, path);
424 if (SHORT1FROMMP(mp1) == IDM_DOSCOMMANDLINE)
425 env = GetCmdSpec(TRUE);
426 else if (SHORT1FROMMP(mp1) != IDM_COMMANDLINE) {
427 env = "WINOS2.COM";
428 type = SEPARATE | FULLSCREEN;
429 }
430 runemf2(type, hwnd, path, NULL, "%s", env);
431 }
432 break;
433
434 case IDM_HELP:
435 if (hwndHelp)
436 WinSendMsg(hwndHelp,
437 HM_DISPLAY_HELP,
438 MPFROM2SHORT(HELP_DATABAR, 0), MPFROMSHORT(HM_RESOURCEID));
439 break;
440
441 case MINI_CLOSE:
442 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
443 break;
444
445 case MINI_BORING:
446 fDullMin = (fDullMin) ? FALSE : TRUE;
447 PrfWriteProfileData(fmprof,
448 FM3Str, "DullDatabar", &fDullMin, sizeof(BOOL));
449 if (G_hevDataMin != NULLHANDLE) {
450 rc = DosPostEventSem(G_hevDataMin);
451 if (rc) {
452 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
453 GetPString(IDS_POSTSEMFAILED));
454 }
455 }
456
457 break;
458
459 case MINI_INCLREMOTE:
460 case MINI_SHOW:
461 if (SHORT1FROMMP(mp1) == MINI_SHOW) {
462 fDataShowDrives = (fDataShowDrives) ? FALSE : TRUE;
463 PrfWriteProfileData(fmprof,
464 appname,
465 "DataShowDrives", &fDataShowDrives, sizeof(BOOL));
466 }
467 else {
468 fDataInclRemote = (fDataInclRemote) ? FALSE : TRUE;
469 PrfWriteProfileData(fmprof,
470 appname,
471 "DataInclRemote", &fDataInclRemote, sizeof(BOOL));
472 }
473 {
474 HENUM henum;
475 HWND hwndChild;
476 USHORT id;
477
478 henum = WinBeginEnumWindows(hwnd);
479 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
480 id = WinQueryWindowUShort(hwndChild, QWS_ID);
481 if (id >= MINI_DRIVEA)
482 WinDestroyWindow(hwndChild);
483 }
484 WinEndEnumWindows(henum);
485 }
486 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
487 break;
488
489 case MINI_FLOAT:
490 fDataToFore = (fDataToFore) ? FALSE : TRUE;
491 PrfWriteProfileData(fmprof,
492 appname, "DataToFore", &fDataToFore, sizeof(BOOL));
493 if (!hwndMain) {
494
495 SWCNTRL swcntrl;
496 HSWITCH hswitch;
497
498 hswitch = (HSWITCH) WinQuerySwitchHandle(hwnd, (PID) 0);
499 if (hswitch) {
500 memset(&swcntrl, 0, sizeof(SWCNTRL));
501 if (!WinQuerySwitchEntry(hswitch, &swcntrl)) {
502 swcntrl.fbJump = (fDataToFore) ? SWL_NOTJUMPABLE : SWL_JUMPABLE;
503 WinChangeSwitchEntry(hswitch, &swcntrl);
504 }
505 }
506 }
507 break;
508 }
509 return 0;
510
511 case WM_SIZE:
512 WinSetWindowPos(hwnd,
513 HWND_TOP,
514 0,
515 0,
516 SHORT1FROMMP(mp2),
517 SHORT2FROMMP(mp2), SWP_MOVE | SWP_SIZE);
518 break;
519
520 case WM_PAINT:
521 {
522 HPS hps;
523 POINTL ptl;
524 SWP swp;
525 RECTL rcl;
526
527 hps = WinBeginPaint(hwnd, (HPS) 0, &rcl);
528 if (hps) {
529 WinFillRect(hps, (PRECTL) & rcl, CLR_PALEGRAY);
530 GpiSetMix(hps, FM_OVERPAINT);
531 GpiSetColor(hps, CLR_WHITE);
532 WinQueryWindowPos(hwnd, &swp);
533 ptl.x = 0;
534 ptl.y = 0;
535 GpiMove(hps, &ptl);
536 ptl.y = swp.cy - 1;
537 GpiLine(hps, &ptl);
538 ptl.x = swp.cx - 1;
539 GpiLine(hps, &ptl);
540 GpiSetColor(hps, CLR_DARKGRAY);
541 ptl.y = 0;
542 GpiLine(hps, &ptl);
543 ptl.x = 0;
544 GpiLine(hps, &ptl);
545 {
546 HENUM henum;
547 HWND hwndTemp;
548
549 henum = WinBeginEnumWindows(hwnd);
550 while ((hwndTemp = WinGetNextWindow(henum)) != NULLHANDLE) {
551 PaintRecessedWindow(hwndTemp,
552 hps, (WinQueryWindowUShort(hwndTemp, QWS_ID)
553 != MINI_TIME), FALSE);
554 }
555 WinEndEnumWindows(henum);
556 }
557 WinEndPaint(hps);
558 }
559 }
560 return 0;
561
562 case UM_PAINT:
563 {
564 CHAR s[90];
565 CHAR szFreeQty[38];
566 CHAR szDrvLtr[] = " :";
567 CHAR *pszFSystem;
568 ULONGLONG ullFreeQty;
569 ULONG ulPercentFree;
570 ULONG wasx;
571 HPS hps = (HPS) mp2;
572 HWND hwndChild;
573 USHORT id;
574 SWP swp;
575 POINTL ptl;
576 tDataMin *pDM;
577
578 id = SHORT1FROMMP(mp1);
579 if (id >= MINI_DRIVEA) {
580 hwndChild = WinWindowFromID(hwnd, id);
581 if (!hwndChild)
582 return 0;
583 if (!WinQueryWindowPos(hwndChild, &swp))
584 return 0;
585 pDM = WinQueryWindowPtr(hwndChild, QWL_DATAMIN_PTR);
586 if (!pDM || pDM->qfsi_rc) {
587 ullFreeQty = 0;
588 ulPercentFree = 0;
589 }
590 else {
591 ullFreeQty = (ULONGLONG) pDM->fsa.cUnitAvail *
592 (pDM->fsa.cSectorUnit * pDM->fsa.cbSector);
593
594 ulPercentFree = (pDM->fsa.cUnit && pDM->fsa.cUnitAvail) ?
595 (pDM->fsa.cUnitAvail * 100) / pDM->fsa.cUnit : 0;
596 }
597
598 CommaFmtULL(szFreeQty, sizeof(szFreeQty), ullFreeQty, ' ');
599 *szDrvLtr = (CHAR) (id - MINI_DRIVEA) + 'A';
600
601 if (!pDM || pDM->qfsi_rc || pDM->qfsa_rc)
602 pszFSystem = "N/A";
603 else {
604 pszFSystem = pDM->fsqb2.szName + pDM->fsqb2.cbName + 1;
605 pszFSystem[15] = 0;
606 }
607 sprintf(s,
608 "%s %13s %lu%%-%s %6s ",
609 szDrvLtr,
610 szFreeQty,
611 ulPercentFree, GetPString(IDS_FREETEXT), pszFSystem);
612 if (!hps)
613 hps = WinGetPS(hwndChild);
614 if (hps) {
615 if (!fDullMin) {
616 ptl.x = 0;
617 ptl.y = 0;
618 GpiMove(hps, &ptl);
619 GpiSetColor(hps, CLR_BLACK);
620 ptl.x = swp.cx - 1;
621 ptl.y = swp.cy - 1;
622 GpiBox(hps, DRO_OUTLINE, &ptl, 0, 0);
623 ptl.x = 1;
624 ptl.y = 1;
625 if (ulPercentFree) {
626 GpiMove(hps, &ptl);
627 GpiSetColor(hps,
628 (ulPercentFree < 11) ? CLR_DARKRED :
629 (ulPercentFree < 26) ? CLR_DARKBLUE :
630 CLR_DARKGREEN);
631 ptl.y = swp.cy - 2;
632 ptl.x = ((swp.cx - 2) * ulPercentFree) / 100;
633 wasx = ptl.x;
634 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
635 GpiSetColor(hps,
636 (ulPercentFree < 11) ? CLR_RED :
637 (ulPercentFree < 26) ? CLR_BLUE : CLR_GREEN);
638 ptl.x = wasx;
639 ptl.y = swp.cy - 2;
640 GpiMove(hps, &ptl);
641 ptl.x = 1;
642 GpiLine(hps, &ptl);
643 ptl.y = 2;
644 ptl.x = 1;
645 GpiLine(hps, &ptl);
646 ptl.x = wasx;
647 }
648 if (ulPercentFree < 99) {
649 GpiSetColor(hps, CLR_DARKGRAY);
650 wasx = ptl.x;
651 ptl.y = 2;
652 GpiMove(hps, &ptl);
653 ptl.y = swp.cy - 2;
654 ptl.x = swp.cx - 2;
655 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
656 ptl.x = wasx;
657 GpiMove(hps, &ptl);
658 GpiSetColor(hps, CLR_PALEGRAY);
659 ptl.x = swp.cx - 3;
660 GpiLine(hps, &ptl);
661 ptl.x = wasx;
662 ptl.y = 1;
663 GpiMove(hps, &ptl);
664 GpiSetColor(hps, CLR_BLACK);
665 ptl.x = swp.cx - 2;
666 GpiLine(hps, &ptl);
667 ptl.y = swp.cy - 3;
668 GpiLine(hps, &ptl);
669 }
670 GpiSetColor(hps, CLR_WHITE);
671 }
672 else {
673 GpiSetColor(hps, CLR_PALEGRAY);
674 ptl.x = 0;
675 ptl.y = 0;
676 GpiMove(hps, &ptl);
677 ptl.x = swp.cx - 1;
678 ptl.y = swp.cy - 1;
679 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
680 GpiSetColor(hps,
681 (ulPercentFree < 11) ? CLR_DARKRED : CLR_DARKBLUE);
682 }
683 GpiSetBackMix(hps, BM_LEAVEALONE);
684 GpiSetMix(hps, FM_OVERPAINT);
685 {
686 POINTL aptl[TXTBOX_COUNT];
687
688 GpiQueryTextBox(hps, strlen(s), s, TXTBOX_COUNT, aptl);
689 ptl.y = ((swp.cy / 2) -
690 ((aptl[TXTBOX_TOPRIGHT].y +
691 aptl[TXTBOX_BOTTOMLEFT].y) / 2));
692 ptl.y++;
693 ptl.x = (swp.cx / 2) - (aptl[TXTBOX_TOPRIGHT].x / 2);
694 if (ptl.x < 2)
695 ptl.x = 2;
696 GpiCharStringAt(hps, &ptl, strlen(s), s);
697 }
698 if (!mp2)
699 WinReleasePS(hps);
700 }
701 } // if drive window
702 }
703 return 0;
704
705 case UM_TIMER:
706 {
707 CHAR s[134];
708 DATETIME dt;
709
710 if (fDataToFore && !NoFloat)
711 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
712 HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
713 if (counter && (counter % 19) && (counter % 20)) {
714 if (!DosGetDateTime(&dt)) {
715 sprintf(s,
716 " %02hu:%02hu:%02hu %s %04u/%02u/%02u",
717 dt.hours,
718 dt.minutes,
719 dt.seconds,
720 GetPString(IDS_SUNDAY + dt.weekday),
721 dt.year, dt.month, dt.day);
722 WinSetDlgItemText(hwnd, MINI_TIME, s);
723 }
724 }
725 else if (!counter || !(counter % 19))
726 PostMsg(hwnd, UM_SETUP6, MPVOID, MPVOID); // Uptime
727 if (!(counter % 4)) {
728 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID); // Memory utilization
729 if (!(counter % 10)) {
730 PostMsg(hwnd, UM_SETUP5, MPVOID, MPVOID); // Process status
731 if (!(counter % 20)) {
732 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID); // Swapper
733 }
734 }
735 }
736 }
737 counter++;
738 return 0;
739
740 case UM_SETUP2:
741 {
742 CHAR s[134], szFileQty[38], szFreeQty[38];
743 FILEFINDBUF3 ffb;
744 ULONG nm = 1L;
745 ULONGLONG ullFreeQty;
746 HDIR hdir = HDIR_CREATE;
747 FSALLOCATE fsa;
748
749 if (*SwapperDat) {
750 DosError(FERR_DISABLEHARDERR);
751 if (!DosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_HIDDEN |
752 FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY,
753 &ffb, sizeof(ffb), &nm, FIL_STANDARD)) {
754 priority_bumped();
755 DosFindClose(hdir);
756 DosError(FERR_DISABLEHARDERR);
757 if (!DosQueryFSInfo(toupper(*SwapperDat) - '@', FSIL_ALLOC,
758 &fsa, sizeof(FSALLOCATE))) {
759 ullFreeQty =
760 (ULONGLONG) fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
761 CommaFmtULL(szFreeQty, sizeof(szFreeQty), ullFreeQty, ' ');
762 }
763 else
764 *szFreeQty = 0;
765
766 CommaFmtULL(szFileQty, sizeof(szFileQty), ffb.cbFile, ' ');
767 sprintf(s, " %s %s%s%s",
768 GetPString(IDS_SWAPTITLETEXT),
769 szFileQty, *szFreeQty ? "/" : NullStr, szFreeQty);
770 WinSetDlgItemText(hwnd, MINI_SWAP, s);
771 }
772 }
773 }
774 return 0;
775
776 case UM_SETUP3: // Memory utilization
777 {
778 CHAR s[134], tm[38], szQty[38];
779 ULONG amem = 0;
780
781 if (!DosQuerySysInfo(QSV_TOTAVAILMEM, QSV_TOTAVAILMEM,
782 (PVOID) & amem, (ULONG) sizeof(amem))) {
783 CommaFmtUL(tm, sizeof(tm), amem, 'M');
784 if (!Dos16MemAvail(&amem))
785 CommaFmtUL(szQty, sizeof(szQty), amem, 'M');
786 else
787 *szQty = 0;
788 sprintf(s, " %s%s%s%s",
789 GetPString(IDS_MEMTITLETEXT),
790 szQty, (*szQty) ? "/" : NullStr, tm);
791 WinSetDlgItemText(hwnd, MINI_MEM, s);
792 }
793 }
794 return 0;
795
796 case UM_SETUP5: // Process status
797 {
798 CHAR s[134], tm[38], szQty[38];
799
800 if (fUseQProcStat && !noqproc) {
801
802 PROCESSINFO *ppi;
803 BUFFHEADER *pbh = NULL;
804 MODINFO *pmi;
805 ULONG numprocs = 0, numthreads = 0;
806 APIRET rc;
807
808 rc = DosAllocMem((PVOID) & pbh, USHRT_MAX + 4096,
809 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
810 if (rc)
811 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
812 GetPString(IDS_OUTOFMEMORY));
813 else {
814 if (DosQProcStatus(pbh, USHRT_MAX))
815 noqproc = TRUE;
816 else {
817 ppi = pbh->ppi;
818 while (ppi->ulEndIndicator != PROCESS_END_INDICATOR) {
819 pmi = pbh->pmi;
820 while (pmi && ppi->hModRef != pmi->hMod)
821 pmi = pmi->pNext;
822 if (pmi) {
823 numprocs++;
824 numthreads += ppi->usThreadCount;
825 }
826 ppi = (PPROCESSINFO) (ppi->ptiFirst + ppi->usThreadCount);
827 }
828 commafmt(szQty, sizeof(szQty), numprocs);
829 commafmt(tm, sizeof(tm), numthreads);
830 sprintf(s,
831 " %s%s %s%s",
832 GetPString(IDS_PROCSTITLETEXT),
833 szQty, GetPString(IDS_THRDSTITLETEXT), tm);
834 WinSetDlgItemText(hwnd, MINI_PROC, s);
835 }
836 DosFreeMem(pbh);
837 }
838 }
839 else {
840 commafmt(szQty, sizeof(szQty),
841 WinQuerySwitchList(WinQueryAnchorBlock(hwnd), (PSWBLOCK) 0,
842 0));
843 sprintf(s, " %s%s", GetPString(IDS_TASKSTITLETEXT), szQty);
844 WinSetDlgItemText(hwnd, MINI_PROC, s);
845 }
846 }
847 return 0;
848
849 case UM_SETUP6: // Uptime
850 {
851 ULONG val = 0, numdays, nummins;
852 CHAR s[128];
853
854 if (!DosQuerySysInfo(QSV_MS_COUNT,
855 QSV_MS_COUNT,
856 (PVOID) & val, (ULONG) sizeof(val))) {
857 val /= 60000L;
858 numdays = val / (60L * 24L);
859 strcpy(s, GetPString(IDS_ELAPSEDTITLETEXT));
860 if (numdays)
861 sprintf(s + strlen(s),
862 " %lu %s%s, ",
863 numdays, GetPString(IDS_DAYTEXT), &"s"[numdays == 1L]);
864 nummins = val % (60L * 24L);
865 sprintf(s + strlen(s), " %lu:%02lu", nummins / 60, nummins % 60);
866 WinSetDlgItemText(hwnd, MINI_TIME, s);
867 }
868 }
869 return 0;
870
871 case WM_SAVEAPPLICATION:
872 {
873 SWP swp;
874
875 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
876 PrfWriteProfileData(fmprof, appname, "DataMinPos", &swp, sizeof(SWP));
877 }
878 break;
879
880 case WM_CLOSE:
881 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
882 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
883 return 0;
884
885 case WM_DESTROY:
886 if (DataHwnd == WinQueryWindow(hwnd, QW_PARENT)) {
887 DataHwnd = (HWND) 0;
888 if (hwndMenu)
889 WinDestroyWindow(hwndMenu);
890 hwndMenu = (HWND) 0;
891 }
892 if (hwndMain) {
893
894 SWP swp;
895 ULONG fl = SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE, ofl;
896
897 ofl = WinQueryWindowULong(hwnd, QWL_USER);
898 WinQueryWindowPos(WinQueryWindow(hwndMain, QW_PARENT), &swp);
899 if (swp.fl & SWP_MINIMIZE)
900 fl |= ((ofl & SWP_MAXIMIZE) ? SWP_MAXIMIZE : SWP_RESTORE);
901 WinSetWindowPos(WinQueryWindow(hwndMain, QW_PARENT),
902 HWND_TOP, 0, 0, 0, 0, fl);
903 }
904 else if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
905 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
906 break;
907 }
908 return WinDefWindowProc(hwnd, msg, mp1, mp2);
909
910} // DataProc
911
912//=== CreateDataBar - create databar windows ===
913
914HWND CreateDataBar(HWND hwndParent, ULONG fl)
915{
916 HWND hwndClient = (HWND) 0;
917 ULONG FrameFlags = 0;
918
919 if (WinCreateStdWindow(hwndParent,
920 WS_VISIBLE,
921 &FrameFlags,
922 WC_DATABAR,
923 NULL, WS_VISIBLE, 0, MINI_FRAME, &hwndClient)) {
924 WinSendMsg(hwndClient, UM_RESTORE, MPFROMLONG(fl), MPVOID);
925 }
926 return hwndClient;
927
928} // CreateDataBar
929
930//=== dataminThread - drive status thread ===
931
932static VOID dataminThread(VOID * pv)
933{
934 HAB hab = NULLHANDLE;
935 HMQ hmq = NULLHANDLE;
936 HWND hwndParent = (HWND) pv;
937 HWND hwnd;
938 HENUM henum;
939 BOOL busy = TRUE;
940 APIRET rc;
941 USHORT id;
942
943 if (G_hevDataMin == NULLHANDLE) {
944 // Create just once for any thread that might use it
945 // Kernel will clean up on exit
946 rc = DosCreateEventSem(NULL, (PHEV) & G_hevDataMin, 0L, FALSE);
947 if (rc) {
948 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
949 GetPString(IDS_CREATESEMFAILED));
950 busy = FALSE;
951 }
952 }
953
954 // fixme to report errors
955 hab = WinInitialize(0);
956 if (hab == NULLHANDLE)
957 busy = FALSE;
958 else {
959 hmq = WinCreateMsgQueue(hab, 0);
960 if (hmq == NULLHANDLE)
961 busy = FALSE;
962 else
963 WinCancelShutdown(hmq, TRUE);
964 }
965
966 while (busy) {
967 HWND hwndSingle = G_hwndSingle;
968
969 G_hwndSingle = NULLHANDLE;
970
971 busy = FALSE;
972
973 if (!WinIsWindow(hab, hwndParent))
974 break;
975
976 henum = WinBeginEnumWindows(hwndParent);
977 while (henum && (hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
978 if (!WinIsWindow(hab, hwnd))
979 continue;
980 if (hwndSingle && hwndSingle != hwnd)
981 continue;
982 id = WinQueryWindowUShort(hwnd, QWS_ID);
983 if (id > MINI_DRIVEA) {
984 ULONG dskNum = id - MINI_DRIVEA + 1;
985 tDataMin *pDM = WinQueryWindowPtr(hwnd, QWL_DATAMIN_PTR);
986 SWP swp;
987 CHAR szPath[] = " :";
988
989 if (!pDM)
990 continue;
991 busy = TRUE;
992 if (!WinQueryWindowPos(hwnd, &swp))
993 continue;
994
995 DosError(FERR_DISABLEHARDERR);
996 pDM->qfsi_rc = DosQueryFSInfo(dskNum,
997 FSIL_ALLOC,
998 &pDM->fsa, sizeof(FSALLOCATE));
999
1000 if (!pDM->qfsi_rc) {
1001 *szPath = (CHAR) dskNum + 'A' - 1;
1002 pDM->qfsa_cb = sizeof(FSQBUFFER2) + 256; // se tDataMin
1003 DosError(FERR_DISABLEHARDERR);
1004 pDM->qfsa_rc = DosQueryFSAttach(szPath, 0, /* Ordinal */
1005 FSAIL_QUERYNAME,
1006 &pDM->fsqb2, &pDM->qfsa_cb);
1007 }
1008 WinInvalidateRect(hwnd, NULL, FALSE);
1009 } // if drive window
1010 } // while henum
1011 WinEndEnumWindows(henum);
1012
1013 if (busy) {
1014 ULONG clPosted;
1015
1016 rc = DosWaitEventSem(G_hevDataMin, 20000L);
1017 if (rc && rc != ERROR_TIMEOUT) {
1018 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1019 GetPString(IDS_POSTSEMFAILED));
1020 }
1021
1022 rc = DosResetEventSem(G_hevDataMin, &clPosted);
1023 if (rc && rc != ERROR_ALREADY_RESET) {
1024 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1025 GetPString(IDS_POSTSEMFAILED));
1026 }
1027 }
1028
1029 } // while
1030
1031 if (hmq != NULLHANDLE)
1032 WinDestroyMsgQueue(hmq);
1033
1034 if (hab != NULLHANDLE)
1035 WinTerminate(hab);
1036
1037} // dataminThread
Note: See TracBrowser for help on using the repository browser.