source: trunk/dll/datamin.c@ 1038

Last change on this file since 1038 was 1038, checked in by Gregg Young, 17 years ago

More fortify cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: datamin.c 1038 2008-07-04 20:33:59Z gyoung $
5
6 Minimized data bar
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2006 Steven H. Levine
10
11 14 Sep 02 SHL Handle large partitions
12 16 Oct 02 SHL Handle large partitions better
13 23 May 05 SHL Use QWL_USER
14 23 May 05 SHL Avoid delays for inaccessible drives
15 25 May 05 SHL Use ULONGLONG and CommaFmtULL
16 06 Jun 05 SHL Drop unused code
17 22 Jul 06 SHL Check more run time errors
18 02 Jan 07 GKY Changed drive information string formating to accomodate 6 char FS names
19 07 Jan 07 GKY Move error strings etc. to string file
20 30 Mar 07 GKY Remove GetPString for window class names
21 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
22 02 Sep 07 GKY Replaced DosQProcStatus with DosQuerySysState to fix trap in thunk code
23
24***********************************************************************/
25
26#include <string.h>
27#include <ctype.h>
28#include <limits.h>
29#include <process.h> // _beginthread
30
31#define INCL_DOS
32#define INCL_DOSERRORS
33#define INCL_WIN
34#define INCL_GPI
35#define INCL_LONGLONG
36
37#include "fm3dlg.h"
38#include "fm3str.h"
39#include "procstat.h"
40#include "datamin.h"
41#include "errutil.h" // Dos_Error...
42#include "strutil.h" // GetPString
43#include "fm3dll.h"
44#include "fortify.h"
45
46#pragma data_seg(DATA2)
47
48static PSZ pszSrcFile = __FILE__;
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 if (pv)
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, pszSrcFile, __LINE__);
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, pszSrcFile, __LINE__,
432 path, NULL, "%s", env);
433 }
434 break;
435
436 case IDM_HELP:
437 if (hwndHelp)
438 WinSendMsg(hwndHelp,
439 HM_DISPLAY_HELP,
440 MPFROM2SHORT(HELP_DATABAR, 0), MPFROMSHORT(HM_RESOURCEID));
441 break;
442
443 case MINI_CLOSE:
444 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
445 break;
446
447 case MINI_BORING:
448 fDullMin = (fDullMin) ? FALSE : TRUE;
449 PrfWriteProfileData(fmprof,
450 FM3Str, "DullDatabar", &fDullMin, sizeof(BOOL));
451 if (G_hevDataMin != NULLHANDLE) {
452 rc = DosPostEventSem(G_hevDataMin);
453 if (rc) {
454 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
455 GetPString(IDS_POSTSEMFAILED));
456 }
457 }
458
459 break;
460
461 case MINI_INCLREMOTE:
462 case MINI_SHOW:
463 if (SHORT1FROMMP(mp1) == MINI_SHOW) {
464 fDataShowDrives = (fDataShowDrives) ? FALSE : TRUE;
465 PrfWriteProfileData(fmprof,
466 appname,
467 "DataShowDrives", &fDataShowDrives, sizeof(BOOL));
468 }
469 else {
470 fDataInclRemote = (fDataInclRemote) ? FALSE : TRUE;
471 PrfWriteProfileData(fmprof,
472 appname,
473 "DataInclRemote", &fDataInclRemote, sizeof(BOOL));
474 }
475 {
476 HENUM henum;
477 HWND hwndChild;
478 USHORT id;
479
480 henum = WinBeginEnumWindows(hwnd);
481 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
482 id = WinQueryWindowUShort(hwndChild, QWS_ID);
483 if (id >= MINI_DRIVEA)
484 WinDestroyWindow(hwndChild);
485 }
486 WinEndEnumWindows(henum);
487 }
488 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
489 break;
490
491 case MINI_FLOAT:
492 fDataToFore = (fDataToFore) ? FALSE : TRUE;
493 PrfWriteProfileData(fmprof,
494 appname, "DataToFore", &fDataToFore, sizeof(BOOL));
495 if (!hwndMain) {
496
497 SWCNTRL swcntrl;
498 HSWITCH hswitch;
499
500 hswitch = (HSWITCH) WinQuerySwitchHandle(hwnd, (PID) 0);
501 if (hswitch) {
502 memset(&swcntrl, 0, sizeof(SWCNTRL));
503 if (!WinQuerySwitchEntry(hswitch, &swcntrl)) {
504 swcntrl.fbJump = (fDataToFore) ? SWL_NOTJUMPABLE : SWL_JUMPABLE;
505 WinChangeSwitchEntry(hswitch, &swcntrl);
506 }
507 }
508 }
509 break;
510 }
511 return 0;
512
513 case WM_SIZE:
514 WinSetWindowPos(hwnd,
515 HWND_TOP,
516 0,
517 0,
518 SHORT1FROMMP(mp2),
519 SHORT2FROMMP(mp2), SWP_MOVE | SWP_SIZE);
520 break;
521
522 case WM_PAINT:
523 {
524 HPS hps;
525 POINTL ptl;
526 SWP swp;
527 RECTL rcl;
528
529 hps = WinBeginPaint(hwnd, (HPS) 0, &rcl);
530 if (hps) {
531 WinFillRect(hps, (PRECTL) & rcl, CLR_PALEGRAY);
532 GpiSetMix(hps, FM_OVERPAINT);
533 GpiSetColor(hps, CLR_WHITE);
534 WinQueryWindowPos(hwnd, &swp);
535 ptl.x = 0;
536 ptl.y = 0;
537 GpiMove(hps, &ptl);
538 ptl.y = swp.cy - 1;
539 GpiLine(hps, &ptl);
540 ptl.x = swp.cx - 1;
541 GpiLine(hps, &ptl);
542 GpiSetColor(hps, CLR_DARKGRAY);
543 ptl.y = 0;
544 GpiLine(hps, &ptl);
545 ptl.x = 0;
546 GpiLine(hps, &ptl);
547 {
548 HENUM henum;
549 HWND hwndTemp;
550
551 henum = WinBeginEnumWindows(hwnd);
552 while ((hwndTemp = WinGetNextWindow(henum)) != NULLHANDLE) {
553 PaintRecessedWindow(hwndTemp,
554 hps, (WinQueryWindowUShort(hwndTemp, QWS_ID)
555 != MINI_TIME), FALSE);
556 }
557 WinEndEnumWindows(henum);
558 }
559 WinEndPaint(hps);
560 }
561 }
562 return 0;
563
564 case UM_PAINT:
565 {
566 CHAR s[90];
567 CHAR szFreeQty[38];
568 CHAR szDrvLtr[] = " :";
569 CHAR *pszFSystem;
570 ULONGLONG ullFreeQty;
571 ULONG ulPercentFree;
572 ULONG wasx;
573 HPS hps = (HPS) mp2;
574 HWND hwndChild;
575 USHORT id;
576 SWP swp;
577 POINTL ptl;
578 tDataMin *pDM;
579
580 id = SHORT1FROMMP(mp1);
581 if (id >= MINI_DRIVEA) {
582 hwndChild = WinWindowFromID(hwnd, id);
583 if (!hwndChild)
584 return 0;
585 if (!WinQueryWindowPos(hwndChild, &swp))
586 return 0;
587 pDM = WinQueryWindowPtr(hwndChild, QWL_DATAMIN_PTR);
588 if (!pDM || pDM->qfsi_rc) {
589 ullFreeQty = 0;
590 ulPercentFree = 0;
591 }
592 else {
593 ullFreeQty = (ULONGLONG) pDM->fsa.cUnitAvail *
594 (pDM->fsa.cSectorUnit * pDM->fsa.cbSector);
595
596 ulPercentFree = (pDM->fsa.cUnit && pDM->fsa.cUnitAvail) ?
597 (pDM->fsa.cUnitAvail * 100) / pDM->fsa.cUnit : 0;
598 }
599
600 CommaFmtULL(szFreeQty, sizeof(szFreeQty), ullFreeQty, ' ');
601 *szDrvLtr = (CHAR) (id - MINI_DRIVEA) + 'A';
602
603 if (!pDM || pDM->qfsi_rc || pDM->qfsa_rc)
604 pszFSystem = "N/A";
605 else {
606 pszFSystem = (PCHAR)(pDM->fsqb2.szName) + pDM->fsqb2.cbName + 1;
607 pszFSystem[15] = 0;
608 }
609 sprintf(s,
610 "%s %13s %lu%%-%s %6s ",
611 szDrvLtr,
612 szFreeQty,
613 ulPercentFree, GetPString(IDS_FREETEXT), pszFSystem);
614 if (!hps)
615 hps = WinGetPS(hwndChild);
616 if (hps) {
617 if (!fDullMin) {
618 ptl.x = 0;
619 ptl.y = 0;
620 GpiMove(hps, &ptl);
621 GpiSetColor(hps, CLR_BLACK);
622 ptl.x = swp.cx - 1;
623 ptl.y = swp.cy - 1;
624 GpiBox(hps, DRO_OUTLINE, &ptl, 0, 0);
625 ptl.x = 1;
626 ptl.y = 1;
627 if (ulPercentFree) {
628 GpiMove(hps, &ptl);
629 GpiSetColor(hps,
630 (ulPercentFree < 11) ? CLR_DARKRED :
631 (ulPercentFree < 26) ? CLR_DARKBLUE :
632 CLR_DARKGREEN);
633 ptl.y = swp.cy - 2;
634 ptl.x = ((swp.cx - 2) * ulPercentFree) / 100;
635 wasx = ptl.x;
636 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
637 GpiSetColor(hps,
638 (ulPercentFree < 11) ? CLR_RED :
639 (ulPercentFree < 26) ? CLR_BLUE : CLR_GREEN);
640 ptl.x = wasx;
641 ptl.y = swp.cy - 2;
642 GpiMove(hps, &ptl);
643 ptl.x = 1;
644 GpiLine(hps, &ptl);
645 ptl.y = 2;
646 ptl.x = 1;
647 GpiLine(hps, &ptl);
648 ptl.x = wasx;
649 }
650 if (ulPercentFree < 99) {
651 GpiSetColor(hps, CLR_DARKGRAY);
652 wasx = ptl.x;
653 ptl.y = 2;
654 GpiMove(hps, &ptl);
655 ptl.y = swp.cy - 2;
656 ptl.x = swp.cx - 2;
657 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
658 ptl.x = wasx;
659 GpiMove(hps, &ptl);
660 GpiSetColor(hps, CLR_PALEGRAY);
661 ptl.x = swp.cx - 3;
662 GpiLine(hps, &ptl);
663 ptl.x = wasx;
664 ptl.y = 1;
665 GpiMove(hps, &ptl);
666 GpiSetColor(hps, CLR_BLACK);
667 ptl.x = swp.cx - 2;
668 GpiLine(hps, &ptl);
669 ptl.y = swp.cy - 3;
670 GpiLine(hps, &ptl);
671 }
672 GpiSetColor(hps, CLR_WHITE);
673 }
674 else {
675 GpiSetColor(hps, CLR_PALEGRAY);
676 ptl.x = 0;
677 ptl.y = 0;
678 GpiMove(hps, &ptl);
679 ptl.x = swp.cx - 1;
680 ptl.y = swp.cy - 1;
681 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
682 GpiSetColor(hps,
683 (ulPercentFree < 11) ? CLR_DARKRED : CLR_DARKBLUE);
684 }
685 GpiSetBackMix(hps, BM_LEAVEALONE);
686 GpiSetMix(hps, FM_OVERPAINT);
687 {
688 POINTL aptl[TXTBOX_COUNT];
689
690 GpiQueryTextBox(hps, strlen(s), s, TXTBOX_COUNT, aptl);
691 ptl.y = ((swp.cy / 2) -
692 ((aptl[TXTBOX_TOPRIGHT].y +
693 aptl[TXTBOX_BOTTOMLEFT].y) / 2));
694 ptl.y++;
695 ptl.x = (swp.cx / 2) - (aptl[TXTBOX_TOPRIGHT].x / 2);
696 if (ptl.x < 2)
697 ptl.x = 2;
698 GpiCharStringAt(hps, &ptl, strlen(s), s);
699 }
700 if (!mp2)
701 WinReleasePS(hps);
702 }
703 } // if drive window
704 }
705 return 0;
706
707 case UM_TIMER:
708 {
709 CHAR s[134];
710 DATETIME dt;
711
712 if (fDataToFore && !NoFloat)
713 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
714 HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
715 if (counter && (counter % 19) && (counter % 20)) {
716 if (!DosGetDateTime(&dt)) {
717 sprintf(s,
718 " %02hu:%02hu:%02hu %s %04u/%02u/%02u",
719 dt.hours,
720 dt.minutes,
721 dt.seconds,
722 GetPString(IDS_SUNDAY + dt.weekday),
723 dt.year, dt.month, dt.day);
724 WinSetDlgItemText(hwnd, MINI_TIME, s);
725 }
726 }
727 else if (!counter || !(counter % 19))
728 PostMsg(hwnd, UM_SETUP6, MPVOID, MPVOID); // Uptime
729 if (!(counter % 4)) {
730 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID); // Memory utilization
731 if (!(counter % 10)) {
732 PostMsg(hwnd, UM_SETUP5, MPVOID, MPVOID); // Process status
733 if (!(counter % 20)) {
734 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID); // Swapper
735 }
736 }
737 }
738 }
739 counter++;
740 return 0;
741
742 case UM_SETUP2:
743 {
744 CHAR s[134], szFileQty[38], szFreeQty[38];
745 FILEFINDBUF3L ffb;
746 ULONG nm = 1;
747 ULONGLONG ullFreeQty;
748 HDIR hdir = HDIR_CREATE;
749 FSALLOCATE fsa;
750
751 if (*SwapperDat) {
752 DosError(FERR_DISABLEHARDERR);
753 if (!xDosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_HIDDEN |
754 FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY,
755 &ffb, sizeof(ffb), &nm, FIL_STANDARDL)) {
756 priority_bumped();
757 DosFindClose(hdir);
758 DosError(FERR_DISABLEHARDERR);
759 if (!DosQueryFSInfo(toupper(*SwapperDat) - '@', FSIL_ALLOC,
760 &fsa, sizeof(FSALLOCATE))) {
761 ullFreeQty =
762 (ULONGLONG) fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
763 CommaFmtULL(szFreeQty, sizeof(szFreeQty), ullFreeQty, ' ');
764 }
765 else
766 *szFreeQty = 0;
767
768 CommaFmtULL(szFileQty, sizeof(szFileQty), ffb.cbFile, ' ');
769 sprintf(s, " %s %s%s%s",
770 GetPString(IDS_SWAPTITLETEXT),
771 szFileQty, *szFreeQty ? "/" : NullStr, szFreeQty);
772 WinSetDlgItemText(hwnd, MINI_SWAP, s);
773 }
774 }
775 }
776 return 0;
777
778 case UM_SETUP3: // Memory utilization
779 {
780 CHAR s[134], tm[38], szQty[38];
781 ULONG amem = 0;
782
783 if (!DosQuerySysInfo(QSV_TOTAVAILMEM, QSV_TOTAVAILMEM,
784 (PVOID) & amem, (ULONG) sizeof(amem))) {
785 CommaFmtUL(tm, sizeof(tm), amem, 'M');
786 if (!Dos16MemAvail(&amem))
787 CommaFmtUL(szQty, sizeof(szQty), amem, 'M');
788 else
789 *szQty = 0;
790 sprintf(s, " %s%s%s%s",
791 GetPString(IDS_MEMTITLETEXT),
792 szQty, (*szQty) ? "/" : NullStr, tm);
793 WinSetDlgItemText(hwnd, MINI_MEM, s);
794 }
795 }
796 return 0;
797
798 case UM_SETUP5: // Process status
799 {
800 CHAR s[134], tm[38], szQty[38];
801
802 if (fUseQProcStat && !noqproc) {
803
804 PROCESSINFO *ppi;
805 BUFFHEADER *pbh = NULL;
806 MODINFO *pmi;
807 ULONG numprocs = 0, numthreads = 0;
808 APIRET rc;
809
810 rc = DosAllocMem((PVOID)&pbh, USHRT_MAX + 4096,
811 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
812 if (rc)
813 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
814 GetPString(IDS_OUTOFMEMORY));
815 else {
816 if (DosQProcStatus((ULONG *)pbh, USHRT_MAX))
817 noqproc = TRUE;
818 else {
819 ppi = pbh->ppi;
820 while (ppi->ulEndIndicator != PROCESS_END_INDICATOR) {
821 pmi = pbh->pmi;
822 while (pmi && ppi->hModRef != pmi->hMod)
823 pmi = pmi->pNext;
824 if (pmi) {
825 numprocs++;
826 numthreads += ppi->usThreadCount;
827 }
828 ppi = (PPROCESSINFO) (ppi->ptiFirst + ppi->usThreadCount);
829 }
830 commafmt(szQty, sizeof(szQty), numprocs);
831 commafmt(tm, sizeof(tm), numthreads);
832 sprintf(s,
833 " %s%s %s%s",
834 GetPString(IDS_PROCSTITLETEXT),
835 szQty, GetPString(IDS_THRDSTITLETEXT), tm);
836 WinSetDlgItemText(hwnd, MINI_PROC, s);
837 }
838 DosFreeMem(pbh);
839 }
840 }
841 else if (fUseQSysState && !noqproc) {
842
843 QSPREC *ppi;
844 QSPTRREC *pbh = NULL;
845 QSLREC *pmi;
846 ULONG numprocs = 0, numthreads = 0;
847 APIRET rc;
848
849 rc = DosAllocMem((PVOID) & pbh, USHRT_MAX + 4096,
850 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
851 if (rc)
852 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
853 GetPString(IDS_OUTOFMEMORY));
854 else { //2 Sep 07 GKY 0x05 = process & Mod data only
855 if (DosQuerySysState(QS_PROCESS | QS_MTE, 0, 0, 0, pbh, USHRT_MAX))
856 noqproc = TRUE;
857 else {
858 ppi = pbh->pProcRec;
859 while (ppi->RecType == 1) {
860 pmi = pbh->pLibRec;
861 while (pmi && ppi->hMte != pmi->hmte)
862 pmi = pmi->pNextRec;
863 if (pmi) {
864 numprocs++;
865 numthreads += ppi->cTCB;
866 }
867 ppi = (QSPREC *) (ppi->pThrdRec + ppi->cTCB);
868 }
869 commafmt(szQty, sizeof(szQty), numprocs);
870 commafmt(tm, sizeof(tm), numthreads);
871 sprintf(s,
872 " %s%s %s%s",
873 GetPString(IDS_PROCSTITLETEXT),
874 szQty, GetPString(IDS_THRDSTITLETEXT), tm);
875 WinSetDlgItemText(hwnd, MINI_PROC, s);
876 }
877 DosFreeMem(pbh);
878 }
879 }
880 else {
881 commafmt(szQty, sizeof(szQty),
882 WinQuerySwitchList(WinQueryAnchorBlock(hwnd), (PSWBLOCK) 0,
883 0));
884 sprintf(s, " %s%s", GetPString(IDS_TASKSTITLETEXT), szQty);
885 WinSetDlgItemText(hwnd, MINI_PROC, s);
886 }
887 }
888 return 0;
889
890 case UM_SETUP6: // Uptime
891 {
892 ULONG val = 0, numdays, nummins;
893 CHAR s[128];
894
895 if (!DosQuerySysInfo(QSV_MS_COUNT,
896 QSV_MS_COUNT,
897 (PVOID) & val, (ULONG) sizeof(val))) {
898 val /= 60000L;
899 numdays = val / (60L * 24L);
900 strcpy(s, GetPString(IDS_ELAPSEDTITLETEXT));
901 if (numdays)
902 sprintf(s + strlen(s),
903 " %lu %s%s, ",
904 numdays, GetPString(IDS_DAYTEXT), &"s"[numdays == 1L]);
905 nummins = val % (60L * 24L);
906 sprintf(s + strlen(s), " %lu:%02lu", nummins / 60, nummins % 60);
907 WinSetDlgItemText(hwnd, MINI_TIME, s);
908 }
909 }
910 return 0;
911
912 case WM_SAVEAPPLICATION:
913 {
914 SWP swp;
915
916 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
917 PrfWriteProfileData(fmprof, appname, "DataMinPos", &swp, sizeof(SWP));
918 }
919 break;
920
921 case WM_CLOSE:
922 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
923 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
924 return 0;
925
926 case WM_DESTROY:
927 if (DataHwnd == WinQueryWindow(hwnd, QW_PARENT)) {
928 DataHwnd = (HWND) 0;
929 if (hwndMenu)
930 WinDestroyWindow(hwndMenu);
931 hwndMenu = (HWND) 0;
932 }
933 if (hwndMain) {
934
935 SWP swp;
936 ULONG fl = SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE, ofl;
937
938 ofl = WinQueryWindowULong(hwnd, QWL_USER);
939 WinQueryWindowPos(WinQueryWindow(hwndMain, QW_PARENT), &swp);
940 if (swp.fl & SWP_MINIMIZE)
941 fl |= ((ofl & SWP_MAXIMIZE) ? SWP_MAXIMIZE : SWP_RESTORE);
942 WinSetWindowPos(WinQueryWindow(hwndMain, QW_PARENT),
943 HWND_TOP, 0, 0, 0, 0, fl);
944 }
945 else if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
946 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
947 break;
948 }
949 return WinDefWindowProc(hwnd, msg, mp1, mp2);
950
951} // DataProc
952
953//=== CreateDataBar - create databar windows ===
954
955HWND CreateDataBar(HWND hwndParent, ULONG fl)
956{
957 HWND hwndClient = (HWND) 0;
958 ULONG FrameFlags = 0;
959
960 if (WinCreateStdWindow(hwndParent,
961 WS_VISIBLE,
962 &FrameFlags,
963 WC_DATABAR,
964 NULL, WS_VISIBLE, 0, MINI_FRAME, &hwndClient)) {
965 WinSendMsg(hwndClient, UM_RESTORE, MPFROMLONG(fl), MPVOID);
966 }
967 return hwndClient;
968
969} // CreateDataBar
970
971//=== dataminThread - drive status thread ===
972
973static VOID dataminThread(VOID * pv)
974{
975 HAB hab = NULLHANDLE;
976 HMQ hmq = NULLHANDLE;
977 HWND hwndParent = (HWND) pv;
978 HWND hwnd;
979 HENUM henum;
980 BOOL busy = TRUE;
981 APIRET rc;
982 USHORT id;
983
984# ifdef FORTIFY
985 Fortify_EnterScope();
986# endif
987 if (G_hevDataMin == NULLHANDLE) {
988 // Create just once for any thread that might use it
989 // Kernel will clean up on exit
990 rc = DosCreateEventSem(NULL, (PHEV) & G_hevDataMin, 0L, FALSE);
991 if (rc) {
992 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
993 GetPString(IDS_CREATESEMFAILED));
994 busy = FALSE;
995 }
996 }
997
998 // fixme to report errors
999 hab = WinInitialize(0);
1000 if (hab == NULLHANDLE)
1001 busy = FALSE;
1002 else {
1003 hmq = WinCreateMsgQueue(hab, 0);
1004 if (hmq == NULLHANDLE)
1005 busy = FALSE;
1006 else
1007 WinCancelShutdown(hmq, TRUE);
1008 }
1009
1010 while (busy) {
1011 HWND hwndSingle = G_hwndSingle;
1012
1013 G_hwndSingle = NULLHANDLE;
1014
1015 busy = FALSE;
1016
1017 if (!WinIsWindow(hab, hwndParent))
1018 break;
1019
1020 henum = WinBeginEnumWindows(hwndParent);
1021 while (henum && (hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
1022 if (!WinIsWindow(hab, hwnd))
1023 continue;
1024 if (hwndSingle && hwndSingle != hwnd)
1025 continue;
1026 id = WinQueryWindowUShort(hwnd, QWS_ID);
1027 if (id > MINI_DRIVEA) {
1028 ULONG dskNum = id - MINI_DRIVEA + 1;
1029 tDataMin *pDM = WinQueryWindowPtr(hwnd, QWL_DATAMIN_PTR);
1030 SWP swp;
1031 CHAR szPath[] = " :";
1032
1033 if (!pDM)
1034 continue;
1035 busy = TRUE;
1036 if (!WinQueryWindowPos(hwnd, &swp))
1037 continue;
1038
1039 DosError(FERR_DISABLEHARDERR);
1040 pDM->qfsi_rc = DosQueryFSInfo(dskNum,
1041 FSIL_ALLOC,
1042 &pDM->fsa, sizeof(FSALLOCATE));
1043
1044 if (!pDM->qfsi_rc) {
1045 *szPath = (CHAR) dskNum + 'A' - 1;
1046 pDM->qfsa_cb = sizeof(FSQBUFFER2) + 256; // se tDataMin
1047 DosError(FERR_DISABLEHARDERR);
1048 pDM->qfsa_rc = DosQueryFSAttach(szPath, 0, /* Ordinal */
1049 FSAIL_QUERYNAME,
1050 &pDM->fsqb2, &pDM->qfsa_cb);
1051 }
1052 WinInvalidateRect(hwnd, NULL, FALSE);
1053 } // if drive window
1054 } // while henum
1055 WinEndEnumWindows(henum);
1056
1057 if (busy) {
1058 ULONG clPosted;
1059
1060 rc = DosWaitEventSem(G_hevDataMin, 20000L);
1061 if (rc && rc != ERROR_TIMEOUT) {
1062 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1063 GetPString(IDS_POSTSEMFAILED));
1064 }
1065
1066 rc = DosResetEventSem(G_hevDataMin, &clPosted);
1067 if (rc && rc != ERROR_ALREADY_RESET) {
1068 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1069 GetPString(IDS_POSTSEMFAILED));
1070 }
1071 }
1072
1073 } // while
1074
1075 if (hmq != NULLHANDLE)
1076 WinDestroyMsgQueue(hmq);
1077
1078 if (hab != NULLHANDLE)
1079 WinTerminate(hab);
1080# ifdef FORTIFY
1081 Fortify_LeaveScope();
1082# endif
1083} // dataminThread
1084
1085#pragma alloc_text(DATAMIN,DataDlgProc,MiniTimeProc)
Note: See TracBrowser for help on using the repository browser.