source: trunk/dll/datamin.c@ 179

Last change on this file since 179 was 179, checked in by root, 20 years ago

Comments

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