source: trunk/dll/datamin.c@ 1498

Last change on this file since 1498 was 1498, checked in by Gregg Young, 16 years ago

Changes to get FM2 to compile with the latest watcom 1.9 beta (mostly type casts of CHAR CONSTANT * to CHAR *). Changes to get the environment settings working everywhere again (broken by the change that moved commands to the INI); Added an environment size variable (set to 2048 which was the largest I found hard coded). Still need to find everywhere the environment size is set and use this variable.

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