source: trunk/dll/datamin.c@ 1156

Last change on this file since 1156 was 1156, checked in by John Small, 17 years ago

Ticket 187: Draft 1: Functions only

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