source: trunk/dll/datamin.c@ 1038

Last change on this file since 1038 was 1038, checked in by Gregg Young, 17 years ago

More fortify cleanup

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