BOOL CLCDOutput::Open(lgLcdOpenContext & OpenContext) { //Close the old device if there is one Close(); DWORD res = lgLcdOpen(&OpenContext); if (ERROR_SUCCESS != res) { if( res == ERROR_INVALID_PARAMETER ) { LCDUITRACE( _T("Open failed: invalid parameter.\n") ); return FALSE; } else if( res == ERROR_ALREADY_EXISTS ) { LCDUITRACE( _T("Open failed: already exists.\n") ); return FALSE; } return FALSE; } m_hDevice = OpenContext.device; m_dwButtonState = 0; // restores SetAsForeground(m_bSetAsForeground); OnOpenedDevice(m_hDevice); return TRUE; }
HRESULT CLCDOutput::HandleErrorFromAPI(DWORD dwRes) { switch(dwRes) { // all is well case ERROR_SUCCESS: case RPC_S_PROTOCOL_ERROR: break; // we lost our device case ERROR_DEVICE_NOT_CONNECTED: LCDUITRACE(_T("lgLcdAPI returned with ERROR_DEVICE_NOT_CONNECTED, closing device\n")); Close(); break; default: LCDUITRACE(_T("lgLcdAPI returned with other error (0x%08x) closing device\n")); Close(); // something else happened, such as LCDMon that was terminated break; } if(ERROR_SUCCESS != dwRes) { return MAKE_HRESULT(SEVERITY_ERROR, 0, dwRes); } return S_OK; }
void CLCDOutput::HandleButtonState(DWORD dwButtonState, DWORD dwButton) { if ( (m_dwButtonState & dwButton) && !(dwButtonState & dwButton) ) { LCDUITRACE(_T("Button 0x%x released\n"), dwButton); OnLCDButtonUp(dwButton); } if ( !(m_dwButtonState & dwButton) && (dwButtonState & dwButton) ) { LCDUITRACE(_T("Button 0x%x pressed\n"), dwButton); OnLCDButtonDown(dwButton); } }
void CLCDOutput::ReadButtons() { if(IsOpened()) { DWORD dwButtonState = 0; DWORD res = lgLcdReadSoftButtons(m_hDevice, &dwButtonState); if (ERROR_SUCCESS != res) { LCDUITRACE(_T("lgLcdReadSoftButtons failed: unplug?\n")); HandleErrorFromAPI(res); } if (m_dwButtonState == dwButtonState) return; // handle the buttons HandleButtonState(dwButtonState, LGLCDBUTTON_BUTTON0); HandleButtonState(dwButtonState, LGLCDBUTTON_BUTTON1); HandleButtonState(dwButtonState, LGLCDBUTTON_BUTTON2); HandleButtonState(dwButtonState, LGLCDBUTTON_BUTTON3); m_dwButtonState = dwButtonState; } }
HRESULT CLCDGfxBase::CreateBitmap(WORD wBitCount) { int nBMISize = sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD); m_pBitmapInfo = (BITMAPINFO *) new BYTE [nBMISize]; if(NULL == m_pBitmapInfo) { LCDUITRACE(_T("CLCDGfxBase::CreateBitmap(): failed to allocate bitmap info.\n")); Shutdown(); return E_OUTOFMEMORY; } ZeroMemory(m_pBitmapInfo, nBMISize); m_pBitmapInfo->bmiHeader.biSize = sizeof(m_pBitmapInfo->bmiHeader); m_pBitmapInfo->bmiHeader.biWidth = m_nWidth; m_pBitmapInfo->bmiHeader.biHeight = -m_nHeight; m_pBitmapInfo->bmiHeader.biPlanes = 1; m_pBitmapInfo->bmiHeader.biBitCount = wBitCount; m_pBitmapInfo->bmiHeader.biCompression = BI_RGB; m_pBitmapInfo->bmiHeader.biSizeImage = (m_nWidth * m_nHeight * m_pBitmapInfo->bmiHeader.biBitCount) / 8; m_pBitmapInfo->bmiHeader.biXPelsPerMeter = 3200; m_pBitmapInfo->bmiHeader.biYPelsPerMeter = 3200; m_pBitmapInfo->bmiHeader.biClrUsed = 256; m_pBitmapInfo->bmiHeader.biClrImportant = 256; for(int nColor = 0; nColor < 256; ++nColor) { m_pBitmapInfo->bmiColors[nColor].rgbRed = (BYTE)((nColor > 128) ? 255 : 0); m_pBitmapInfo->bmiColors[nColor].rgbGreen = (BYTE)((nColor > 128) ? 255 : 0); m_pBitmapInfo->bmiColors[nColor].rgbBlue = (BYTE)((nColor > 128) ? 255 : 0); m_pBitmapInfo->bmiColors[nColor].rgbReserved = 0; } m_hBitmap = CreateDIBSection(m_hDC, m_pBitmapInfo, DIB_RGB_COLORS, (PVOID *) &m_pBitmapBits, NULL, 0); if(NULL == m_hBitmap) { LCDUITRACE(_T("CLCDGfxBase::CreateBitmap(): failed to create bitmap.\n")); Shutdown(); return E_FAIL; } return S_OK; }
void CLCDOutput::OnClosingDevice(int hDevice) { UNREFERENCED_PARAMETER(hDevice); LCDUITRACE(_T("CLCDOutput::OnClosingDevice\n")); if (IsOpened()) { lgLcdClose(m_hDevice); m_hDevice = LGLCD_INVALID_DEVICE; } ClearBitmap(m_pLastBitmap); }
//************************************************************************ // // CLCDOutput::HandleErrorFromAPI // //************************************************************************ void CLCDOutput::HandleErrorFromAPI(DWORD dwRes) { switch(dwRes) { // all is well case ERROR_SUCCESS: break; // we lost our device case ERROR_DEVICE_NOT_CONNECTED: LCDUITRACE(_T("lgLcdAPI returned with ERROR_DEVICE_NOT_CONNECTED, closing device\n")); OnClosingDevice(m_hDevice); break; default: LCDUITRACE(_T("lgLcdAPI returned with other error (0x%08x) closing device and connection\n")); OnClosingDevice(m_hDevice); OnDisconnecting(m_hConnection); // something else happened, such as LCDMon that was terminated break; } }
HRESULT CLCDGfxBase::Initialize(void) { m_hDC = CreateCompatibleDC(NULL); if(NULL == m_hDC) { LCDUITRACE(_T("CLCDGfxBase::Initialize(): failed to create compatible DC.\n")); Shutdown(); return E_FAIL; } return S_OK; }
HRESULT CLCDOutput::Initialize(lgLcdConnectContext* pContext, BOOL bUseWindow) { UNREFERENCED_PARAMETER(bUseWindow); DWORD res = ERROR_SUCCESS; CLCDManager::Initialize(); // initialize our screens LCD_MGR_LIST::iterator it = m_LCDMgrList.begin(); while(it != m_LCDMgrList.end()) { CLCDManager *pMgr = *it; LCDUIASSERT(NULL != pMgr); pMgr->Initialize(); ++it; } // LCD Stuff LCDUIASSERT(lInitCount >= 0); if(1 == InterlockedIncrement(&lInitCount)) { // need to call lgLcdInit once res = lgLcdInit(); if (ERROR_SUCCESS != res) { InterlockedDecrement(&lInitCount); LCDUITRACE(_T("WARNING: lgLcdInit failed\n")); return E_FAIL; } } m_lcdConnectCtxEx.appFriendlyName = _T("My App"); m_lcdConnectCtxEx.isPersistent = FALSE; m_lcdConnectCtxEx.isAutostartable = FALSE; m_lcdConnectCtxEx.connection = LGLCD_INVALID_CONNECTION; // Initialize the added version 3.0 API fields m_lcdConnectCtxEx.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BASIC; m_lcdConnectCtxEx.dwReserved1 = 0; m_lcdConnectCtxEx.onNotify.notificationCallback = NULL; m_lcdConnectCtxEx.onNotify.notifyContext = NULL; // if user passed in the context, fill it up if (NULL != pContext) { memcpy(&m_lcdConnectCtxEx, pContext, sizeof(lgLcdConnectContext)); } return S_OK; }
BOOL CLCDOutput::DoesBitmapNeedUpdate(lgLcdBitmap160x43x1* pCurrentBitmap) { // The bitmap is different from the last one sent // send the bitmap BOOL bBitmapChanged = 0 != memcmp(pCurrentBitmap, m_pLastBitmap, sizeof(lgLcdBitmap160x43x1)); BOOL bPriorityChanged = m_bPriorityHasChanged; if (bBitmapChanged) { LCDUITRACE(_T("Resubmitting bitmap (bitmap changed)\n")); } else if (bPriorityChanged) { LCDUITRACE(_T("Resubmitting bitmap (priority changed)\n")); } // Save the current bitmap memcpy(m_pLastBitmap, pCurrentBitmap, sizeof(lgLcdBitmap160x43x1)); // Reset the priority change m_bPriorityHasChanged = FALSE; return (bBitmapChanged || bPriorityChanged); }
void CLCDOutput::OnDisconnecting(int hConnection) { UNREFERENCED_PARAMETER(hConnection); LCDUITRACE(_T("CLCDOutput::OnDisconnecting\n")); // let's hope our device is already gone LCDUIASSERT(!IsOpened()); if (LGLCD_INVALID_CONNECTION != m_hConnection) { lgLcdDisconnect(m_hConnection); m_hConnection = LGLCD_INVALID_CONNECTION; ZeroMemory(m_pLastBitmap, sizeof(lgLcdBitmap160x43x1)); } }
HRESULT CLCDManager::Initialize(void) { HRESULT hRes = CLCDCollection::Initialize(); if(FAILED(hRes)) { LCDUITRACE(_T("CLCDManager::Initialize(): failed to initialize base class.\n")); Shutdown(); return hRes; } SetOrigin(0, 0); SetSize(LGLCD_BMP_WIDTH, LGLCD_BMP_HEIGHT); hRes = m_Gfx.Initialize(GetWidth(), GetHeight()); if(FAILED(hRes)) { LCDUITRACE(_T("CLCDManager::Initialize(): failed to initialize graphics component.\n")); Shutdown(); return hRes; } return S_OK; }
HRESULT CLCDManager::Draw(void) { LCDUIASSERT(NULL != m_Gfx.GetHDC()); LCDUIASSERT(NULL != m_Gfx.GetHBITMAP()); if((NULL == m_Gfx.GetHDC()) || (NULL == m_Gfx.GetHBITMAP())) { LCDUITRACE(_T("CLCDManager::Draw(): trying to draw without successful Initialize() first.!\n")); return E_FAIL; } // select our bitmap into the Gfx DC m_Gfx.BeginDraw(); m_Gfx.ClearScreen(); // invoke LCD UI Elements OnDraw(m_Gfx); // select it back out of it m_Gfx.EndDraw(); return S_OK; }
/****f* LCD.SDK/Initialize(LPCTSTR.friendlyName,AppletSupportType.supportType,BOOL.isAutoStartable,BOOL.isPersistent,lgLcdConfigureContext*configContext,lgLcdSoftbuttonsChangedContext*softbuttonChangedContext) * NAME * HRESULT Initialize(LPCTSTR friendlyName, * AppletSupportType supportType, * BOOL isAutoStartable = FALSE, * BOOL isPersistent = FALSE, * lgLcdConfigureContext* configContext = NULL, * lgLcdNotificationContext* notificationContext = NULL, * lgLcdSoftbuttonsChangedContext* softbuttonChangedContext = NULL) * FUNCTION * Does necessary initialization. This method SHOULD ONLY be called if * the empty constructor is used: CEzLcd(). * INPUTS * friendlyName - friendly name of the applet/game. This name will be * displayed in the Logitech G-series LCD Manager. * supportType - What type of displays the applet supports. Options * are: * - LG_MONOCHROME_MODE_ONLY * - LG_COLOR_MODE_ONLY * - LG_DUAL_MODE * IsAutoStartable - Determines if the applet is to be started * automatically every time by the LCD manager software * (Part of G15 software package). * IsPersistent - Determines if the applet's friendlyName will remain * in the list of applets seen by the LCD manager * software after the applet terminates. * configContext - Pointer to the lgLcdConfigContext structure used * during callback into the applet. * softbuttonChangedContext - softbutton callback (if the user does * not want to use LCD SDK's native handler). * RETURN VALUE * S_OK if it can connect to the LCD Manager. * E_FAIL otherwise. ****** */ HRESULT CEzLcd::Initialize(LPCTSTR friendlyName, AppletSupportType supportType, BOOL isAutoStartable, BOOL isPersistent, lgLcdConfigureContext* configContext, lgLcdSoftbuttonsChangedContext* softbuttonChangedContext) { if ( (m_pageCountMono != 0) || (m_pageCountColor != 0) ) { // Maybe the user is calling the old constructor and calling InitYourself as well. // Alert him of the problem. If the old constructor is called, then InitYourself should // not be called. InitYourself should be called, when the empty parameter constructor is // called, CEzLcd() return E_FAIL; } LCDUI_tcscpy(m_friendlyName, friendlyName); m_initNeeded = TRUE; m_initSucceeded = FALSE; m_currentDeviceFamily = LGLCD_DEVICE_FAMILY_OTHER; m_preferredDeviceFamily = LGLCD_DEVICE_FAMILY_OTHER; m_configContext = configContext; // Keep the context structure pointer m_isPersistent = isPersistent; m_isAutoStartable = isAutoStartable; // No active page to start with m_activePageMono = m_activePageColor = NULL; m_currentPageNumberShownMono = m_currentPageNumberShownColor = 0; // Will now connect to the real library and see it the lgLcdInit() succeeds lgLcdConnectContextEx lgdConnectContextEx_; lgLcdConfigureContext lgdConfigureContext_; if (m_configContext != NULL) { lgdConfigureContext_.configCallback = m_configContext->configCallback; lgdConfigureContext_.configContext = m_configContext->configContext; } else { lgdConfigureContext_.configCallback = NULL; lgdConfigureContext_.configContext = NULL; } lgdConnectContextEx_.appFriendlyName = m_friendlyName; lgdConnectContextEx_.isPersistent = m_isPersistent; lgdConnectContextEx_.isAutostartable = m_isAutoStartable; lgdConnectContextEx_.onConfigure = lgdConfigureContext_; switch(supportType) { case LG_MONOCHROME_MODE_ONLY: lgdConnectContextEx_.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BW; break; case LG_COLOR_MODE_ONLY: lgdConnectContextEx_.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_QVGA; break; case LG_DUAL_MODE: lgdConnectContextEx_.dwAppletCapabilitiesSupported = LGLCD_APPLET_CAP_BW|LGLCD_APPLET_CAP_QVGA; break; default: break; } m_SupportType = supportType; lgdConnectContextEx_.dwReserved1 = NULL; lgdConnectContextEx_.onNotify.notificationCallback = NULL; lgdConnectContextEx_.onNotify.notifyContext = NULL; if( NULL == softbuttonChangedContext ) { m_SBContext.softbuttonsChangedCallback = OnButtonCB; m_SBContext.softbuttonsChangedContext = this; } else { m_SBContext.softbuttonsChangedCallback = softbuttonChangedContext->softbuttonsChangedCallback; m_SBContext.softbuttonsChangedContext = softbuttonChangedContext->softbuttonsChangedContext; } if (FALSE == m_connection.Initialize(lgdConnectContextEx_, &m_SBContext)) { // This means the LCD SDK's lgLcdInit failed, and therefore // we will not be able to ever connect to the LCD, even if // a G-series keyboard is actually connected. LCDUITRACE(_T("ERROR: LCD SDK initialization failed\n")); m_initSucceeded = FALSE; return E_FAIL; } else { m_initSucceeded = TRUE; } // Add the first page(s) for backwards compatibility if( m_SupportType == LG_COLOR_MODE_ONLY || m_SupportType == LG_DUAL_MODE ) { ModifyDisplay(LG_COLOR); AddNewPage(); ModifyControlsOnPage(0); ShowPage(0); } if( m_SupportType == LG_MONOCHROME_MODE_ONLY || m_SupportType == LG_DUAL_MODE ) { ModifyDisplay(LG_MONOCHROME); AddNewPage(); ModifyControlsOnPage(0); ShowPage(0); } m_initNeeded = FALSE; // Default mode is Monochrome return S_OK; }
HANDLE CEzLcdPage::AddText(LGObjectType type, LGTextSize size, INT alignment, INT maxLengthPixels, INT numberOfLines) { LCDUIASSERT(LG_SCROLLING_TEXT == type || LG_STATIC_TEXT == type || LG_RIGHTFOCUS_TEXT == type); CLCDText* pStaticText_; CLCDText* pRightFocusText_; CLCDStreamingText* pStreamingText_; INT iBoxHeight_ = LG_MEDIUM_FONT_TEXT_BOX_HEIGHT; INT iFontSize_ = LG_MEDIUM_FONT_SIZE; INT iLocalOriginY_ = LG_MEDIUM_FONT_LOGICAL_ORIGIN_Y; switch (type) { case LG_SCROLLING_TEXT: pStreamingText_ = new CLCDStreamingText(); LCDUIASSERT(NULL != pStreamingText_); pStreamingText_->Initialize(); pStreamingText_->SetOrigin(0, 0); pStreamingText_->SetFontFaceName(LG_FONT); pStreamingText_->SetAlignment(alignment); pStreamingText_->SetText(_T(" ")); pStreamingText_->SetGapText(LG_SCROLLING_GAP_TEXT); pStreamingText_->SetStartDelay(LG_SCROLLING_DELAY_MS); if (LG_SMALL == size || LG_TINY == size) { iBoxHeight_ = LG_SMALL_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_SMALL_FONT_SIZE; iLocalOriginY_ = LG_SMALL_FONT_LOGICAL_ORIGIN_Y; pStreamingText_->SetSpeed(LG_SCROLLING_SPEED_SMALL_MONOCHROME); pStreamingText_->SetScrollingStep(LG_SCROLLING_STEP_SMALL_MONOCHROME); } else if (LG_MEDIUM == size) { iBoxHeight_ = LG_MEDIUM_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_MEDIUM_FONT_SIZE; iLocalOriginY_ = LG_MEDIUM_FONT_LOGICAL_ORIGIN_Y; pStreamingText_->SetSpeed(LG_SCROLLING_SPEED_MEDIUM_MONOCHROME); pStreamingText_->SetScrollingStep(LG_SCROLLING_STEP_MEDIUM_MONOCHROME); } else if (LG_BIG == size) { pStreamingText_->SetFontWeight(FW_BOLD); iBoxHeight_ = LG_BIG_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_BIG_FONT_SIZE; iLocalOriginY_ = LG_BIG_FONT_LOGICAL_ORIGIN_Y; pStreamingText_->SetSpeed(LG_SCROLLING_SPEED_BIG_MONOCHROME); pStreamingText_->SetScrollingStep(LG_SCROLLING_STEP_BIG_MONOCHROME); } pStreamingText_->SetSize(maxLengthPixels, iBoxHeight_); pStreamingText_->SetFontPointSize(iFontSize_); pStreamingText_->SetLogicalOrigin(0, iLocalOriginY_); pStreamingText_->SetObjectType(LG_SCROLLING_TEXT); AddObject(pStreamingText_); return pStreamingText_; break; case LG_STATIC_TEXT: pStaticText_ = new CLCDText(); LCDUIASSERT(NULL != pStaticText_); pStaticText_->Initialize(); pStaticText_->SetOrigin(0, 0); pStaticText_->SetFontFaceName(LG_FONT); pStaticText_->SetAlignment(alignment); pStaticText_->SetBackgroundMode(OPAQUE); pStaticText_->SetText(_T(" ")); if (LG_SMALL == size || LG_TINY == size) { iBoxHeight_ = numberOfLines * LG_SMALL_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_SMALL_FONT_SIZE; iLocalOriginY_ = LG_SMALL_FONT_LOGICAL_ORIGIN_Y; } else if (LG_MEDIUM == size) { iBoxHeight_ = numberOfLines * LG_MEDIUM_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_MEDIUM_FONT_SIZE; iLocalOriginY_ = LG_MEDIUM_FONT_LOGICAL_ORIGIN_Y; } else if (LG_BIG == size) { pStaticText_->SetFontWeight(FW_BOLD); iBoxHeight_ = numberOfLines * LG_BIG_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_BIG_FONT_SIZE; iLocalOriginY_ = LG_BIG_FONT_LOGICAL_ORIGIN_Y; } pStaticText_->SetSize(maxLengthPixels, iBoxHeight_); pStaticText_->SetFontPointSize(iFontSize_); pStaticText_->SetLogicalOrigin(0, iLocalOriginY_); pStaticText_->SetObjectType(LG_STATIC_TEXT); if (1 < numberOfLines) pStaticText_->SetWordWrap(TRUE); AddObject(pStaticText_); return pStaticText_; break; case LG_RIGHTFOCUS_TEXT: pRightFocusText_ = new CLCDText(); LCDUIASSERT(NULL != pRightFocusText_); pRightFocusText_->Initialize(); pRightFocusText_->SetOrigin(0, 0); pRightFocusText_->SetFontFaceName(LG_ARIAL_FONT); pRightFocusText_->SetAlignment(alignment); pRightFocusText_->SetBackgroundMode(TRANSPARENT); pRightFocusText_->SetText(_T(" ")); if (LG_SMALL == size || LG_TINY == size) { iBoxHeight_ = numberOfLines * LG_SMALL_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_SMALL_FONT_SIZE; iLocalOriginY_ = LG_SMALL_FONT_LOGICAL_ORIGIN_Y; } else if (LG_MEDIUM == size) { iBoxHeight_ = numberOfLines * LG_MEDIUM_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_MEDIUM_FONT_SIZE; iLocalOriginY_ = LG_MEDIUM_FONT_LOGICAL_ORIGIN_Y; } else if (LG_BIG == size) { pRightFocusText_->SetFontWeight(FW_BOLD); iBoxHeight_ = numberOfLines * LG_BIG_FONT_TEXT_BOX_HEIGHT; iFontSize_ = LG_BIG_FONT_SIZE; iLocalOriginY_ = LG_BIG_FONT_LOGICAL_ORIGIN_Y; } pRightFocusText_->SetSize(maxLengthPixels, iBoxHeight_); pRightFocusText_->SetFontPointSize(iFontSize_); pRightFocusText_->SetLogicalOrigin(0, iLocalOriginY_); pRightFocusText_->SetObjectType(LG_RIGHTFOCUS_TEXT); if (1 < numberOfLines) pRightFocusText_->SetWordWrap(TRUE); AddObject(pRightFocusText_); return pRightFocusText_; default: LCDUITRACE(_T("ERROR: trying to add text object with undefined type\n")); } return NULL; }
HRESULT CLCDGfx::Initialize(int nWidth, int nHeight) { m_nWidth = nWidth; m_nHeight = nHeight; m_hDC = CreateCompatibleDC(NULL); if(NULL == m_hDC) { LCDUITRACE(_T("CLCDGfx::Initialize(): failed to create compatible DC.\n")); Shutdown(); return E_FAIL; } int nBMISize = sizeof(BITMAPINFO) + 256 * sizeof(RGBQUAD); m_pBitmapInfo = (BITMAPINFO *) DNew BYTE [nBMISize]; if(NULL == m_pBitmapInfo) { LCDUITRACE(_T("CLCDGfx::Initialize(): failed to allocate bitmap info.\n")); Shutdown(); return E_OUTOFMEMORY; } ZeroMemory(m_pBitmapInfo, nBMISize); m_pBitmapInfo->bmiHeader.biSize = sizeof(m_pBitmapInfo->bmiHeader); m_pBitmapInfo->bmiHeader.biWidth = m_nWidth; m_pBitmapInfo->bmiHeader.biHeight = -m_nHeight; m_pBitmapInfo->bmiHeader.biPlanes = 1; m_pBitmapInfo->bmiHeader.biBitCount = 8; m_pBitmapInfo->bmiHeader.biCompression = BI_RGB; m_pBitmapInfo->bmiHeader.biSizeImage = (m_nWidth * m_nHeight * m_pBitmapInfo->bmiHeader.biBitCount) / 8; m_pBitmapInfo->bmiHeader.biXPelsPerMeter = 3200; m_pBitmapInfo->bmiHeader.biYPelsPerMeter = 3200; m_pBitmapInfo->bmiHeader.biClrUsed = 256; m_pBitmapInfo->bmiHeader.biClrImportant = 256; for(int nColor = 0; nColor < 256; ++nColor) { m_pBitmapInfo->bmiColors[nColor].rgbRed = (BYTE)((nColor > 128) ? 255 : 0); m_pBitmapInfo->bmiColors[nColor].rgbGreen = (BYTE)((nColor > 128) ? 255 : 0); m_pBitmapInfo->bmiColors[nColor].rgbBlue = (BYTE)((nColor > 128) ? 255 : 0); m_pBitmapInfo->bmiColors[nColor].rgbReserved = 0; } m_hBitmap = CreateDIBSection(m_hDC, m_pBitmapInfo, DIB_RGB_COLORS, (PVOID *) &m_pBitmapBits, NULL, 0); if(NULL == m_hBitmap) { LCDUITRACE(_T("CLCDGfx::Initialize(): failed to create bitmap.\n")); Shutdown(); return E_FAIL; } m_pLCDScreen = DNew lgLcdBitmap160x43x1; if(NULL == m_pLCDScreen) { LCDUITRACE(_T("CLCDGfx::Initialize(): failed to allocate the lcd screen structure.\n")); Shutdown(); return E_OUTOFMEMORY; } return S_OK; }