Esempio n. 1
0
WORD Install(CHAR szSourcePath[],CHAR szDestPath)
    {
    HFILE hSource;
    HFILE hDestination;
    WORD wCount;
    WORD wStatus;
    WORD wTemp;
    WORD wAttrib;
    WORD wIndex;
    DWORD dwFilePosition;
    WORD wDestPathLength;
    WORD wSourcePathLength;

    DosGetDateTime(&stDateTime);
    stCodeKey.dwCopyKey = (DWORD)stDateTime.hours;
    stCodeKey.dwCopyKey |= (DWORD)stDateTime.minutes << 4;
    stCodeKey.dwCopyKey |= (DWORD)stDateTime.seconds << 10;
    stCodeKey.dwCopyKey |= (DWORD)stDateTime.hundredths << 16;
    stCodeKey.dwCopyKey |= (DWORD)stDateTime.day << 23;
    stCodeKey.dwCopyKey |= (DWORD)stDateTime.month << 27;
    stCodeKey.dwCopyKey |= (DWORD)stDateTime.year << 31;

    wSourcePathLength = strlen(szSourthPath);
    AppendPath(&szSourcePath[wSourcePathLength)],szSourceFile);
    if (DosSetFileMode(abySourcePath,0x0000,0L));
    if ((wLastError = DosOpen(abySourcePath,(PHFILE)&hSource,(PUSHORT)&wStatus,0L,0,0x01,0x61a2,0L)) != 0)
      return(SOURCE_FILE_OPEN);

    DosChgFilePtr(hSource,oFileOffset + oCopyCount,0,&dwFilePosition);
    if ((wLastError = DosRead(hSource,&(BYTE)wTemp,2,&wCount)) != 0)
      return(SOURCE_FILE_READ);

    if (wTemp == 0)
      return(SOURCE_NO_LICENSE);

    if ((wLastError = DosQFileMode(abyDestPath,&wAttrib,0L)) != 0)
      return(SOURCE_FILE_MODE);

    if ((wAttrib & 0x0010) != 0x0010)
      return(DEST_BAD_PATH);

    wDestPathLength = strlen(szDestPath);
    AppendPath(&szDestPath[wDestPathLength],szDeviceFile);
    if (wLastError = FileCopy(szSourcePath,szDestPath) != 0)
        return(SOURCE_FILE_COPY);

    if ((wLastError = DosOpen(szDestPath,(PHFILE)&hDestination,(PUSHORT)&wStatus,0L,0,1,0x6192,0L)) != 0)
        return(DEST_FILE_OPEN);

    stCodeKey.wCopyCount = 0;
    DosChgFilePtr(hDestination,oFileOffset + oCopyKey,0,&dwFilePosition);
    if ((wLastError = DosWrite(hDestination,&(BYTE)stCodeKey.dwCopyKey,6,&wCount)) != 0)
        return(DEST_WRITE_CODE_KEY);

    DosClose(hDestination);
    DosSetFileMode(abyDestPath,0x0021,0L);
    stCodeKey.wCopyCount = wTemp;

    AppendPath(&abyDestPath[wDestPathLength],abyHiddenFile);
    AppendPath(&abySourcePath[wSourcePathLength],abyHiddenFile);

    if (wLastError = FileCopy(abySourcePath,abyDestPath) != 0)
        {
        DosClose(hSource);
        AppendPath(&abySourcePath[wSourcePathLength],abyDeviceFile);
        DosDelete(abyDestPath,0L);
        return(HIDE_FILE_COPY);
        }

    if ((wLastError = DosOpen(abyDestPath,(PHFILE)&hDestination,(PUSHORT)&wStatus,0L,0,1,0x6192,0L)) != 0)
        {
        DosClose(hSource);
        AppendPath(&abySourcePath[wSourcePathLength],abyDeviceFile);
        DosDelete(abyDestPath,0L);
        return(HIDE_FILE_COPY);
        }

    DosChgFilePtr(hDestination,20,0,&dwFilePosition);
    if ((wLastError = DosWrite(hDestination,(&(BYTE)stCodeKey.dwCopyKey),20,&wCount)) != 0)
        {
        DosClose(hDestination);
        DosClose(hSource);
        AppendPath(&abySourcePath[wSourcePathLength],abyDeviceFile);
        DosDelete(abyDestPath,0L);
        return(HIDE_FILE_WRITE);
        }

    DosClose(hDestination);

    DosSetFileMode(abySourcePath,0x0027,0L);
    DosSetFileMode(abyDestPath,0x0027,0L);

    stCodeKey.wCopyCount--;
    DosChgFilePtr(hSource,oFileOffset + oCopyCount,0,&dwFilePosition);
    if ((wLastError = DosWrite(hSource,&(BYTE)stCodeKey.wCopyCount,2,&wCount)) != 0)
        {
        DosClose(hSource);
        DosSetFileMode(abyDestPath,0x0000,0L);
        DosDelete(abyDestPath,0L);
        return(SOURCE_WRITE_CODE_KEY);
        }
    DosClose(hSource);
    AppendPath(&abyDestPath[wDestPathLength],abyDeviceFile);
    if (FixConfigFile())
        {
        printf("% successfully installed.  You must use UNINST.EXE to move the\n",abyDeviceFile);
        printf("device driver to another machine or directory\n");
        if (stCodeKey.wCopyCount != 0)
            {
            printf("\nThere are %u %s device driver licenses still\n",stCodeKey.wCopyCount,abyDeviceFile);
            printf("available for installation.\n\n");
            }
        }
    }
Esempio n. 2
0
int main (int argc,
          PSZ argv[])
{
  PERFSTRUCT TS_Start;                       /* time information about start */
  PERFSTRUCT TS_End;                        /* time information about finish */
  float      seconds;                                     /* elapsed seconds */
  ANALYSE    total;
  APIRET     rc;                                           /* API-Returncode */
  ULONG      ulCounter;                                      /* loop counter */
  DATETIME   dtDateTime;          /* structure to hold current date and time */


  /****************************************************************************
   * Initialize Globals                                                       *
   ****************************************************************************/

  memset (&total,                                /* reset variable structure */
          0,
          sizeof(ANALYSE));

  memset (&Globals,                              /* reset variable structure */
          0,
          sizeof(GLOBALS));

  Globals.ulFileMask = FILE_NORMAL    |
                       FILE_DIRECTORY |
                       FILE_SYSTEM    |
                       FILE_READONLY  |
                       FILE_HIDDEN;

  Globals.fTotalAgeCreation   = 0.0;
  Globals.fTotalAgeLastWrite  = 0.0;
  Globals.fTotalAgeLastAccess = 0.0;
  Globals.fTotalAgeCurrent    =

  DosGetDateTime(&dtDateTime);                          /* query system time */

  Globals.fTotalAgeCurrent = ToolsDateToAge(dtDateTime.day,  /* transform it */
                                            dtDateTime.month,
                                            dtDateTime.year);

  Globals.fTotalCompression   = 0.0;

  Options.ulRecursionDepthMaximum = -1;                           /* maximum */




  /***************************************************************************
   * Parse arguments                                                         *
   ***************************************************************************/

  rc = ArgStandard (argc,                            /* CLI-Parameter parsen */
                    argv,
                    TabArguments,
                    &Options.fsHelp);
  if (rc != NO_ERROR)
  {
    ToolsErrorDos(rc);                                /* print error message */
    exit(1);                                                /* abort program */
  }

  if (Options.fsHelp)                        /* check if user specified help */
  {
    help();
    ArgHelp(TabArguments);
    return (NO_ERROR);
  }


  /***************************************************************************
   * Map arguments                                                           *
   ***************************************************************************/

  if (!Options.fsPath)               /* user specified no path, take current */
    strcpy (Globals.DUPathStr,".");                      /* current, default */
  else
    strcpy (Globals.DUPathStr,Options.pszPath);                 /* user path */


  if (!Options.fsFind)           /* user did not specify maximum find number */
    Options.ulFindNumberMaximum = 65535 / sizeof(FILEFINDBUF3);
  else
    Options.ulFindNumberMaximum = 1;        /* for some Windows 95 requester */
 /* OS/2 2.x, 3.x provide by far best performance when avoiding 64k switches */

  Globals.ulFileFindBufferSize = sizeof(FILEFINDBUF3) * /* our target struct */
                                 Options.ulFindNumberMaximum;

  if (!Options.fsSpeedNr)                 /* if user only wants to scan once */
    Options.ulSpeedNr = 1;                            /* this is the default */

  if (Options.fsFiles2)        /* whenever user wants more file information, */
    Options.fsFiles = TRUE;                      /* also map the basic level */


  /****************************************************************************
   * Processing ...                                                           *
   ****************************************************************************/

  ProcessRootPath(Globals.DUPathStr);       /* get fully qualified path name */

  printf ("\nScanning [%s]",
          Globals.DUPathStr);

  if (Options.fsSpeed)                             /* measure scanning speed */
  {
    printf (" (measuring scanning speed %ux)",
           Options.ulSpeedNr);


    ToolsPerfQuery (&TS_Start);                    /* exact time measurement */

    for (ulCounter = 1;
         ulCounter <= Options.ulSpeedNr;
         ulCounter++)
      ProcessScanSpeed (Globals.DUPathStr);

    ToolsPerfQuery (&TS_End);                      /* exact time measurement */
    seconds = TS_End.fSeconds - TS_Start.fSeconds;     /* calculate duration */

  }
  else
  {
    if (Options.fsIterate)                               /* iteration mode ? */
      printf (" (iterative)");


    ToolsPerfQuery (&TS_Start);                    /* exact time measurement */

    /* ... attributes ... */
    rc = ProcessScan (Globals.DUPathStr,
                      &total);
    if (rc != NO_ERROR)                                  /* check for errors */
      ToolsErrorDosEx(rc,          /* and the operating system error message */
                      Globals.DUPathStr);

    ToolsPerfQuery (&TS_End);                      /* exact time measurement */
    seconds = TS_End.fSeconds - TS_Start.fSeconds;     /* calculate duration */


    StrValueToSizeFloat (Globals.szBuf_1,
                    total.llBytesSize);
    StrValueToSizeFloat (Globals.szBuf_2,
                    total.llBytesAllocated);

    printf ("\nTotal       : [%7.0f files, %s filesize, %s allocated]",
            total.llFiles,
            Globals.szBuf_1,
            Globals.szBuf_2);


    if (Options.fsAttributes)                        /* Attribute anzeigen ? */
    {
      printf ("\nStatistics"
              "\n� Attributes");

      if (Globals.attrNormal)
        printf ("\n  � Files without attributes: [%8u]",
                Globals.attrNormal);

      if (Globals.attrArchived)
        printf ("\n  � Files archived:           [%8u]",
                Globals.attrArchived);

      if (Globals.attrReadonly)
        printf ("\n  � Files read-only:          [%8u]",
                Globals.attrReadonly);

      if (Globals.attrHidden)
        printf ("\n  � Files hidden:             [%8u]",
                Globals.attrHidden);

      if (Globals.attrSystem)
        printf ("\n  � Files system:             [%8u]",
                Globals.attrSystem);

      if (Globals.attrCompressed)
        printf ("\n  � Files compressed:         [%8u]",
                Globals.attrCompressed);

      if (Globals.attrDirectory)
      {
        printf ("\n  � Directories:              [%8u]"
                "\n    � '.' and '..' included:  [%8u]"
                "\n    � remaining rest:         [%8u]",
                Globals.attrDirectory,
                Globals.attrDirpseudo,
                Globals.attrDirectory - Globals.attrDirpseudo);
      }

      if (Globals.attrUndefined)
        printf ("\n  � WARNING: files with undefined attributes: [%8u]",
                Globals.attrUndefined);

      /***********************************************************************
       * Averages                                                            *
       ***********************************************************************/

      if (total.llFiles != 0)
      {
        printf ("\n� Averages"
                "\n  � File Ages and Dates"
                "\n    � Average file creation          %6.1f days ago"
                "\n    � Average last file access       %6.1f days ago"
                "\n    � Average last file modification %6.1f days ago",
                -Globals.fTotalAgeCreation     / (float)total.llFiles,
                -Globals.fTotalAgeLastAccess   / (float)total.llFiles,
                -Globals.fTotalAgeLastWrite    / (float)total.llFiles);

        printf ("\n  � File Size and Allocation"
                "\n    � Average file size       %10.0fb"
                "\n    � Average allocation size %10.0fb"
                "\n    � Average slack space     %10.0fb",
                (float)total.llBytesSize      / (float)total.llFiles,
                (float)total.llBytesAllocated / (float)total.llFiles,
                ( (float)total.llBytesAllocated - (float)total.llBytesSize)
                  / (float)total.llFiles);

        if (Globals.attrCompressed != 0)
          printf ("\n  � Compression"
                  "\n    � Average file compression (compressed only) 1:%2.2f"
                  "\n    � Average file compression (total)           1:%2.2f",
                  Globals.fTotalCompression     / (float)Globals.attrCompressed,
                  Globals.fTotalCompression     / (float)total.llFiles);
      }


      /***********************************************************************
       * Superlatives, Records, Minima and Maxima                            *
       ***********************************************************************/

      printf ("\n� Superlatives");

      /***************
       * Compression *
       ***************/

      if (Globals.bMaximumCompression || Globals.bMinimumCompression)
        printf ("\n  � Compression");

      if (Globals.bMaximumCompression)
        printf ("\n    � Maximum Ratio  1:%2.2f %s",
                Globals.fMaximumCompression,
                Globals.pszMaximumCompression);

      if (Globals.bMinimumCompression)
        printf ("\n    � Minimum Ratio   1:%2.2f %s",
                Globals.fMinimumCompression,
                Globals.pszMinimumCompression);


      /*****************************
       * Files size and allocation *
       *****************************/

      printf ("\n  � File Size and Allocation");

      if (Globals.bMaximumFileSize)
        printf ("\n    � Maximum File Size        %9ub %s",
                Globals.ulMaximumFileSize,
                Globals.pszMaximumFileSize);

      if (Globals.bMaximumAllocationSize)
        printf ("\n    � Maximum Allocation Size  %9ub %s",
                Globals.ulMaximumAllocationSize,
                Globals.pszMaximumAllocationSize);

      if (Globals.bMaximumSlackSpace)
        printf ("\n    � Maximum Slack Space      %9ib %s",
                Globals.iMaximumSlackSpace,
                Globals.pszMaximumSlackSpace);

      if (Globals.bMinimumFileSize)
        printf ("\n    � Minimum File Size        %9ub %s",
                Globals.ulMinimumFileSize,
                Globals.pszMinimumFileSize);

      if (Globals.bMinimumAllocationSize)
        printf ("\n    � Minimum Allocation Size  %9ub %s",
                Globals.ulMinimumAllocationSize,
                Globals.pszMinimumAllocationSize);

      if (Globals.bMaximumSlackSpace)
        printf ("\n    � Minimum Slack Space      %9ib %s",
                Globals.iMinimumSlackSpace,
                Globals.pszMinimumSlackSpace);


      /************************
       * Files ages and dates *
       ************************/

      printf ("\n  � File Ages and Dates");

      if (Globals.bMaximumCreation)
      {
        StrFDateTimeToString(Globals.fdateMaximumCreation,   /* map the date */
                             Globals.ftimeMaximumCreation,
                             Globals.szFileDate);

        printf ("\n    � Most recently created   %s %s",
                Globals.szFileDate,
                Globals.pszMaximumCreation);
      }

      if (Globals.bMaximumLastAccess)
      {
        StrFDateTimeToString(Globals.fdateMaximumLastAccess, /* map the date */
                             Globals.ftimeMaximumLastAccess,
                             Globals.szFileDate);

        printf ("\n    � Most recently accessed  %s %s",
                Globals.szFileDate,
                Globals.pszMaximumLastAccess);
      }

      if (Globals.bMaximumLastWrite)
      {
        StrFDateTimeToString(Globals.fdateMaximumLastWrite,  /* map the date */
                             Globals.ftimeMaximumLastWrite,
                             Globals.szFileDate);

        printf ("\n    � Most recently modified  %s %s",
                Globals.szFileDate,
                Globals.pszMaximumLastWrite);
      }

      if (Globals.bMinimumCreation)
      {
        StrFDateTimeToString(Globals.fdateMinimumCreation,   /* map the date */
                             Globals.ftimeMinimumCreation,
                             Globals.szFileDate);

        printf ("\n    � Least recently created  %s %s",
                Globals.szFileDate,
                Globals.pszMinimumCreation);
      }

      if (Globals.bMinimumLastAccess)
      {
        StrFDateTimeToString(Globals.fdateMinimumLastAccess, /* map the date */
                             Globals.ftimeMinimumLastAccess,
                             Globals.szFileDate);

        printf ("\n    � Least recently accessed %s %s",
                Globals.szFileDate,
                Globals.pszMinimumLastAccess);
      }

      if (Globals.bMinimumLastWrite)
      {
        StrFDateTimeToString(Globals.fdateMinimumLastWrite,  /* map the date */
                             Globals.ftimeMinimumLastWrite,
                             Globals.szFileDate);

        printf ("\n    � Least recently modified %s %s",
                Globals.szFileDate,
                Globals.pszMinimumLastWrite);
      }

    }
  }

  if (seconds)
    printf ("\n[%8u] files, [%9.4f] sec, [%9.3f] files/sec\n",
            Globals.ulFilesScanned,
            seconds,
            ((float)Globals.ulFilesScanned / seconds));

  return NO_ERROR;
}
Esempio n. 3
0
int main(VOID) {



    DATETIME   DateTime = {0};       /* Structure to hold date/time info.   */

    APIRET     rc       = NO_ERROR;  /* Return code                         */



    rc = DosGetDateTime(&DateTime);  /* Retrieve the current date and time  */

    if (rc != NO_ERROR) {

        printf ("DosGetDateTime error : return code = %u\n", rc);

        return 1;

    }



    DateTime.hours = (UCHAR) ((BYTE) DateTime.hours + 1);    /* Set clock ahead

                                                 for Daylight Savings Time  */



    rc = DosSetDateTime(&DateTime);  /* Update the date and time            */



    if (rc!= NO_ERROR) {

        printf ("DosSetDateTime error : return code = %u\n", rc);

        return 1;

    }



    rc = DosGetDateTime(&DateTime);  /* Retrieve the date and time          */



    if (rc!= NO_ERROR) {

        printf ("DosGetDateTime error : return code = %u\n", rc);

        return 1;

    } else {

        printf("Today is %d-%d-%d; the time is now %d:%2.2d\n", DateTime.month,

               DateTime.day, DateTime.year, DateTime.hours, DateTime.minutes);

    }

    return NO_ERROR;

}
Esempio n. 4
0
File: time.c Progetto: DeadZen/qse
int qse_gettime (qse_ntime_t* t)
{
#if defined(_WIN32)
	SYSTEMTIME st;
	FILETIME ft;
	ULARGE_INTEGER li;

	/* 
	 * MSDN: The FILETIME structure is a 64-bit value representing the 
	 *       number of 100-nanosecond intervals since January 1, 1601 (UTC).
	 */

	GetSystemTime (&st);
	if (SystemTimeToFileTime (&st, &ft) == FALSE) return -1;

	li.LowPart = ft.dwLowDateTime;
	li.HighPart = ft.dwHighDateTime;

     /* li.QuadPart is in the 100-nanosecond intervals */
	t->sec = (li.QuadPart / (QSE_NSECS_PER_SEC / 100)) - EPOCH_DIFF_SECS;
	t->nsec = (li.QuadPart % (QSE_NSECS_PER_SEC / 100)) * 100;

	return 0;

#elif defined(__OS2__)

	APIRET rc;
	DATETIME dt;
	qse_btime_t bt;

	/* Can I use DosQuerySysInfo(QSV_TIME_LOW) and 
	 * DosQuerySysInfo(QSV_TIME_HIGH) for this instead? 
	 * Maybe, resolution too low as it returns values 
	 * in seconds. */

	rc = DosGetDateTime (&dt);
	if (rc != NO_ERROR) return -1;

	bt.year = dt.year - QSE_BTIME_YEAR_BASE;
	bt.mon = dt.month - 1;
	bt.mday = dt.day;
	bt.hour = dt.hours;
	bt.min = dt.minutes;
	bt.sec = dt.seconds;
	/*bt.msec = dt.hundredths * 10;*/
	bt.isdst = -1; /* determine dst for me */

	if (qse_timelocal (&bt, t) <= -1) return -1;
	t->nsec = QSE_MSEC_TO_NSEC(dt.hundredths * 10);
	return 0;

#elif defined(__DOS__)

	struct dostime_t dt;
	struct dosdate_t dd;
	qse_btime_t bt;

	_dos_gettime (&dt);
	_dos_getdate (&dd);

	bt.year = dd.year - QSE_BTIME_YEAR_BASE;
	bt.mon = dd.month - 1;
	bt.mday = dd.day;
	bt.hour = dt.hour;
	bt.min = dt.minute;
	bt.sec = dt.second;
	/*bt.msec = dt.hsecond * 10; */
	bt.isdst = -1; /* determine dst for me */

	if (qse_timelocal (&bt, t) <= -1) return -1;
	t->nsec = QSE_MSEC_TO_NSEC(dt.hsecond * 10);
	return 0;

#elif defined(macintosh)
	unsigned long tv;
	
	GetDateTime (&tv);
	
	t->sec = tv;
	tv->nsec = 0;
	
	return 0;

#elif defined(HAVE_GETTIMEOFDAY)
	struct timeval tv;
	int n;

	/* TODO: consider using clock_gettime() if it's avaialble.. -lrt may be needed */
	n = QSE_GETTIMEOFDAY (&tv, QSE_NULL);
	if (n == -1) return -1;

	t->sec = tv.tv_sec;
	t->nsec = QSE_USEC_TO_NSEC(tv.tv_usec);
	return 0;

#else
	t->sec = QSE_TIME (QSE_NULL);
	t->nsec = 0;

	return 0;
#endif
}
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     {
     static DATETIME   dtPrevious ;
     static HDC        hdc ;
     static LONG       xPixelsPerMeter, yPixelsPerMeter ;
     static POINTL     aptlHour   [5] = { 0,-15, 10,0, 0,60, -10,0, 0,-15 },
                       aptlMinute [5] = { 0,-20,  5,0, 0,80,  -5,0, 0,-20 },
                       aptlSecond [2] = { 0,  0,  0,80 } ;
     static WINDOWINFO wi ;
     DATETIME          dt ;
     HPS               hps ;
     INT               iDiamMM, iAngle ;
     POINTL            aptl [3] ;

     switch (msg)
          {
          case WM_CREATE:
               hdc = WinOpenWindowDC (hwnd) ;

               DevQueryCaps (hdc, CAPS_VERTICAL_RESOLUTION,
                                  1L, &yPixelsPerMeter) ;
               DevQueryCaps (hdc, CAPS_HORIZONTAL_RESOLUTION,
                                  1L, &xPixelsPerMeter) ;

               DosGetDateTime (&dtPrevious) ;
               dtPrevious.hours = (dtPrevious.hours * 5) % 60 +
                                   dtPrevious.minutes / 12 ;
               return 0 ;

          case WM_SIZE:
               wi.cxClient = SHORT1FROMMP (mp2) ;
               wi.cyClient = SHORT2FROMMP (mp2) ;

               iDiamMM = min (wi.cxClient * 1000L / xPixelsPerMeter,
                              wi.cyClient * 1000L / yPixelsPerMeter) ;

               wi.cxPixelDiam = xPixelsPerMeter * iDiamMM / 1000 ;
               wi.cyPixelDiam = yPixelsPerMeter * iDiamMM / 1000 ;
               return 0 ;

          case WM_TIMER:
               DosGetDateTime (&dt) ;
               dt.hours = (dt.hours * 5) % 60 + dt.minutes / 12 ;

               hps = WinGetPS (hwnd) ;
               GpiSetColor (hps, CLR_BACKGROUND) ;

               DrawHand (hps, aptlSecond, 2, dtPrevious.seconds, &wi) ;

               if (dt.hours   != dtPrevious.hours ||
                   dt.minutes != dtPrevious.minutes)
                    {
                    DrawHand (hps, aptlHour,   5, dtPrevious.hours,   &wi) ;
                    DrawHand (hps, aptlMinute, 5, dtPrevious.minutes, &wi) ;
                    }

               GpiSetColor (hps, CLR_NEUTRAL) ;

               DrawHand (hps, aptlHour,   5, dt.hours,   &wi) ;
               DrawHand (hps, aptlMinute, 5, dt.minutes, &wi) ;
               DrawHand (hps, aptlSecond, 2, dt.seconds, &wi) ;

               WinReleasePS (hps) ;
               dtPrevious = dt ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ;
               GpiErase (hps) ;

               for (iAngle = 0 ; iAngle < 60 ; iAngle++)
                    {
                    aptl[0].x = 0 ;
                    aptl[0].y = 90 ;

                    RotatePoint    (aptl, 1, iAngle) ;
                    ScalePoint     (aptl, 1, &wi) ;
                    TranslatePoint (aptl, 1, &wi) ;

                    aptl[2].x = aptl[2].y = iAngle % 5 ? 2 : 10 ;

                    ScalePoint (aptl + 2, 1, &wi) ;

                    aptl[0].x -= aptl[2].x / 2 ;
                    aptl[0].y -= aptl[2].y / 2 ;

                    aptl[1].x = aptl[0].x + aptl[2].x ;
                    aptl[1].y = aptl[0].y + aptl[2].y ;

                    GpiMove (hps, aptl) ;
                    GpiBox (hps, DRO_OUTLINEFILL, aptl + 1,
                                 aptl[2].x, aptl[2].y) ;
                    }
               DrawHand (hps, aptlHour,   5, dtPrevious.hours,   &wi) ;
               DrawHand (hps, aptlMinute, 5, dtPrevious.minutes, &wi) ;
               DrawHand (hps, aptlSecond, 2, dtPrevious.seconds, &wi) ;

               WinEndPaint (hps) ;
               return 0 ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }
Esempio n. 6
0
MRESULT EXPENTRY SwapProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) {

  static HWND hwndMenu = (HWND)0;

  switch(msg) {
    case WM_CREATE:
      {
        MRESULT mr = PFNWPStatic(hwnd,msg,mp1,mp2);

        WinSendMsg(hwnd,
                   UM_SETUP,
                   MPVOID,
                   MPVOID);
        return mr;
      }

    case WM_MOUSEMOVE:

      break;

    case WM_PRESPARAMCHANGED:
      {
        char *rootname = "SwapMon";

        switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
          case CLOCK_FRAME:
            rootname = "Clock";
            break;
          case HARD_FRAME:
            rootname = "Hard";
            break;
          case CPU_FRAME:
            rootname = "CPU";
            break;
          case CLP_FRAME:
            rootname = "ClipMon";
            break;
          case MEM_FRAME:
            rootname = "Mem";
            break;
          case TSK_FRAME:
            rootname = "Task";
            break;
        }
        PresParamChanged(hwnd,
                         rootname,
                         mp1,
                         mp2);
        PostMsg(hwnd,
                UM_TIMER,
                MPVOID,
                MPVOID);
        PostMsg(hwnd,
                UM_REFRESH,
                MPVOID,
                MPFROMSHORT(TRUE));
      }
      break;

    case WM_APPTERMINATENOTIFY:
      if(WinQueryWindowUShort(hwnd,QWS_ID) == CPU_FRAME) {
        if(!StartCPUThreads())
          WinDestroyWindow(hwnd);
      }
      break;

    case WM_BUTTON1MOTIONSTART:
      {
        POINTL ptl;

        ptl.x = SHORT1FROMMP(mp1);
        ptl.y = SHORT2FROMMP(mp1);
        WinMapWindowPoints(hwnd,
                           HWND_DESKTOP,
                           &ptl,
                           1L);
        PostMsg(hwndConfig,
                UM_SHOWME,
                MPFROM2SHORT((USHORT)ptl.x,(USHORT)ptl.y),
                mp2);
      }
      return MRFROMSHORT(TRUE);

    case WM_BUTTON2MOTIONSTART:
      {
        TRACKINFO TrackInfo;
        SWP       Position;

        memset(&TrackInfo,0,sizeof(TrackInfo));
        TrackInfo.cxBorder   = 1 ;
        TrackInfo.cyBorder   = 1 ;
        TrackInfo.cxGrid     = 1 ;
        TrackInfo.cyGrid     = 1 ;
        TrackInfo.cxKeyboard = 8 ;
        TrackInfo.cyKeyboard = 8 ;
        WinQueryWindowPos(hwnd,&Position);
        TrackInfo.rclTrack.xLeft   = Position.x ;
        TrackInfo.rclTrack.xRight  = Position.x + Position.cx ;
        TrackInfo.rclTrack.yBottom = Position.y ;
        TrackInfo.rclTrack.yTop    = Position.y + Position.cy ;
        WinQueryWindowPos(HWND_DESKTOP,&Position);
        TrackInfo.rclBoundary.xLeft   = Position.x ;
        TrackInfo.rclBoundary.xRight  = Position.x + Position.cx ;
        TrackInfo.rclBoundary.yBottom = Position.y ;
        TrackInfo.rclBoundary.yTop    = Position.y + Position.cy ;
        TrackInfo.ptlMinTrackSize.x = 0 ;
        TrackInfo.ptlMinTrackSize.y = 0 ;
        TrackInfo.ptlMaxTrackSize.x = Position.cx ;
        TrackInfo.ptlMaxTrackSize.y = Position.cy ;
        TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY ;
        if(WinTrackRect(HWND_DESKTOP,
                        (HPS)0,
                        &TrackInfo)) {
          WinSetWindowPos(hwnd,
                          HWND_TOP,
                          TrackInfo.rclTrack.xLeft,
                          TrackInfo.rclTrack.yBottom,
                          0,
                          0,
                          SWP_MOVE);
          switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
            case SWAP_FRAME:
              WinQueryWindowPos(hwnd,&swpSwap);
              SavePrf("SwapSwp",
                      &swpSwap,
                      sizeof(SWP));
              break;
            case CLOCK_FRAME:
              WinQueryWindowPos(hwnd,&swpClock);
              SavePrf("ClockSwp",
                      &swpClock,
                      sizeof(SWP));
              break;
            case HARD_FRAME:
              WinQueryWindowPos(hwnd,&swpHard);
              SavePrf("HardSwp",
                      &swpHard,
                      sizeof(SWP));
              break;
            case CPU_FRAME:
              WinQueryWindowPos(hwnd,&swpCPU);
              SavePrf("CPUSwp",
                      &swpCPU,
                      sizeof(SWP));
              break;
            case CLP_FRAME:
              WinQueryWindowPos(hwnd,&swpClip);
              SavePrf("ClipSwp",
                      &swpClip,
                      sizeof(SWP));
              break;
            case MEM_FRAME:
              WinQueryWindowPos(hwnd,&swpMem);
              SavePrf("MemSwp",
                      &swpMem,
                      sizeof(SWP));
              break;
            case TSK_FRAME:
              WinQueryWindowPos(hwnd,&swpTask);
              SavePrf("TaskSwp",
                      &swpTask,
                      sizeof(SWP));
              break;
          }
        }
      }
      return MRFROMSHORT(TRUE);

    case WM_BUTTON1DOWN:
      WinSetWindowPos(hwnd,
                      HWND_TOP,
                      0,
                      0,
                      0,
                      0,
                      SWP_ZORDER | SWP_DEACTIVATE);
      return MRFROMSHORT(TRUE);

    case WM_BUTTON1DBLCLK:
    case WM_BUTTON1CLICK:
      if((!fNoMonClick &&
          msg == WM_BUTTON1CLICK) ||
         (fNoMonClick &&
          msg == WM_BUTTON1DBLCLK)) {
        switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
          case HARD_FRAME:
            {
              ULONG ulDriveNum,ulDriveMap,x;

              ulDriveMon = min(ulDriveMon,26);
              if(!DosQCurDisk(&ulDriveNum,
                              &ulDriveMap)) {
                for(x = ulDriveMon + 1;x < 26;x++) {
                  if(ulDriveMap & (1 << x)) {
                    ulDriveMon = x;
                    break;
                  }
                }
                if(x >= 26) {
                  for(x = 3;x < ulDriveMon - 1;x++) {
                    if(ulDriveMap & (1 << x)) {
                      ulDriveMon = x;
                      break;
                    }
                  }
                }
                SavePrf("MonDrive",
                        &ulDriveMon,
                        sizeof(ULONG));
              }
              PostMsg(hwnd,
                      UM_TIMER,
                      MPVOID,
                      MPVOID);
            }
            break;

          case CLP_FRAME:
          case MEM_FRAME:
          case TSK_FRAME:
          case SWAP_FRAME:
          case CLOCK_FRAME:
          case CPU_FRAME:
            {
              USHORT cmd = CPU_PULSE;

              switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
                case MEM_FRAME:
                  cmd = CLOCK_CMDLINE;
                  break;
                case TSK_FRAME:
                  cmd = CPU_KILLPROC;
                  break;
                case CLP_FRAME:
                  cmd = CLOCK_CLIPBOARD;
                  break;
                case SWAP_FRAME:
                  cmd = SWAP_LAUNCHPAD;
                  break;
                case CLOCK_FRAME:
                  cmd = CLOCK_SETTINGS;
                  if((WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) != 0)
                    cmd = CLOCK_CLOCK;
                  break;
              }
              PostMsg(hwnd,
                      WM_COMMAND,
                      MPFROM2SHORT(cmd,0),
                      MPVOID);
            }
            break;
        }
        return MRFROMSHORT(TRUE);
      }
      else
        PostMsg(hwnd,
                UM_TIMER,
                MPVOID,
                MPVOID);
      break;

    case WM_CONTEXTMENU:
      WinInvalidateRect(hwnd,
                        NULL,
                        FALSE);
      WinSendMsg(hwnd,
                 UM_TIMER,
                 MPVOID,
                 MPVOID);
      WinSetWindowPos(hwnd,
                      HWND_TOP,
                      0,
                      0,
                      0,
                      0,
                      SWP_ZORDER | SWP_DEACTIVATE);
      {
        USHORT id;

        id = WinQueryWindowUShort(hwnd,QWS_ID);
        hwndMenu = WinLoadMenu(HWND_DESKTOP,
                               0,
                               id);
        if(hwndMenu) {

          POINTL   ptl;
          SWP      swp;
          ULONG    ulDriveNum,ulDriveMap,x;
          MENUITEM mi;
          char     s[80];

          SetPresParams(hwndMenu,
                        -1,
                        -1,
                        -1,
                        helvtext);
          switch(id) {
            case CLP_FRAME:
              WinSendMsg(hwndMenu,
                         MM_SETITEMATTR,
                         MPFROM2SHORT(CLP_APPEND,FALSE),
                         MPFROM2SHORT(MIA_CHECKED,
                                      ((fClipAppend) ? MIA_CHECKED : 0)));
              break;

            case HARD_FRAME:
              if(!DosQCurDisk(&ulDriveNum,
                              &ulDriveMap)) {
                mi.iPosition = 0;
                mi.hwndSubMenu = (HWND)0;
                mi.hItem = 0L;
                mi.afStyle = MIS_TEXT | MIS_STATIC;
                mi.afAttribute = MIA_FRAMED;
                mi.id = -1;
                sprintf(s,
                        "Current drive is %c:",
                        (char)(ulDriveMon + '@'));
                WinSendMsg(hwndMenu,
                           MM_INSERTITEM,
                           MPFROMP(&mi),
                           MPFROMP(s));
                mi.iPosition = MIT_END;
                for(x = 2;x < 26;x++) {
                  if(ulDriveMap & (1 << x)) {
                    if(x != ulDriveMon - 1) {
                      mi.afStyle = MIS_TEXT;
                      mi.afAttribute = 0;
                      mi.id = HARD_C + (x - 2);
                      if(fShowFreeInMenus)
                        SetDriveText(x + 1,
                                     s);
                      else
                        sprintf(s,
                                "%c:",
                                (char)(x + 'A'));
                      WinSendMsg(hwndMenu,
                                 MM_INSERTITEM,
                                 MPFROMP(&mi),
                                 MPFROMP(s));
                    }
                  }
                }
              }
              break;

            case CLOCK_FRAME:
              WinEnableMenuItem(hwndMenu,
                                CLOCK_VIRTUAL,
                                fDesktops);
              WinEnableMenuItem(hwndMenu,
                                CLOCK_CLIPBOARD,
                                (ClipHwnd != (HWND)0));
              break;

            default:
              break;
          }
          WinQueryWindowPos(hwnd,
                            &swp);
          ptl.x = SHORT1FROMMP(mp1);
          ptl.y = SHORT2FROMMP(mp1);
          WinMapWindowPoints(hwnd,
                             HWND_DESKTOP,
                             &ptl,
                             1L);
          ptl.y = max(ptl.y,swp.y + swp.cy + 4);
          if(!WinPopupMenu(HWND_DESKTOP,
                           hwnd,
                           hwndMenu,
                           ptl.x - 4,
                           ptl.y - 4,
                           0,
                           PU_HCONSTRAIN | PU_VCONSTRAIN |
                           PU_KEYBOARD   | PU_MOUSEBUTTON1)) {
            WinDestroyWindow(hwndMenu);
            hwndMenu = (HWND)0;
          }
        }
      }
      return MRFROMSHORT(TRUE);

    case WM_MENUEND:
      WinSetFocus(HWND_DESKTOP,
                  HWND_DESKTOP);
      WinDestroyWindow((HWND)mp2);
      if(hwndMenu == (HWND)mp2)
        hwndMenu = (HWND)0;
      return 0;

    case UM_SETUP:
      {
        char *rootname = "SwapMon";

        switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
          case SWAP_FRAME:
            SwapHwnd = hwnd;
            swaptick = 0;
            break;
          case CLOCK_FRAME:
            ClockHwnd = hwnd;
            rootname = "Clock";
            break;
          case TSK_FRAME:
            TaskHwnd = hwnd;
            rootname = "Task";
            break;
          case MEM_FRAME:
            MemHwnd = hwnd;
            rootname = "Mem";
            break;
          case HARD_FRAME:
            HardHwnd = hwnd;
            rootname = "Hard";
            break;
          case CPU_FRAME:
            CPUHwnd = hwnd;
            rootname = "CPU";
            PostMsg(hwnd,
                    UM_REFRESH,
                    MPVOID,
                    MPFROMSHORT(TRUE));
            break;
          case CLP_FRAME:
            ClipMonHwnd = hwnd;
            rootname = "ClipMon";
            PostMsg(hwnd,
                    UM_REFRESH,
                    MPVOID,
                    MPFROMSHORT(TRUE));
            break;
        }
        if(!RestorePresParams(hwnd,rootname))
          SetPresParams(hwnd,
                        RGB_WHITE,
                        RGB_BLACK,
                        RGB_BLACK,
                        helvtext);
      }
      PostMsg(hwnd,
              UM_TIMER,
              MPVOID,
              MPVOID);
      return 0;

    case UM_REFRESH:
      switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
        case CLP_FRAME:
          {
            char  s[] = " Clip: [TtBbMmP] + ",*p;
            ULONG fmt[] = {CF_TEXT,CF_DSPTEXT,
                           CF_BITMAP,CF_DSPBITMAP,
                           CF_METAFILE,CF_DSPMETAFILE,
                           CF_PALETTE,0};
            ULONG x,ret;

            if(WinOpenClipbrd(WinQueryAnchorBlock(hwnd))) {
              p = s + 8;
              for(x = 0;fmt[x];x++) {
                ret = WinQueryClipbrdData(WinQueryAnchorBlock(hwnd),
                                          fmt[x]);
                if(!ret)
                  *p = '-';
                p++;
              }
              p += 2;
              if(!fClipAppend)
                *p = 0;
              WinCloseClipbrd(WinQueryAnchorBlock(hwnd));
            }
            else
              strcpy(s + 7,
                     "Can't open. ");
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpClip,
                           s);
          }
          break;

        case CPU_FRAME:
          {
            char        s[32];
            ULONG       percent,lastaverage;
            static BOOL lastavgset = 0;

            *s = 0;
            if(mp2) {
              strcpy(s," CPU: -% ");
              if(fAverage)
                strcat(s,"Avg: -%) ");
            }
            else {
              percent = ((MaxCount - (ULONG)mp1) * 100) / MaxCount;
              lastaverage = AveCPU;
              AveCPU = (((AveCPU * NumAveCPU) + percent) /
                        ((ULONG)NumAveCPU + 1));
              NumAveCPU++;
              if(!NumAveCPU)
                NumAveCPU = 65535;
              if(percent != LastPercent ||
                 (AveCPU != lastaverage &&
                  fAverage) ||
                 NumAveCPU == 1 ||
                 lastavgset != fAverage) {
                lastavgset = fAverage;
                LastPercent = percent;
                sprintf(s,
                        " CPU: %lu%% ",
                        percent);
                if(fAverage)
                  sprintf(s + strlen(s),
                          "(Avg: %lu%%) ",
                          AveCPU);
              }
            }
            if(*s)
              SetMonitorSize(hwnd,
                             hwndMenu,
                             &swpCPU,
                             s);
          }
          break;
      }
      return 0;

    case WM_TIMER:
      if(fSwapFloat &&
         !hwndMenu)
        WinSetWindowPos(hwnd,
                        HWND_TOP,
                        0,
                        0,
                        0,
                        0,
                        SWP_ZORDER | SWP_SHOW);
      if(WinQueryWindowUShort(hwnd,QWS_ID) == CLP_FRAME) {
        if(!ClipHwnd)
          WinDestroyWindow(hwnd);
        else
          TakeClipboard();
      }
      return 0;

    case UM_TIMER:
      switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
        case CLP_FRAME:
          ClipMonHwnd = hwnd;
          WinSendMsg(hwnd,
                     WM_TIMER,
                     MPVOID,
                     MPVOID);
          break;

        case CPU_FRAME:
          CPUHwnd = hwnd;
          WinSendMsg(hwnd,
                     WM_TIMER,
                     MPVOID,
                     MPVOID);
          break;

        case HARD_FRAME:
          {
            char s[80];

            HardHwnd = hwnd;
            SetDriveText(ulDriveMon,
                         s);
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpHard,
                           s);
          }
          break;

        case SWAP_FRAME:
          {
            FILEFINDBUF3 ffb;
            ULONG        nm = 1,fl = SWP_SIZE | SWP_SHOW | SWP_MOVE,
                         sh,sl,nh;
            HDIR         hdir = HDIR_CREATE;
            FSALLOCATE   fsa;
            char         s[128],ss[8],sss[8],mb,smb;
            static ULONG lastcbFile = 0;
            static BOOL  warned = FALSE;
            static char  SwapperDat[CCHMAXPATH] = "";

            strcpy(s,
                   " Unable to locate SWAPPER.DAT. ");
            SwapHwnd = hwnd;
            if(!*SwapperDat)
              FindSwapperDat(SwapperDat);
            if(*SwapperDat) {
              DosError(FERR_DISABLEHARDERR);
              if(!DosFindFirst(SwapperDat,
                               &hdir,
                               FILE_NORMAL | FILE_HIDDEN |
                               FILE_SYSTEM | FILE_ARCHIVED | FILE_READONLY,
                               &ffb,
                               sizeof(ffb),
                               &nm,
                               FIL_STANDARD)) {
                DosFindClose(hdir);
                if(ffb.cbFile != lastcbFile && lastcbFile)
                  swaptick = 9;
                lastcbFile = ffb.cbFile;
                DosError(FERR_DISABLEHARDERR);
                if(!DosQueryFSInfo(toupper(*SwapperDat) - '@',
                                   FSIL_ALLOC,
                                   &fsa,
                                   sizeof(FSALLOCATE)))
                  nm = fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector);
                else
                  nm = 0;
                if(nm <= 32768 * 1024) {
                  swaptick = 10;
                  if(!warned) {
                    SetPresParams(hwnd,
                                  RGB_RED,
                                  -1,
                                  -1,
                                  NULL);
                    warned = TRUE;
                    DosBeep(250,15);
                  }
                }
                else if(warned) {
                  PostMsg(hwnd,
                          UM_SETUP,
                          MPVOID,
                          MPVOID);
                  warned = FALSE;
                }
                mb = MakeNumber(nm,
                                &nh,
                                &sl);
                *sss = 0;
                if(sl)
                  sprintf(sss,
                          ".%02lu",
                          sl);
                smb = MakeNumber(ffb.cbFile,
                                 &sh,
                                 &sl);
                *ss = 0;
                if(sl)
                  sprintf(ss,
                          ".%02lu",
                          sl);
                sprintf(s,
                        " Swap: %lu%s%cb ",
                        sh,
                        ss,
                        smb);
                if(fShowSwapFree)
                  sprintf(s + strlen(s),
                          "(%lu%s%cb free) ",
                          nh,
                          sss,
                          mb);
              }
            }
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpSwap,
                           s);
          }
          break;

        case TSK_FRAME:
          {
            PROCESSINFO  *ppi;
            BUFFHEADER   *pbh = NULL;
            MODINFO      *pmi;
            long          numprocs = -1,numthreads = -1;
            char          s[80];

            if(!DosAllocMem((PVOID)&pbh,
                            USHRT_MAX + 4096,
                            PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE)) {
              if(!DosQProcStatus(pbh,
                                 USHRT_MAX)) {
                numprocs = numthreads = 0;
                ppi = pbh->ppi;
                while(ppi->ulEndIndicator != PROCESS_END_INDICATOR ) {
                  pmi = pbh->pmi;
                  while(pmi &&
                        ppi->hModRef != pmi->hMod)
                    pmi = pmi->pNext;
                  if(pmi) {
                    numprocs++;
                    numthreads += ppi->usThreadCount;
                  }
                  ppi = (PPROCESSINFO)(ppi->ptiFirst + ppi->usThreadCount);
                }
              }
              DosFreeMem(pbh);
              sprintf(s,
                      " Procs: %ld  Thrds: %ld ",
                      numprocs,
                      numthreads);
              SetMonitorSize(hwnd,
                             hwndMenu,
                             &swpTask,
                             s);
            }
          }
          break;

        case MEM_FRAME:
          {
            ULONG sh,sl,nh,amem;
            char  s[128],ss[8],sss[8],mb,smb;

            strcpy(s,
                   "Can't check virtual memory.");
            MemHwnd = hwnd;
            if(!DosQuerySysInfo(QSV_TOTAVAILMEM,
                                QSV_TOTAVAILMEM,
                                &amem,
                                sizeof(amem))) {
              mb = MakeNumber(amem,
                              &nh,
                              &sl);
              *ss = 0;
              if(sl)
                sprintf(ss,
                        ".%02lu",
                        sl);
              sprintf(s,
                      " VMem: %lu%s%cb ",
                      nh,
                      ss,
                      mb);
            }
            if(fShowPMem) {
              if(!Dos16MemAvail(&amem)) {
                mb = MakeNumber(amem,
                                &nh,
                                &sl);
                *ss = 0;
                if(sl)
                  sprintf(ss,
                          ".%02lu",
                          sl);
                sprintf(s + strlen(s),
                        " PMem: %lu%s%cb ",
                        nh,
                        ss,
                        mb);
              }
            }
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpMem,
                           s);
          }
          break;

        case CLOCK_FRAME:
          {
            char      s[80];
            DATETIME  dt;

            ClockHwnd = hwnd;
            if(!DosGetDateTime(&dt)) {
              sprintf(s,
                      " %0*u:%02u%s ",
                      ((ampm) ? 0 : 2),
                      (dt.hours % ((ampm) ? 12 : 24)) +
                       ((ampm && !(dt.hours % 12)) ? 12 : 0),
                      dt.minutes,
                      ((ampm) ? (dt.hours > 11) ? "pm" : "am" : ""));
              if(showdate)
                sprintf(s + strlen(s),
                        "%02u/%02u ",
                        dt.month,
                        dt.day);
            }
            else
              strcpy(s,"Unknown time");
            SetMonitorSize(hwnd,
                           hwndMenu,
                           &swpClock,
                           s);
          }
          break;
      }
      return 0;

    case WM_COMMAND:
      {
        BOOL ctrl,shift;

        ctrl = ((WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000) != 0);
        shift = ((WinGetKeyState(HWND_DESKTOP,VK_SHIFT) & 0x8000) != 0);

        switch(SHORT1FROMMP(mp1)) {
          case CLP_CLEAR:
            if(WinOpenClipbrd(WinQueryAnchorBlock(hwnd))) {
              WinEmptyClipbrd(WinQueryAnchorBlock(hwnd));
              WinCloseClipbrd(WinQueryAnchorBlock(hwnd));
              PostMsg(hwnd,
                      UM_REFRESH,
                      MPVOID,
                      MPVOID);
            }
            break;

          case CLP_APPEND:
            fClipAppend = (fClipAppend) ? FALSE : TRUE;
            SavePrf("ClipAppend",
                    &fClipAppend,
                    sizeof(BOOL));
            PostMsg(hwnd,
                    UM_REFRESH,
                    MPVOID,
                    MPVOID);
            if(ClipSetHwnd)
              PostMsg(ClipSetHwnd,
                      UM_REFRESH,
                      MPVOID,
                      MPVOID);
            break;

          case MSE_HELP:
            ViewHelp(hwnd,
                     "Monitors page");
            break;

          case CPU_PULSE:
            {
              PROGDETAILS pgd;

              WinSetWindowPos(hwnd,
                              HWND_TOP,
                              0,
                              0,
                              0,
                              0,
                              SWP_ACTIVATE | SWP_FOCUSACTIVATE);
              memset(&pgd,
                     0,
                     sizeof(pgd));
              pgd.Length = sizeof(pgd);
              pgd.swpInitial.fl = SWP_ACTIVATE | SWP_ZORDER;
              pgd.swpInitial.hwndInsertBehind = HWND_TOP;
              pgd.progt.fbVisible = SHE_VISIBLE;
              pgd.progt.progc = PROG_DEFAULT;
              pgd.pszExecutable = "PULSE.EXE";
              if(WinStartApp(CPUHwnd,
                             &pgd,
                             NULL,
                             NULL,
                             0)) {
                if(CPUHwnd) {
                  closethreads = 1;
                  DosSleep(1);
                  PostMsg(CPUHwnd,
                          UM_REFRESH,
                          MPVOID,
                          MPFROMSHORT(TRUE));
                }
              }
            }
            break;

          case CPU_RESET:
            AveCPU = 0;
            NumAveCPU = 0;
            break;

          case CLOCK_VIRTUAL:
          case CLOCK_SWITCHLIST:
          case CLOCK_CMDLINE:
          case CLOCK_CLIPBOARD:
          case CLOCK_CALCULATOR:
          case HARD_FM2:
          case MSE_FRAME:
            {
              ULONG msg2 = UM_SHOWME;
              MPARAM mp12 = 0,mp22 = 0;
              HWND   hwndP = hwndConfig;

              switch(SHORT1FROMMP(mp1)) {
                case CLOCK_CMDLINE:
                  mp12 = MPFROMLONG(((WinGetKeyState(HWND_DESKTOP,VK_CTRL) & 0x8000) != 0));
                  msg2 = UM_CMDLINE;
                  break;
                case CLOCK_CLIPBOARD:
                  msg2 = UM_CLIPMGR;
                  hwndP = ObjectHwnd3;
                  break;
                case CLOCK_SWITCHLIST:
                  msg2 = UM_SWITCHLIST;
                  break;
                case CLOCK_VIRTUAL:
                  msg2 = UM_VIRTUAL;
                  break;
                case CLOCK_CALCULATOR:
                  msg2 = UM_CALC;
                  break;
                case HARD_FM2:
                  msg2 = UM_STARTWIN;
                  mp12 = MPFROM2SHORT(C_STARTFM2,0);
                  break;
              }
              PostMsg(hwndP,
                      msg2,
                      mp12,
                      mp22);
            }
            break;

          case CLOCK_SETTINGS:
          case CLOCK_CLOCK:
          case SWAP_LAUNCHPAD:
          case SWAP_WARPCENTER:
          case SWAP_CONNECTIONS:
          case SWAP_INFO:
          case SWAP_SETTINGS:
          case SWAP_SYSTEM:
          case SWAP_TEMPS:
          case SWAP_FM2:
          case HARD_OPEN:
          case CVR_COLORPALETTE:
          case CVR_HICOLORPALETTE:
          case CVR_FONTPALETTE:
          case CPU_KILLPROC:
          case CPU_HARDWARE:
            {
              char *p = "<WP_CLOCK>",*pp = defopen;
              char s[8];

              switch(SHORT1FROMMP(mp1)) {
                case HARD_OPEN:
                  sprintf(s,
                          "%c:\\",
                          (char)(ulDriveMon + '@'));
                  p = s;
                  break;
                case SWAP_FM2:
                  p = "<FM3_Folder>";
                  break;
                case SWAP_TEMPS:
                  p = "<WP_TEMPS>";
                  break;
                case SWAP_SYSTEM:
                  p = "<WP_OS2SYS>";
                  break;
                case SWAP_SETTINGS:
                  p = "<WP_CONFIG>";
                  break;
                case SWAP_INFO:
                  p = "<WP_INFO>";
                  break;
                case SWAP_CONNECTIONS:
                  p = "<WP_CONNECTIONSFOLDER>";
                  break;
                case SWAP_WARPCENTER:
                  p = "<WP_WARPCENTER>";
                  break;
                case SWAP_LAUNCHPAD:
                  p = "<WP_LAUNCHPAD>";
                  break;
                case CLOCK_SETTINGS:
                  pp = setopen;
                  break;
                case CVR_COLORPALETTE:
                  p = "<WP_LORESCLRPAL>";
                  break;
                case CVR_HICOLORPALETTE:
                  p = "<WP_HIRESCLRPAL>";
                  break;
                case CVR_FONTPALETTE:
                  p = "<WP_FNTPAL>";
                  break;
                case CPU_KILLPROC:
                  p = "<FM/2_KILLPROC>";
                  break;
                case CPU_HARDWARE:
                  p = "<WP_HWMGR>";
                  break;
              }
              OpenObject(p,
                         pp);
            }
            break;

          case HARD_VDIR:
            {
              PROGDETAILS pgd;
              char        s[36];

              sprintf(s,
                      "/C VDIR.CMD %c:\\",
                      (char)(ulDriveMon + '@'));
              memset(&pgd,
                     0,
                     sizeof(pgd));
              pgd.Length = sizeof(pgd);
              pgd.swpInitial.fl = SWP_MINIMIZE | SWP_ACTIVATE | SWP_ZORDER;
              pgd.swpInitial.hwndInsertBehind = HWND_TOP;
              pgd.progt.fbVisible = SHE_VISIBLE;
              pgd.progt.progc = PROG_DEFAULT;
              pgd.pszExecutable = "CMD.EXE";
              WinStartApp((HWND)0,
                          &pgd,
                          s,
                          NULL,
                          0);
            }
            break;

          case HARD_CHKDSK:
            {
              PROGDETAILS pgd;
              char        s[8];

              WinSetWindowPos(hwnd,
                              HWND_TOP,
                              0,
                              0,
                              0,
                              0,
                              SWP_ACTIVATE | SWP_FOCUSACTIVATE);
              sprintf(s,
                      "%c:",
                      (char)(ulDriveMon + '@'));
              memset(&pgd,
                     0,
                     sizeof(pgd));
              pgd.Length = sizeof(pgd);
              pgd.swpInitial.fl = SWP_ACTIVATE | SWP_ZORDER;
              pgd.swpInitial.hwndInsertBehind = HWND_TOP;
              pgd.progt.fbVisible = SHE_VISIBLE;
              pgd.progt.progc = PROG_DEFAULT;
              pgd.pszExecutable = "PMCHKDSK.EXE";
              WinStartApp((HWND)0,
                          &pgd,
                          s,
                          NULL,
                          0);
            }
            break;

          default:
            if(SHORT1FROMMP(mp1) >= HARD_C &&
               SHORT1FROMMP(mp1) <= HARD_C + 24) {
              ulDriveMon = (SHORT1FROMMP(mp1) - HARD_C) + 3;
              PostMsg(hwnd,
                      UM_TIMER,
                      MPVOID,
                      MPVOID);
              if(ctrl)
                PostMsg(hwnd,
                        WM_COMMAND,
                        MPFROM2SHORT(HARD_OPEN,0),
                        MPVOID);
              else if(shift)
                PostMsg(hwnd,
                        WM_COMMAND,
                        MPFROM2SHORT(HARD_VDIR,0),
                        MPVOID);
            }
            break;
        }
      }
      return 0;

    case WM_DESTROY:
      switch(WinQueryWindowUShort(hwnd,QWS_ID)) {
        case SWAP_FRAME:
          SwapHwnd = (HWND)0;
          break;
        case CLOCK_FRAME:
          ClockHwnd = (HWND)0;
          break;
        case HARD_FRAME:
          HardHwnd = (HWND)0;
          break;
        case CPU_FRAME:
          closethreads = 1;
          DosSleep(1);
          CPUHwnd = (HWND)0;
          break;
        case CLP_FRAME:
          ClipMonHwnd = (HWND)0;
          break;
        case MEM_FRAME:
          MemHwnd = (HWND)0;
          break;
        case TSK_FRAME:
          TaskHwnd = (HWND)0;
          break;
      }
      break;
  }
  return PFNWPStatic(hwnd,msg,mp1,mp2);
}
Esempio n. 7
0
void RNG_SystemInfoForRNG(void)
{
   unsigned long *plong = 0;
   PTIB ptib;
   PPIB ppib;
   APIRET rc = NO_ERROR;
   DATETIME dt;
   COUNTRYCODE cc = {0};
   COUNTRYINFO ci = {0};
   unsigned long actual = 0;
   char path[_MAX_PATH]="";
   char fullpath[_MAX_PATH]="";
   unsigned long pathlength = sizeof(path);
   FSALLOCATE fsallocate;
   FILESTATUS3 fstatus;
   unsigned long defaultdrive = 0;
   unsigned long logicaldrives = 0;
   unsigned long sysInfo[QSV_MAX] = {0};
   char buffer[20];
   int nBytes = 0;

   nBytes = RNG_GetNoise(buffer, sizeof(buffer));
   RNG_RandomUpdate(buffer, nBytes);
   
   /* allocate memory and use address and memory */
   plong = (unsigned long *)malloc(sizeof(*plong));
   RNG_RandomUpdate(&plong, sizeof(plong));
   RNG_RandomUpdate(plong, sizeof(*plong));
   free(plong);

   /* process info */
   rc = DosGetInfoBlocks(&ptib, &ppib);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(ptib, sizeof(*ptib));
      RNG_RandomUpdate(ppib, sizeof(*ppib));
   }

   /* time */
   rc = DosGetDateTime(&dt);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&dt, sizeof(dt));
   }

   /* country */
   rc = DosQueryCtryInfo(sizeof(ci), &cc, &ci, &actual);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&cc, sizeof(cc));
      RNG_RandomUpdate(&ci, sizeof(ci));
      RNG_RandomUpdate(&actual, sizeof(actual));
   }

   /* current directory */
   rc = DosQueryCurrentDir(0, path, &pathlength);
   strcat(fullpath, "\\");
   strcat(fullpath, path);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(fullpath, strlen(fullpath));
      // path info
      rc = DosQueryPathInfo(fullpath, FIL_STANDARD, &fstatus, sizeof(fstatus));
      if (rc == NO_ERROR)
      {
         RNG_RandomUpdate(&fstatus, sizeof(fstatus));
      }
   }

   /* file system info */
   rc = DosQueryFSInfo(0, FSIL_ALLOC, &fsallocate, sizeof(fsallocate));
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&fsallocate, sizeof(fsallocate));
   }

   /* drive info */
   rc = DosQueryCurrentDisk(&defaultdrive, &logicaldrives);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&defaultdrive, sizeof(defaultdrive));
      RNG_RandomUpdate(&logicaldrives, sizeof(logicaldrives));
   }

   /* system info */
   rc = DosQuerySysInfo(1L, QSV_MAX, (PVOID)&sysInfo, sizeof(ULONG)*QSV_MAX);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&sysInfo, sizeof(sysInfo));
   }

   // now let's do some files
   ReadSystemFiles();

   /* more noise */
   nBytes = RNG_GetNoise(buffer, sizeof(buffer));
   RNG_RandomUpdate(buffer, nBytes);
}