source: trunk/dll/datamin.c@ 1036

Last change on this file since 1036 was 1009, checked in by Steven Levine, 17 years ago

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

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