Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. void CChromaSDKImpl::ShowBitmap(UINT DeviceType, HBITMAP hBitmap)
  2. {
  3.     HWND hDesktopWin = GetDesktopWindow();
  4.     HDC hDesktopDC = ::GetDC(hDesktopWin);
  5.     if (hDesktopDC)
  6.     {
  7.         HDC hDestDC = ::CreateCompatibleDC(hDesktopDC);
  8.  
  9.         ::SelectObject(hDestDC, hBitmap);
  10.  
  11.         BITMAP bm;
  12.         ::GetObject(hBitmap, sizeof(bm), &bm);
  13.  
  14.         BITMAPINFOHEADER bmi = { 0 };
  15.         bmi.biSize = sizeof(BITMAPINFOHEADER);
  16.         bmi.biPlanes = bm.bmPlanes;
  17.         bmi.biBitCount = bm.bmBitsPixel;
  18.  
  19.         if (DeviceType == 1)
  20.         {
  21.             bmi.biWidth = ChromaSDK::Keyboard::MAX_COLUMN;
  22.             bmi.biHeight = ChromaSDK::Keyboard::MAX_ROW;
  23.         }
  24.         else if (DeviceType == 5)
  25.         {
  26.             bmi.biWidth = ChromaSDK::Keypad::MAX_COLUMN;
  27.             bmi.biHeight = ChromaSDK::Keypad::MAX_ROW;
  28.         }
  29.         else if (DeviceType == 4)
  30.         {
  31.             bmi.biWidth = 1;
  32.             bmi.biHeight = 1;
  33.         }
  34.  
  35.         bmi.biCompression = BI_RGB;
  36.         bmi.biSizeImage = 0;
  37.  
  38.         BYTE *pBits = NULL;
  39.         pBits = (BYTE*)malloc(4 * bmi.biWidth * bmi.biHeight);
  40.         ZeroMemory(pBits, (4 * bmi.biWidth * bmi.biHeight));
  41.  
  42.         if ((DeviceType == 1) && CreateKeyboardEffect)
  43.         {
  44.             ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE Effect = {};
  45.             for (UINT i = 0; i<ChromaSDK::Keyboard::MAX_ROW; i++)
  46.             {
  47.                 // Get ths RGB bits for each row
  48.                 ::GetDIBits(hDestDC, hBitmap, i, 1, pBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
  49.  
  50.                 COLORREF *pColor = (COLORREF*)pBits;
  51.  
  52.                 for (UINT j = 0; j<ChromaSDK::Keyboard::MAX_COLUMN; j++)
  53.                 {
  54.                     // Fill up the array
  55.                     Effect.Color[i][j] = RGB(GetBValue(*pColor), GetGValue(*pColor), GetRValue(*pColor));
  56.                     pColor++;
  57.                 }
  58.             }
  59.  
  60.             // Set the effect
  61.             CreateKeyboardEffect(ChromaSDK::Keyboard::CHROMA_CUSTOM, &Effect, NULL);
  62.         }
  63.         else if ((DeviceType == 5) && CreateKeypadEffect)
  64.         {
  65.             ChromaSDK::Keypad::CUSTOM_EFFECT_TYPE Effect = {};
  66.             for (UINT i = 0; i<ChromaSDK::Keypad::MAX_ROW; i++)
  67.             {
  68.                 // Get ths RGB bits for each row
  69.                 ::GetDIBits(hDestDC, hBitmap, i, 1, pBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
  70.  
  71.                 COLORREF *pColor = (COLORREF*)pBits;
  72.  
  73.                 for (UINT j = 0; j<ChromaSDK::Keypad::MAX_COLUMN; j++)
  74.                 {
  75.                     // Fill up the array
  76.                     Effect.Color[i][j] = RGB(GetBValue(*pColor), GetGValue(*pColor), GetRValue(*pColor));
  77.                     pColor++;
  78.                 }
  79.             }
  80.  
  81.             // Set the effect
  82.             CreateKeypadEffect(ChromaSDK::Keypad::CHROMA_CUSTOM, &Effect, NULL);
  83.         }
  84.         else if ((DeviceType == 4) && CreateHeadsetEffect)
  85.         {
  86.             ChromaSDK::Headset::STATIC_EFFECT_TYPE Effect = {};
  87.             ::GetDIBits(hDestDC, hBitmap, 0, 1, pBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
  88.  
  89.             COLORREF *pColor = (COLORREF*)pBits;
  90.             Effect.Color = RGB(GetBValue(*pColor), GetGValue(*pColor), GetRValue(*pColor));
  91.  
  92.             CreateHeadsetEffect(ChromaSDK::Headset::CHROMA_STATIC, &Effect, NULL);
  93.         }
  94.  
  95.         free(pBits);
  96.  
  97.         // Free memories.
  98.         ::DeleteDC(hDestDC);
  99.  
  100.         ::ReleaseDC(hDesktopWin, hDesktopDC);
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement