source: trunk/dll/datamin.c@ 1369

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

Add check for p-rotectonly system to gray out dos/win commandline choices etc. Ticket 325 It also fixes problem with some drives not being scanned on startup.

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