source: trunk/dll/datamin.c@ 1222

Last change on this file since 1222 was 1222, checked in by John Small, 17 years ago

Ticket 187: Moved typedef's and some #define's from fm3dll.h

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