home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / mag&info / msjv7_4.zip / WINQA.ARJ / MOUCAP.TXT next >
Text File  |  1992-07-01  |  4KB  |  136 lines

  1. // Format of the mouse cursor header.
  2. typedef struct    tagCURSORHEADER
  3.     {
  4.     WORD    wHotSpotX;
  5.     WORD    wHotSpotY;
  6.     WORD    wExtentX;
  7.     WORD    wExtentY;
  8.     WORD    wFunnyNumber;
  9.     BYTE    ucNumberOfPlanes;
  10.     BYTE    ucBitsPerPixel;
  11.     }    CURSORHEADER;
  12.  
  13. typedef CURSORHEADER FAR * LPCURSORHEADER;
  14.  
  15. // This code may be added to GENERIC's MainWndProc message switch.
  16. case WM_KEYDOWN:
  17.     switch ( wParam )
  18.     {
  19.     case VK_SPACE:
  20.         {
  21.         // Capture the client area to memory, BitBlt the mouse cursor
  22.         //        onto it, and then BitBlt it all back to the screen.
  23.         // Several of the function calls should really be checked
  24.         //        for error returns.
  25.  
  26.         HCURSOR        hCursor;
  27.         POINT        pCurPos;
  28.         LPSTR        lpGMemCursor;
  29.         LPSTR        lpBits;
  30.         LPCURSORHEADER  lpCursorHdr;
  31.         WORD        wBitsOffset, wHotX, wHotY, wExtX, wExtY;
  32.         HDC         hDCClient, hDCMemory, hDCTemp;
  33.         RECT        rClient;
  34.         HBITMAP        hBMCursorAND, hBMCursorXOR;
  35.         HBITMAP        hBMOldTemp, hBMOldMem, hBMMemory;
  36.  
  37.         // Get the current cursor position in client coords.
  38.         GetCursorPos( &pCurPos );
  39.         ScreenToClient( hWnd, &pCurPos );
  40.  
  41.         // Get the current cursor handle.
  42.         hCursor = SetCursor( LoadCursor( NULL, IDC_ARROW ) );
  43.         // Put the cursor back like we found it.
  44.         SetCursor( hCursor );
  45.  
  46.         // Lock the cursor handle down.
  47.         lpGMemCursor = GlobalLock( hCursor );
  48.  
  49.         // Cast the structure pointer to the cursor address.
  50.         lpCursorHdr = (LPCURSORHEADER)lpGMemCursor;
  51.  
  52.         wHotX = lpCursorHdr->wHotSpotX;
  53.         wHotY = lpCursorHdr->wHotSpotY;
  54.         wExtX = lpCursorHdr->wExtentX;
  55.         wExtY = lpCursorHdr->wExtentY;
  56.  
  57.         // Build a pointer to the first bitmap.
  58.         wBitsOffset = sizeof( CURSORHEADER );
  59.         lpBits =  lpGMemCursor + wBitsOffset;
  60.  
  61.         hBMCursorAND = CreateBitmap( wExtX, wExtY,
  62.             lpCursorHdr->ucNumberOfPlanes,
  63.             lpCursorHdr->ucBitsPerPixel,
  64.             lpBits );
  65.  
  66.         // Build a pointer to the second bitmap.
  67.         // NOTE: This calculation will be wrong if the cursor
  68.         //        bitmap width is not a multiple of 8!
  69.         wBitsOffset = sizeof( CURSORHEADER ) +
  70.             (( wExtX / 8 ) * wExtY );
  71.         lpBits =  lpGMemCursor + wBitsOffset;
  72.  
  73.         hBMCursorXOR = CreateBitmap( wExtX, wExtY,
  74.             lpCursorHdr->ucNumberOfPlanes,
  75.             lpCursorHdr->ucBitsPerPixel,
  76.             lpBits );
  77.  
  78.         // We're done with the orginal cursor, so unlock it.
  79.         GlobalUnlock( hCursor );
  80.  
  81.         // Create DCs.
  82.         hDCClient = GetDC( hWnd );
  83.         hDCMemory = CreateCompatibleDC( hDCClient );
  84.         hDCTemp   = CreateCompatibleDC( hDCClient );
  85.  
  86.         // Build a bitmap the same size as the client rectangle.
  87.         GetClientRect( hWnd, &rClient );
  88.         hBMMemory = CreateCompatibleBitmap( hDCClient,
  89.             rClient.right, rClient.bottom );
  90.  
  91.         // Select the new bitmap into the memory device context.
  92.         hBMOldMem = SelectObject( hDCMemory, hBMMemory );
  93.  
  94.         // BitBlt the client window to the memory DC.
  95.         BitBlt( hDCMemory, 0, 0, rClient.right, rClient.bottom,
  96.             hDCClient, 0, 0, SRCCOPY );
  97.  
  98.         // Select the first cursor bitmap into the temp DC.
  99.         hBMOldTemp = SelectObject( hDCTemp, hBMCursorAND );
  100.  
  101.         // BitBlt the first (AND) cursor bitmap to the memory DC.
  102.         BitBlt( hDCMemory, pCurPos.x - wHotX, pCurPos.y - wHotY,
  103.             wExtX, wExtY, hDCTemp, 0, 0, SRCAND );
  104.  
  105.         // Select the other cursor bitmap into the temp DC.
  106.         // NOTE: Don't overwrite the original bitmap handle!
  107.         SelectObject( hDCTemp, hBMCursorXOR );
  108.  
  109.         // BitBlt the second (XOR) cursor bitmap to the memory DC.
  110.         BitBlt( hDCMemory, pCurPos.x - wHotX, pCurPos.y - wHotY,
  111.             wExtX, wExtY, hDCTemp, 0, 0, SRCINVERT );
  112.  
  113.         // This is where you would save the memory bitmap or print it.
  114.         // For this test we'll just blast it back onto the client area.
  115.         BitBlt( hDCClient, 0, 0, rClient.right, rClient.bottom,
  116.             hDCMemory, 0, 0, SRCCOPY );
  117.  
  118.         // Select the orginal bitmaps back into the DCs.
  119.         SelectObject( hDCMemory, hBMOldMem );
  120.         SelectObject( hDCTemp, hBMOldTemp );
  121.  
  122.         // Delete DCs.
  123.         DeleteDC( hDCMemory );
  124.         DeleteDC( hDCTemp );
  125.         ReleaseDC( hWnd, hDCClient );
  126.  
  127.         // Delete the created bitmaps.
  128.         DeleteObject( hBMCursorAND );
  129.         DeleteObject( hBMCursorXOR );
  130.         DeleteObject( hBMMemory );
  131.         break;
  132.         }
  133.     }
  134.     break;
  135.  
  136.