source: trunk/dll/datamin.c@ 1397

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

Some clean up of the date formatting code

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