home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / memsz231.zip / MEMSIZE.CPP < prev    next >
C/C++ Source or Header  |  1994-06-08  |  123KB  |  3,115 lines

  1. /**************************************************************** MEMSIZE.CPP
  2.  *                                                                          *
  3.  * System Resources Monitor                                                 *
  4.  *                                                                          *
  5.  * (C) Copyright 1991-1994 by Richard W. Papo.                              *
  6.  *                                                                          *
  7.  * This is 'FreeWare'.  As such, it may be copied and distributed           *
  8.  * freely.  If you want to use part of it in your own program, please       *
  9.  * give credit where credit is due.  If you want to change the              *
  10.  * program, please refer the change request to me or send me the            *
  11.  * modified source code.  I can be reached at CompuServe 72607,3111         *
  12.  * and on Internet at RPapo@Msen.com.                                       *
  13.  *                                                                          *
  14.  ****************************************************************************/
  15.  
  16. // Bugs to Fix:
  17. //
  18. //   (1) When Float To Top is active, then the E editor dies upon displaying
  19. //       its file-type-set dialog.  CLOCK has the same problem.  IBM is helping.
  20. //
  21. // Things to do:
  22. //
  23. //   (1) Provide an item to serve as a button to cause a secondary
  24. //       drive status window to be displayed (requested by Leland Sheppard).
  25. //
  26. //   (2) Provide colored highlights for different levels, configurable
  27. //       by item.
  28. //
  29.  
  30. #define INCL_BASE
  31. #define INCL_PM
  32. #include <os2.h>
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37.  
  38. #include "debug.h"
  39. #include "helpwin.h"
  40. #include "module.h"
  41. #include "process.h"
  42. #include "profile.h"
  43. #include "restring.h"
  44. #include "support.h"
  45. #include "window.h"
  46.  
  47. #include "about.h"
  48. #include "config.h"
  49.  
  50. #include "items.h"
  51.  
  52. #include "memsize.h"
  53.  
  54. #define STATIC
  55.  
  56.  
  57. /****************************************************************************
  58.  *                                                                          *
  59.  *                       Definitions & Declarations                         *
  60.  *                                                                          *
  61.  ****************************************************************************/
  62.  
  63.   // Constants
  64.  
  65. #define WM_REFRESH        (WM_USER)
  66.  
  67. #define MAX_DRIVES        (26)
  68. #define DRIVE_ERROR       (0xFFFFFFFFL)
  69.  
  70. enum
  71. {
  72.   ITEM_CLOCK,
  73.   ITEM_ELAPSEDTIME,
  74.   ITEM_MEMORYFREE,
  75.   ITEM_SWAPFILESIZE,
  76.   ITEM_SWAPDISKFREE,
  77.   ITEM_SPOOLFILESIZE,
  78.   ITEM_CPULOAD,
  79.   ITEM_TASKCOUNT,
  80.   ITEM_TOTALFREE,
  81.   ITEM_BASE_COUNT
  82. } ;
  83.  
  84.  
  85.   // Data Types
  86.  
  87. typedef struct {
  88.   BOOL Active ;
  89.   PULONG Counter ;
  90.   PUSHORT Interval ;
  91.   PBYTE Priority ;
  92.   HWND Owner ;
  93. } MONITOR_PARMS, *PMONITOR_PARMS ;
  94.  
  95. typedef struct {
  96.   BOOL Active ;
  97.   ULONG Counter ;
  98. } COUNTER_PARMS, *PCOUNTER_PARMS ;
  99.  
  100. typedef struct {      // Parameters saved to system.
  101.  
  102.   // The Display Item List - - -
  103.   Item           *Items [ ITEM_BASE_COUNT + MAX_DRIVES ] ;
  104.   int             ItemCount ;
  105.  
  106.   // Data required for the display item objects to function.
  107.   ULONG           IdleCount ;
  108.   ULONG           MaxCount ;
  109.   BYTE            SwapPath [_MAX_PATH] ;
  110.   ULONG           MinFree ;
  111.   PBYTE           SpoolPath ;
  112.   COUNTRYINFO     CountryInfo ;
  113.   ResourceString *Day ;
  114.   ResourceString *Days ;
  115.   ResourceString *DaysOfWeek ;
  116.   ResourceString *DriveError ;
  117.  
  118.   // Window size and location
  119.   SWP    Position ;
  120.   BOOL   fPosition ;
  121.  
  122.   // User Options
  123.   BOOL   HideControls ;
  124.   BOOL   fHideControls ;
  125.  
  126.   BOOL   Float ;
  127.   BOOL   fFloat ;
  128.  
  129.   BOOL   Animate ;
  130.   BOOL   fAnimate ;
  131.  
  132.   BOOL   ShowFileSystemNames ;
  133.   BOOL   fShowFileSystemNames ;
  134.  
  135.   BYTE   MonitorPriority ;
  136.   BOOL   fMonitorPriority ;
  137.  
  138.   USHORT TimerInterval ;
  139.   BOOL   fTimerInterval ;
  140.  
  141.   // Presentation Parameters
  142.   BYTE   FontNameSize [80] ;
  143.   BOOL   fFontNameSize ;
  144.  
  145.   COLOR  BackColor ;
  146.   BOOL   fBackColor ;
  147.  
  148.   COLOR  TextColor ;
  149.   BOOL   fTextColor ;
  150.  
  151. } INIDATA, *PINIDATA ;
  152.  
  153. typedef struct {      // Data structure for window.
  154.    Process       *Proc ;
  155.    Module        *Library ;
  156.    Profile       *IniFile ;
  157.  
  158.    INIDATA        IniData ;
  159.  
  160.    TID            IdleLoopTID ;
  161.    COUNTER_PARMS  IdleLoopParms ;
  162.  
  163.    TID            MonitorTID ;
  164.    MONITOR_PARMS  MonitorParms ;
  165.  
  166.    HWND           hwndTitleBar ;
  167.    HWND           hwndSysMenu ;
  168.    HWND           hwndMinMax ;
  169.  
  170.    ULONG          Drives ;
  171.  
  172.    long           Width ;
  173.    long           Height ;
  174. } DATA, *PDATA ;
  175.  
  176. typedef struct {
  177.    short Filler ;
  178.    Process *Proc ;
  179.    Module *Library ;
  180.    Profile *IniFile ;
  181. } PARMS, *PPARMS ;
  182.  
  183.  
  184.   // Function Prototypes
  185.  
  186. extern int main ( int argc, char *argv[] ) ;
  187.  
  188. STATIC FNWP MessageProcessor ;
  189.  
  190. STATIC METHODFUNCTION Create ;
  191. STATIC METHODFUNCTION Destroy ;
  192. STATIC METHODFUNCTION Size ;
  193. STATIC METHODFUNCTION SaveApplication ;
  194. STATIC METHODFUNCTION Paint ;
  195. STATIC METHODFUNCTION Command ;
  196. STATIC METHODFUNCTION ResetDefaults ;
  197. STATIC METHODFUNCTION HideControlsCmd ;
  198. STATIC METHODFUNCTION Configure ;
  199. STATIC METHODFUNCTION About ;
  200. STATIC METHODFUNCTION ButtonDown ;
  201. STATIC METHODFUNCTION ButtonDblClick ;
  202. STATIC METHODFUNCTION PresParamChanged ;
  203. STATIC METHODFUNCTION SysColorChange ;
  204. STATIC METHODFUNCTION QueryKeysHelp ;
  205. STATIC METHODFUNCTION HelpError ;
  206. STATIC METHODFUNCTION ExtHelpUndefined ;
  207. STATIC METHODFUNCTION HelpSubitemNotFound ;
  208. STATIC METHODFUNCTION Refresh ;
  209.  
  210. STATIC int GetIniData ( HAB Anchor, HMODULE Library, HINI IniHandle, PINIDATA IniData ) ;
  211. STATIC VOID PutIniData ( HINI IniHandle, PINIDATA IniData ) ;
  212.  
  213. STATIC PSZ ScanSystemConfig ( HAB Anchor, PSZ Keyword ) ;
  214.  
  215. STATIC void ResizeWindow ( HWND hwnd, PINIDATA IniData ) ;
  216.  
  217. STATIC void HideControls
  218. (
  219.   BOOL fHide,
  220.   HWND hwndFrame,
  221.   HWND hwndSysMenu,
  222.   HWND hwndTitleBar,
  223.   HWND hwndMinMax
  224. ) ;
  225.  
  226. STATIC void UpdateWindow ( HWND hwnd, PDATA Data, BOOL All ) ;
  227.  
  228. STATIC VOID _Optlink MonitorLoopThread ( PVOID Parameter ) ;
  229.  
  230. STATIC VOID UpdateDriveList
  231. (
  232.   HAB Anchor,
  233.   HMODULE Library,
  234.   HINI IniHandle,
  235.   PINIDATA IniData,
  236.   ULONG OldDrives,
  237.   ULONG NewDrives
  238. ) ;
  239.  
  240. STATIC int CheckDrive ( USHORT Drive, PBYTE FileSystem ) ;
  241.  
  242. STATIC ULONG CalibrateLoadMeter ( PCOUNTER_PARMS Parms ) ;
  243.  
  244. STATIC VOID _Optlink CounterThread ( PVOID Parameter ) ;
  245.  
  246.  
  247.   // Global Data
  248.  
  249. HMODULE LibraryHandle ;
  250.  
  251.  
  252. /****************************************************************************
  253.  *                                                                          *
  254.  *      Program Mainline                                                    *
  255.  *                                                                          *
  256.  ****************************************************************************/
  257.  
  258. extern int main ( int argc, char *argv[] ) {
  259.  
  260.  /***************************************************************************
  261.   * Initialize the process.                                                 *
  262.   ***************************************************************************/
  263.  
  264.   Process Proc ;
  265.  
  266.  /***************************************************************************
  267.   * Open the resource library.                                              *
  268.   ***************************************************************************/
  269.  
  270.   Module Library ( PSZ(PROGRAM_NAME) ) ;
  271.   LibraryHandle = Library.QueryHandle() ;
  272.  
  273.  /***************************************************************************
  274.   * Get the program title.                                                  *
  275.   ***************************************************************************/
  276.  
  277.   ResourceString Title ( Library.QueryHandle(), IDS_TITLE ) ;
  278.  
  279.  /***************************************************************************
  280.   * Decipher command-line parameters.                                       *
  281.   ***************************************************************************/
  282.  
  283.   BOOL Reset = FALSE ;
  284.  
  285.   ResourceString ResetCommand ( Library.QueryHandle(), IDS_PARMS_RESET ) ;
  286.  
  287.   while ( --argc ) {
  288.  
  289.     argv ++ ;
  290.  
  291.     if ( *argv[0] == '?' ) {
  292.       ResourceString Message ( Library.QueryHandle(), IDS_PARAMETERLIST ) ;
  293.       WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  294.         PSZ(Title), 0, MB_ENTER | MB_NOICON ) ;
  295.       return ( 0 ) ;
  296.     }
  297.  
  298.     if ( !stricmp ( *argv, PCHAR(ResetCommand) ) ) {
  299.       Reset = TRUE ;
  300.       continue ;
  301.     }
  302.  
  303.     {
  304.       ResourceString Format ( Library.QueryHandle(), IDS_ERROR_INVALIDPARM ) ;
  305.       BYTE Message [200] ;
  306.       sprintf ( PCHAR(Message), PCHAR(Format), *argv ) ;
  307.       WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, Message,
  308.         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  309.       abort ( ) ;
  310.     }
  311.   }
  312.  
  313.  /***************************************************************************
  314.   * Create the help instance.                                               *
  315.   ***************************************************************************/
  316.  
  317.   ResourceString HelpTitle ( Library.QueryHandle(), IDS_HELPTITLE ) ;
  318.  
  319.   HelpWindow Help ( Proc.QueryAnchor(), 0,
  320.     ID_MAIN, PSZ(PROGRAM_NAME ".hlp"), PSZ(HelpTitle) ) ;
  321.  
  322.   if ( Help.QueryHandle() == 0 ) {
  323.     ERRORID Error = WinGetLastError ( Proc.QueryAnchor() ) ;
  324.     ResourceString Format ( Library.QueryHandle(), IDS_ERROR_CREATEHELP ) ;
  325.     CHAR Message [200] ;
  326.     sprintf ( Message, PCHAR(Format), Error ) ;
  327.     Log ( "%s", Message ) ;
  328.     WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  329.       PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  330.   }
  331.  
  332.  /***************************************************************************
  333.   * Open/create the profile file.  Reset if requested.                      *
  334.   ***************************************************************************/
  335.  
  336.   Profile IniFile ( PSZ(PROGRAM_NAME),
  337.     Proc.QueryAnchor(), Library.QueryHandle(),
  338.     IDD_PROFILE_PATH, Help.QueryHandle(), Reset ) ;
  339.  
  340.   if ( IniFile.QueryHandle() == 0 ) {
  341.     ResourceString Message ( Library.QueryHandle(), IDS_ERROR_PRFOPENPROFILE ) ;
  342.     Log ( "%s", PSZ(Message) ) ;
  343.     WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  344.       PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  345.     abort ( ) ;
  346.   }
  347.  
  348.  /***************************************************************************
  349.   * Read the profile to find out if we're to animate the frame window.      *
  350.   ***************************************************************************/
  351.  
  352.   BOOL Animate = FALSE ;
  353.   ULONG Size ;
  354.   if
  355.   (
  356.     PrfQueryProfileSize ( IniFile.QueryHandle(), PSZ(PROGRAM_NAME), PSZ("Animate"), &Size )
  357.     AND
  358.     ( ( Size == sizeof(Animate) ) OR ( Size == sizeof(short) ) )
  359.     AND
  360.     PrfQueryProfileData ( IniFile.QueryHandle(), PSZ(PROGRAM_NAME), PSZ("Animate"), &Animate, &Size )
  361.   )
  362.   {
  363.     ;
  364.   }
  365.  
  366.  /***************************************************************************
  367.   * Create the frame window.                                                *
  368.   ***************************************************************************/
  369.  
  370.   FRAMECDATA FrameControlData ;
  371.   FrameControlData.cb = sizeof(FrameControlData) ;
  372.   FrameControlData.flCreateFlags =
  373.     FCF_TITLEBAR | FCF_SYSMENU | FCF_BORDER |
  374.     FCF_ICON | FCF_MINBUTTON | FCF_NOBYTEALIGN | FCF_ACCELTABLE ;
  375.   FrameControlData.hmodResources = 0 ;
  376.   FrameControlData.idResources = ID_MAIN ;
  377.  
  378.   Window Frame ( HWND_DESKTOP, WC_FRAME, PSZ(Title),
  379.     Animate ? WS_ANIMATE : 0, 
  380.     0, 0, 0, 0, HWND_DESKTOP, HWND_TOP, ID_MAIN,
  381.     &FrameControlData, NULL ) ;
  382.  
  383.   if ( Frame.QueryHandle() == 0 ) {
  384.     ERRORID Error = WinGetLastError ( Proc.QueryAnchor() ) ;
  385.     ResourceString Format ( Library.QueryHandle(), IDS_ERROR_CREATEFRAME ) ;
  386.     CHAR Message [200] ;
  387.     sprintf ( Message, PCHAR(Format), Error ) ;
  388.     Log ( "%s", Message ) ;
  389.     WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  390.       PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  391.     abort ( ) ;
  392.   }
  393.  
  394.  /***************************************************************************
  395.   * Associate the help instance with the frame window.                      *
  396.   ***************************************************************************/
  397.  
  398.   if ( Help.QueryHandle() ) {
  399.     WinAssociateHelpInstance ( Help.QueryHandle(), Frame.QueryHandle() ) ;
  400.   }
  401.  
  402.  /***************************************************************************
  403.   * Register the client window class.                                       *
  404.   ***************************************************************************/
  405.  
  406.   if
  407.   (
  408.     !WinRegisterClass
  409.     (
  410.       Proc.QueryAnchor(),
  411.       PSZ(CLASS_NAME),
  412.       MessageProcessor,
  413.       CS_MOVENOTIFY,
  414.       sizeof(PVOID)
  415.     )
  416.   )
  417.   {
  418.     ERRORID Error = WinGetLastError ( Proc.QueryAnchor() ) ;
  419.     ResourceString Format ( Library.QueryHandle(), IDS_ERROR_WINREGISTERCLASS ) ;
  420.     CHAR Message [200] ;
  421.     sprintf ( Message, PCHAR(Format), CLASS_NAME, Error ) ;
  422.     Log ( "%s", Message ) ;
  423.     WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  424.       PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  425.     abort ( ) ;
  426.   }
  427.  
  428.  /***************************************************************************
  429.   * Create the client window.                                               *
  430.   ***************************************************************************/
  431.  
  432.   PARMS Parms ;
  433.   Parms.Filler = 0 ;
  434.   Parms.Proc = & Proc ;
  435.   Parms.Library = & Library ;
  436.   Parms.IniFile = & IniFile ;
  437.  
  438.   Window Client ( Frame.QueryHandle(), PSZ(CLASS_NAME), PSZ(""), 0, 0, 0, 0, 0,
  439.      Frame.QueryHandle(), HWND_BOTTOM, FID_CLIENT, &Parms, NULL ) ;
  440.  
  441.   if ( Client.QueryHandle() == 0 ) {
  442.     ERRORID Error = WinGetLastError ( Proc.QueryAnchor() ) ;
  443.     ResourceString Format ( Library.QueryHandle(), IDS_ERROR_CREATECLIENT ) ;
  444.     CHAR Message [200] ;
  445.     sprintf ( Message, PCHAR(Format), Error ) ;
  446.     Log ( "%s", Message ) ;
  447.     WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  448.       PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  449.     abort ( ) ;
  450.   }
  451.  
  452.  /***************************************************************************
  453.   * Wait for and process messages to the window's queue.  Terminate         *
  454.   *   when the WM_QUIT message is received.                                 *
  455.   ***************************************************************************/
  456.  
  457.   QMSG QueueMessage ;
  458.   while ( WinGetMsg ( Proc.QueryAnchor(), &QueueMessage, 0, 0, 0 ) ) {
  459.     WinDispatchMsg ( Proc.QueryAnchor(), &QueueMessage ) ;
  460.   }
  461.  
  462.  /***************************************************************************
  463.   * Discard all that was requested of the system and terminate.             *
  464.   ***************************************************************************/
  465.  
  466.   return ( 0 ) ;
  467. }
  468.  
  469. /****************************************************************************
  470.  *                                                                          *
  471.  *      Window Message Processor                                            *
  472.  *                                                                          *
  473.  ****************************************************************************/
  474.  
  475. STATIC MRESULT EXPENTRY MessageProcessor ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  476.  
  477.  /***************************************************************************
  478.   * Dispatch the message according to the method table and return the       *
  479.   *   result.  Any messages not defined above get handled by the system     *
  480.   *   default window processor.                                             *
  481.   ***************************************************************************/
  482.  
  483.   static METHOD Methods [] =
  484.   {
  485.     { WM_CREATE,                Create              },
  486.     { WM_DESTROY,               Destroy             },
  487.     { WM_SIZE,                  Size                },
  488.     { WM_MOVE,                  Size                },
  489.     { WM_SAVEAPPLICATION,       SaveApplication     },
  490.     { WM_PAINT,                 Paint               },
  491.     { WM_BUTTON1DOWN,           ButtonDown          },
  492.     { WM_BUTTON2DOWN,           ButtonDown          },
  493.     { WM_BUTTON1DBLCLK,         ButtonDblClick      },
  494.     { WM_BUTTON2DBLCLK,         ButtonDblClick      },
  495.     { WM_PRESPARAMCHANGED,      PresParamChanged    },
  496.     { WM_SYSCOLORCHANGE,        SysColorChange      },
  497.     { WM_COMMAND,               Command             },
  498.     { HM_QUERY_KEYS_HELP,       QueryKeysHelp       },
  499.     { HM_ERROR,                 HelpError           },
  500.     { HM_EXT_HELP_UNDEFINED,    ExtHelpUndefined    },
  501.     { HM_HELPSUBITEM_NOT_FOUND, HelpSubitemNotFound },
  502.     { WM_REFRESH,               Refresh             }
  503.   } ;
  504.  
  505.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefWindowProc ) ) ;
  506. }
  507.  
  508. /****************************************************************************
  509.  *                                                                          *
  510.  *      Create the main window.                                             *
  511.  *                                                                          *
  512.  ****************************************************************************/
  513.  
  514. STATIC MRESULT APIENTRY Create ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  515.  
  516.  /***************************************************************************
  517.   * Allocate instance data.                                                 *
  518.   ***************************************************************************/
  519.  
  520.   PDATA Data = PDATA ( malloc ( sizeof(DATA) ) ) ;
  521.  
  522.   memset ( Data, 0, sizeof(DATA) ) ;
  523.  
  524.   WinSetWindowPtr ( hwnd, QWL_USER, Data ) ;
  525.  
  526.  /***************************************************************************
  527.   * Grab any parameters from the WM_CREATE message.                         *
  528.   ***************************************************************************/
  529.  
  530.   PPARMS Parms = (PPARMS) PVOIDFROMMP ( mp1 ) ;
  531.  
  532.   Data->Proc = Parms->Proc ;
  533.   Data->Library = Parms->Library ;
  534.   Data->IniFile = Parms->IniFile ;
  535.  
  536.  /***************************************************************************
  537.   * Get the current drive mask.                                             *
  538.   ***************************************************************************/
  539.  
  540.   ULONG Drive ;
  541.   DosQueryCurrentDisk ( &Drive, &Data->Drives ) ;
  542.  
  543.  /***************************************************************************
  544.   * Calibrate the old-style load meter, if the high resolution timer's      *
  545.   *   available.                                                            *
  546.   ***************************************************************************/
  547.  
  548.   Data->IniData.MaxCount = CalibrateLoadMeter ( &Data->IdleLoopParms ) ;
  549.   Data->IniData.MaxCount = (ULONG) max ( 1, Data->IniData.MaxCount ) ;
  550.  
  551.  /***************************************************************************
  552.   * Get profile data. Try the OS2.INI first, then try for private INI.      *
  553.   *   If obtained from OS2.INI, erase it afterwards.                        *
  554.   ***************************************************************************/
  555.  
  556.   if ( GetIniData ( Data->Proc->QueryAnchor(), Data->Library->QueryHandle(), HINI_USERPROFILE, &Data->IniData ) ) {
  557.     GetIniData ( Data->Proc->QueryAnchor(), Data->Library->QueryHandle(), Data->IniFile->QueryHandle(), &Data->IniData ) ;
  558.   } else {
  559.     PrfWriteProfileData ( HINI_USERPROFILE, PSZ(PROGRAM_NAME), 0, 0, 0 ) ;
  560.   }
  561.  
  562.  /***************************************************************************
  563.   * Get the frame handle.                                                   *
  564.   ***************************************************************************/
  565.  
  566.   HWND hwndFrame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  567.  
  568.  /***************************************************************************
  569.   * Get the control window handles.                                         *
  570.   ***************************************************************************/
  571.  
  572.   Data->hwndSysMenu  = WinWindowFromID ( hwndFrame, FID_SYSMENU  ) ;
  573.   Data->hwndTitleBar = WinWindowFromID ( hwndFrame, FID_TITLEBAR ) ;
  574.   Data->hwndMinMax   = WinWindowFromID ( hwndFrame, FID_MINMAX   ) ;
  575.  
  576.  /***************************************************************************
  577.   * Add basic extensions to the system menu.                                *
  578.   ***************************************************************************/
  579.  
  580.   static MENUITEM MenuSeparator =
  581.     { MIT_END, MIS_SEPARATOR, 0, 0, 0, 0 } ;
  582.  
  583.   AddSysMenuItem ( hwndFrame, &MenuSeparator, 0 ) ;
  584.  
  585.   static MENUITEM MenuItems [] =
  586.   {
  587.     { MIT_END, MIS_TEXT,      0, IDM_SAVE_APPLICATION, 0, 0 },
  588.     { MIT_END, MIS_TEXT,      0, IDM_RESET_DEFAULTS,   0, 0 },
  589.     { MIT_END, MIS_TEXT,      0, IDM_HIDE_CONTROLS,    0, 0 },
  590.     { MIT_END, MIS_TEXT,      0, IDM_CONFIGURE,        0, 0 },
  591.   } ;
  592.  
  593.   for ( int i=0; i<sizeof(MenuItems)/sizeof(MenuItems[0]); i++ ) {
  594.     ResourceString MenuText ( Data->Library->QueryHandle(), i+IDS_SAVE_APPLICATION ) ;
  595.     AddSysMenuItem ( hwndFrame, MenuItems+i, PSZ(MenuText) ) ;
  596.   }
  597.  
  598.   AddSysMenuItem ( hwndFrame, &MenuSeparator, 0 ) ;
  599.  
  600.  /***************************************************************************
  601.   * Add 'About' to the system menu.                                         *
  602.   ***************************************************************************/
  603.  
  604.   static MENUITEM MenuAbout =
  605.     { MIT_END, MIS_TEXT, 0, IDM_ABOUT, 0, 0 } ;
  606.  
  607.   ResourceString AboutText ( Data->Library->QueryHandle(), IDS_ABOUT ) ;
  608.  
  609.   AddSysMenuItem ( hwndFrame, &MenuAbout, PSZ(AboutText) ) ;
  610.  
  611.  /***************************************************************************
  612.   * Add 'Help' to the system menu.                                          *
  613.   ***************************************************************************/
  614.  
  615.   static MENUITEM MenuHelp =
  616.     { MIT_END, MIS_HELP, 0, 0, 0, 0 } ;
  617.  
  618.   ResourceString HelpText ( Data->Library->QueryHandle(), IDS_HELP ) ;
  619.  
  620.   AddSysMenuItem ( hwndFrame, &MenuHelp, PSZ(HelpText) ) ;
  621.  
  622.  /***************************************************************************
  623.   * Start the new load meter.                                               *
  624.   ***************************************************************************/
  625.  
  626.   Data->IdleLoopParms.Active = TRUE ;
  627.   Data->IdleLoopTID = _beginthread ( CounterThread, NULL, 0x3000, &Data->IdleLoopParms ) ;
  628.   DosSuspendThread ( Data->IdleLoopTID ) ;
  629.   DosSetPriority ( PRTYS_THREAD, PRTYC_IDLETIME, PRTYD_MINIMUM, Data->IdleLoopTID ) ;
  630.  
  631.   Data->IniData.IdleCount = 0 ;
  632.   Data->IdleLoopParms.Counter = 0 ;
  633.  
  634.   if ( Data->IniData.Items[ITEM_CPULOAD]->QueryFlag() ) {
  635.     DosResumeThread ( Data->IdleLoopTID ) ;
  636.   }
  637.  
  638.   Data->MonitorParms.Active = TRUE ;
  639.   Data->MonitorParms.Counter = & Data->IdleLoopParms.Counter ;
  640.   Data->MonitorParms.Interval = & Data->IniData.TimerInterval ;
  641.   Data->MonitorParms.Priority = & Data->IniData.MonitorPriority ;
  642.   Data->MonitorParms.Owner = hwnd ;
  643.   Data->MonitorTID = _beginthread ( MonitorLoopThread, NULL, 0x3000, &Data->MonitorParms ) ;
  644.  
  645.  /***************************************************************************
  646.   * Add the program to the system task list.                                *
  647.   ***************************************************************************/
  648.  
  649.   ResourceString Title ( Data->Library->QueryHandle(), IDS_TITLE ) ;
  650.   Add2TaskList ( hwndFrame, PSZ(Title) ) ;
  651.  
  652.  /***************************************************************************
  653.   * Position & size the window.  For some reason, we must move and size     *
  654.   *   the window to the saved position before applying the resizing         *
  655.   *   function as fine-tuning.  Maybe the positioning request fails if      *
  656.   *   the window has no size?                                               *
  657.   ***************************************************************************/
  658.  
  659.   WinSetWindowPos ( hwndFrame, HWND_BOTTOM,
  660.     Data->IniData.Position.x, Data->IniData.Position.y,
  661.     Data->IniData.Position.cx, Data->IniData.Position.cy,
  662.     SWP_SIZE | SWP_MOVE | SWP_ZORDER |
  663.     ( Data->IniData.Position.fl & SWP_MINIMIZE ) |
  664.     ( Data->IniData.Position.fl & SWP_RESTORE ) ) ;
  665.  
  666.   ResizeWindow ( hwnd, &Data->IniData ) ;
  667.  
  668.  /***************************************************************************
  669.   * Hide the controls if so configured.                                     *
  670.   ***************************************************************************/
  671.  
  672.   if ( Data->IniData.HideControls
  673.     AND NOT ( Data->IniData.Position.fl & SWP_MINIMIZE ) ) {
  674.  
  675.     CheckMenuItem ( hwndFrame, FID_SYSMENU, IDM_HIDE_CONTROLS, Data->IniData.HideControls ) ;
  676.  
  677.     HideControls
  678.     (
  679.       TRUE,
  680.       hwndFrame,
  681.       Data->hwndSysMenu,
  682.       Data->hwndTitleBar,
  683.       Data->hwndMinMax
  684.     ) ;
  685.   }
  686.  
  687.  /***************************************************************************
  688.   * Get the saved presentation parameters and reinstate them.               *
  689.   ***************************************************************************/
  690.  
  691.   if ( Data->IniData.fFontNameSize ) {
  692.     WinSetPresParam ( hwnd, PP_FONTNAMESIZE,
  693.       strlen(PCHAR(Data->IniData.FontNameSize))+1, Data->IniData.FontNameSize ) ;
  694.   }
  695.  
  696.   if ( Data->IniData.fBackColor ) {
  697.     WinSetPresParam ( hwnd, PP_BACKGROUNDCOLOR,
  698.       sizeof(Data->IniData.BackColor), &Data->IniData.BackColor ) ;
  699.   }
  700.  
  701.   if ( Data->IniData.fTextColor ) {
  702.     WinSetPresParam ( hwnd, PP_FOREGROUNDCOLOR,
  703.       sizeof(Data->IniData.TextColor), &Data->IniData.TextColor ) ;
  704.   }
  705.  
  706.  /***************************************************************************
  707.   * Determine our font size.                                                *
  708.   ***************************************************************************/
  709.  
  710.   HPS hPS = WinGetPS ( hwnd ) ;
  711.   RECTL Rectangle ;
  712.   WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  713.   WinDrawText ( hPS, 1, PSZ(" "), &Rectangle, 0L, 0L, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  714.   Data->Width  = Rectangle.xRight - Rectangle.xLeft ;
  715.   Data->Height = Rectangle.yTop - Rectangle.yBottom ;
  716.   WinReleasePS ( hPS ) ;
  717.  
  718.  /***************************************************************************
  719.   * Now that the window's in order, make it visible.                        *
  720.   ***************************************************************************/
  721.  
  722.   WinShowWindow ( hwndFrame, TRUE ) ;
  723.  
  724.  /***************************************************************************
  725.   * Success?  Return no error.                                              *
  726.   ***************************************************************************/
  727.  
  728.   return ( 0 ) ;
  729. }
  730.  
  731. /****************************************************************************
  732.  *                                                                          *
  733.  *      Destroy main window.                                                *
  734.  *                                                                          *
  735.  ****************************************************************************/
  736.  
  737. STATIC MRESULT APIENTRY Destroy ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  738.  
  739.  /***************************************************************************
  740.   * Find the instance data.                                                 *
  741.   ***************************************************************************/
  742.  
  743.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  744.  
  745.  /***************************************************************************
  746.   * Kill the extra threads.                                                 *
  747.   ***************************************************************************/
  748.  
  749.   DosResumeThread ( Data->MonitorTID ) ;
  750.   Data->MonitorParms.Active = FALSE ;
  751.   DosWaitThread ( &Data->MonitorTID, DCWW_WAIT ) ;
  752.  
  753.   DosResumeThread ( Data->IdleLoopTID ) ;
  754.   Data->IdleLoopParms.Active = FALSE ;
  755.   DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, Data->IdleLoopTID ) ;
  756.   DosWaitThread ( &Data->IdleLoopTID, DCWW_WAIT ) ;
  757.  
  758.  /***************************************************************************
  759.   * Release the instance memory.                                            *
  760.   ***************************************************************************/
  761.  
  762.   free ( Data ) ;
  763.  
  764.  /***************************************************************************
  765.   * We're done.                                                             *
  766.   ***************************************************************************/
  767.  
  768.   return ( MRFROMSHORT ( 0 ) ) ;
  769. }
  770.  
  771. /****************************************************************************
  772.  *                                                                          *
  773.  *      Process window resize message.                                      *
  774.  *                                                                          *
  775.  ****************************************************************************/
  776.  
  777. STATIC MRESULT APIENTRY Size ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  778.  
  779.  /***************************************************************************
  780.   * Find the instance data.                                                 *
  781.   ***************************************************************************/
  782.  
  783.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  784.  
  785.  /***************************************************************************
  786.   * Find out the window's new position and size.                            *
  787.   ***************************************************************************/
  788.  
  789.   HWND hwndFrame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  790.  
  791.   SWP Position ;
  792.   WinQueryWindowPos ( hwndFrame, &Position ) ;
  793.  
  794.   if ( NOT ( Position.fl & SWP_MINIMIZE )
  795.     AND NOT ( Position.fl & SWP_MAXIMIZE ) ) {
  796.  
  797.     Data->IniData.Position.x = Position.x ;
  798.     Data->IniData.Position.y = Position.y ;
  799.  
  800.     Data->IniData.Position.cx = Position.cx ;
  801.     Data->IniData.Position.cy = Position.cy ;
  802.   }
  803.  
  804.  /***************************************************************************
  805.   * If hiding the controls . . .                                            *
  806.   ***************************************************************************/
  807.  
  808.   if ( Data->IniData.HideControls ) {
  809.  
  810.    /*************************************************************************
  811.     * If changing to or from minimized state . . .                          *
  812.     *************************************************************************/
  813.  
  814.     if ( ( Position.fl & SWP_MINIMIZE ) != ( Data->IniData.Position.fl & SWP_MINIMIZE ) )
  815.     {
  816.  
  817.      /***********************************************************************
  818.       * Hide the controls if no longer minimized.                           *
  819.       ***********************************************************************/
  820.  
  821.       HideControls
  822.       (
  823.         NOT ( Position.fl & SWP_MINIMIZE ),
  824.         hwndFrame,
  825.         Data->hwndSysMenu,
  826.         Data->hwndTitleBar,
  827.         Data->hwndMinMax
  828.       ) ;
  829.     }
  830.   }
  831.  
  832.   Data->IniData.Position.fl = Position.fl ;
  833.  
  834.  /***************************************************************************
  835.   * We're done.                                                             *
  836.   ***************************************************************************/
  837.  
  838.   return ( 0 ) ;
  839. }
  840.  
  841. /****************************************************************************
  842.  *                                                                          *
  843.  *      Process SAVE APPLICATION message.                                   *
  844.  *                                                                          *
  845.  ****************************************************************************/
  846.  
  847. STATIC MRESULT APIENTRY SaveApplication ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  848.  
  849.  /***************************************************************************
  850.   * Find the instance data.                                                 *
  851.   ***************************************************************************/
  852.  
  853.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  854.  
  855.  /***************************************************************************
  856.   * Call function to put all profile data out to the system.                *
  857.   ***************************************************************************/
  858.  
  859.   PutIniData ( Data->IniFile->QueryHandle(), &Data->IniData ) ;
  860.  
  861.  /***************************************************************************
  862.   * We're done.  Let the system complete default processing.                *
  863.   ***************************************************************************/
  864.  
  865.   return ( WinDefWindowProc ( hwnd, WM_SAVEAPPLICATION, 0, 0 ) ) ;
  866. }
  867.  
  868. /****************************************************************************
  869.  *                                                                          *
  870.  *      Repaint entire window.                                              *
  871.  *                                                                          *
  872.  ****************************************************************************/
  873.  
  874. STATIC MRESULT APIENTRY Paint ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  875.  
  876.  /***************************************************************************
  877.   * Find the instance data.                                                 *
  878.   ***************************************************************************/
  879.  
  880.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  881.  
  882.  /***************************************************************************
  883.   * Get presentation space and make it use RGB colors.                      *
  884.   ***************************************************************************/
  885.  
  886.   HPS hPS = WinBeginPaint ( hwnd, HPS(NULL), PRECTL(NULL) ) ;
  887.   GpiCreateLogColorTable ( hPS, LCOL_RESET, LCOLF_RGB, 0L, 0L, PLONG(NULL) ) ;
  888.  
  889.  /***************************************************************************
  890.   * Clear the window.                                                       *
  891.   ***************************************************************************/
  892.  
  893.   RECTL Rectangle ;
  894.   WinQueryWindowRect ( hwnd, &Rectangle ) ;
  895.  
  896.   GpiMove ( hPS, (PPOINTL) &Rectangle.xLeft ) ;
  897.   GpiSetColor ( hPS, Data->IniData.BackColor ) ;
  898.   GpiBox ( hPS, DRO_FILL, (PPOINTL) &Rectangle.xRight, 0L, 0L ) ;
  899.  
  900.  /***************************************************************************
  901.   * Release presentation space.                                             *
  902.   ***************************************************************************/
  903.  
  904.   WinEndPaint ( hPS ) ;
  905.  
  906.  /***************************************************************************
  907.   * Update the window and return.                                           *
  908.   ***************************************************************************/
  909.  
  910.   UpdateWindow ( hwnd, Data, TRUE ) ;
  911.  
  912.   return ( 0 ) ;
  913. }
  914.  
  915. /****************************************************************************
  916.  *                                                                          *
  917.  *      Process commands received by Main Window                            *
  918.  *                                                                          *
  919.  ****************************************************************************/
  920.  
  921. STATIC MRESULT APIENTRY Command ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  922.  
  923.  /***************************************************************************
  924.   * Dispatch all other commands through the method table.                   *
  925.   ***************************************************************************/
  926.  
  927.   static METHOD Methods [] =
  928.   {
  929.     { IDM_SAVE_APPLICATION, SaveApplication },
  930.     { IDM_RESET_DEFAULTS,   ResetDefaults   },
  931.     { IDM_HIDE_CONTROLS,    HideControlsCmd },
  932.     { IDM_CONFIGURE,        Configure       },
  933.     { IDM_EXIT,             Exit            },
  934.     { IDM_ABOUT,            About           },
  935.   } ;
  936.  
  937.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), PFNWP(NULL) ) ) ;
  938. }
  939.  
  940. /****************************************************************************
  941.  *                                                                          *
  942.  *      Process Reset Defaults menu command.                                *
  943.  *                                                                          *
  944.  ****************************************************************************/
  945.  
  946. STATIC MRESULT APIENTRY ResetDefaults ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  947.  
  948.  /***************************************************************************
  949.   * Find the instance data.                                                 *
  950.   ***************************************************************************/
  951.  
  952.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  953.  
  954.  /***************************************************************************
  955.   * Reset all profile data for this program.                                *
  956.   ***************************************************************************/
  957.  
  958.   PrfWriteProfileData ( Data->IniFile->QueryHandle(), PSZ(PROGRAM_NAME), 0, 0, 0 ) ;
  959.  
  960.  /***************************************************************************
  961.   * Reset the program's presentation parameters.                            *
  962.   ***************************************************************************/
  963.  
  964.   WinRemovePresParam ( hwnd, PP_FONTNAMESIZE ) ;
  965.   WinRemovePresParam ( hwnd, PP_FOREGROUNDCOLOR ) ;
  966.   WinRemovePresParam ( hwnd, PP_BACKGROUNDCOLOR ) ;
  967.  
  968.  /***************************************************************************
  969.   * Done.                                                                   *
  970.   ***************************************************************************/
  971.  
  972.   return ( MRFROMSHORT ( 0 ) ) ;
  973. }
  974.  
  975. /****************************************************************************
  976.  *                                                                          *
  977.  *      Process Hide Controls menu command.                                 *
  978.  *                                                                          *
  979.  ****************************************************************************/
  980.  
  981. STATIC MRESULT APIENTRY HideControlsCmd ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  982.  
  983.  /***************************************************************************
  984.   * Find the instance data.                                                 *
  985.   ***************************************************************************/
  986.  
  987.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  988.  
  989.  /***************************************************************************
  990.   * Toggle the Hide Controls setting.                                       *
  991.   ***************************************************************************/
  992.  
  993.   Data->IniData.HideControls = Data->IniData.HideControls ? FALSE : TRUE ;
  994.   Data->IniData.fHideControls = TRUE ;
  995.  
  996.  /***************************************************************************
  997.   * Get the frame handle.                                                   *
  998.   ***************************************************************************/
  999.  
  1000.   HWND hwndFrame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  1001.  
  1002.  /***************************************************************************
  1003.   * If controls aren't hidden yet, update the menu check-mark.              *
  1004.   ***************************************************************************/
  1005.  
  1006.   if ( Data->IniData.HideControls )
  1007.     CheckMenuItem ( hwndFrame, FID_SYSMENU, IDM_HIDE_CONTROLS, Data->IniData.HideControls ) ;
  1008.  
  1009.  /***************************************************************************
  1010.   * If not minimized right now, hide or reveal the controls.                *
  1011.   ***************************************************************************/
  1012.  
  1013.   if ( NOT ( Data->IniData.Position.fl & SWP_MINIMIZE ) )
  1014.   {
  1015.     HideControls
  1016.     (
  1017.       Data->IniData.HideControls,
  1018.       hwndFrame,
  1019.       Data->hwndSysMenu,
  1020.       Data->hwndTitleBar,
  1021.       Data->hwndMinMax
  1022.     ) ;
  1023.   }
  1024.  
  1025.  /***************************************************************************
  1026.   * If controls are no longer hidden, update the menu check-mark.           *
  1027.   ***************************************************************************/
  1028.  
  1029.   if ( NOT Data->IniData.HideControls )
  1030.     CheckMenuItem ( hwndFrame, FID_SYSMENU, IDM_HIDE_CONTROLS, Data->IniData.HideControls ) ;
  1031.  
  1032.  /***************************************************************************
  1033.   * Done.                                                                   *
  1034.   ***************************************************************************/
  1035.  
  1036.   return ( MRFROMSHORT ( 0 ) ) ;
  1037. }
  1038.  
  1039. /****************************************************************************
  1040.  *                                                                          *
  1041.  *      Process Configure command.                                          *
  1042.  *                                                                          *
  1043.  ****************************************************************************/
  1044.  
  1045. STATIC MRESULT APIENTRY Configure ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1046.  
  1047.  /***************************************************************************
  1048.   * Find the instance data.                                                 *
  1049.   ***************************************************************************/
  1050.  
  1051.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1052.  
  1053.  /***************************************************************************
  1054.   * Invoke the Configure dialog.  If cancelled, just return.                *
  1055.   ***************************************************************************/
  1056.  
  1057.   CONFIG_PARMS Parms ;
  1058.   Parms.id                  = IDD_CONFIGURE ;
  1059.   Parms.hwndHelp            = WinQueryHelpInstance ( hwnd ) ;
  1060.   Parms.HideControls        = Data->IniData.HideControls ;
  1061.   Parms.Float               = Data->IniData.Float ;
  1062.   Parms.Animate             = Data->IniData.Animate ;
  1063.   Parms.ShowFileSystemNames = Data->IniData.ShowFileSystemNames ;
  1064.   Parms.MonitorPriority     = Data->IniData.MonitorPriority ;
  1065.   Parms.TimerInterval       = Data->IniData.TimerInterval ;
  1066.  
  1067.   Parms.ItemCount           = Data->IniData.ItemCount ;
  1068.  
  1069.   PSZ  ItemNames [ ITEM_BASE_COUNT + MAX_DRIVES ] ;
  1070.   BOOL ItemFlags [ ITEM_BASE_COUNT + MAX_DRIVES ] ;
  1071.   for ( int i=0; i<Data->IniData.ItemCount; i++ )
  1072.   {
  1073.     ItemNames[i] = Data->IniData.Items[i]->QueryOption () ;
  1074.     ItemFlags[i] = Data->IniData.Items[i]->QueryFlag () ;
  1075.   }
  1076.   Parms.ItemNames = ItemNames ;
  1077.   Parms.ItemFlags = ItemFlags ;
  1078.  
  1079.   if ( WinDlgBox ( HWND_DESKTOP, hwnd, PFNWP(ConfigureProcessor),
  1080.     Data->Library->QueryHandle(), IDD_CONFIGURE, &Parms ) == FALSE )
  1081.   {
  1082.     return ( MRFROMSHORT ( 0 ) ) ;
  1083.   }
  1084.  
  1085.  /***************************************************************************
  1086.   * Save the new monitor priority.                                          *
  1087.   ***************************************************************************/
  1088.  
  1089.   Data->IniData.fMonitorPriority = TRUE ;
  1090.   Data->IniData.MonitorPriority = Parms.MonitorPriority ;
  1091.  
  1092.  /***************************************************************************
  1093.   * Save the new timer interval.                                            *
  1094.   ***************************************************************************/
  1095.  
  1096.   Data->IniData.fTimerInterval = TRUE ;
  1097.   Data->IniData.TimerInterval = Parms.TimerInterval ;
  1098.  
  1099.  /***************************************************************************
  1100.   * Save the float-to-top flag.                                             *
  1101.   ***************************************************************************/
  1102.  
  1103.   Data->IniData.fFloat = TRUE ;
  1104.   Data->IniData.Float = Parms.Float ;
  1105.  
  1106.  /***************************************************************************
  1107.   * Save the window animate flag.                                           *
  1108.   ***************************************************************************/
  1109.  
  1110.   Data->IniData.fAnimate = TRUE ;
  1111.   Data->IniData.Animate = Parms.Animate ;
  1112.  
  1113.  /***************************************************************************
  1114.   * Save the hide controls flag, and adjust the window if it changed.       *
  1115.   ***************************************************************************/
  1116.  
  1117.   Data->IniData.fHideControls = TRUE ;
  1118.   if ( Data->IniData.HideControls != Parms.HideControls ) {
  1119.     HWND FrameWindow = WinQueryWindow ( hwnd, QW_PARENT ) ;
  1120.     Data->IniData.HideControls = Parms.HideControls ;
  1121.     if ( Data->IniData.HideControls )
  1122.       CheckMenuItem ( FrameWindow, FID_SYSMENU, IDM_HIDE_CONTROLS, Data->IniData.HideControls ) ;
  1123.     if ( NOT ( Data->IniData.Position.fl & SWP_MINIMIZE ) ) {
  1124.       HideControls
  1125.       (
  1126.         Data->IniData.HideControls,
  1127.         FrameWindow,
  1128.         Data->hwndSysMenu,
  1129.         Data->hwndTitleBar,
  1130.         Data->hwndMinMax
  1131.       ) ;
  1132.     }
  1133.     if ( NOT Data->IniData.HideControls )
  1134.       CheckMenuItem ( FrameWindow, FID_SYSMENU, IDM_HIDE_CONTROLS, Data->IniData.HideControls ) ;
  1135.   }
  1136.  
  1137.  /***************************************************************************
  1138.   * Determine if the display item list has changed.  If not, return.        *
  1139.   ***************************************************************************/
  1140.  
  1141.   BOOL ItemsChanged = FALSE ;
  1142.   for ( i=0; i<Data->IniData.ItemCount; i++ ) {
  1143.     if ( ItemFlags[i] != Data->IniData.Items[i]->QueryFlag() ) {
  1144.       ItemsChanged = TRUE ;
  1145.       break ;
  1146.     }
  1147.   }
  1148.  
  1149.   if ( NOT ItemsChanged AND ( Data->IniData.ShowFileSystemNames == Parms.ShowFileSystemNames ) ) {
  1150.     return ( MRFROMSHORT ( 0 ) ) ;
  1151.   }
  1152.  
  1153.  /***************************************************************************
  1154.   * Save the show file-system names flag.                                   *
  1155.   ***************************************************************************/
  1156.  
  1157.   Data->IniData.fShowFileSystemNames = TRUE ;
  1158.   Data->IniData.ShowFileSystemNames = Parms.ShowFileSystemNames ;
  1159.  
  1160.   for ( i=ITEM_BASE_COUNT; i<Data->IniData.ItemCount; i++ ) {
  1161.      ((DriveFree*)Data->IniData.Items[i])->SetShowFileSystemName ( Data->IniData.ShowFileSystemNames ) ;
  1162.   } /* endfor */
  1163.  
  1164.  /***************************************************************************
  1165.   * If CPU load monitoring has changed, start/stop the monitoring thread.   *
  1166.   ***************************************************************************/
  1167.  
  1168.   if ( ItemFlags[ITEM_CPULOAD] != Data->IniData.Items[ITEM_CPULOAD]->QueryFlag() ) {
  1169.     if ( ItemFlags[ITEM_CPULOAD] )
  1170.       DosResumeThread ( Data->IdleLoopTID ) ;
  1171.     else
  1172.       DosSuspendThread ( Data->IdleLoopTID ) ;
  1173.   }
  1174.  
  1175.  /***************************************************************************
  1176.   * Save the new item flags.                                                *
  1177.   ***************************************************************************/
  1178.  
  1179.   for ( i=0; i<Data->IniData.ItemCount; i++ ) {
  1180.     if ( ItemFlags[i] )
  1181.       Data->IniData.Items[i]->SetFlag ( ) ;
  1182.     else
  1183.       Data->IniData.Items[i]->ResetFlag ( ) ;
  1184.   }
  1185.  
  1186.  /***************************************************************************
  1187.   * Resize the display window.                                              *
  1188.   ***************************************************************************/
  1189.  
  1190.   ResizeWindow ( hwnd, &Data->IniData ) ;
  1191.  
  1192.  /***************************************************************************
  1193.   * Done.                                                                   *
  1194.   ***************************************************************************/
  1195.  
  1196.   return ( MRFROMSHORT ( 0 ) ) ;
  1197. }
  1198.  
  1199. /****************************************************************************
  1200.  *                                                                          *
  1201.  *      Process About menu command.                                         *
  1202.  *                                                                          *
  1203.  ****************************************************************************/
  1204.  
  1205. STATIC MRESULT APIENTRY About ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1206.  
  1207.  /***************************************************************************
  1208.   * Find the instance data.                                                 *
  1209.   ***************************************************************************/
  1210.  
  1211.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1212.  
  1213.  /***************************************************************************
  1214.   * Invoke the About dialog.                                                *
  1215.   ***************************************************************************/
  1216.  
  1217.   ABOUT_PARMS Parms ;
  1218.   Parms.id = IDD_ABOUT ;
  1219.   Parms.hwndHelp = WinQueryHelpInstance ( hwnd ) ;
  1220.  
  1221.   WinDlgBox ( HWND_DESKTOP, hwnd, PFNWP(AboutProcessor),
  1222.     Data->Library->QueryHandle(), IDD_ABOUT, &Parms ) ;
  1223.  
  1224.  /***************************************************************************
  1225.   * Done.                                                                   *
  1226.   ***************************************************************************/
  1227.  
  1228.   return ( MRFROMSHORT ( 0 ) ) ;
  1229. }
  1230.  
  1231. /****************************************************************************
  1232.  *                                                                          *
  1233.  *      Process Mouse Button being pressed.                                 *
  1234.  *                                                                          *
  1235.  ****************************************************************************/
  1236.  
  1237. STATIC MRESULT APIENTRY ButtonDown ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1238.  
  1239.  /***************************************************************************
  1240.   * Find the instance data.                                                 *
  1241.   ***************************************************************************/
  1242.  
  1243.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1244.  
  1245.  /***************************************************************************
  1246.   * Determine the new window position.                                      *
  1247.   ***************************************************************************/
  1248.  
  1249.   TRACKINFO TrackInfo ;
  1250.   memset ( &TrackInfo, 0, sizeof(TrackInfo) ) ;
  1251.  
  1252.   TrackInfo.cxBorder = 1 ;
  1253.   TrackInfo.cyBorder = 1 ;
  1254.   TrackInfo.cxGrid = 1 ;
  1255.   TrackInfo.cyGrid = 1 ;
  1256.   TrackInfo.cxKeyboard = 8 ;
  1257.   TrackInfo.cyKeyboard = 8 ;
  1258.  
  1259.   HWND hwndFrame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  1260.  
  1261.   SWP Position ;
  1262.   WinQueryWindowPos ( hwndFrame, &Position ) ;
  1263.   TrackInfo.rclTrack.xLeft   = Position.x ;
  1264.   TrackInfo.rclTrack.xRight  = Position.x + Position.cx ;
  1265.   TrackInfo.rclTrack.yBottom = Position.y ;
  1266.   TrackInfo.rclTrack.yTop    = Position.y + Position.cy ;
  1267.  
  1268.   WinQueryWindowPos ( HWND_DESKTOP, &Position ) ;
  1269.   TrackInfo.rclBoundary.xLeft   = Position.x ;
  1270.   TrackInfo.rclBoundary.xRight  = Position.x + Position.cx ;
  1271.   TrackInfo.rclBoundary.yBottom = Position.y ;
  1272.   TrackInfo.rclBoundary.yTop    = Position.y + Position.cy ;
  1273.  
  1274.   TrackInfo.ptlMinTrackSize.x = 0 ;
  1275.   TrackInfo.ptlMinTrackSize.y = 0 ;
  1276.   TrackInfo.ptlMaxTrackSize.x = Position.cx ;
  1277.   TrackInfo.ptlMaxTrackSize.y = Position.cy ;
  1278.  
  1279.   TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY ;
  1280.  
  1281.   if ( WinTrackRect ( HWND_DESKTOP, HPS(NULL), &TrackInfo ) )
  1282.   {
  1283.     WinSetWindowPos ( hwndFrame, 0,
  1284.       (SHORT) TrackInfo.rclTrack.xLeft,
  1285.       (SHORT) TrackInfo.rclTrack.yBottom,
  1286.       0, 0, SWP_MOVE ) ;
  1287.   }
  1288.  
  1289.  /***************************************************************************
  1290.   * Return through the default processor, letting window activation         *
  1291.   *   and other system functions occur.                                     *
  1292.   ***************************************************************************/
  1293.  
  1294.   return ( WinDefWindowProc ( hwnd, msg, mp1, mp2 ) ) ;
  1295. }
  1296.  
  1297. /****************************************************************************
  1298.  *                                                                          *
  1299.  *      Process Mouse Button having been double-clicked.                    *
  1300.  *                                                                          *
  1301.  ****************************************************************************/
  1302.  
  1303. STATIC MRESULT APIENTRY ButtonDblClick ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1304.  
  1305.  /***************************************************************************
  1306.   * Send message to self to stop hiding the controls.                       *
  1307.   ***************************************************************************/
  1308.  
  1309.   WinPostMsg ( hwnd, WM_COMMAND,
  1310.     MPFROM2SHORT ( IDM_HIDE_CONTROLS, 0 ),
  1311.     MPFROM2SHORT ( CMDSRC_OTHER, TRUE ) ) ;
  1312.  
  1313.  /***************************************************************************
  1314.   * Return through the default processor, letting window activation         *
  1315.   *   and other system functions occur.                                     *
  1316.   ***************************************************************************/
  1317.  
  1318.   return ( WinDefWindowProc ( hwnd, msg, mp1, mp2 ) ) ;
  1319. }
  1320.  
  1321. /****************************************************************************
  1322.  *                                                                          *
  1323.  *      Process Presentation Parameter Changed notification.                *
  1324.  *                                                                          *
  1325.  ****************************************************************************/
  1326.  
  1327. STATIC MRESULT APIENTRY PresParamChanged ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1328.  
  1329.  /***************************************************************************
  1330.   * Find the instance data.                                                 *
  1331.   ***************************************************************************/
  1332.  
  1333.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1334.  
  1335.  /***************************************************************************
  1336.   * Get the presentation parameter that changed.                            *
  1337.   ***************************************************************************/
  1338.  
  1339.   switch ( LONGFROMMP(mp1) )
  1340.   {
  1341.  
  1342.    /*************************************************************************
  1343.     * If font, note the fact that we now have a font to be saved as         *
  1344.     *   part of the configuration.  Get the font metrics and resize         *
  1345.     *   the window appropriately.                                           *
  1346.     *************************************************************************/
  1347.  
  1348.     case PP_FONTNAMESIZE:
  1349.     {
  1350.       ULONG ppid ;
  1351.       if ( WinQueryPresParam ( hwnd, PP_FONTNAMESIZE, 0, &ppid,
  1352.         sizeof(Data->IniData.FontNameSize), &Data->IniData.FontNameSize,
  1353.         0 ) )
  1354.       {
  1355.         Data->IniData.fFontNameSize = TRUE ;
  1356.       }
  1357.       else
  1358.       {
  1359.         strcpy ( PCHAR(Data->IniData.FontNameSize), "" ) ;
  1360.         Data->IniData.fFontNameSize = FALSE ;
  1361.         PrfWriteProfileData ( Data->IniFile->QueryHandle(), PSZ(PROGRAM_NAME), PSZ("FontNameSize"), NULL, 0 ) ;
  1362.       }
  1363.  
  1364.       HPS hPS = WinGetPS ( hwnd ) ;
  1365.       RECTL Rectangle ;
  1366.       WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  1367.       WinDrawText ( hPS, 1, PSZ(" "), &Rectangle, 0L, 0L, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  1368.       Data->Width  = Rectangle.xRight - Rectangle.xLeft ;
  1369.       Data->Height = Rectangle.yTop - Rectangle.yBottom ;
  1370.       WinReleasePS ( hPS ) ;
  1371.       ResizeWindow ( hwnd, &Data->IniData ) ;
  1372.       break ;
  1373.     }
  1374.  
  1375.    /*************************************************************************
  1376.     * If background color, note the fact and repaint the window.            *
  1377.     *************************************************************************/
  1378.  
  1379.     case PP_BACKGROUNDCOLOR:
  1380.     {
  1381.       ULONG ppid ;
  1382.       if ( WinQueryPresParam ( hwnd, PP_BACKGROUNDCOLOR, 0, &ppid,
  1383.         sizeof(Data->IniData.BackColor), &Data->IniData.BackColor, 0 ) )
  1384.       {
  1385.         Data->IniData.fBackColor = TRUE ;
  1386.       }
  1387.       else
  1388.       {
  1389.         Data->IniData.BackColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_WINDOW, 0L ) ;
  1390.         Data->IniData.fBackColor = FALSE ;
  1391.         PrfWriteProfileData ( Data->IniFile->QueryHandle(), PSZ(PROGRAM_NAME), PSZ("BackgroundColor"), NULL, 0 ) ;
  1392.       }
  1393.       WinInvalidateRect ( hwnd, PRECTL(NULL), TRUE ) ;
  1394.       break ;
  1395.     }
  1396.  
  1397.    /*************************************************************************
  1398.     * If foreground color, note the fact and repaint the window.            *
  1399.     *************************************************************************/
  1400.  
  1401.     case PP_FOREGROUNDCOLOR:
  1402.     {
  1403.       ULONG ppid ;
  1404.       if ( WinQueryPresParam ( hwnd, PP_FOREGROUNDCOLOR, 0, &ppid,
  1405.         sizeof(Data->IniData.TextColor), &Data->IniData.TextColor, 0 ) )
  1406.       {
  1407.         Data->IniData.fTextColor = TRUE ;
  1408.       }
  1409.       else
  1410.       {
  1411.         Data->IniData.TextColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_OUTPUTTEXT, 0L ) ;
  1412.         Data->IniData.fTextColor = FALSE ;
  1413.         PrfWriteProfileData ( Data->IniFile->QueryHandle(), PSZ(PROGRAM_NAME), PSZ("ForegroundColor"), NULL, 0 ) ;
  1414.       }
  1415.       WinInvalidateRect ( hwnd, PRECTL(NULL), TRUE ) ;
  1416.       break ;
  1417.     }
  1418.   }
  1419.  
  1420.  /***************************************************************************
  1421.   * Return through the default processor, letting window activation         *
  1422.   *   and other system functions occur.                                     *
  1423.   ***************************************************************************/
  1424.  
  1425.   return ( WinDefWindowProc ( hwnd, msg, mp1, mp2 ) ) ;
  1426. }
  1427.  
  1428. /****************************************************************************
  1429.  *                                                                          *
  1430.  *      Process System Color Change notification.                           *
  1431.  *                                                                          *
  1432.  ****************************************************************************/
  1433.  
  1434. STATIC MRESULT APIENTRY SysColorChange ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1435.  
  1436.  /***************************************************************************
  1437.   * Find the instance data.                                                 *
  1438.   ***************************************************************************/
  1439.  
  1440.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1441.  
  1442.  /***************************************************************************
  1443.   * If we aren't using custom colors, then query for the new defaults.      *
  1444.   ***************************************************************************/
  1445.  
  1446.   if ( NOT Data->IniData.fBackColor )
  1447.   {
  1448.     Data->IniData.BackColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_WINDOW, 0L ) ;
  1449.   }
  1450.  
  1451.   if ( NOT Data->IniData.fTextColor )
  1452.   {
  1453.     Data->IniData.TextColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_OUTPUTTEXT, 0L ) ;
  1454.   }
  1455.  
  1456.  /***************************************************************************
  1457.   * Return value must be NULL, according to the documentation.              *
  1458.   ***************************************************************************/
  1459.  
  1460.   return ( MRFROMP ( NULL ) ) ;
  1461. }
  1462.  
  1463. /****************************************************************************
  1464.  *                                                                          *
  1465.  *      Process Query for Keys Help resource id.                            *
  1466.  *                                                                          *
  1467.  ****************************************************************************/
  1468.  
  1469. STATIC MRESULT APIENTRY QueryKeysHelp ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1470.  
  1471.  /***************************************************************************
  1472.   * Simply return the ID of the Keys Help panel.                            *
  1473.   ***************************************************************************/
  1474.  
  1475.   return ( (MRESULT) IDM_KEYS_HELP ) ;
  1476. }
  1477.  
  1478. /****************************************************************************
  1479.  *                                                                          *
  1480.  *      Process Help Manager Error                                          *
  1481.  *                                                                          *
  1482.  ****************************************************************************/
  1483.  
  1484. STATIC MRESULT APIENTRY HelpError ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1485.  
  1486.  /***************************************************************************
  1487.   * Local Declarations                                                      *
  1488.   ***************************************************************************/
  1489.  
  1490.   static struct
  1491.   {
  1492.     ULONG Error ;
  1493.     USHORT StringId ;
  1494.   }
  1495.   HelpErrors [] =
  1496.   {
  1497.     { HMERR_NO_FRAME_WND_IN_CHAIN,     IDS_HMERR_NO_FRAME_WND_IN_CHAIN },
  1498.     { HMERR_INVALID_ASSOC_APP_WND,     IDS_HMERR_INVALID_ASSOC_APP_WND },
  1499.     { HMERR_INVALID_ASSOC_HELP_INST,   IDS_HMERR_INVALID_ASSOC_HELP_IN },
  1500.     { HMERR_INVALID_DESTROY_HELP_INST, IDS_HMERR_INVALID_DESTROY_HELP_ },
  1501.     { HMERR_NO_HELP_INST_IN_CHAIN,     IDS_HMERR_NO_HELP_INST_IN_CHAIN },
  1502.     { HMERR_INVALID_HELP_INSTANCE_HDL, IDS_HMERR_INVALID_HELP_INSTANCE },
  1503.     { HMERR_INVALID_QUERY_APP_WND,     IDS_HMERR_INVALID_QUERY_APP_WND },
  1504.     { HMERR_HELP_INST_CALLED_INVALID,  IDS_HMERR_HELP_INST_CALLED_INVA },
  1505.     { HMERR_HELPTABLE_UNDEFINE,        IDS_HMERR_HELPTABLE_UNDEFINE    },
  1506.     { HMERR_HELP_INSTANCE_UNDEFINE,    IDS_HMERR_HELP_INSTANCE_UNDEFIN },
  1507.     { HMERR_HELPITEM_NOT_FOUND,        IDS_HMERR_HELPITEM_NOT_FOUND    },
  1508.     { HMERR_INVALID_HELPSUBITEM_SIZE,  IDS_HMERR_INVALID_HELPSUBITEM_S },
  1509.     { HMERR_HELPSUBITEM_NOT_FOUND,     IDS_HMERR_HELPSUBITEM_NOT_FOUND },
  1510.     { HMERR_INDEX_NOT_FOUND,           IDS_HMERR_INDEX_NOT_FOUND       },
  1511.     { HMERR_CONTENT_NOT_FOUND,         IDS_HMERR_CONTENT_NOT_FOUND     },
  1512.     { HMERR_OPEN_LIB_FILE,             IDS_HMERR_OPEN_LIB_FILE         },
  1513.     { HMERR_READ_LIB_FILE,             IDS_HMERR_READ_LIB_FILE         },
  1514.     { HMERR_CLOSE_LIB_FILE,            IDS_HMERR_CLOSE_LIB_FILE        },
  1515.     { HMERR_INVALID_LIB_FILE,          IDS_HMERR_INVALID_LIB_FILE      },
  1516.     { HMERR_NO_MEMORY,                 IDS_HMERR_NO_MEMORY             },
  1517.     { HMERR_ALLOCATE_SEGMENT,          IDS_HMERR_ALLOCATE_SEGMENT      },
  1518.     { HMERR_FREE_MEMORY,               IDS_HMERR_FREE_MEMORY           },
  1519.     { HMERR_PANEL_NOT_FOUND,           IDS_HMERR_PANEL_NOT_FOUND       },
  1520.     { HMERR_DATABASE_NOT_OPEN,         IDS_HMERR_DATABASE_NOT_OPEN     },
  1521.     { 0,                               IDS_HMERR_UNKNOWN               }
  1522.   } ;
  1523.  
  1524.   ULONG ErrorCode = (ULONG) LONGFROMMP ( mp1 ) ;
  1525.  
  1526.  /***************************************************************************
  1527.   * Find the instance data.                                                 *
  1528.   ***************************************************************************/
  1529.  
  1530.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1531.  
  1532.  /***************************************************************************
  1533.   * Find the error code in the message table.                               *
  1534.   ***************************************************************************/
  1535.  
  1536.   int Index = 0 ;
  1537.   while ( HelpErrors[Index].Error
  1538.     AND ( HelpErrors[Index].Error != ErrorCode ) )
  1539.   {
  1540.     Index ++ ;
  1541.   }
  1542.  
  1543.  /***************************************************************************
  1544.   * Get the message texts.                                                  *
  1545.   ***************************************************************************/
  1546.  
  1547.   ResourceString Title ( Data->Library->QueryHandle(), IDS_HMERR ) ;
  1548.  
  1549.   ResourceString Message ( Data->Library->QueryHandle(), HelpErrors[Index].StringId ) ;
  1550.  
  1551.  /***************************************************************************
  1552.   * Display the error message.                                              *
  1553.   ***************************************************************************/
  1554.  
  1555.   WinMessageBox
  1556.   (
  1557.     HWND_DESKTOP,
  1558.     hwnd,
  1559.     PSZ(Message),
  1560.     PSZ(Title),
  1561.     0,
  1562.     MB_OK | MB_WARNING
  1563.   ) ;
  1564.  
  1565.  /***************************************************************************
  1566.   * Return zero, indicating that the message was processed.                 *
  1567.   ***************************************************************************/
  1568.  
  1569.   return ( MRFROMSHORT ( 0 ) ) ;
  1570. }
  1571.  
  1572. /****************************************************************************
  1573.  *                                                                          *
  1574.  *      Process "Extended Help Undefined" notification                      *
  1575.  *                                                                          *
  1576.  ****************************************************************************/
  1577.  
  1578. STATIC MRESULT APIENTRY ExtHelpUndefined ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1579.  
  1580.  /***************************************************************************
  1581.   * Find the instance data.                                                 *
  1582.   ***************************************************************************/
  1583.  
  1584.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1585.  
  1586.  /***************************************************************************
  1587.   * Get the message texts.                                                  *
  1588.   ***************************************************************************/
  1589.  
  1590.   ResourceString Title ( Data->Library->QueryHandle(), IDS_HMERR ) ;
  1591.  
  1592.   ResourceString Message ( Data->Library->QueryHandle(), IDS_HMERR_EXTHELPUNDEFINED ) ;
  1593.  
  1594.  /***************************************************************************
  1595.   * Display the error message.                                              *
  1596.   ***************************************************************************/
  1597.  
  1598.   WinMessageBox
  1599.   (
  1600.     HWND_DESKTOP,
  1601.     hwnd,
  1602.     PSZ(Message),
  1603.     PSZ(Title),
  1604.     0,
  1605.     MB_OK | MB_WARNING
  1606.   ) ;
  1607.  
  1608.  /***************************************************************************
  1609.   * Return zero, indicating that the message was processed.                 *
  1610.   ***************************************************************************/
  1611.  
  1612.   return ( MRFROMSHORT ( 0 ) ) ;
  1613. }
  1614.  
  1615. /****************************************************************************
  1616.  *                                                                          *
  1617.  *      Process "Help Subitem Not Found" notification                       *
  1618.  *                                                                          *
  1619.  ****************************************************************************/
  1620.  
  1621. STATIC MRESULT APIENTRY HelpSubitemNotFound ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1622.  
  1623.  /***************************************************************************
  1624.   * Find the instance data.                                                 *
  1625.   ***************************************************************************/
  1626.  
  1627.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1628.  
  1629.  /***************************************************************************
  1630.   * Get the title text.                                                     *
  1631.   ***************************************************************************/
  1632.  
  1633.   ResourceString Title ( Data->Library->QueryHandle(), IDS_HMERR ) ;
  1634.  
  1635.  /***************************************************************************
  1636.   * Format the error message.                                               *
  1637.   ***************************************************************************/
  1638.  
  1639.   USHORT Topic = (USHORT) SHORT1FROMMP ( mp2 ) ;
  1640.   USHORT Subtopic = (USHORT) SHORT2FROMMP ( mp2 ) ;
  1641.  
  1642.   ResourceString Frame   ( Data->Library->QueryHandle(), IDS_HELPMODE_FRAME ) ;
  1643.   ResourceString Menu    ( Data->Library->QueryHandle(), IDS_HELPMODE_MENU ) ;
  1644.   ResourceString Window  ( Data->Library->QueryHandle(), IDS_HELPMODE_WINDOW ) ;
  1645.   ResourceString Unknown ( Data->Library->QueryHandle(), IDS_HELPMODE_UNKNOWN ) ;
  1646.  
  1647.   PBYTE Mode ;
  1648.   switch ( SHORT1FROMMP ( mp1 ) )
  1649.   {
  1650.     case HLPM_FRAME:
  1651.       Mode = PSZ(Frame) ;
  1652.       break ;
  1653.  
  1654.     case HLPM_MENU:
  1655.       Mode = PSZ(Menu) ;
  1656.       break ;
  1657.  
  1658.     case HLPM_WINDOW:
  1659.       Mode = PSZ(Window) ;
  1660.       break ;
  1661.  
  1662.     default:
  1663.       Mode = PSZ(Unknown) ;
  1664.   }
  1665.  
  1666.   ResourceString Format ( Data->Library->QueryHandle(), IDS_HELPSUBITEMNOTFOUND ) ;
  1667.  
  1668.   BYTE Message [200] ;
  1669.   sprintf ( PCHAR(Message), PCHAR(Format), Mode, Topic, Subtopic ) ;
  1670.  
  1671.  /***************************************************************************
  1672.   * Display the error message.                                              *
  1673.   ***************************************************************************/
  1674.  
  1675.   WinMessageBox
  1676.   (
  1677.     HWND_DESKTOP,
  1678.     hwnd,
  1679.     Message,
  1680.     PSZ(Title),
  1681.     0,
  1682.     MB_OK | MB_WARNING
  1683.   ) ;
  1684.  
  1685.  /***************************************************************************
  1686.   * Return zero, indicating that the message was processed.                 *
  1687.   ***************************************************************************/
  1688.  
  1689.   return ( MRFROMSHORT ( 0 ) ) ;
  1690. }
  1691.  
  1692. /****************************************************************************
  1693.  *                                                                          *
  1694.  *      Process Refresh message.                                            *
  1695.  *                                                                          *
  1696.  ****************************************************************************/
  1697.  
  1698. STATIC MRESULT APIENTRY Refresh ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1699.  
  1700.  /***************************************************************************
  1701.   * Find the instance data.                                                 *
  1702.   ***************************************************************************/
  1703.  
  1704.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1705.  
  1706.  /***************************************************************************
  1707.   * If we're supposed to float the window, do so here.                      *
  1708.   ***************************************************************************/
  1709.  
  1710.   if ( Data->IniData.Float )
  1711.     WinSetWindowPos ( WinQueryWindow(hwnd,QW_PARENT), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER ) ;
  1712.  
  1713.  /***************************************************************************
  1714.   * Save the idle counter.                                                  *
  1715.   ***************************************************************************/
  1716.  
  1717.   Data->IniData.IdleCount = LONGFROMMP ( mp1 ) ;
  1718.  
  1719.  /***************************************************************************
  1720.   * Determine if drive mask has changed.                                    *
  1721.   ***************************************************************************/
  1722.  
  1723.   ULONG Drive ;
  1724.   ULONG Drives ;
  1725.   DosQueryCurrentDisk ( &Drive, &Drives ) ;
  1726.  
  1727.   if ( Drives != Data->Drives ) {
  1728.  
  1729.    /*************************************************************************
  1730.     * It has.  First save the display options.                              *
  1731.     *************************************************************************/
  1732.  
  1733.     SaveApplication ( hwnd, WM_SAVEAPPLICATION, 0, 0 ) ;
  1734.  
  1735.    /*************************************************************************
  1736.     * Next, update the drive item list.                                     *
  1737.     *************************************************************************/
  1738.  
  1739.     UpdateDriveList ( Data->Proc->QueryAnchor(), Data->Library->QueryHandle(), Data->IniFile->QueryHandle(), 
  1740.       &Data->IniData, Data->Drives, Drives ) ;
  1741.  
  1742.    /*************************************************************************
  1743.     * If the controls are hidden, hide the whole window and reveal the      *
  1744.     *   controls.  Otherwise the menu wouldn't get updated correctly.       *
  1745.     *************************************************************************/
  1746.  
  1747.     if ( Data->IniData.HideControls ) {
  1748.       WinShowWindow ( WinQueryWindow(hwnd,QW_PARENT), FALSE ) ;
  1749.       HideControls
  1750.       (
  1751.         FALSE,
  1752.         WinQueryWindow ( hwnd, QW_PARENT ),
  1753.         Data->hwndSysMenu,
  1754.         Data->hwndTitleBar,
  1755.         Data->hwndMinMax
  1756.       ) ;
  1757.     }
  1758.  
  1759.    /*************************************************************************
  1760.     * If the controls were supposed to be hidden, hide them once more and   *
  1761.     *   show the window to the world again.                                 *
  1762.     *************************************************************************/
  1763.  
  1764.     if ( Data->IniData.HideControls ) {
  1765.       HideControls
  1766.       (
  1767.         TRUE,
  1768.         WinQueryWindow ( hwnd, QW_PARENT ),
  1769.         Data->hwndSysMenu,
  1770.         Data->hwndTitleBar,
  1771.         Data->hwndMinMax
  1772.       ) ;
  1773.       WinShowWindow ( WinQueryWindow(hwnd,QW_PARENT), TRUE ) ;
  1774.     }
  1775.  
  1776.    /*************************************************************************
  1777.     * Save the updated drive mask.                                          *
  1778.     *************************************************************************/
  1779.  
  1780.     Data->Drives = Drives ;
  1781.  
  1782.    /*************************************************************************
  1783.     * Resize the window to accommodate the new option list.                 *
  1784.     *************************************************************************/
  1785.  
  1786.     ResizeWindow ( hwnd, &Data->IniData ) ;
  1787.   }
  1788.  
  1789.  /***************************************************************************
  1790.   * Update the statistics.                                                  *
  1791.   ***************************************************************************/
  1792.  
  1793.   UpdateWindow ( hwnd, Data, FALSE ) ;
  1794.  
  1795.  /***************************************************************************
  1796.   * Return zero, indicating that the message was processed.                 *
  1797.   ***************************************************************************/
  1798.  
  1799.   return ( MRFROMSHORT ( 0 ) ) ;
  1800. }
  1801.  
  1802.  
  1803. /****************************************************************************
  1804.  *                                                                          *
  1805.  *                           Get IniData Data                               *
  1806.  *                                                                          *
  1807.  ****************************************************************************/
  1808.  
  1809. STATIC int GetIniData ( HAB Anchor, HMODULE Library, HINI IniHandle, PINIDATA IniData ) {
  1810.  
  1811.  /***************************************************************************
  1812.   * Get the window's current size and position.                             *
  1813.   ***************************************************************************/
  1814.  
  1815.   #pragma pack(2)
  1816.   typedef struct {
  1817.     USHORT Filler ;
  1818.     USHORT fs ;
  1819.     USHORT cy, cx, y, x ;
  1820.     HWND hwndInsertBehind ;
  1821.     HWND hwnd ;
  1822.   } OLDSWP ;
  1823.   #pragma pack()
  1824.  
  1825.   ULONG Size ;
  1826.   memset ( &IniData->Position, 0, sizeof(IniData->Position) ) ;
  1827.   IniData->fPosition = FALSE ;
  1828.   if ( PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Position"), &Size ) )
  1829.   {
  1830.     if ( Size == sizeof(OLDSWP)-sizeof(USHORT) )
  1831.     {
  1832.       OLDSWP OldPosition ;
  1833.       if ( PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Position"), &OldPosition.fs, &Size ) )
  1834.       {
  1835.         IniData->Position.fl = OldPosition.fs ;
  1836.         IniData->Position.cy = OldPosition.cy ;
  1837.         IniData->Position.cx = OldPosition.cx ;
  1838.         IniData->Position.y = OldPosition.y ;
  1839.         IniData->Position.x = OldPosition.x ;
  1840.         IniData->Position.hwndInsertBehind = OldPosition.hwndInsertBehind ;
  1841.         IniData->Position.hwnd = OldPosition.hwnd ;
  1842.         IniData->fPosition = TRUE ;
  1843.       }
  1844.     }
  1845.     else if ( Size == sizeof(IniData->Position) )
  1846.     {
  1847.       if ( PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Position"), &IniData->Position, &Size ) )
  1848.       {
  1849.         IniData->fPosition = TRUE ;
  1850.       }
  1851.     }
  1852.   }
  1853.  
  1854.   if ( NOT IniData->fPosition )
  1855.   {
  1856.     if ( IniHandle == HINI_USERPROFILE )
  1857.     {
  1858.       return ( 1 ) ;
  1859.     }
  1860.   }
  1861.  
  1862.  /***************************************************************************
  1863.   * Get the program options.                                                *
  1864.   ***************************************************************************/
  1865.  
  1866.   IniData->HideControls = FALSE ;
  1867.   IniData->fHideControls = FALSE ;
  1868.   if 
  1869.   ( 
  1870.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("HideControls"), &Size )
  1871.     AND
  1872.     ( ( Size == sizeof(IniData->HideControls) ) OR ( Size == sizeof(short) ) )
  1873.     AND
  1874.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("HideControls"), &IniData->HideControls, &Size )
  1875.   )
  1876.   {
  1877.     IniData->fHideControls = TRUE ;
  1878.   }
  1879.  
  1880.   IniData->Float = FALSE ;
  1881.   IniData->fFloat = FALSE ;
  1882.   if 
  1883.   ( 
  1884.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Float"), &Size )
  1885.     AND
  1886.     ( Size == sizeof(IniData->Float) ) 
  1887.     AND
  1888.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Float"), &IniData->Float, &Size )
  1889.   )
  1890.   {
  1891.     IniData->fFloat = TRUE ;
  1892.   }
  1893.  
  1894.   IniData->Animate = FALSE ;
  1895.   IniData->fAnimate = FALSE ;
  1896.   if
  1897.   (
  1898.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Animate"), &Size )
  1899.     AND
  1900.     ( Size == sizeof(IniData->Animate) ) 
  1901.     AND
  1902.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("Animate"), &IniData->Animate, &Size )
  1903.   )
  1904.   {
  1905.     IniData->fAnimate = TRUE ;
  1906.   }
  1907.  
  1908.   IniData->ShowFileSystemNames = TRUE ;
  1909.   IniData->fShowFileSystemNames = FALSE ;
  1910.   if
  1911.   (
  1912.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("ShowFileSystemNames"), &Size )
  1913.     AND
  1914.     ( Size == sizeof(IniData->ShowFileSystemNames) )
  1915.     AND
  1916.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("ShowFileSystemNames"), &IniData->ShowFileSystemNames, &Size )
  1917.   )
  1918.   {
  1919.     IniData->fShowFileSystemNames = TRUE ;
  1920.   }
  1921.  
  1922.   IniData->MonitorPriority = PRTYD_MAXIMUM ;
  1923.   IniData->fMonitorPriority = FALSE ;
  1924.   if
  1925.   (
  1926.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("MonitorPriority"), &Size )
  1927.     AND
  1928.     ( Size == sizeof(IniData->MonitorPriority) )
  1929.     AND
  1930.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("MonitorPriority"), &IniData->MonitorPriority, &Size )
  1931.   )
  1932.   {
  1933.     IniData->fMonitorPriority = TRUE ;
  1934.   }
  1935.  
  1936.   IniData->TimerInterval = 1000 ;
  1937.   IniData->fTimerInterval = FALSE ;
  1938.   if 
  1939.   ( 
  1940.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("TimerInterval"), &Size )
  1941.     AND
  1942.     ( ( Size == sizeof(IniData->TimerInterval) ) OR ( Size == sizeof(short) ) )
  1943.     AND
  1944.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("TimerInterval"), &IniData->TimerInterval, &Size ) 
  1945.   )
  1946.   {
  1947.     IniData->fTimerInterval = TRUE ;
  1948.   }
  1949.  
  1950.  /***************************************************************************
  1951.   * Get the presentation parameters.                                        *
  1952.   ***************************************************************************/
  1953.  
  1954.   strcpy ( PCHAR(IniData->FontNameSize), "" ) ;
  1955.   IniData->fFontNameSize = FALSE ;
  1956.   if
  1957.   (
  1958.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("FontNameSize"), &Size )
  1959.     AND
  1960.     ( Size == sizeof(IniData->FontNameSize) )
  1961.     AND
  1962.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("FontNameSize"), &IniData->FontNameSize, &Size )
  1963.   )
  1964.   {
  1965.     IniData->fFontNameSize = TRUE ;
  1966.   }
  1967.  
  1968.   IniData->BackColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_WINDOW, 0L ) ;
  1969.   IniData->fBackColor = FALSE ;
  1970.   if
  1971.   (
  1972.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("BackgroundColor"), &Size )
  1973.     AND
  1974.     ( Size == sizeof(IniData->BackColor) )
  1975.     AND
  1976.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("BackgroundColor"), &IniData->BackColor, &Size )
  1977.   )
  1978.   {
  1979.     IniData->fBackColor = TRUE ;
  1980.   }
  1981.  
  1982.   IniData->TextColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_OUTPUTTEXT, 0L ) ;
  1983.   IniData->fTextColor = FALSE ;
  1984.   if
  1985.   (
  1986.     PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ("ForegroundColor"), &Size )
  1987.     AND
  1988.     ( Size == sizeof(IniData->TextColor) )
  1989.     AND
  1990.     PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ("ForegroundColor"), &IniData->TextColor, &Size )
  1991.   )
  1992.   {
  1993.     IniData->fTextColor = TRUE ;
  1994.   }
  1995.  
  1996.  /***************************************************************************
  1997.   * Initialize the global resource strings.                                 *
  1998.   ***************************************************************************/
  1999.  
  2000.   IniData->Day        = new ResourceString ( Library, IDS_DAY ) ;
  2001.   IniData->Days       = new ResourceString ( Library, IDS_DAYS ) ;
  2002.   IniData->DaysOfWeek = new ResourceString ( Library, IDS_DAYSOFWEEK ) ;
  2003.   IniData->DriveError = new ResourceString ( Library, IDS_DRIVEERROR ) ;
  2004.  
  2005.  /***************************************************************************
  2006.   * Get country information.                                                *
  2007.   ***************************************************************************/
  2008.  
  2009.   COUNTRYCODE CountryCode ;
  2010.   ULONG Count ;
  2011.   ULONG Status ;
  2012.  
  2013.   CountryCode.country = 0 ;
  2014.   CountryCode.codepage = 0 ;
  2015.  
  2016.   Status = DosGetCtryInfo ( sizeof(IniData->CountryInfo), &CountryCode,
  2017.     &IniData->CountryInfo, &Count ) ;
  2018.   if ( Status )
  2019.   {
  2020.     IniData->CountryInfo.fsDateFmt = DATEFMT_MM_DD_YY ;
  2021.     IniData->CountryInfo.fsTimeFmt = 0 ;
  2022.     IniData->CountryInfo.szDateSeparator[0] = '/' ;
  2023.     IniData->CountryInfo.szDateSeparator[1] = 0 ;
  2024.     IniData->CountryInfo.szTimeSeparator[0] = ':' ;
  2025.     IniData->CountryInfo.szTimeSeparator[1] = 0 ;
  2026.     IniData->CountryInfo.szThousandsSeparator[0] = ',' ;
  2027.     IniData->CountryInfo.szThousandsSeparator[1] = 0 ;
  2028.   }
  2029.  
  2030.  /***************************************************************************
  2031.   * Get the SWAPPATH statement from CONFIG.SYS.                             *
  2032.   ***************************************************************************/
  2033.  
  2034.   PSZ Swappath = ScanSystemConfig ( Anchor, PSZ("SWAPPATH") ) ;
  2035.  
  2036.   if ( Swappath == NULL ) {
  2037.     Swappath = PSZ("C:\\OS2\\SYSTEM 0") ;
  2038.   }
  2039.  
  2040.   sscanf ( PCHAR(Swappath), "%s %li",
  2041.     IniData->SwapPath, &IniData->MinFree ) ;
  2042.  
  2043.  /***************************************************************************
  2044.   * Find out where the spool work directory is.                             *
  2045.   ***************************************************************************/
  2046.  
  2047.   IniData->SpoolPath = 0 ;
  2048.  
  2049.   if ( PrfQueryProfileSize ( HINI_PROFILE, PSZ("PM_SPOOLER"), PSZ("DIR"), &Size ) )
  2050.   {
  2051.     IniData->SpoolPath = PSZ ( malloc ( (int)Size ) ) ;
  2052.  
  2053.     if ( IniData->SpoolPath )
  2054.     {
  2055.       if ( PrfQueryProfileData ( HINI_PROFILE, PSZ("PM_SPOOLER"), PSZ("DIR"), IniData->SpoolPath, &Size ) )
  2056.       {
  2057.         PBYTE p = PBYTE( strchr ( PCHAR(IniData->SpoolPath), ';' ) ) ;
  2058.         if ( p )
  2059.         {
  2060.           *p = 0 ;
  2061.         }
  2062.       }
  2063.       else
  2064.       {
  2065.         free ( IniData->SpoolPath ) ;
  2066.         IniData->SpoolPath = 0 ;
  2067.       }
  2068.     }
  2069.   }
  2070.  
  2071.   if ( IniData->SpoolPath == 0 )
  2072.      IniData->SpoolPath = PSZ ( "C:\\SPOOL" ) ;
  2073.  
  2074.  /***************************************************************************
  2075.   * Build the fixed portion of the item list.                               *
  2076.   ***************************************************************************/
  2077.  
  2078.   ResourceString ClockLabel ( Library, IDS_SHOW_CLOCK_LABEL ) ;
  2079.   ResourceString ClockOption ( Library, IDS_SHOW_CLOCK_OPTION ) ;
  2080.   IniData->Items[ITEM_CLOCK] = new Clock ( ITEM_CLOCK,
  2081.     PSZ("ShowClock"), PSZ(ClockLabel), PSZ(ClockOption),
  2082.     IniData->CountryInfo, IniData->DaysOfWeek ) ;
  2083.  
  2084.   ResourceString ElapsedLabel ( Library, IDS_SHOW_ELAPSED_LABEL ) ;
  2085.   ResourceString ElapsedOption ( Library, IDS_SHOW_ELAPSED_OPTION ) ;
  2086.   IniData->Items[ITEM_ELAPSEDTIME] = new ElapsedTime ( ITEM_ELAPSEDTIME,
  2087.     PSZ("ShowElapsed"), PSZ(ElapsedLabel), PSZ(ElapsedOption),
  2088.     IniData->CountryInfo,
  2089.     IniData->Day,
  2090.     IniData->Days ) ;
  2091.  
  2092.   ResourceString SwapSizeLabel ( Library, IDS_SHOW_SWAPSIZE_LABEL ) ;
  2093.   ResourceString SwapSizeOption ( Library, IDS_SHOW_SWAPSIZE_OPTION ) ;
  2094.   IniData->Items[ITEM_SWAPFILESIZE] = new SwapSize ( ITEM_SWAPFILESIZE,
  2095.     PSZ("ShowSwapsize"), PSZ(SwapSizeLabel), PSZ(SwapSizeOption),
  2096.     IniData->CountryInfo,
  2097.     IniData->SwapPath ) ;
  2098.  
  2099.   ResourceString SwapFreeLabel ( Library, IDS_SHOW_SWAPFREE_LABEL ) ;
  2100.   ResourceString SwapFreeOption ( Library, IDS_SHOW_SWAPFREE_OPTION ) ;
  2101.   IniData->Items[ITEM_SWAPDISKFREE] = new SwapFree ( ITEM_SWAPDISKFREE,
  2102.     PSZ("ShowSwapfree"), PSZ(SwapFreeLabel), PSZ(SwapFreeOption),
  2103.     IniData->CountryInfo,
  2104.     IniData->SwapPath,
  2105.     IniData->MinFree ) ;
  2106.  
  2107.   ResourceString MemoryLabel ( Library, IDS_SHOW_MEMORY_LABEL ) ;
  2108.   ResourceString MemoryOption ( Library, IDS_SHOW_MEMORY_OPTION ) ;
  2109.   IniData->Items[ITEM_MEMORYFREE] = new MemoryFree ( ITEM_MEMORYFREE,
  2110.     PSZ("ShowMemory"), PSZ(MemoryLabel), PSZ(MemoryOption),
  2111.     IniData->CountryInfo,
  2112.     (SwapFree*)IniData->Items[ITEM_SWAPDISKFREE] ) ;
  2113.  
  2114.   ResourceString SpoolSizeLabel ( Library, IDS_SHOW_SPOOLSIZE_LABEL ) ;
  2115.   ResourceString SpoolSizeOption ( Library, IDS_SHOW_SPOOLSIZE_OPTION ) ;
  2116.   IniData->Items[ITEM_SPOOLFILESIZE] = new SpoolSize ( ITEM_SPOOLFILESIZE,
  2117.     PSZ("ShowSpoolSize"), PSZ(SpoolSizeLabel), PSZ(SpoolSizeOption),
  2118.     IniData->CountryInfo,
  2119.     IniData->SpoolPath ) ;
  2120.  
  2121.   ResourceString CpuLoadLabel ( Library, IDS_SHOW_CPULOAD_LABEL ) ;
  2122.   ResourceString CpuLoadOption ( Library, IDS_SHOW_CPULOAD_OPTION ) ;
  2123.   IniData->Items[ITEM_CPULOAD] = new CpuLoad ( ITEM_CPULOAD,
  2124.     PSZ("ShowCpuLoad"), PSZ(CpuLoadLabel), PSZ(CpuLoadOption),
  2125.     IniData->MaxCount,
  2126.     &IniData->IdleCount ) ;
  2127.  
  2128.   ResourceString TaskCountLabel ( Library, IDS_SHOW_TASKCOUNT_LABEL ) ;
  2129.   ResourceString TaskCountOption ( Library, IDS_SHOW_TASKCOUNT_OPTION ) ;
  2130.   IniData->Items[ITEM_TASKCOUNT] = new TaskCount ( ITEM_TASKCOUNT,
  2131.     PSZ("ShowTaskCount"), PSZ(TaskCountLabel), PSZ(TaskCountOption),
  2132.     Anchor ) ;
  2133.  
  2134.   ResourceString TotalFreeLabel ( Library, IDS_SHOW_TOTALFREE_LABEL ) ;
  2135.   ResourceString TotalFreeOption ( Library, IDS_SHOW_TOTALFREE_OPTION ) ;
  2136.   IniData->Items[ITEM_TOTALFREE] = new TotalFree ( ITEM_TOTALFREE,
  2137.     PSZ("ShowTotalFree"), PSZ(TotalFreeLabel), PSZ(TotalFreeOption),
  2138.     IniData->CountryInfo, 0 ) ;
  2139.  
  2140.   for ( int i=0; i<ITEM_BASE_COUNT; i++ )
  2141.   {
  2142.     BOOL Flag = TRUE ;
  2143.     if 
  2144.     ( 
  2145.       PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), IniData->Items[i]->QueryName(), &Size )
  2146.       AND
  2147.       ( ( Size == sizeof(Flag) ) OR ( Size == sizeof(short) ) )
  2148.       AND 
  2149.       PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), IniData->Items[i]->QueryName(), &Flag, &Size )
  2150.     )
  2151.     {
  2152.       ;
  2153.     }
  2154.  
  2155.     if ( Flag )
  2156.       IniData->Items[i]->SetFlag() ;
  2157.     else
  2158.       IniData->Items[i]->ResetFlag() ;
  2159.   }
  2160.  
  2161.  /***************************************************************************
  2162.   * Add items for each drive on the system.                                 *
  2163.   ***************************************************************************/
  2164.  
  2165.   ULONG Drive, Drives ;
  2166.   DosQueryCurrentDisk ( &Drive, &Drives ) ;
  2167.   UpdateDriveList ( Anchor, Library, IniHandle, IniData, 0, Drives ) ;
  2168.  
  2169.   return ( 0 ) ;
  2170. }
  2171.  
  2172. /****************************************************************************
  2173.  *                                                                          *
  2174.  *                           Put IniData Data                               *
  2175.  *                                                                          *
  2176.  ****************************************************************************/
  2177.  
  2178. STATIC void PutIniData ( HINI IniHandle, PINIDATA IniData )
  2179. {
  2180.  /***************************************************************************
  2181.   * Save the window's current size and position.                            *
  2182.   ***************************************************************************/
  2183.  
  2184.   PrfWriteProfileData
  2185.   (
  2186.     IniHandle,
  2187.     PSZ(PROGRAM_NAME),
  2188.     PSZ("Position"),
  2189.     &IniData->Position,
  2190.     sizeof(IniData->Position)
  2191.   ) ;
  2192.  
  2193.  /***************************************************************************
  2194.   * Save the program options.                                               *
  2195.   ***************************************************************************/
  2196.  
  2197.   if ( IniData->fHideControls )
  2198.   {
  2199.     PrfWriteProfileData
  2200.     (
  2201.       IniHandle,
  2202.       PSZ(PROGRAM_NAME),
  2203.       PSZ("HideControls"),
  2204.       &IniData->HideControls,
  2205.       sizeof(IniData->HideControls)
  2206.     ) ;
  2207.   }
  2208.  
  2209.   if ( IniData->fFloat )
  2210.   {
  2211.     PrfWriteProfileData
  2212.     (
  2213.       IniHandle,
  2214.       PSZ(PROGRAM_NAME),
  2215.       PSZ("Float"),
  2216.       &IniData->Float,
  2217.       sizeof(IniData->Float)
  2218.     ) ;
  2219.   }
  2220.  
  2221.   if ( IniData->fAnimate )
  2222.   {
  2223.     PrfWriteProfileData
  2224.     (
  2225.       IniHandle,
  2226.       PSZ(PROGRAM_NAME),
  2227.       PSZ("Animate"),
  2228.       &IniData->Animate,
  2229.       sizeof(IniData->Animate)
  2230.     ) ;
  2231.   }
  2232.  
  2233.   if ( IniData->fShowFileSystemNames )
  2234.   {
  2235.     PrfWriteProfileData
  2236.     (
  2237.       IniHandle,
  2238.       PSZ(PROGRAM_NAME),
  2239.       PSZ("ShowFileSystemNames"),
  2240.       &IniData->ShowFileSystemNames,
  2241.       sizeof(IniData->ShowFileSystemNames)
  2242.     ) ;
  2243.   }
  2244.  
  2245.   if ( IniData->fMonitorPriority )
  2246.   {
  2247.     PrfWriteProfileData
  2248.     (
  2249.       IniHandle,
  2250.       PSZ(PROGRAM_NAME),
  2251.       PSZ("MonitorPriority"),
  2252.       &IniData->MonitorPriority,
  2253.       sizeof(IniData->MonitorPriority)
  2254.     ) ;
  2255.   }
  2256.  
  2257.   if ( IniData->fTimerInterval )
  2258.   {
  2259.     PrfWriteProfileData
  2260.     (
  2261.       IniHandle,
  2262.       PSZ(PROGRAM_NAME),
  2263.       PSZ("TimerInterval"),
  2264.       &IniData->TimerInterval,
  2265.       sizeof(IniData->TimerInterval)
  2266.     ) ;
  2267.   }
  2268.  
  2269.  /***************************************************************************
  2270.   * Save the item options.                                                  *
  2271.   ***************************************************************************/
  2272.  
  2273.   for ( int i=0; i<IniData->ItemCount; i++ )
  2274.   {
  2275.     Item *pItem = IniData->Items [i] ;
  2276.     BOOL Flag = pItem->QueryFlag() ;
  2277.  
  2278.     PrfWriteProfileData
  2279.     (
  2280.       IniHandle,
  2281.       PSZ(PROGRAM_NAME),
  2282.       pItem->QueryName(),
  2283.       &Flag,
  2284.       sizeof(Flag)
  2285.     ) ;
  2286.   }
  2287.  
  2288.  /***************************************************************************
  2289.   * Save the presentation parameters.                                       *
  2290.   ***************************************************************************/
  2291.  
  2292.   if ( IniData->fFontNameSize )
  2293.   {
  2294.     PrfWriteProfileData
  2295.     (
  2296.       IniHandle,
  2297.       PSZ(PROGRAM_NAME),
  2298.       PSZ("FontNameSize"),
  2299.       IniData->FontNameSize,
  2300.       sizeof(IniData->FontNameSize)
  2301.     ) ;
  2302.   }
  2303.  
  2304.   if ( IniData->fBackColor )
  2305.   {
  2306.     PrfWriteProfileData
  2307.     (
  2308.       IniHandle,
  2309.       PSZ(PROGRAM_NAME),
  2310.       PSZ("BackgroundColor"),
  2311.       &IniData->BackColor,
  2312.       sizeof(IniData->BackColor)
  2313.     ) ;
  2314.   }
  2315.  
  2316.   if ( IniData->fTextColor )
  2317.   {
  2318.     PrfWriteProfileData
  2319.     (
  2320.       IniHandle,
  2321.       PSZ(PROGRAM_NAME),
  2322.       PSZ("ForegroundColor"),
  2323.       &IniData->TextColor,
  2324.       sizeof(IniData->TextColor)
  2325.     ) ;
  2326.   }
  2327. }
  2328.  
  2329. /****************************************************************************
  2330.  *                                                                          *
  2331.  *      Scan CONFIG.SYS for a keyword.  Return the value.                   *
  2332.  *                                                                          *
  2333.  ****************************************************************************/
  2334.  
  2335. STATIC PSZ ScanSystemConfig ( HAB Anchor, PSZ Keyword )
  2336. {
  2337.  /***************************************************************************
  2338.   * Get the boot drive number from the global information segment.          *
  2339.   ***************************************************************************/
  2340.  
  2341.   ULONG BootDrive ;
  2342.   DosQuerySysInfo ( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &BootDrive, sizeof(BootDrive) ) ;
  2343.  
  2344.  /***************************************************************************
  2345.   * Convert the keyword to upper case.                                      *
  2346.   ***************************************************************************/
  2347.  
  2348.   WinUpper ( Anchor, 0, 0, Keyword ) ;
  2349.  
  2350.  /***************************************************************************
  2351.   * Build the CONFIG.SYS path.                                              *
  2352.   ***************************************************************************/
  2353.  
  2354.   char Path [_MAX_PATH] ;
  2355.   Path[0] = (char) ( BootDrive + 'A' - 1 ) ;
  2356.   Path[1] = 0 ;
  2357.   strcat ( Path, ":\\CONFIG.SYS" ) ;
  2358.  
  2359.  /***************************************************************************
  2360.   * Open CONFIG.SYS for reading.                                            *
  2361.   ***************************************************************************/
  2362.  
  2363.   FILE *File = fopen ( Path, "r" ) ;
  2364.   if ( NOT File )
  2365.   {
  2366.     return ( 0 ) ;
  2367.   }
  2368.  
  2369.  /***************************************************************************
  2370.   * While there're more lines in CONFIG.SYS, read a line and check it.      *
  2371.   ***************************************************************************/
  2372.  
  2373.   static char Buffer [500] ;
  2374.   while ( fgets ( Buffer, sizeof(Buffer), File ) )
  2375.   {
  2376.  
  2377.    /*************************************************************************
  2378.     * Clean any trailing newline character from the input string.           *
  2379.     *************************************************************************/
  2380.  
  2381.     if ( Buffer[strlen(Buffer)-1] == '\n' )
  2382.     {
  2383.       Buffer[strlen(Buffer)-1] = 0 ;
  2384.     }
  2385.  
  2386.    /*************************************************************************
  2387.     * If keyword starts the line, we've found the line we want.  Close      *
  2388.     *   the file and return a pointer to the parameter text.                *
  2389.     *************************************************************************/
  2390.  
  2391.     WinUpper ( Anchor, 0, 0, PSZ(Buffer) ) ;
  2392.  
  2393.     if ( NOT strncmp ( Buffer, PCHAR(Keyword), strlen(PCHAR(Keyword)) )
  2394.       AND ( Buffer[strlen(PCHAR(Keyword))] == '=' ) )
  2395.     {
  2396.       fclose ( File ) ;
  2397.       return ( PSZ( Buffer + strlen(PCHAR(Keyword)) + 1 ) ) ;
  2398.     }
  2399.   }
  2400.  
  2401.  /***************************************************************************
  2402.   * Close the file.  We haven't found the line we wanted.                   *
  2403.   ***************************************************************************/
  2404.  
  2405.   fclose ( File ) ;
  2406.  
  2407.   return ( 0 ) ;
  2408. }
  2409.  
  2410. /****************************************************************************
  2411.  *                                                                          *
  2412.  *                       Resize Client Window                               *
  2413.  *                                                                          *
  2414.  ****************************************************************************/
  2415.  
  2416. STATIC void ResizeWindow ( HWND hwnd, PINIDATA IniData )
  2417. {
  2418.  /***************************************************************************
  2419.   * If the window is visible and minimized, restore it invisibly.           *
  2420.   ***************************************************************************/
  2421.  
  2422.   HWND hwndFrame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  2423.  
  2424.   SHORT fHadToHide = FALSE ;
  2425.   SHORT fHadToRestore = FALSE ;
  2426.   if ( IniData->Position.fl & SWP_MINIMIZE )
  2427.   {
  2428.     if ( WinIsWindowVisible ( hwndFrame ) )
  2429.     {
  2430.       WinShowWindow ( hwndFrame, FALSE ) ;
  2431.       fHadToHide = TRUE ;
  2432.     }
  2433.     WinSetWindowPos ( hwndFrame, 0, 0, 0, 0, 0, SWP_RESTORE ) ;
  2434.     fHadToRestore = TRUE ;
  2435.   }
  2436.  
  2437.  /***************************************************************************
  2438.   * Determine how many items are to be displayed.                           *
  2439.   ***************************************************************************/
  2440.  
  2441.   HPS hPS = WinGetPS ( hwnd ) ;
  2442.  
  2443.   int Count = 0 ;
  2444.   LONG Widest = 0 ;
  2445.   LONG Height = 0 ;
  2446.  
  2447.   for ( int i=0; i<IniData->ItemCount; i++ )
  2448.   {
  2449.     Item *pItem = IniData->Items [i] ;
  2450.  
  2451.     if ( pItem->QueryFlag() )
  2452.     {
  2453.       Count ++ ;
  2454.  
  2455.       RECTL Rectangle ;
  2456.       pItem->Measure ( hPS, Rectangle ) ;
  2457.  
  2458.       Widest = max ( Widest, (Rectangle.xRight-Rectangle.xLeft+1) ) ;
  2459.  
  2460.       Height += Rectangle.yTop - Rectangle.yBottom ;
  2461.     }
  2462.   }
  2463.  
  2464.   WinReleasePS ( hPS ) ;
  2465.  
  2466.  /***************************************************************************
  2467.   * Get the window's current size & position.                               *
  2468.   ***************************************************************************/
  2469.  
  2470.   RECTL Rectangle ;
  2471.   WinQueryWindowRect ( hwndFrame, &Rectangle ) ;
  2472.  
  2473.   WinCalcFrameRect ( hwndFrame, &Rectangle, TRUE ) ;
  2474.  
  2475.  /***************************************************************************
  2476.   * Adjust the window's width & height.                                     *
  2477.   ***************************************************************************/
  2478.  
  2479.   Rectangle.xRight  = Rectangle.xLeft + Widest ;
  2480.  
  2481.   Rectangle.yTop    = Rectangle.yBottom + Height ;
  2482.  
  2483.  /***************************************************************************
  2484.   * Compute new frame size and apply it.                                    *
  2485.   ***************************************************************************/
  2486.  
  2487.   WinCalcFrameRect ( hwndFrame, &Rectangle, FALSE ) ;
  2488.  
  2489.   WinSetWindowPos ( hwndFrame, 0, 0, 0,
  2490.     (SHORT) (Rectangle.xRight-Rectangle.xLeft),
  2491.     (SHORT) (Rectangle.yTop-Rectangle.yBottom),
  2492.     SWP_SIZE ) ;
  2493.  
  2494.  /***************************************************************************
  2495.   * Return the window to its original state.                                *
  2496.   ***************************************************************************/
  2497.  
  2498.   if ( fHadToRestore )
  2499.   {
  2500.     WinSetWindowPos ( hwndFrame, 0,
  2501.       IniData->Position.x, IniData->Position.y,
  2502.       IniData->Position.cx, IniData->Position.cy,
  2503.       SWP_MOVE | SWP_SIZE | SWP_MINIMIZE ) ;
  2504.   }
  2505.  
  2506.   if ( fHadToHide )
  2507.   {
  2508.     WinShowWindow ( hwndFrame, TRUE ) ;
  2509.   }
  2510.  
  2511.  /***************************************************************************
  2512.   * Invalidate the window so that it gets repainted.                        *
  2513.   ***************************************************************************/
  2514.  
  2515.   WinInvalidateRect ( hwnd, PRECTL(NULL), TRUE ) ;
  2516. }
  2517.  
  2518. /****************************************************************************
  2519.  *                                                                          *
  2520.  *                      Hide Window Controls                                *
  2521.  *                                                                          *
  2522.  ****************************************************************************/
  2523.  
  2524. STATIC void HideControls
  2525. (
  2526.   BOOL fHide,
  2527.   HWND hwndFrame,
  2528.   HWND hwndSysMenu,
  2529.   HWND hwndTitleBar,
  2530.   HWND hwndMinMax
  2531. )
  2532. {
  2533.  /***************************************************************************
  2534.   * Get original window position and state.                                 *
  2535.   ***************************************************************************/
  2536.  
  2537.   SWP OldPosition ;
  2538.   WinQueryWindowPos ( hwndFrame, &OldPosition ) ;
  2539.  
  2540.   BOOL WasVisible = WinIsWindowVisible ( hwndFrame ) ;
  2541.  
  2542.  /***************************************************************************
  2543.   * Restore and hide the window.                                            *
  2544.   ***************************************************************************/
  2545.  
  2546.   WinSetWindowPos ( hwndFrame, 0, 0, 0, 0, 0, SWP_RESTORE | SWP_HIDE ) ;
  2547.  
  2548.  /***************************************************************************
  2549.   * Determine client window and location.                                   *
  2550.   ***************************************************************************/
  2551.  
  2552.   SWP Position ;
  2553.   WinQueryWindowPos ( hwndFrame, &Position ) ;
  2554.  
  2555.   RECTL Rectangle ;
  2556.   Rectangle.xLeft   = Position.x ;
  2557.   Rectangle.xRight  = Position.x + Position.cx ;
  2558.   Rectangle.yBottom = Position.y ;
  2559.   Rectangle.yTop    = Position.y + Position.cy ;
  2560.  
  2561.   WinCalcFrameRect ( hwndFrame, &Rectangle, TRUE ) ;
  2562.  
  2563.  /***************************************************************************
  2564.   * Hide or reveal the controls windows by changing their parentage.        *
  2565.   ***************************************************************************/
  2566.  
  2567.   if ( fHide )
  2568.   {
  2569.     WinSetParent ( hwndSysMenu,  HWND_OBJECT, FALSE ) ;
  2570.     WinSetParent ( hwndTitleBar, HWND_OBJECT, FALSE ) ;
  2571.     WinSetParent ( hwndMinMax,   HWND_OBJECT, FALSE ) ;
  2572.   }
  2573.   else
  2574.   {
  2575.     WinSetParent ( hwndSysMenu,  hwndFrame, TRUE ) ;
  2576.     WinSetParent ( hwndTitleBar, hwndFrame, TRUE ) ;
  2577.     WinSetParent ( hwndMinMax,   hwndFrame, TRUE ) ;
  2578.   }
  2579.  
  2580.  /***************************************************************************
  2581.   * Tell the frame that things have changed.  Let it update the window.     *
  2582.   ***************************************************************************/
  2583.  
  2584.   WinSendMsg ( hwndFrame, WM_UPDATEFRAME,
  2585.     MPFROMSHORT ( FCF_TITLEBAR | FCF_SYSMENU | FCF_MINBUTTON ), 0L ) ;
  2586.  
  2587.  /***************************************************************************
  2588.   * Reposition the frame around the client window, which is left be.        *
  2589.   ***************************************************************************/
  2590.  
  2591.   WinCalcFrameRect ( hwndFrame, &Rectangle, FALSE ) ;
  2592.  
  2593.   WinSetWindowPos ( hwndFrame, 0,
  2594.     (SHORT) Rectangle.xLeft,  (SHORT) Rectangle.yBottom,
  2595.     (SHORT) (Rectangle.xRight-Rectangle.xLeft),
  2596.     (SHORT) (Rectangle.yTop-Rectangle.yBottom),
  2597.     SWP_SIZE | SWP_MOVE ) ;
  2598.  
  2599.  /***************************************************************************
  2600.   * If window was maximized, put it back that way.                          *
  2601.   ***************************************************************************/
  2602.  
  2603.   if ( OldPosition.fl & SWP_MAXIMIZE )
  2604.   {
  2605.     WinSetWindowPos ( hwndFrame, 0,
  2606.       (SHORT) Rectangle.xLeft,  (SHORT) Rectangle.yBottom,
  2607.       (SHORT) (Rectangle.xRight-Rectangle.xLeft),
  2608.       (SHORT) (Rectangle.yTop-Rectangle.yBottom),
  2609.       SWP_SIZE | SWP_MOVE |
  2610.       ( OldPosition.fl & SWP_MAXIMIZE ) ) ;
  2611.   }
  2612.  
  2613.  /***************************************************************************
  2614.   * If the window was visible in the first place, show it.                  *
  2615.   ***************************************************************************/
  2616.  
  2617.   if ( WasVisible ) {
  2618.     WinShowWindow ( hwndFrame, TRUE ) ;
  2619.   }
  2620. }
  2621.  
  2622. /****************************************************************************
  2623.  *                                                                          *
  2624.  *    Update Window                                                         *
  2625.  *                                                                          *
  2626.  ****************************************************************************/
  2627.  
  2628. STATIC void UpdateWindow ( HWND hwnd, PDATA Data, BOOL All )
  2629. {
  2630.  /***************************************************************************
  2631.   * Determine how many items are to be displayed.                           *
  2632.   ***************************************************************************/
  2633.  
  2634.   int Count = 0 ;
  2635.   for ( int i=0; i<Data->IniData.ItemCount; i++ ) {
  2636.     if ( Data->IniData.Items[i]->QueryFlag() ) {
  2637.       Count ++ ;
  2638.     }
  2639.   }
  2640.  
  2641.  /***************************************************************************
  2642.   * Get presentation space and make it use RGB colors.                      *
  2643.   ***************************************************************************/
  2644.  
  2645.   HPS hPS = WinGetPS ( hwnd ) ;
  2646.   GpiCreateLogColorTable ( hPS, LCOL_RESET, LCOLF_RGB, 0L, 0L, PLONG(NULL) ) ;
  2647.  
  2648.  /***************************************************************************
  2649.   * Get the window's size and determine the initial position.               *
  2650.   ***************************************************************************/
  2651.  
  2652.   RECTL Rectangle ;
  2653.   WinQueryWindowRect ( hwnd, &Rectangle ) ;
  2654.  
  2655.   Rectangle.xLeft += Data->Width / 2 ;
  2656.   Rectangle.xRight -= Data->Width / 2 ;
  2657.  
  2658.   Rectangle.yBottom = Data->Height * ( Count - 1 ) ;
  2659.   Rectangle.yTop = Rectangle.yBottom + Data->Height ;
  2660.  
  2661.  /***************************************************************************
  2662.   * Review all items.  Display those changed, or all.                       *
  2663.   ***************************************************************************/
  2664.  
  2665.   for ( i=0; i<Data->IniData.ItemCount; i++ ) {
  2666.     Item *pItem = Data->IniData.Items [i] ;
  2667.     if ( pItem->QueryFlag() ) {
  2668.       pItem->Repaint ( hPS, Rectangle, Data->IniData.TextColor, Data->IniData.BackColor, All ) ;
  2669.       Rectangle.yBottom -= Data->Height ;
  2670.       Rectangle.yTop    -= Data->Height ;
  2671.     }
  2672.   }
  2673.  
  2674.  /***************************************************************************
  2675.   * Release the presentation space and return.                              *
  2676.   ***************************************************************************/
  2677.  
  2678.   WinReleasePS ( hPS ) ;
  2679. }
  2680.  
  2681.  
  2682. /****************************************************************************
  2683.  *                                                                          *
  2684.  *    Monitor Loop Thread                                                   *
  2685.  *                                                                          *
  2686.  ****************************************************************************/
  2687.  
  2688. STATIC VOID _Optlink MonitorLoopThread ( PVOID Parameter )
  2689. {
  2690.  /***************************************************************************
  2691.   * Get the thread parameter.                                               *
  2692.   ***************************************************************************/
  2693.  
  2694.   PMONITOR_PARMS Parms = PMONITOR_PARMS ( Parameter ) ;
  2695.  
  2696.  /***************************************************************************
  2697.   * Set this thread's priority.                                             *
  2698.   ***************************************************************************/
  2699.  
  2700.   DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 ) ;
  2701.   DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MINIMUM+(*Parms->Priority), 0 ) ;
  2702.  
  2703.  /***************************************************************************
  2704.   * Start up the high resolution timer, if it is available.                 *
  2705.   ***************************************************************************/
  2706.  
  2707.   BOOL HiResTimer = OpenTimer ( ) ;
  2708.  
  2709.  /***************************************************************************
  2710.   * Loop while active . . .                                                 *
  2711.   ***************************************************************************/
  2712.  
  2713.   while ( Parms->Active ) {
  2714.  
  2715.    /*************************************************************************
  2716.     * Reset the last time and count seen.                                   *
  2717.     *************************************************************************/
  2718.  
  2719.     ULONG LastMilliseconds ;
  2720.     TIMESTAMP Time [2] ;
  2721.  
  2722.     if ( HiResTimer )
  2723.       GetTime ( &Time[0] ) ;
  2724.     else
  2725.       DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &LastMilliseconds, sizeof(LastMilliseconds) ) ;
  2726.  
  2727.     ULONG LastCounter = *Parms->Counter ;
  2728.  
  2729.    /*************************************************************************
  2730.     * Adjust priority and sleep a bit.                                      *
  2731.     *************************************************************************/
  2732.  
  2733. //  DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 ) ;
  2734. //  DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MINIMUM+(*Parms->Priority), 0 ) ;
  2735.     DosSleep ( *Parms->Interval ) ;
  2736.  
  2737.    /*************************************************************************
  2738.     * Find out how much time and counts went by.                            *
  2739.     *************************************************************************/
  2740.  
  2741.     ULONG CurrentCounter = *Parms->Counter ;
  2742.  
  2743.     ULONG DeltaMilliseconds ;
  2744.  
  2745.     if ( HiResTimer ) {
  2746.       GetTime ( &Time[1] ) ;
  2747.  
  2748.       ULONG Nanoseconds ;
  2749.       DeltaMilliseconds = ComputeElapsedTime ( &Time[0], &Time[1], &Nanoseconds ) ;
  2750.  
  2751.       if ( Nanoseconds >= 500000L )
  2752.         DeltaMilliseconds ++ ;
  2753.     } else {
  2754.       ULONG Milliseconds ;
  2755.       DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &Milliseconds, sizeof(Milliseconds) ) ;
  2756.       DeltaMilliseconds = Milliseconds - LastMilliseconds ;
  2757.     }
  2758.  
  2759.    /*************************************************************************
  2760.     * Find out how much idle time was counted.  Adjust it to persecond.     *
  2761.     *************************************************************************/
  2762.  
  2763.     ULONG Counter = (ULONG) ( ( (double)(CurrentCounter-LastCounter) * 1000L ) / (double)DeltaMilliseconds ) ;
  2764.  
  2765.    /*************************************************************************
  2766.     * Tell the owner window to refresh its statistics.                      *
  2767.     *************************************************************************/
  2768.  
  2769.     WinPostMsg ( Parms->Owner, WM_REFRESH, MPFROMLONG(Counter), 0L ) ;
  2770.   }
  2771. }
  2772.  
  2773. /****************************************************************************
  2774.  *                                                                          *
  2775.  *      Update the Item List to reflect changes in the available drives.    *
  2776.  *                                                                          *
  2777.  ****************************************************************************/
  2778.  
  2779. STATIC VOID UpdateDriveList
  2780. (
  2781.   HAB Anchor,
  2782.   HMODULE Library,
  2783.   HINI IniHandle,
  2784.   PINIDATA IniData,
  2785.   ULONG OldDrives,
  2786.   ULONG NewDrives
  2787. )
  2788. {
  2789.  /***************************************************************************
  2790.   * Get format strings.                                                     *
  2791.   ***************************************************************************/
  2792.  
  2793.   ResourceString LabelFormat ( Library, IDS_SHOW_DRIVE_FREE_LABEL ) ;
  2794.   ResourceString OptionFormat ( Library, IDS_SHOW_DRIVE_FREE_OPTION ) ;
  2795.  
  2796.  /***************************************************************************
  2797.   * Save the old item list for comparison.                                  *
  2798.   ***************************************************************************/
  2799.  
  2800.   Item *OldItems [ ITEM_BASE_COUNT + MAX_DRIVES ] ;
  2801.  
  2802.   memset ( OldItems, 0, sizeof(OldItems) ) ;
  2803.  
  2804.   USHORT OldCount = 0 ;
  2805.   if ( OldDrives )
  2806.   {
  2807.     OldCount = IniData->ItemCount ;
  2808.     memcpy ( OldItems, IniData->Items, sizeof(OldItems) ) ;
  2809.   }
  2810.  
  2811.  /***************************************************************************
  2812.   * Add items for each drive on the system.                                 *
  2813.   ***************************************************************************/
  2814.  
  2815.   USHORT Count = ITEM_BASE_COUNT ;
  2816.   USHORT OldIndex = ITEM_BASE_COUNT ;
  2817.  
  2818.   ULONG Drives = 0 ;
  2819.   NewDrives >>= 2 ;
  2820.   OldDrives >>= 2 ;
  2821.  
  2822.   for ( int Drive=3; Drive<=MAX_DRIVES; Drive++ )
  2823.   {
  2824.     while ( ( OldIndex < OldCount )
  2825.       AND ( (SHORT)OldItems[OldIndex]->QueryId() < ITEM_BASE_COUNT + Drive ) )
  2826.     {
  2827.       OldIndex ++ ;
  2828.     }
  2829.  
  2830.     if ( NewDrives & 1 )
  2831.     {
  2832.       if ( OldDrives & 1 )
  2833.       {
  2834.         Drives |= ( 1 << (Drive-1) ) ;
  2835.         if ( ( OldIndex < OldCount )
  2836.           AND ( (SHORT)OldItems[OldIndex]->QueryId() == ITEM_BASE_COUNT + Drive ) )
  2837.         {
  2838.           IniData->Items[Count++] = OldItems[OldIndex++] ;
  2839.         }
  2840.       }
  2841.       else
  2842.       {
  2843.         BYTE FileSystem [80] ;
  2844.         int DriveType = CheckDrive ( Drive, FileSystem ) ;
  2845.         if ( DriveType ) {
  2846.  
  2847.           if ( DriveType > 0 )
  2848.             Drives |= ( 1 << (Drive-1) ) ;
  2849.  
  2850.           BYTE Name [80] ;
  2851.           sprintf ( PCHAR(Name),   "ShowDrive%c:", Drive+'A'-1 ) ;
  2852.  
  2853.           BYTE Label [80] ;
  2854.           sprintf ( PCHAR(Label),  PCHAR(LabelFormat),  Drive+'A'-1 ) ;
  2855.  
  2856.           BYTE Option [80] ;
  2857.           sprintf ( PCHAR(Option), PCHAR(OptionFormat), Drive+'A'-1 ) ;
  2858.  
  2859.           IniData->Items[Count++] = new DriveFree ( ITEM_BASE_COUNT+Drive,
  2860.             Name, Label, Option, IniData->CountryInfo,
  2861.             Drive, IniData->DriveError, IniData->ShowFileSystemNames, FileSystem ) ;
  2862.         }
  2863.       }
  2864.     }
  2865.     else
  2866.     {
  2867.       if ( OldDrives & 1 )
  2868.       {
  2869.         delete OldItems[OldIndex++] ;
  2870.       }
  2871.       else
  2872.       {
  2873.         // Do nothing.
  2874.       }
  2875.     }
  2876.  
  2877.     NewDrives >>= 1 ;
  2878.     OldDrives >>= 1 ;
  2879.   }
  2880.  
  2881.  /***************************************************************************
  2882.   * Save the new item count.                                                *
  2883.   ***************************************************************************/
  2884.  
  2885.   IniData->ItemCount = Count ;
  2886.  
  2887.  /***************************************************************************
  2888.   * Fetch the display flags for the drives.                                 *
  2889.   ***************************************************************************/
  2890.  
  2891.   for ( int i=ITEM_BASE_COUNT; i<IniData->ItemCount; i++ )
  2892.   {
  2893.     BOOL Flag = TRUE ;
  2894.     Item *pItem = IniData->Items [i] ;
  2895.     ULONG Size ;
  2896.  
  2897.     if
  2898.     (
  2899.       PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), pItem->QueryName(), &Size )
  2900.       AND
  2901.       ( ( Size == sizeof(Flag) ) OR ( Size == sizeof(short) ) )
  2902.       AND
  2903.       PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), pItem->QueryName(), &Flag, &Size )
  2904.     )
  2905.     {
  2906.       ;
  2907.     }
  2908.  
  2909.     if ( Flag )
  2910.       pItem->SetFlag () ;
  2911.     else
  2912.       pItem->ResetFlag () ;
  2913.   }
  2914.  
  2915.  /***************************************************************************
  2916.   * Update the total free space object.                                     *
  2917.   ***************************************************************************/
  2918.  
  2919.   ( (TotalFree*) IniData->Items [ ITEM_TOTALFREE ] ) -> ResetMask ( Drives ) ;
  2920. }
  2921.  
  2922. /****************************************************************************
  2923.  *                                                                          *
  2924.  *      Check to see if drive should be added to display list.              *
  2925.  *                                                                          *
  2926.  ****************************************************************************/
  2927.  
  2928. STATIC int CheckDrive ( USHORT Drive, PBYTE FileSystem ) {
  2929.  
  2930.  /***************************************************************************
  2931.   * First, check to see if drive is local or remote.  Remote drives are     *
  2932.   *   always monitored.                                                     *
  2933.   ***************************************************************************/
  2934.  
  2935.   BYTE Path [3] ;
  2936.   Path[0] = (BYTE) ( Drive + 'A' - 1 ) ;
  2937.   Path[1] = ':' ;
  2938.   Path[2] = 0 ;
  2939.  
  2940.   DosError ( FERR_DISABLEHARDERR ) ;
  2941.  
  2942.   BYTE Buffer [1024] ;
  2943.   ULONG Size = sizeof(Buffer) ;
  2944.   ULONG Status = DosQueryFSAttach ( Path, 0, FSAIL_QUERYNAME, (PFSQBUFFER2)Buffer, &Size ) ;
  2945.   DosError ( FERR_ENABLEHARDERR ) ;
  2946.  
  2947.   if ( Status ) {
  2948. //  Log ( "ERROR: Unable to query drive %s for file system.  Status %04X.",
  2949. //    Path, Status ) ;
  2950.     return ( 0 ) ;   // Don't monitor.
  2951.   }
  2952.  
  2953.   USHORT cbName = PFSQBUFFER2(Buffer)->cbName ;
  2954.   strcpy ( PCHAR(FileSystem), PCHAR(PFSQBUFFER2(Buffer+cbName)->szFSDName) ) ;
  2955.  
  2956.   if ( PFSQBUFFER2(Buffer)->iType == FSAT_REMOTEDRV ) {
  2957.     return ( -1 ) ;  // Monitor but don't include in the total over all drives.
  2958.   }
  2959.  
  2960.  /***************************************************************************
  2961.   * Attempt to open the local drive as an entire device.  If unable to do   *
  2962.   *   so, we cannot monitor this drive.                                     *
  2963.   ***************************************************************************/
  2964.  
  2965.   ULONG Action ;
  2966.   HFILE Handle ;
  2967.   Status = DosOpen ( Path, &Handle, &Action, 0, 0, FILE_OPEN,
  2968.     OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
  2969.     OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0 ) ;
  2970.  
  2971.   if ( Status ) {
  2972. //  Log ( "ERROR: Unable to open local drive %s.  Status %04X.",
  2973. //    Path, Status ) ;
  2974.     return ( 0 ) ;   // Don't monitor.
  2975.   }
  2976.  
  2977.  /***************************************************************************
  2978.   * Check to see if the drive has removable media.  We cannot monitor such. *
  2979.   ***************************************************************************/
  2980.  
  2981.   BOOL Addit = FALSE ;
  2982.   BYTE Command = 0 ;
  2983.   BYTE NonRemovable ;
  2984.  
  2985.   ULONG LengthIn = sizeof(Command) ;
  2986.   ULONG LengthOut = sizeof(NonRemovable);
  2987.  
  2988.   if ( 
  2989.     NOT DosDevIOCtl 
  2990.     ( 
  2991.       Handle, 8, 0x20, 
  2992.       &Command, sizeof(Command), &LengthIn,
  2993.       &NonRemovable, sizeof(NonRemovable), &LengthOut 
  2994.     ) 
  2995.   ) {
  2996.     Addit = NonRemovable ;
  2997.   }
  2998.  
  2999.  /***************************************************************************
  3000.   * Close the drive.                                                        *
  3001.   ***************************************************************************/
  3002.  
  3003.   DosClose ( Handle ) ;
  3004.  
  3005.  /***************************************************************************
  3006.   * Return the final verdict.                                               *
  3007.   ***************************************************************************/
  3008.  
  3009.   return ( Addit ) ;    // Monitor and include in overall total if not removable.
  3010. }
  3011.  
  3012. /****************************************************************************
  3013.  *                                                                          *
  3014.  *                       Calibrate the Load Meter                           *
  3015.  *                                                                          *
  3016.  ****************************************************************************/
  3017.  
  3018. STATIC ULONG CalibrateLoadMeter ( PCOUNTER_PARMS Parms ) {
  3019.  
  3020.  /***************************************************************************
  3021.   * Set result to zero as a default.                                        *
  3022.   ***************************************************************************/
  3023.  
  3024.   double AdjustedMaxLoad = 0.0 ;
  3025.  
  3026.  /***************************************************************************
  3027.   * If HRTIMER.SYS has been installed . . .                                 *
  3028.   ***************************************************************************/
  3029.  
  3030.   if ( OpenTimer ( ) ) {
  3031.  
  3032.    /*************************************************************************
  3033.     * Increase this thread's priority to the maximum.                       *
  3034.     *************************************************************************/
  3035.  
  3036.     DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 ) ;
  3037.  
  3038.    /*************************************************************************
  3039.     * Create the calibration thread and set its priority next highest.      *
  3040.     *************************************************************************/
  3041.  
  3042.     Parms->Active = TRUE ;
  3043.     TID tidCalibrate = _beginthread ( CounterThread, NULL, 0x3000, Parms ) ;
  3044.     DosSuspendThread ( tidCalibrate ) ;
  3045.     DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, tidCalibrate ) ;
  3046.     DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, -1, tidCalibrate ) ;
  3047.  
  3048.    /*************************************************************************
  3049.     * Reset the calibration count, get the time, and let the counter go.    *
  3050.     *************************************************************************/
  3051.  
  3052.     Parms->Counter = 0 ;
  3053.     TIMESTAMP Time[2] ;
  3054.     GetTime ( &Time[0] ) ;
  3055.     DosResumeThread ( tidCalibrate ) ;
  3056.  
  3057.    /*************************************************************************
  3058.     * Sleep for one second.                                                 *
  3059.     *************************************************************************/
  3060.  
  3061.     DosSleep ( 1000 ) ;
  3062.  
  3063.    /*************************************************************************
  3064.     * Suspend the calibration counter and get the time.                     *
  3065.     *************************************************************************/
  3066.  
  3067.     Parms->Active = FALSE ;
  3068.     DosWaitThread ( &tidCalibrate, DCWW_WAIT ) ;
  3069.     GetTime ( &Time[1] ) ;
  3070.  
  3071.    /*************************************************************************
  3072.     * Return priorities to normal.                                          *
  3073.     *************************************************************************/
  3074.  
  3075.     DosSetPriority ( PRTYS_THREAD, PRTYC_REGULAR, 0, 0 ) ;
  3076.  
  3077.    /*************************************************************************
  3078.     * Get the elapsed time and adjust the calibration count.                *
  3079.     *************************************************************************/
  3080.  
  3081.     ULONG Milliseconds ;
  3082.     ULONG Nanoseconds ;
  3083.     Milliseconds = ComputeElapsedTime ( &Time[0], &Time[1], &Nanoseconds ) ;
  3084.  
  3085.     AdjustedMaxLoad = (double)Parms->Counter * 1.0E9 ;
  3086.     AdjustedMaxLoad /= (double)Milliseconds*1.0E6L + (double)Nanoseconds ;
  3087.  
  3088.    /*************************************************************************
  3089.     * Close down the connection to HRTIMER.SYS.                             *
  3090.     *************************************************************************/
  3091.  
  3092.     CloseTimer ( ) ;
  3093.   }
  3094.  
  3095.  /***************************************************************************
  3096.   * Return the adjusted calibration count.  If HRTIMER was not there, it    *
  3097.   *   will be zero.                                                         *
  3098.   ***************************************************************************/
  3099.  
  3100.   return ( (ULONG)AdjustedMaxLoad ) ;
  3101. }
  3102.  
  3103. /****************************************************************************
  3104.  *                                                                          *
  3105.  *                    General Purpose Counter Thread                        *
  3106.  *                                                                          *
  3107.  ****************************************************************************/
  3108.  
  3109. STATIC VOID _Optlink CounterThread ( PVOID Parameter ) {
  3110.    PCOUNTER_PARMS Parms = PCOUNTER_PARMS ( Parameter ) ;
  3111.    while ( Parms->Active ) {
  3112.       Parms->Counter ++ ;
  3113.    }
  3114. }
  3115.