source: trunk/dll/datamin.c@ 689

Last change on this file since 689 was 689, checked in by Steven Levine, 18 years ago

Commit OpenWatcom compatibility updates

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