source: trunk/dll/datamin.c@ 1156

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

Ticket 187: Draft 1: Functions only

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