source: trunk/dll/datamin.c@ 553

Last change on this file since 553 was 553, checked in by Gregg Young, 19 years ago

Minor cleanup to new drive flags/fonts; Added help info for new flags

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