#include #include #include LedDisplay::LedDisplay(HWND hDisplayWindow,Point windowPoint) : mWindowPoint(windowPoint), mhDisplayWindow(hDisplayWindow), mCurrentNumber(0), mHasSpecialChar(TRUE), mCurrentSpecialChar(DashChar), #if defined(__FLAT__) mhFilm(::LoadBitmap((HINSTANCE)::GetWindowLong(hDisplayWindow,GWL_HINSTANCE),"LED")) #else mhFilm(::LoadBitmap((HINSTANCE)::GetWindowWord(hDisplayWindow,GWW_HINSTANCE),"LED")) #endif { } LedDisplay::~LedDisplay() { if(mhFilm){::DeleteObject(mhFilm);mhFilm=0;} } void LedDisplay::setNumber(SpecialChar specialChar) { mHasSpecialChar=TRUE; mCurrentSpecialChar=specialChar; paint(); } void LedDisplay::setNumber(WORD someNumber) { mHasSpecialChar=FALSE; mCurrentNumber=someNumber; paint(); } void LedDisplay::paint(void) { HBITMAP hOldBitmap; HDC hDisplayDC; HDC hMemDC; WORD firstOffset; WORD secondOffset; WORD thirdOffset; hDisplayDC=::GetDC(mhDisplayWindow); hMemDC=::CreateCompatibleDC(hDisplayDC); hOldBitmap=(HBITMAP)::SelectObject(hMemDC,mhFilm); positions(firstOffset,secondOffset,thirdOffset); ::BitBlt(hDisplayDC,mWindowPoint.x(),mWindowPoint.y(),Width,Height, hMemDC,0,firstOffset*Height,SRCCOPY); ::BitBlt(hDisplayDC,mWindowPoint.x()+Width,mWindowPoint.y(),Width,Height, hMemDC,0,secondOffset*Height,SRCCOPY); ::BitBlt(hDisplayDC,mWindowPoint.x()+(Width*2),mWindowPoint.y(),Width,Height, hMemDC,0,thirdOffset*Height,SRCCOPY); ::SelectObject(hMemDC,hOldBitmap); ::DeleteObject(hMemDC); ::ReleaseDC(mhDisplayWindow,hDisplayDC); } void LedDisplay::positions(WORD &firstOffset,WORD &secondOffset,WORD &thirdOffset)const { String numberString; if(mHasSpecialChar) { if(BlankChar==mCurrentSpecialChar) firstOffset=secondOffset=thirdOffset=OffsetBlankChar; else firstOffset=secondOffset=thirdOffset=OffsetDashChar; } else { ::sprintf(numberString,"%03d",mCurrentNumber); firstOffset=charPosition(*(numberString)); secondOffset=charPosition(*((LPSTR)numberString+1)); thirdOffset=charPosition(*((LPSTR)numberString+2)); } }