source: trunk/dll/datamin.c@ 1375

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

Updated history; comments minor code cleanup for recent changes

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