source: trunk/dll/datamin.c@ 1036

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

Add xfree xstrdup Fortify support
Add MT capable Fortify scope logic

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