source: trunk/dll/datamin.c@ 1482

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

Fixed separate parameters; added the ability to set it either globally or for just one app; some files only contain white space changes.

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