source: trunk/dll/datamin.c@ 1391

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

Move nontranslated strings to init.c and codepage.c; use those strings in place of GetPString calls. Move other strings to a StringTable; minor cleanup and code changes to codepage.c to use a string array instead of GetPString calls. Ticket 340

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