DWORD CMySliderCtrl::SetBitmaps(HBITMAP hChannel, COLORREF crTransCh, HBITMAP hThumb, COLORREF crTransThumb) { int nRetValue = 0; BITMAP csBitmapSize; m_BgSet = FALSE; // Free any loaded resource FreeResources(); if (hChannel) { m_csBitmaps[0].hBitmap = hChannel; m_csBitmaps[0].crTransparent = crTransCh; // Get bitmap size nRetValue = ::GetObject(hChannel, sizeof(csBitmapSize), &csBitmapSize); if (nRetValue == 0) { FreeResources(); return BTNST_INVALIDRESOURCE; } // if m_csBitmaps[0].dwWidth = (DWORD)csBitmapSize.bmWidth; m_csBitmaps[0].dwHeight = (DWORD)csBitmapSize.bmHeight; // Create mask for bitmap In m_csBitmaps[0].hMask = CreateBitmapMask(hChannel, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransCh); if (m_csBitmaps[0].hMask == NULL) { FreeResources(); return BTNST_FAILEDMASK; } // if } if (hThumb) { m_csBitmaps[3].hBitmap = hThumb; m_csBitmaps[3].crTransparent = crTransThumb; // Get bitmap size nRetValue = ::GetObject(hThumb, sizeof(csBitmapSize), &csBitmapSize); if (nRetValue == 0) { FreeResources(); return BTNST_INVALIDRESOURCE; } // if m_csBitmaps[3].dwWidth = (DWORD)csBitmapSize.bmWidth; m_csBitmaps[3].dwHeight = (DWORD)csBitmapSize.bmHeight; // Create mask for bitmap Out m_csBitmaps[3].hMask = CreateBitmapMask(hThumb, m_csBitmaps[3].dwWidth, m_csBitmaps[3].dwHeight, crTransThumb); if (m_csBitmaps[3].hMask == NULL) { FreeResources(); return BTNST_FAILEDMASK; } // if } // if SizeToContent(); Invalidate(); return BTNST_OK; } // End of SetBitmaps
// This function assigns bitmaps to the button. // Any previous icon or bitmap will be removed. // // Parameters: // [IN] hBitmapIn // Handle fo the bitmap to show when the mouse is over the button. // Pass NULL to remove any bitmap from the button. // [IN] crTransColorIn // Color (inside hBitmapIn) to be used as transparent color. // [IN] hBitmapOut // Handle to the bitmap to show when the mouse is outside the button. // Can be NULL. // [IN] crTransColorOut // Color (inside hBitmapOut) to be used as transparent color. // // Return value: // BTNST_OK // Function executed successfully. // BTNST_INVALIDRESOURCE // Failed loading the specified resource. // BTNST_FAILEDMASK // Failed creating mask bitmap. // DWORD CButtonST::SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut, COLORREF crTransColorOut) { int nRetValue; BITMAP csBitmapSize; // Free any loaded resource FreeResources(); if (hBitmapIn) { m_csBitmaps[0].hBitmap = hBitmapIn; m_csBitmaps[0].crTransparent = crTransColorIn; // Get bitmap size nRetValue = ::GetObject(hBitmapIn, sizeof(csBitmapSize), &csBitmapSize); if (nRetValue == 0) { FreeResources(); return BTNST_INVALIDRESOURCE; } // if m_csBitmaps[0].dwWidth = (DWORD)csBitmapSize.bmWidth; m_csBitmaps[0].dwHeight = (DWORD)csBitmapSize.bmHeight; // Create mask for bitmap In m_csBitmaps[0].hMask = CreateBitmapMask(hBitmapIn, m_csBitmaps[0].dwWidth, m_csBitmaps[0].dwHeight, crTransColorIn); if (m_csBitmaps[0].hMask == NULL) { FreeResources(); return BTNST_FAILEDMASK; } // if if (hBitmapOut) { m_csBitmaps[1].hBitmap = hBitmapOut; m_csBitmaps[1].crTransparent = crTransColorOut; // Get bitmap size nRetValue = ::GetObject(hBitmapOut, sizeof(csBitmapSize), &csBitmapSize); if (nRetValue == 0) { FreeResources(); return BTNST_INVALIDRESOURCE; } // if m_csBitmaps[1].dwWidth = (DWORD)csBitmapSize.bmWidth; m_csBitmaps[1].dwHeight = (DWORD)csBitmapSize.bmHeight; // Create mask for bitmap Out m_csBitmaps[1].hMask = CreateBitmapMask(hBitmapOut, m_csBitmaps[1].dwWidth, m_csBitmaps[1].dwHeight, crTransColorOut); if (m_csBitmaps[1].hMask == NULL) { FreeResources(); return BTNST_FAILEDMASK; } // if } // if } // if Invalidate(); return BTNST_OK; } // End of SetBitmaps
DWORD SkinBmp::SetBitmaps(CWnd * cwnd, CDC * dc, HBITMAP hBitmap, COLORREF crTransBitmap) { int nRetValue = 0; BITMAP csBitmapSize; // Free any loaded resource FreeResources(); cwnd->GetClientRect(m_ClientRect); if (hBitmap) { // Get bitmap size nRetValue = ::GetObject(hBitmap, sizeof(csBitmapSize), &csBitmapSize); if (nRetValue == 0) { FreeResources(); return FALSE; } // if // resize bitmap into client area HDC hdcSrc = CreateCompatibleDC(NULL); HBITMAP hbmOldSrc = (HBITMAP)::SelectObject(hdcSrc, hBitmap); HBITMAP hbmResized = ::CreateCompatibleBitmap(dc->m_hDC,m_ClientRect.Width(),m_ClientRect.Height()); HDC hdcTmp = CreateCompatibleDC(NULL); HBITMAP hbmTmp = (HBITMAP)::SelectObject(hdcTmp, hbmResized); ::StretchBlt(hdcTmp,0,0,m_ClientRect.Width(),m_ClientRect.Height(), hdcSrc,0,0,csBitmapSize.bmWidth,csBitmapSize.bmHeight,SRCCOPY); ::SelectObject(hdcSrc, hbmOldSrc); ::DeleteDC(hdcSrc); ::DeleteObject(hBitmap); ::SelectObject(hdcTmp, hbmTmp); ::DeleteDC(hdcTmp); hBitmap = hbmResized; m_Bitmaps.hBitmap = hBitmap; m_Bitmaps.crTransparent = crTransBitmap; m_Bitmaps.dwWidth = m_ClientRect.Width(); m_Bitmaps.dwHeight = m_ClientRect.Height(); // Create mask for bitmap In m_Bitmaps.hMask = CreateBitmapMask(hBitmap, m_Bitmaps.dwWidth, m_Bitmaps.dwHeight, crTransBitmap); if (m_Bitmaps.hMask == NULL) { FreeResources(); return FALSE; } // if } m_UseSkin = TRUE; // Invalidate(); return TRUE; } // End of SetBitmaps
void LevelView::ReimportTilemap() { DeleteObject(tilemap); DeleteObject(myMask); if(strlen(tilemapPath) > 0) { tilemap = LoadImage(NULL, tilemapPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); myMask = CreateBitmapMask(tilemap, RGB(0,0,0), tilemapWidth, tilemapHeight); } }
void LevelView::SetTiles(vector<Tile> tiles, LPCSTR path) { tilemapPath = path; vector<Tile>::iterator iterator = tiles.begin(); //if(myTiles == NULL) myTiles = new vector<Tile *>(); while(iterator!=tiles.end()) { Tile tile = *iterator; myTiles->push_back(new Tile(tile.GridX, tile.GridY, tile.TileX, tile.TileY, tile.Transparant, tile.Depth)); iterator++; } tilemap = LoadImage(NULL, tilemapPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); myMask = CreateBitmapMask(tilemap, RGB(0,0,0), tilemapWidth, tilemapHeight); }
CListViewCtrlEx::CListViewCtrlEx( void ) { m_hWndObserver = NULL; m_nHoverItem = -1; m_nHoverSubItem = -1; m_fontLink.Attach( BkFontPool::GetFont(FALSE,TRUE,FALSE,0) ); m_fontBold.Attach( BkFontPool::GetFont(TRUE,FALSE,FALSE) ); m_fontTitle.Attach( BkFontPool::GetFont(TRUE,FALSE,FALSE,4) ); m_fontDef.Attach( BkFontPool::GetFont(BKF_DEFAULTFONT)); m_bitmapCheck.Attach( BkBmpPool::GetBitmap(IDB_BITMAP_LISTCTRL_CHECK) ); m_bitmapExpand.Attach( BkBmpPool::GetBitmap(IDB_BITMAP_MINUS_PLUS) ); m_bitmapRadio.Attach( BkBmpPool::GetBitmap(IDB_BITMAP_LISTCTRL_RADIO) ); m_bitmapCombo.Attach(BkBmpPool::GetBitmap(IDB_BITMAP_LISTCTRL_COMBO)); CreateBitmapMask(m_bitmapRadio, m_bitmapRadioMask, 0, 0, 0); m_strEmptyString = _T("ûÓÐÄÚÈÝ"); m_bOnlyShowRisk = false; ::InitializeCriticalSection(&m_hListLock); }
void LevelView::StartGame() { DeleteObject(tilemap); DeleteObject(myMask); if(myTiles != NULL) { Tile * pTile; vector<Tile*>::iterator iterator = myTiles->begin(); while(iterator != myTiles->end()) { pTile = *iterator; delete pTile; iterator++; } myTiles->clear(); } if(surfaces != NULL) { Surface * pSurface; vector<Surface*>::iterator it = surfaces->begin(); while(it != surfaces->end()) { pSurface = *it; pSurface = NULL; it++; } surfaces->clear(); } if(strlen(tilemapPath) > 0) { tilemap = LoadImage(NULL, tilemapPath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); myMask = CreateBitmapMask(tilemap, RGB(0,0,0), tilemapWidth, tilemapHeight); } }
void DrawListBox(HWND hwnd,LISTBOX *lb,HDC hdc) { HDC hdcmem = CreateCompatibleDC(hdc); HDC hdcBuffer = CreateCompatibleDC(hdc); HBITMAP hbmOldBuffer; HBITMAP hbmOld; RECT rect; RECT rect1; GetClientRect(hwnd,&rect); HBITMAP hbmBuffer = CreateCompatibleBitmap(hdc,rect.right,rect.bottom); hbmOldBuffer=(HBITMAP)SelectObject(hdcBuffer,hbmBuffer); HBRUSH active=CreateSolidBrush(MAKECOLORREF(lb->cdt->lbdt.Current)); HBRUSH select=CreateSolidBrush(MAKECOLORREF(lb->cdt->lbdt.Selected)); hbmOld=(HBITMAP)SelectObject(hdcmem,lb->background[lb->cdt->lbdt.bitmapindex]); // draw background FillRectWithPattern(hdcBuffer,&rect,hdcmem,&lb->cdt->lbdt.bitmap); int bwidth,bheight; int nRows=SendMessage(hwnd,LB_GETCOUNT,0,0); char text[50]; int center= MulDiv(lb->cdt->lbdt.ItemHeight - lb->bmf[lb->cdt->lbdt.fontindex].height,1,2); //int center=0; RECT rc_active,rc_selected; // find selected row int nCurSel=SendMessage(hwnd,LB_GETCURSEL,0,0); if (nCurSel != LB_ERR) { SendMessage(hwnd,LB_GETITEMRECT,nCurSel,(LPARAM) &rc_selected); //draw background of selected row FillRect(hdcBuffer ,&rc_selected,select); } SendMessage(hwnd,LB_GETITEMRECT,lb->active,(LPARAM) &rc_active); // draw background of active row FillRect(hdcBuffer ,&rc_active,active); int start=SendMessage(hwnd,LB_GETTOPINDEX,0,0); int num=rect.bottom/lb->cdt->lbdt.ItemHeight; int end=min(nRows,start+num+1); for (int i=start;i < end;i++) { SendMessage(hwnd,LB_GETTEXT,(WPARAM)i,(LPARAM)&text); // draw text to bitmap HBITMAP hbmText=DrawTextToBitmap(hdc,text,&lb->bmf[lb->cdt->lbdt.fontindex],&bwidth,&bheight); // create bitmap mask HBITMAP mask=CreateBitmapMask(hbmText,MAKECOLORREF(lb->bmf[lb->cdt->lbdt.fontindex].bgColor)); //BITMAP mask=CreateBitmapMask(hbmText,RGB(0,109,192)); SelectObject(hdcmem,mask); SendMessage(hwnd,LB_GETITEMRECT,i,(LPARAM) &rect1); // draw text mask bitmap in buffer BitBlt(hdcBuffer, lb->leftindent, rect1.top+center, bwidth, bheight, hdcmem, 0, 0, SRCAND); SelectObject(hdcmem,hbmText); // draw text bitmap in buffer BitBlt(hdcBuffer, lb->leftindent, rect1.top+center, bwidth, bheight, hdcmem, 0, 0, SRCPAINT); SelectObject(hdcmem,hbmOld); DeleteObject(hbmText); DeleteObject(mask); } DrawFocusRect(hdcBuffer,&rc_selected); // draw buffer on screen BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcBuffer, 0, 0, SRCCOPY); //restore old object an delete hdc SelectObject(hdcmem, hbmOld); DeleteDC(hdcmem); SelectObject(hdcBuffer,hbmOldBuffer); DeleteDC(hdcBuffer); DeleteObject(hbmBuffer); DeleteObject(select); DeleteObject(active); }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: { UINT ret; BITMAP bm; g_hbmBall = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BALL)); if(g_hbmBall == NULL) MessageBox(hwnd, "Could not load IDB_BALL!", "Error", MB_OK | MB_ICONEXCLAMATION); g_hbmMask = CreateBitmapMask(g_hbmBall, RGB(0, 0, 0)); if(g_hbmMask == NULL) MessageBox(hwnd, "Could not create mask!", "Error", MB_OK | MB_ICONEXCLAMATION); GetObject(g_hbmBall, sizeof(bm), &bm); ZeroMemory(&g_ballInfo, sizeof(g_ballInfo)); g_ballInfo.width = bm.bmWidth; g_ballInfo.height = bm.bmHeight; g_ballInfo.dx = BALL_MOVE_DELTA; g_ballInfo.dy = BALL_MOVE_DELTA; ret = SetTimer(hwnd, ID_TIMER, 50, NULL); if(ret == 0) MessageBox(hwnd, "Could not SetTimer()!", "Error", MB_OK | MB_ICONEXCLAMATION); } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_PAINT: { RECT rcClient; PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); GetClientRect(hwnd, &rcClient); DrawBall(hdc, &rcClient); EndPaint(hwnd, &ps); } break; case WM_TIMER: { RECT rcClient; HDC hdc = GetDC(hwnd); GetClientRect(hwnd, &rcClient); UpdateBall(&rcClient); DrawBall(hdc, &rcClient); ReleaseDC(hwnd, hdc); } break; case WM_DESTROY: KillTimer(hwnd, ID_TIMER); DeleteObject(g_hbmBall); DeleteObject(g_hbmMask); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: switch(LOWORD(wParam)) { case ID_FILE_EXIT: PostMessage(hwnd, WM_CLOSE, 0, 0); break; } break; case WM_SIZE: RedrawControls(); break; case WM_CREATE: { HMENU hMenu, hSubMenu; hMenu = CreateMenu(); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, ID_FILE_OPEN, "&Open..."); AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "&Exit"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File"); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, "&About..."); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help"); SetMenu(hwnd, hMenu); } { g_hbmBall = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1)); if(g_hbmBall == NULL) { MessageBox(hwnd, "Could not load IDB_BALL!", "Error", MB_OK | MB_ICONEXCLAMATION); } g_hbmMask = CreateBitmapMask(g_hbmBall, RGB(0, 0, 0)); if(g_hbmMask == NULL) { MessageBox(hwnd, "Could not create mask!", "Error", MB_OK | MB_ICONEXCLAMATION); } } { if(S_OK != InitializeComponent(hwnd)) { MessageBox(hwnd, "Could not create components!", "Error", MB_OK | MB_ICONEXCLAMATION); // XXX: Any cleaning needed? PostQuitMessage(0); } } break; case WM_PAINT: { BITMAP bm; PAINTSTRUCT ps; HBITMAP hbmOld; HDC hdc = BeginPaint(hwnd, &ps); HDC hdcMem = CreateCompatibleDC(hdc); GetObject(g_hbmBall, sizeof(bm), &bm); hbmOld = (HBITMAP) SelectObject(hdcMem, g_hbmMask); BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCAND); SelectObject(hdcMem, g_hbmBall); BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCPAINT); SelectObject(hdcMem, hbmOld); DeleteDC(hdcMem); EndPaint(hwnd, &ps); } break; case WM_LBUTTONDOWN: #if 0 { char szFileName[MAX_PATH]; HMODULE hModule = GetModuleHandle(NULL); GetModuleFileName(hModule, szFileName, MAX_PATH); MessageBox(hwnd, szFileName, "Test", MB_OK | MB_ICONINFORMATION); } #endif break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }