Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CChromaSDKImpl::ShowBitmap(UINT DeviceType, HBITMAP hBitmap)
- {
- HWND hDesktopWin = GetDesktopWindow();
- HDC hDesktopDC = ::GetDC(hDesktopWin);
- if (hDesktopDC)
- {
- HDC hDestDC = ::CreateCompatibleDC(hDesktopDC);
- ::SelectObject(hDestDC, hBitmap);
- BITMAP bm;
- ::GetObject(hBitmap, sizeof(bm), &bm);
- BITMAPINFOHEADER bmi = { 0 };
- bmi.biSize = sizeof(BITMAPINFOHEADER);
- bmi.biPlanes = bm.bmPlanes;
- bmi.biBitCount = bm.bmBitsPixel;
- if (DeviceType == 1)
- {
- bmi.biWidth = ChromaSDK::Keyboard::MAX_COLUMN;
- bmi.biHeight = ChromaSDK::Keyboard::MAX_ROW;
- }
- else if (DeviceType == 5)
- {
- bmi.biWidth = ChromaSDK::Keypad::MAX_COLUMN;
- bmi.biHeight = ChromaSDK::Keypad::MAX_ROW;
- }
- else if (DeviceType == 4)
- {
- bmi.biWidth = 1;
- bmi.biHeight = 1;
- }
- bmi.biCompression = BI_RGB;
- bmi.biSizeImage = 0;
- BYTE *pBits = NULL;
- pBits = (BYTE*)malloc(4 * bmi.biWidth * bmi.biHeight);
- ZeroMemory(pBits, (4 * bmi.biWidth * bmi.biHeight));
- if ((DeviceType == 1) && CreateKeyboardEffect)
- {
- ChromaSDK::Keyboard::CUSTOM_EFFECT_TYPE Effect = {};
- for (UINT i = 0; i<ChromaSDK::Keyboard::MAX_ROW; i++)
- {
- // Get ths RGB bits for each row
- ::GetDIBits(hDestDC, hBitmap, i, 1, pBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
- COLORREF *pColor = (COLORREF*)pBits;
- for (UINT j = 0; j<ChromaSDK::Keyboard::MAX_COLUMN; j++)
- {
- // Fill up the array
- Effect.Color[i][j] = RGB(GetBValue(*pColor), GetGValue(*pColor), GetRValue(*pColor));
- pColor++;
- }
- }
- // Set the effect
- CreateKeyboardEffect(ChromaSDK::Keyboard::CHROMA_CUSTOM, &Effect, NULL);
- }
- else if ((DeviceType == 5) && CreateKeypadEffect)
- {
- ChromaSDK::Keypad::CUSTOM_EFFECT_TYPE Effect = {};
- for (UINT i = 0; i<ChromaSDK::Keypad::MAX_ROW; i++)
- {
- // Get ths RGB bits for each row
- ::GetDIBits(hDestDC, hBitmap, i, 1, pBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
- COLORREF *pColor = (COLORREF*)pBits;
- for (UINT j = 0; j<ChromaSDK::Keypad::MAX_COLUMN; j++)
- {
- // Fill up the array
- Effect.Color[i][j] = RGB(GetBValue(*pColor), GetGValue(*pColor), GetRValue(*pColor));
- pColor++;
- }
- }
- // Set the effect
- CreateKeypadEffect(ChromaSDK::Keypad::CHROMA_CUSTOM, &Effect, NULL);
- }
- else if ((DeviceType == 4) && CreateHeadsetEffect)
- {
- ChromaSDK::Headset::STATIC_EFFECT_TYPE Effect = {};
- ::GetDIBits(hDestDC, hBitmap, 0, 1, pBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
- COLORREF *pColor = (COLORREF*)pBits;
- Effect.Color = RGB(GetBValue(*pColor), GetGValue(*pColor), GetRValue(*pColor));
- CreateHeadsetEffect(ChromaSDK::Headset::CHROMA_STATIC, &Effect, NULL);
- }
- free(pBits);
- // Free memories.
- ::DeleteDC(hDestDC);
- ::ReleaseDC(hDesktopWin, hDesktopDC);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement