source: trunk/dll/datamin.c@ 1628

Last change on this file since 1628 was 1628, checked in by Gregg Young, 14 years ago

Hard coded the flags for the xDosAlloc* wrappers and added a description for each of them.

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