Ejemplo n.º 1
0
/**********************************************************************
 * Function: CopyClipBoardData2TempFile
 * Info    : Check clipboard for text data and copy them to temp file
 * Result  : NO_ERROR, ERROR_ACCESS_DENIED, ERROR_OPEN_FAILED
 **********************************************************************/
ULONG CopyClipBoardData2TempFile(void)
{

  ULONG Result = NO_ERROR, MsgID;
  PSZ pszMem;
  FILE *fp;
  int c;

  if (WinOpenClipbrd(Hab))
  {
    pszMem = (PSZ) WinQueryClipbrdData(Hab, CF_TEXT);
    if (NULL == pszMem)
     Result = ERROR_INVALID_DATA;
    else
    {
      if (NULL != (fp = fopen(TempFile, "wb")))
      {
        while (0 != (c = (int)(*pszMem)))
        {
         fputc(c, fp);
         ++pszMem;
        }
        fclose(fp);

      }
      else
       Result = ERROR_OPEN_FAILED;
    }

    WinCloseClipbrd(Hab);

  }
  else
   Result = ERROR_ACCESS_DENIED;

  if (NO_ERROR != Result)
  {
   switch(Result)
   {
    case ERROR_INVALID_DATA:
      MsgID = IDS_INVALID_CLIPBOARD_DATA;
     break;

    case ERROR_ACCESS_DENIED:
      MsgID = IDS_NO_CLIPBOARD_ACCESS;
     break;

    default:
      MsgID = IDS_GENERAL_PROCESS_FAILURE;
     break;

   }

   Len = WinLoadString(Hab, hRessourceModule, MsgID,
                       MSGSTRN_MAXLEN, Msg);
   WinMessageBox(HWND_DESKTOP, hwndMainDialog, Msg, NULL, 0, MB_ERROR | MB_OK);
  }
  return Result;

}
Ejemplo n.º 2
0
void clipsrv(void *foo) {
    HAB hab;
    HMQ hmq;
    ULONG Cmd;
    ULONG len;
    char *text;
    void *shmem = "the text";
    
    hab = NULLHANDLE;

    if ((WinOpenClipbrd(hab) == TRUE) &&
        ((text = (char *) WinQueryClipbrdData(hab, CF_TEXT)) != 0))
    {
        DosGetSharedMem(text, PAG_READ);
        len = strlen(text);
        puts(text);
    }
    WinCloseClipbrd(hab);
    
    len = strlen(shmem);
    if (len) {
        DosAllocSharedMem((void **)&text,
                          0,
                          len + 1,
                          PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE | OBJ_GETTABLE);
        strcpy(text, shmem);
    }
    
    if (WinOpenClipbrd(hab) == TRUE) {
        if (!WinSetClipbrdData(hab, (ULONG) text, CF_TEXT, CFI_POINTER))
            DosBeep(100, 1500);
        WinCloseClipbrd(hab);
    }
}
Ejemplo n.º 3
0
// *******************************************************************************
// FUNCTION:     GetBitmapFromClipboard
//
// FUNCTION USE: Retrieves bitmap data from the clipboard
//
// DESCRIPTION:  This function is used to handle the paste functionality, by 
//               retrieving bitmap data (CF_BITMAP) from the clipboard.  The
//               function will set a bitmap into an HPS if passed a valid PS
//               handle.
//
//               NOTE: This routine has been slightly modified from the routine
//                     used in the Chapter 4 sample program.
//
// PARAMETERS:   HPS      Presentation space handle to place the bitmap in.
//
// RETURNS:      TRUE     success
//               FALSE    error
//
// HISTORY:
//
// *******************************************************************************
HBITMAP GetBitmapFromClipboard(HPS hpsSource)
{
 HAB     habTemp;
 HBITMAP hbmTemp;
 APIRET  rc;

 static HBITMAP hbmClip;

 // --------------------------------------------------------------------------           
 // Get an anchor block handle                                                           
 // --------------------------------------------------------------------------           
 habTemp = WinQueryAnchorBlock(HWND_DESKTOP);                                                            

 // --------------------------------------------------------------------------             
 // Open the clipboard                                                              
 // --------------------------------------------------------------------------             
 rc = WinOpenClipbrd (habTemp);                                                      

 // --------------------------------------------------------------------------                  
 // If we get an error opening, return FALSE and post message  
 // --------------------------------------------------------------------------                  
 if (!rc)  
  {                                                                                   
   return rc;                                                                         
  }                                                                                   
                                                                                 
 // --------------------------------------------------------------------------                 
 // Get the bitmap data out of the clipboard                                 
 // --------------------------------------------------------------------------                 
 hbmTemp = (HBITMAP) WinQueryClipbrdData (habTemp, CF_BITMAP);                        

 // --------------------------------------------------------------------------                       
 // WinQueryClipbrdData will return a NULLHANDLE if there is no 
 // bitmap data in the clipboard or if an error occurred.
 // --------------------------------------------------------------------------             
 if (hbmTemp != NULLHANDLE)                                                        
  {                                                                                
   // --------------------------------------------------------------------------                     
   // Duplicate our bitmap handle.                                                            
   // --------------------------------------------------------------------------                     
   hbmClip = DuplicateBitmap (hbmTemp, hpsSource);                                          
   if (hbmClip == NULLHANDLE)                                                     
    {                                                                              
     DisplayMessages(NULLHANDLE, "Error Duplicating Bitmap", MSG_EXCLAMATION);     
    }                                                                              
  }                                                                                

 // --------------------------------------------------------------------------                          
 // Close the clipboard and return our bitmap handle                                                
 // --------------------------------------------------------------------------                          
 WinCloseClipbrd (habTemp);                                                           
 return hbmClip;
}
Ejemplo n.º 4
0
char *get_clipboard (void)
{
    char   *clipdata = NULL;

    create_pm ();
    if (WinOpenClipbrd (hab0) == TRUE)
    {
        clipdata = (char *) WinQueryClipbrdData (hab0, CF_TEXT);
        if (clipdata != NULL)
        {
            // make a local copy
            clipdata = strdup (clipdata);
        }
    }
    
    WinCloseClipbrd (hab0);
    destroy_pm ();

    return clipdata;
}
Ejemplo n.º 5
0
bool GetClipboardContents(char *buffer, const char *last)
{
    /* XXX -- Currently no clipboard support implemented with GCC */
#ifndef __INNOTEK_LIBC__
    HAB hab = 0;

    if (WinOpenClipbrd(hab))
    {
        const char *text = (const char*)WinQueryClipbrdData(hab, CF_TEXT);

        if (text != NULL)
        {
            strecpy(buffer, text, last);
            WinCloseClipbrd(hab);
            return true;
        }

        WinCloseClipbrd(hab);
    }
#endif
    return false;
}
Ejemplo n.º 6
0
 int icqskin_queryClipboard(HICQ icq, int sz, char *buffer)
 {
    HAB  hab   = icqQueryAnchorBlock(icq);
    char *ptr;

    *buffer = 0;

    if(!WinOpenClipbrd(hab))
       return -1;

    ptr = (char *) WinQueryClipbrdData(hab , CF_TEXT);

    if(ptr)
    {
       strncpy(buffer,ptr,sz);
       *(buffer+sz) = '0';
    }

    WinCloseClipbrd(hab);

    return strlen(buffer);
 }
Ejemplo n.º 7
0
/*-------------------------------------------------------------------------
                            ActMsgContextMenu
--------------------------------------------------------------------------*/
MRESULT ActMsgContextMenu( WNDATTR *wndattr, USHORT x, USHORT y )
{
 BOOL state;

   if (Popup == NULLHANDLE)
      return MRFROMSHORT( TRUE );

   if (MateScrollWnd != NULLHANDLE) {
      if (WinIsWindow( wndattr->hab, MateScrollWnd ) == FALSE)
         MateScrollWnd = NULLHANDLE;
   }

   state = (LPListMarkedLines( wndattr->list ) == 0);
   SetAttr( CMD_COPY, MIA_DISABLED, state );
   SetAttr( CMD_UNMARK, MIA_DISABLED, state );
   SetAttr( CMD_REARRANGE, MIA_DISABLED, state );

   WinOpenClipbrd( wndattr->hab );
   state = (WinQueryClipbrdData( wndattr->hab, CF_TEXT ) == 0);
   WinCloseClipbrd( wndattr->hab );
   SetAttr( CMD_PASTE, MIA_DISABLED, state );

   state = (WinQueryClipbrdViewer( wndattr->hab ) == wndattr->Client);
   SetAttr( CMD_ACCUM, MIA_CHECKED, state );

   state = (MateScrollWnd != NULLHANDLE);
   SetAttr( CMD_MATE, MIA_CHECKED, state );

   WinPopupMenu( wndattr->Frame,
                 wndattr->Frame,
                 Popup,
                 x, y, CMD_ABOUT,
                 PU_HCONSTRAIN | PU_VCONSTRAIN | PU_POSITIONONITEM |
                 PU_KEYBOARD | PU_MOUSEBUTTON1 | PU_MOUSEBUTTON2 );

   return MRFROMSHORT( FALSE );
}
Ejemplo n.º 8
0
PRBool nsClipboard::GetClipboardDataByID(ULONG ulFormatID, const char *aFlavor)
{
  PVOID pDataMem;
  PRUint32 NumOfBytes;
  PRBool TempBufAllocated = PR_FALSE;

  PVOID pClipboardData = reinterpret_cast<PVOID>(WinQueryClipbrdData( 0, ulFormatID ));

  if (!pClipboardData) 
    return PR_FALSE;

  if (strstr( aFlavor, "text/" ))  // All text/.. flavors are null-terminated
  {
    pDataMem = pClipboardData;

    if (ulFormatID == CF_TEXT)     // CF_TEXT is one byte character set
    {
      PRUint32 NumOfChars = strlen( static_cast<char*>(pDataMem) );
      NumOfBytes = NumOfChars;

      if (!strcmp( aFlavor, kUnicodeMime ))  // Asked for unicode, but only plain text available.  Convert it!
      {
        nsAutoChar16Buffer buffer;
        PRInt32 bufLength;
        MultiByteToWideChar(0, static_cast<char*>(pDataMem), NumOfChars,
                            buffer, bufLength);
        pDataMem = ToNewUnicode(nsDependentString(buffer.Elements()));
        TempBufAllocated = PR_TRUE;
        NumOfBytes = bufLength * sizeof(UniChar);
      }

    }
    else                           // All other text/.. flavors are in unicode
    {
      PRUint32 NumOfChars = UniStrlen( static_cast<UniChar*>(pDataMem) );
      NumOfBytes = NumOfChars * sizeof(UniChar);
      PVOID pTempBuf = nsMemory::Alloc(NumOfBytes);
      memcpy(pTempBuf, pDataMem, NumOfBytes);
      pDataMem = pTempBuf;
      TempBufAllocated = PR_TRUE;
    }

    // DOM wants LF only, so convert from CRLF
    nsLinebreakHelpers::ConvertPlatformToDOMLinebreaks( aFlavor, &pDataMem,   // pDataMem could be reallocated !!
                                                        reinterpret_cast<PRInt32*>(&NumOfBytes) );  // yuck

  }
  else                             // Assume rest of flavors are binary data
  {
    if (ulFormatID == CF_BITMAP)
    {
      if (!strcmp( aFlavor, kJPEGImageMime ))
      {
        // OS2TODO  Convert bitmap to jpg
#ifdef DEBUG
        printf( "nsClipboard:: No JPG found on clipboard; need to convert BMP\n");
#endif
      }
      else if (!strcmp( aFlavor, kGIFImageMime ))
      {
        // OS2TODO  Convert bitmap to gif
#ifdef DEBUG
        printf( "nsClipboard:: No GIF found on clipboard; need to convert BMP\n");
#endif
      }
      else if (!strcmp( aFlavor, kPNGImageMime ))
      {
        // OS2TODO  Convert bitmap to png
#ifdef DEBUG
        printf( "nsClipboard:: No PNG found on clipboard; need to convert BMP\n");
#endif
      }
    }
    else
    {
      pDataMem = static_cast<PBYTE>(pClipboardData) + sizeof(PRUint32);
      NumOfBytes = *(static_cast<PRUint32*>(pClipboardData));
    }
  }

  nsCOMPtr<nsISupports> genericDataWrapper;
  nsPrimitiveHelpers::CreatePrimitiveForData( aFlavor, pDataMem, NumOfBytes, getter_AddRefs(genericDataWrapper) );
#ifdef DEBUG
  nsresult errCode =
#endif
  mTransferable->SetTransferData( aFlavor, genericDataWrapper, NumOfBytes );
#ifdef DEBUG
  if (errCode != NS_OK)
    printf( "nsClipboard:: Error setting data into transferable\n" );
#endif

  if (TempBufAllocated)
    nsMemory::Free(pDataMem);

  return PR_TRUE;
}
/*********************************************************************
 *  Name: EditPaste
 *
 *  Description : Processes the Edit menu's Paste item.
 *
 *  Concepts : Called whenever Paste from the Edit menu is selected
 *             Sends a MLM_PASTE message to the MLE control.
 *
 *  API's : WinSendMsg
 *
 *  Parameters : mp2 - Message parameter
 *
 *  Returns: Void
 *
 ****************************************************************/
VOID EditPaste(MPARAM mp1, MPARAM mp2)
{
   HAB hab;
   PCHAR pchClipText;
   APIRET rc;
   ULONG  BidiAttr;
   BOOL   fSetClipConv;
   PCHAR  pCompareText;
   BOOL   fSuccess;


   szPasteText[0] = '\0'; /* Init */


   //
   // Check if we have to set the 'Clipboard Conversion'
   // BidiAttribute, and if so - to which value.
   //
   switch(SHORT1FROMMP(mp1)) {

      case IDM_EDITPASTE_NOCONV:
         BidiAttr     = 0L;
         fSetClipConv = TRUE;
         pCompareText = szCopyImplicitText;
         break;

      case IDM_EDITPASTE_CONV_VISUAL:
         BidiAttr     = BDA_TEXTTYPE_VISUAL | BDA_INIT| BDA_LEVEL;
         fSetClipConv = TRUE;
         pCompareText = szCopyVisualText;
         break;

      case IDM_EDITPASTE_CONV_IMPLICIT:
         BidiAttr     = BDA_TEXTTYPE_IMPLICIT | BDA_INIT| BDA_LEVEL;
         fSetClipConv = TRUE;
         pCompareText = szCopyImplicitText;
         break;

      case IDM_EDITPASTE_AUTOCONV:
      default:
         BidiAttr     = 0L;
         fSetClipConv = FALSE;
         pCompareText = szCopyImplicitText;

   } /* end switch */


   hab =  WinQueryAnchorBlock( hwndMain);
   WinOpenClipbrd  ( hab ) ;

   //
   // Here we set (if necessary) the clipboard conversion attr
   //
   if (fSetClipConv == TRUE)
       WinSetLangInfo (NULLHANDLE,
                       LI_BD_CLIP_CONV_ATTR,
                       BidiAttr,
                       0L,
                       (ULONG)CF_TEXT,
                       0L);



   pchClipText =  (PCHAR) WinQueryClipbrdData (hab, CF_TEXT ) ;
   if (pchClipText != 0) {

      //
      // Get the clipboard text, and compare it to pCompareText.
      //
      strcpy(szPasteText, pchClipText);


      //if (strcmp( szPasteText, pCompareText) != 0) {
      //  fSuccess = FALSE;
      //} else {
      //      fSuccess = TRUE;  // Good!
      //}
      //
      //ReportTestResult(HWND_DESKTOP, fSuccess);

   }  /* endif */

   WinCloseClipbrd ( hab ) ;

   WinInvalidateRect(hwndMain, NULL, FALSE);

}   /* End of EditPaste()                                               */
Ejemplo n.º 10
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);
}