source: trunk/dll/datamin.c@ 1335

Last change on this file since 1335 was 1335, checked in by Steven Levine, 17 years ago

Ticket 26: Add exception handlers to all threads using xbeginthread

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 28.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: datamin.c 1335 2008-12-12 23:49:02Z stevenhl $
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 NoFloat = TRUE;
387 if (!PopupMenu(hwnd, hwnd, hwndMenu))
388 NoFloat = FALSE;
389 }
390 if (msg == UM_CONTEXTMENU)
391 return 0;
392 break;
393
394 case WM_BUTTON2DBLCLK:
395 if (!(SHORT2FROMMP(mp2) & KC_SHIFT)) {
396 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(MINI_FLOAT, 0), MPVOID);
397 break;
398 }
399 /* else intentional fallthru */
400 case WM_CHORD:
401 case WM_BUTTON3DBLCLK:
402 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(MINI_SHOW, 0), MPVOID);
403 break;
404
405 case UM_BUTTON1MOTIONSTART:
406 case WM_BUTTON1MOTIONSTART:
407 {
408 TRACKINFO TrackInfo;
409 SWP Position;
410
411 memset(&TrackInfo, 0, sizeof(TrackInfo));
412 TrackInfo.cxBorder = 1;
413 TrackInfo.cyBorder = 1;
414 TrackInfo.cxGrid = 1;
415 TrackInfo.cyGrid = 1;
416 TrackInfo.cxKeyboard = 8;
417 TrackInfo.cyKeyboard = 8;
418 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &Position);
419 TrackInfo.rclTrack.xLeft = Position.x;
420 TrackInfo.rclTrack.xRight = Position.x + Position.cx;
421 TrackInfo.rclTrack.yBottom = Position.y;
422 TrackInfo.rclTrack.yTop = Position.y + Position.cy;
423 WinQueryWindowPos(HWND_DESKTOP, &Position);
424 TrackInfo.rclBoundary.xLeft = Position.x;
425 TrackInfo.rclBoundary.xRight = Position.x + Position.cx;
426 TrackInfo.rclBoundary.yBottom = Position.y;
427 TrackInfo.rclBoundary.yTop = Position.y + Position.cy;
428 TrackInfo.ptlMinTrackSize.x = 0;
429 TrackInfo.ptlMinTrackSize.y = 0;
430 TrackInfo.ptlMaxTrackSize.x = Position.cx;
431 TrackInfo.ptlMaxTrackSize.y = Position.cy;
432 TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY;
433 if (WinTrackRect(HWND_DESKTOP, (HPS) 0, &TrackInfo)) {
434 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
435 HWND_TOP, TrackInfo.rclTrack.xLeft,
436 TrackInfo.rclTrack.yBottom, 0, 0, SWP_MOVE);
437 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
438 }
439 }
440 break;
441
442 case WM_HELP:
443 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_HELP, 0), MPVOID);
444 break;
445
446 case WM_COMMAND:
447 switch (SHORT1FROMMP(mp1)) {
448 case IDM_COMMANDLINE:
449 case IDM_DOSCOMMANDLINE:
450 case IDM_WINFULLSCREEN:
451 {
452 CHAR *env = GetCmdSpec(FALSE), path[CCHMAXPATH];
453 INT type = SEPARATE | WINDOWED;
454
455 *path = 0;
456 TopWindowName(hwnd, (HWND) 0, path);
457 if (SHORT1FROMMP(mp1) == IDM_DOSCOMMANDLINE)
458 env = GetCmdSpec(TRUE);
459 else if (SHORT1FROMMP(mp1) != IDM_COMMANDLINE) {
460 env = "WINOS2.COM";
461 type = SEPARATE | FULLSCREEN;
462 }
463 runemf2(type, hwnd, pszSrcFile, __LINE__,
464 path, NULL, "%s", env);
465 }
466 break;
467
468 case IDM_HELP:
469 if (hwndHelp)
470 WinSendMsg(hwndHelp,
471 HM_DISPLAY_HELP,
472 MPFROM2SHORT(HELP_DATABAR, 0), MPFROMSHORT(HM_RESOURCEID));
473 break;
474
475 case MINI_CLOSE:
476 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
477 break;
478
479 case MINI_BORING:
480 fDullMin = (fDullMin) ? FALSE : TRUE;
481 PrfWriteProfileData(fmprof,
482 FM3Str, "DullDatabar", &fDullMin, sizeof(BOOL));
483 if (G_hevDataMin != NULLHANDLE) {
484 rc = DosPostEventSem(G_hevDataMin);
485 if (rc) {
486 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
487 GetPString(IDS_POSTSEMFAILED));
488 }
489 }
490
491 break;
492
493 case MINI_INCLREMOTE:
494 case MINI_SHOW:
495 if (SHORT1FROMMP(mp1) == MINI_SHOW) {
496 fDataShowDrives = (fDataShowDrives) ? FALSE : TRUE;
497 PrfWriteProfileData(fmprof,
498 appname,
499 "DataShowDrives", &fDataShowDrives, sizeof(BOOL));
500 }
501 else {
502 fDataInclRemote = (fDataInclRemote) ? FALSE : TRUE;
503 PrfWriteProfileData(fmprof,
504 appname,
505 "DataInclRemote", &fDataInclRemote, sizeof(BOOL));
506 }
507 {
508 HENUM henum;
509 HWND hwndChild;
510 USHORT id;
511
512 henum = WinBeginEnumWindows(hwnd);
513 while ((hwndChild = WinGetNextWindow(henum)) != NULLHANDLE) {
514 id = WinQueryWindowUShort(hwndChild, QWS_ID);
515 if (id >= MINI_DRIVEA)
516 WinDestroyWindow(hwndChild);
517 }
518 WinEndEnumWindows(henum);
519 }
520 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
521 break;
522
523 case MINI_FLOAT:
524 fDataToFore = (fDataToFore) ? FALSE : TRUE;
525 PrfWriteProfileData(fmprof,
526 appname, "DataToFore", &fDataToFore, sizeof(BOOL));
527 if (!hwndMain) {
528
529 SWCNTRL swcntrl;
530 HSWITCH hswitch;
531
532 hswitch = (HSWITCH) WinQuerySwitchHandle(hwnd, (PID) 0);
533 if (hswitch) {
534 memset(&swcntrl, 0, sizeof(SWCNTRL));
535 if (!WinQuerySwitchEntry(hswitch, &swcntrl)) {
536 swcntrl.fbJump = (fDataToFore) ? SWL_NOTJUMPABLE : SWL_JUMPABLE;
537 WinChangeSwitchEntry(hswitch, &swcntrl);
538 }
539 }
540 }
541 break;
542 }
543 return 0;
544
545 case WM_SIZE:
546 WinSetWindowPos(hwnd,
547 HWND_TOP,
548 0,
549 0,
550 SHORT1FROMMP(mp2),
551 SHORT2FROMMP(mp2), SWP_MOVE | SWP_SIZE);
552 break;
553
554 case WM_PAINT:
555 {
556 HPS hps;
557 POINTL ptl;
558 SWP swp;
559 RECTL rcl;
560
561 hps = WinBeginPaint(hwnd, (HPS) 0, &rcl);
562 if (hps) {
563 WinFillRect(hps, (PRECTL) & rcl, CLR_PALEGRAY);
564 GpiSetMix(hps, FM_OVERPAINT);
565 GpiSetColor(hps, CLR_WHITE);
566 WinQueryWindowPos(hwnd, &swp);
567 ptl.x = 0;
568 ptl.y = 0;
569 GpiMove(hps, &ptl);
570 ptl.y = swp.cy - 1;
571 GpiLine(hps, &ptl);
572 ptl.x = swp.cx - 1;
573 GpiLine(hps, &ptl);
574 GpiSetColor(hps, CLR_DARKGRAY);
575 ptl.y = 0;
576 GpiLine(hps, &ptl);
577 ptl.x = 0;
578 GpiLine(hps, &ptl);
579 {
580 HENUM henum;
581 HWND hwndTemp;
582
583 henum = WinBeginEnumWindows(hwnd);
584 while ((hwndTemp = WinGetNextWindow(henum)) != NULLHANDLE) {
585 PaintRecessedWindow(hwndTemp,
586 hps, (WinQueryWindowUShort(hwndTemp, QWS_ID)
587 != MINI_TIME), FALSE);
588 }
589 WinEndEnumWindows(henum);
590 }
591 WinEndPaint(hps);
592 }
593 }
594 return 0;
595
596 case UM_PAINT:
597 {
598 CHAR s[90];
599 CHAR szFreeQty[38];
600 CHAR szDrvLtr[] = " :";
601 CHAR *pszFSystem;
602 ULONGLONG ullFreeQty;
603 ULONG ulPercentFree;
604 ULONG wasx;
605 HPS hps = (HPS) mp2;
606 HWND hwndChild;
607 USHORT id;
608 SWP swp;
609 POINTL ptl;
610 tDataMin *pDM;
611
612 id = SHORT1FROMMP(mp1);
613 if (id >= MINI_DRIVEA) {
614 hwndChild = WinWindowFromID(hwnd, id);
615 if (!hwndChild)
616 return 0;
617 if (!WinQueryWindowPos(hwndChild, &swp))
618 return 0;
619 pDM = WinQueryWindowPtr(hwndChild, QWL_DATAMIN_PTR);
620 if (!pDM || pDM->qfsi_rc) {
621 ullFreeQty = 0;
622 ulPercentFree = 0;
623 }
624 else {
625 ullFreeQty = (ULONGLONG) pDM->fsa.cUnitAvail *
626 (pDM->fsa.cSectorUnit * pDM->fsa.cbSector);
627
628 ulPercentFree = (pDM->fsa.cUnit && pDM->fsa.cUnitAvail) ?
629 (pDM->fsa.cUnitAvail * 100) / pDM->fsa.cUnit : 0;
630 }
631
632 CommaFmtULL(szFreeQty, sizeof(szFreeQty), ullFreeQty, ' ');
633 *szDrvLtr = (CHAR) (id - MINI_DRIVEA) + 'A';
634
635 if (!pDM || pDM->qfsi_rc || pDM->qfsa_rc)
636 pszFSystem = "N/A";
637 else {
638 pszFSystem = (PCHAR)(pDM->fsqb2.szName) + pDM->fsqb2.cbName + 1;
639 pszFSystem[15] = 0;
640 }
641 sprintf(s,
642 "%s %13s %lu%%-%s %6s ",
643 szDrvLtr,
644 szFreeQty,
645 ulPercentFree, GetPString(IDS_FREETEXT), pszFSystem);
646 if (!hps)
647 hps = WinGetPS(hwndChild);
648 if (hps) {
649 if (!fDullMin) {
650 ptl.x = 0;
651 ptl.y = 0;
652 GpiMove(hps, &ptl);
653 GpiSetColor(hps, CLR_BLACK);
654 ptl.x = swp.cx - 1;
655 ptl.y = swp.cy - 1;
656 GpiBox(hps, DRO_OUTLINE, &ptl, 0, 0);
657 ptl.x = 1;
658 ptl.y = 1;
659 if (ulPercentFree) {
660 GpiMove(hps, &ptl);
661 GpiSetColor(hps,
662 (ulPercentFree < 11) ? CLR_DARKRED :
663 (ulPercentFree < 26) ? CLR_DARKBLUE :
664 CLR_DARKGREEN);
665 ptl.y = swp.cy - 2;
666 ptl.x = ((swp.cx - 2) * ulPercentFree) / 100;
667 wasx = ptl.x;
668 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
669 GpiSetColor(hps,
670 (ulPercentFree < 11) ? CLR_RED :
671 (ulPercentFree < 26) ? CLR_BLUE : CLR_GREEN);
672 ptl.x = wasx;
673 ptl.y = swp.cy - 2;
674 GpiMove(hps, &ptl);
675 ptl.x = 1;
676 GpiLine(hps, &ptl);
677 ptl.y = 2;
678 ptl.x = 1;
679 GpiLine(hps, &ptl);
680 ptl.x = wasx;
681 }
682 if (ulPercentFree < 99) {
683 GpiSetColor(hps, CLR_DARKGRAY);
684 wasx = ptl.x;
685 ptl.y = 2;
686 GpiMove(hps, &ptl);
687 ptl.y = swp.cy - 2;
688 ptl.x = swp.cx - 2;
689 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
690 ptl.x = wasx;
691 GpiMove(hps, &ptl);
692 GpiSetColor(hps, CLR_PALEGRAY);
693 ptl.x = swp.cx - 3;
694 GpiLine(hps, &ptl);
695 ptl.x = wasx;
696 ptl.y = 1;
697 GpiMove(hps, &ptl);
698 GpiSetColor(hps, CLR_BLACK);
699 ptl.x = swp.cx - 2;
700 GpiLine(hps, &ptl);
701 ptl.y = swp.cy - 3;
702 GpiLine(hps, &ptl);
703 }
704 GpiSetColor(hps, CLR_WHITE);
705 }
706 else {
707 GpiSetColor(hps, CLR_PALEGRAY);
708 ptl.x = 0;
709 ptl.y = 0;
710 GpiMove(hps, &ptl);
711 ptl.x = swp.cx - 1;
712 ptl.y = swp.cy - 1;
713 GpiBox(hps, DRO_OUTLINEFILL, &ptl, 0, 0);
714 GpiSetColor(hps,
715 (ulPercentFree < 11) ? CLR_DARKRED : CLR_DARKBLUE);
716 }
717 GpiSetBackMix(hps, BM_LEAVEALONE);
718 GpiSetMix(hps, FM_OVERPAINT);
719 {
720 POINTL aptl[TXTBOX_COUNT];
721
722 GpiQueryTextBox(hps, strlen(s), s, TXTBOX_COUNT, aptl);
723 ptl.y = ((swp.cy / 2) -
724 ((aptl[TXTBOX_TOPRIGHT].y +
725 aptl[TXTBOX_BOTTOMLEFT].y) / 2));
726 ptl.y++;
727 ptl.x = (swp.cx / 2) - (aptl[TXTBOX_TOPRIGHT].x / 2);
728 if (ptl.x < 2)
729 ptl.x = 2;
730 GpiCharStringAt(hps, &ptl, strlen(s), s);
731 }
732 if (!mp2)
733 WinReleasePS(hps);
734 }
735 } // if drive window
736 }
737 return 0;
738
739 case UM_TIMER:
740 {
741 CHAR s[134];
742 DATETIME dt;
743
744 if (fDataToFore && !NoFloat)
745 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT),
746 HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
747 if (counter && (counter % 19) && (counter % 20)) {
748 if (!DosGetDateTime(&dt)) {
749 sprintf(s,
750 " %02hu:%02hu:%02hu %s %04u/%02u/%02u",
751 dt.hours,
752 dt.minutes,
753 dt.seconds,
754 GetPString(IDS_SUNDAY + dt.weekday),
755 dt.year, dt.month, dt.day);
756 WinSetDlgItemText(hwnd, MINI_TIME, s);
757 }
758 }
759 else if (!counter || !(counter % 19))
760 PostMsg(hwnd, UM_SETUP6, MPVOID, MPVOID); // Uptime
761 if (!(counter % 4)) {
762 PostMsg(hwnd, UM_SETUP3, MPVOID, MPVOID); // Memory utilization
763 if (!(counter % 10)) {
764 PostMsg(hwnd, UM_SETUP5, MPVOID, MPVOID); // Process status
765 if (!(counter % 20)) {
766 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID); // Swapper
767 }
768 }
769 }
770 }
771 counter++;
772 return 0;
773
774 case UM_SETUP2:
775 {
776 CHAR s[134], szFileQty[38], szFreeQty[38];
777 FILEFINDBUF3L ffb;
778 ULONG nm = 1;
779 ULONGLONG ullFreeQty;
780 HDIR hdir = HDIR_CREATE;
781 FSALLOCATE fsa;
782
783 if (*SwapperDat) {
784 DosError(FERR_DISABLEHARDERR);
785 if (!xDosFindFirst(SwapperDat, &hdir, FILE_NORMAL | FILE_HIDDEN |
786 FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY,
787 &ffb, sizeof(ffb), &nm, FIL_STANDARDL)) {
788 priority_bumped();
789 DosFindClose(hdir);
790 DosError(FERR_DISABLEHARDERR);
791 if (!DosQueryFSInfo(toupper(*SwapperDat) - '@', FSIL_ALLOC,
792 &fsa, sizeof(FSALLOCATE))) {
793 ullFreeQty =
794 (ULONGLONG) fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
795 CommaFmtULL(szFreeQty, sizeof(szFreeQty), ullFreeQty, ' ');
796 }
797 else
798 *szFreeQty = 0;
799
800 CommaFmtULL(szFileQty, sizeof(szFileQty), ffb.cbFile, ' ');
801 sprintf(s, " %s %s%s%s",
802 GetPString(IDS_SWAPTITLETEXT),
803 szFileQty, *szFreeQty ? "/" : NullStr, szFreeQty);
804 WinSetDlgItemText(hwnd, MINI_SWAP, s);
805 }
806 }
807 }
808 return 0;
809
810 case UM_SETUP3: // Memory utilization
811 {
812 CHAR s[134], tm[38], szQty[38];
813 ULONG amem = 0;
814
815 if (!DosQuerySysInfo(QSV_TOTAVAILMEM, QSV_TOTAVAILMEM,
816 (PVOID) & amem, (ULONG) sizeof(amem))) {
817 CommaFmtUL(tm, sizeof(tm), amem, 'M');
818 if (!Dos16MemAvail(&amem))
819 CommaFmtUL(szQty, sizeof(szQty), amem, 'M');
820 else
821 *szQty = 0;
822 sprintf(s, " %s%s%s%s",
823 GetPString(IDS_MEMTITLETEXT),
824 szQty, (*szQty) ? "/" : NullStr, tm);
825 WinSetDlgItemText(hwnd, MINI_MEM, s);
826 }
827 }
828 return 0;
829
830 case UM_SETUP5: // Process status
831 {
832 CHAR s[134], tm[38], szQty[38];
833
834 if (fUseQProcStat && !noqproc) {
835
836 PROCESSINFO *ppi;
837 BUFFHEADER *pbh = NULL;
838 MODINFO *pmi;
839 ULONG numprocs = 0, numthreads = 0;
840 APIRET rc;
841
842 rc = DosAllocMem((PVOID)&pbh, USHRT_MAX + 4096,
843 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
844 if (rc)
845 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
846 GetPString(IDS_OUTOFMEMORY));
847 else {
848 if (DosQProcStatus((ULONG *)pbh, USHRT_MAX))
849 noqproc = TRUE;
850 else {
851 ppi = pbh->ppi;
852 while (ppi->ulEndIndicator != PROCESS_END_INDICATOR) {
853 pmi = pbh->pmi;
854 while (pmi && ppi->hModRef != pmi->hMod)
855 pmi = pmi->pNext;
856 if (pmi) {
857 numprocs++;
858 numthreads += ppi->usThreadCount;
859 }
860 ppi = (PPROCESSINFO) (ppi->ptiFirst + ppi->usThreadCount);
861 }
862 commafmt(szQty, sizeof(szQty), numprocs);
863 commafmt(tm, sizeof(tm), numthreads);
864 sprintf(s,
865 " %s%s %s%s",
866 GetPString(IDS_PROCSTITLETEXT),
867 szQty, GetPString(IDS_THRDSTITLETEXT), tm);
868 WinSetDlgItemText(hwnd, MINI_PROC, s);
869 }
870 DosFreeMem(pbh);
871 }
872 }
873 else if (fUseQSysState && !noqproc) {
874
875 QSPREC *ppi;
876 QSPTRREC *pbh = NULL;
877 QSLREC *pmi;
878 ULONG numprocs = 0, numthreads = 0;
879 APIRET rc;
880
881 rc = DosAllocMem((PVOID) & pbh, USHRT_MAX + 4096,
882 PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
883 if (rc)
884 Dos_Error(MB_CANCEL, rc, hwnd, pszSrcFile, __LINE__,
885 GetPString(IDS_OUTOFMEMORY));
886 else { //2 Sep 07 GKY 0x05 = process & Mod data only
887 if (DosQuerySysState(QS_PROCESS | QS_MTE, 0, 0, 0, pbh, USHRT_MAX))
888 noqproc = TRUE;
889 else {
890 ppi = pbh->pProcRec;
891 while (ppi->RecType == 1) {
892 pmi = pbh->pLibRec;
893 while (pmi && ppi->hMte != pmi->hmte)
894 pmi = pmi->pNextRec;
895 if (pmi) {
896 numprocs++;
897 numthreads += ppi->cTCB;
898 }
899 ppi = (QSPREC *) (ppi->pThrdRec + ppi->cTCB);
900 }
901 commafmt(szQty, sizeof(szQty), numprocs);
902 commafmt(tm, sizeof(tm), numthreads);
903 sprintf(s,
904 " %s%s %s%s",
905 GetPString(IDS_PROCSTITLETEXT),
906 szQty, GetPString(IDS_THRDSTITLETEXT), tm);
907 WinSetDlgItemText(hwnd, MINI_PROC, s);
908 }
909 DosFreeMem(pbh);
910 }
911 }
912 else {
913 commafmt(szQty, sizeof(szQty),
914 WinQuerySwitchList(WinQueryAnchorBlock(hwnd), (PSWBLOCK) 0,
915 0));
916 sprintf(s, " %s%s", GetPString(IDS_TASKSTITLETEXT), szQty);
917 WinSetDlgItemText(hwnd, MINI_PROC, s);
918 }
919 }
920 return 0;
921
922 case UM_SETUP6: // Uptime
923 {
924 ULONG val = 0, numdays, nummins;
925 CHAR s[128];
926
927 if (!DosQuerySysInfo(QSV_MS_COUNT,
928 QSV_MS_COUNT,
929 (PVOID) & val, (ULONG) sizeof(val))) {
930 val /= 60000L;
931 numdays = val / (60L * 24L);
932 strcpy(s, GetPString(IDS_ELAPSEDTITLETEXT));
933 if (numdays)
934 sprintf(s + strlen(s),
935 " %lu %s%s, ",
936 numdays, GetPString(IDS_DAYTEXT), &"s"[numdays == 1L]);
937 nummins = val % (60L * 24L);
938 sprintf(s + strlen(s), " %lu:%02lu", nummins / 60, nummins % 60);
939 WinSetDlgItemText(hwnd, MINI_TIME, s);
940 }
941 }
942 return 0;
943
944 case WM_SAVEAPPLICATION:
945 {
946 SWP swp;
947
948 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
949 PrfWriteProfileData(fmprof, appname, "DataMinPos", &swp, sizeof(SWP));
950 }
951 break;
952
953 case WM_CLOSE:
954 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
955 WinDestroyWindow(WinQueryWindow(hwnd, QW_PARENT));
956 return 0;
957
958 case WM_DESTROY:
959 if (DataHwnd == WinQueryWindow(hwnd, QW_PARENT)) {
960 DataHwnd = (HWND) 0;
961 if (hwndMenu)
962 WinDestroyWindow(hwndMenu);
963 hwndMenu = (HWND) 0;
964 }
965 if (hwndMain) {
966
967 SWP swp;
968 ULONG fl = SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE, ofl;
969
970 ofl = WinQueryWindowULong(hwnd, QWL_USER);
971 WinQueryWindowPos(WinQueryWindow(hwndMain, QW_PARENT), &swp);
972 if (swp.fl & SWP_MINIMIZE)
973 fl |= ((ofl & SWP_MAXIMIZE) ? SWP_MAXIMIZE : SWP_RESTORE);
974 WinSetWindowPos(WinQueryWindow(hwndMain, QW_PARENT),
975 HWND_TOP, 0, 0, 0, 0, fl);
976 }
977 else if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
978 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
979 break;
980 }
981 return WinDefWindowProc(hwnd, msg, mp1, mp2);
982
983} // DataProc
984
985//=== CreateDataBar - create databar windows ===
986
987HWND CreateDataBar(HWND hwndParent, ULONG fl)
988{
989 HWND hwndClient = (HWND) 0;
990 ULONG FrameFlags = 0;
991
992 if (WinCreateStdWindow(hwndParent,
993 WS_VISIBLE,
994 &FrameFlags,
995 WC_DATABAR,
996 NULL, WS_VISIBLE, 0, MINI_FRAME, &hwndClient)) {
997 WinSendMsg(hwndClient, UM_RESTORE, MPFROMLONG(fl), MPVOID);
998 }
999 return hwndClient;
1000
1001} // CreateDataBar
1002
1003//=== dataminThread - drive status thread ===
1004
1005static VOID dataminThread(VOID * pv)
1006{
1007 HAB hab = NULLHANDLE;
1008 HMQ hmq = NULLHANDLE;
1009 HWND hwndParent = (HWND) pv;
1010 HWND hwnd;
1011 HENUM henum;
1012 BOOL busy = TRUE;
1013 APIRET rc;
1014 USHORT id;
1015
1016# ifdef FORTIFY
1017 Fortify_EnterScope();
1018# endif
1019 if (G_hevDataMin == NULLHANDLE) {
1020 // Create just once for any thread that might use it
1021 // Kernel will clean up on exit
1022 rc = DosCreateEventSem(NULL, (PHEV) & G_hevDataMin, 0L, FALSE);
1023 if (rc) {
1024 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1025 GetPString(IDS_CREATESEMFAILED));
1026 busy = FALSE;
1027 }
1028 }
1029
1030 // fixme to report errors
1031 hab = WinInitialize(0);
1032 if (hab == NULLHANDLE)
1033 busy = FALSE;
1034 else {
1035 hmq = WinCreateMsgQueue(hab, 0);
1036 if (hmq == NULLHANDLE)
1037 busy = FALSE;
1038 else
1039 WinCancelShutdown(hmq, TRUE);
1040 }
1041
1042 while (busy) {
1043 HWND hwndSingle = G_hwndSingle;
1044
1045 G_hwndSingle = NULLHANDLE;
1046
1047 busy = FALSE;
1048
1049 if (!WinIsWindow(hab, hwndParent))
1050 break;
1051
1052 henum = WinBeginEnumWindows(hwndParent);
1053 while (henum && (hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
1054 if (!WinIsWindow(hab, hwnd))
1055 continue;
1056 if (hwndSingle && hwndSingle != hwnd)
1057 continue;
1058 id = WinQueryWindowUShort(hwnd, QWS_ID);
1059 if (id > MINI_DRIVEA) {
1060 ULONG dskNum = id - MINI_DRIVEA + 1;
1061 tDataMin *pDM = WinQueryWindowPtr(hwnd, QWL_DATAMIN_PTR);
1062 SWP swp;
1063 CHAR szPath[] = " :";
1064
1065 if (!pDM)
1066 continue;
1067 busy = TRUE;
1068 if (!WinQueryWindowPos(hwnd, &swp))
1069 continue;
1070
1071 DosError(FERR_DISABLEHARDERR);
1072 pDM->qfsi_rc = DosQueryFSInfo(dskNum,
1073 FSIL_ALLOC,
1074 &pDM->fsa, sizeof(FSALLOCATE));
1075
1076 if (!pDM->qfsi_rc) {
1077 *szPath = (CHAR) dskNum + 'A' - 1;
1078 pDM->qfsa_cb = sizeof(FSQBUFFER2) + 256; // se tDataMin
1079 DosError(FERR_DISABLEHARDERR);
1080 pDM->qfsa_rc = DosQueryFSAttach(szPath, 0, /* Ordinal */
1081 FSAIL_QUERYNAME,
1082 &pDM->fsqb2, &pDM->qfsa_cb);
1083 }
1084 WinInvalidateRect(hwnd, NULL, FALSE);
1085 } // if drive window
1086 } // while henum
1087 WinEndEnumWindows(henum);
1088
1089 if (busy) {
1090 ULONG clPosted;
1091
1092 rc = DosWaitEventSem(G_hevDataMin, 20000L);
1093 if (rc && rc != ERROR_TIMEOUT) {
1094 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1095 GetPString(IDS_POSTSEMFAILED));
1096 }
1097
1098 rc = DosResetEventSem(G_hevDataMin, &clPosted);
1099 if (rc && rc != ERROR_ALREADY_RESET) {
1100 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1101 GetPString(IDS_POSTSEMFAILED));
1102 }
1103 }
1104
1105 } // while
1106
1107 if (hmq != NULLHANDLE)
1108 WinDestroyMsgQueue(hmq);
1109
1110 if (hab != NULLHANDLE)
1111 WinTerminate(hab);
1112# ifdef FORTIFY
1113 Fortify_LeaveScope();
1114# endif
1115} // dataminThread
1116
1117#pragma alloc_text(DATAMIN,DataDlgProc,MiniTimeProc)
Note: See TracBrowser for help on using the repository browser.