source: trunk/dll/datamin.c@ 549

Last change on this file since 549 was 549, checked in by root, 19 years ago

Support additional file systems types (Gregg)
Reorganize menus (Gregg)
Enhance unzip option controls (Gregg)
Remember search options in Seek and Scan (Gregg)
Allow drive flag editing for not ready drives (Gregg)
Correct bitmap loading defects (Steven)
Update documentation (Gregg)
Add newer, better bitmaps (David)
Update Readme to discuss move to Netlabs (Steve)

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