void CStaticEx::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用 CStatic::OnPaint() dc.SetTextColor(m_text_color); dc.SetBkMode(TRANSPARENT); dc.SelectObject(this->GetFont()); CRect rect; this->GetClientRect(&rect); if (m_draw_background_color) dc.FillSolidRect(rect, m_back_color); else DrawThemeParentBackground(m_hWnd, dc.GetSafeHdc(), &rect); //重绘控件区域以解决文字重叠的问题 CSize text_size = dc.GetTextExtent(m_text); UINT format{ DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX }; //CDC::DrawText()函数的文本格式 if (text_size.cx > rect.Width()) //如果文本宽度超过了矩形区域的宽度,设置了居中时左对齐 { if (m_align == Alignment::RIGHT) format |= DT_RIGHT; } else { switch (m_align) { case Alignment::RIGHT: format |= DT_RIGHT; break; case Alignment::CENTER: format |= DT_CENTER; break; } } dc.DrawText(m_text, rect, format); }
static void GB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused) { static const int states[] = { GBS_NORMAL, GBS_DISABLED, GBS_NORMAL, GBS_NORMAL, GBS_NORMAL }; RECT bgRect, textRect, contentRect; int state = states[ drawState ]; WCHAR *text = get_button_text(hwnd); LOGFONTW lf; HFONT font, hPrevFont = NULL; BOOL created_font = FALSE; HRESULT hr = GetThemeFont(theme, hDC, BP_GROUPBOX, state, TMT_FONT, &lf); if (SUCCEEDED(hr)) { font = CreateFontIndirectW(&lf); if (!font) TRACE("Failed to create font\n"); else { hPrevFont = SelectObject(hDC, font); created_font = TRUE; } } else { font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0); hPrevFont = SelectObject(hDC, font); } GetClientRect(hwnd, &bgRect); textRect = bgRect; if (text) { SIZE textExtent; GetTextExtentPoint32W(hDC, text, lstrlenW(text), &textExtent); bgRect.top += (textExtent.cy / 2); textRect.left += 10; textRect.bottom = textRect.top + textExtent.cy; textRect.right = textRect.left + textExtent.cx + 4; ExcludeClipRect(hDC, textRect.left, textRect.top, textRect.right, textRect.bottom); } GetThemeBackgroundContentRect(theme, hDC, BP_GROUPBOX, state, &bgRect, &contentRect); ExcludeClipRect(hDC, contentRect.left, contentRect.top, contentRect.right, contentRect.bottom); if (IsThemeBackgroundPartiallyTransparent(theme, BP_GROUPBOX, state)) DrawThemeParentBackground(hwnd, hDC, NULL); DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL); SelectClipRgn(hDC, NULL); if (text) { InflateRect(&textRect, -2, 0); DrawThemeText(theme, hDC, BP_GROUPBOX, state, text, lstrlenW(text), 0, 0, &textRect); HeapFree(GetProcessHeap(), 0, text); } if (created_font) DeleteObject(font); if (hPrevFont) SelectObject(hDC, hPrevFont); }
HRESULT xpt_DrawTheme(XPTHANDLE xptHandle, HWND hwnd, HDC hdc, int type, int state, const RECT *sizeRect, const RECT *clipRect) { mir_cslock lck(xptCS); if (xpt_IsThemed(xptHandle)) { if (IsThemeBackgroundPartiallyTransparent(((XPTObject*)xptHandle)->hThemeHandle, type, state)) { DrawThemeParentBackground(hwnd, hdc, sizeRect); return DrawThemeBackground(((XPTObject*)xptHandle)->hThemeHandle, hdc, type, state, sizeRect, clipRect); } } return S_FALSE; }
static void CB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags) { static const int cb_states[3][5] = { { CBS_UNCHECKEDNORMAL, CBS_UNCHECKEDDISABLED, CBS_UNCHECKEDHOT, CBS_UNCHECKEDPRESSED, CBS_UNCHECKEDNORMAL }, { CBS_CHECKEDNORMAL, CBS_CHECKEDDISABLED, CBS_CHECKEDHOT, CBS_CHECKEDPRESSED, CBS_CHECKEDNORMAL }, { CBS_MIXEDNORMAL, CBS_MIXEDDISABLED, CBS_MIXEDHOT, CBS_MIXEDPRESSED, CBS_MIXEDNORMAL } }; static const int rb_states[2][5] = { { RBS_UNCHECKEDNORMAL, RBS_UNCHECKEDDISABLED, RBS_UNCHECKEDHOT, RBS_UNCHECKEDPRESSED, RBS_UNCHECKEDNORMAL }, { RBS_CHECKEDNORMAL, RBS_CHECKEDDISABLED, RBS_CHECKEDHOT, RBS_CHECKEDPRESSED, RBS_CHECKEDNORMAL } }; static const int cb_size = 13; RECT bgRect, textRect; HFONT font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0); HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL; LRESULT checkState = SendMessageW(hwnd, BM_GETCHECK, 0, 0); DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE); int part = ((dwStyle & BUTTON_TYPE) == BS_RADIOBUTTON) || ((dwStyle & BUTTON_TYPE) == BS_AUTORADIOBUTTON) ? BP_RADIOBUTTON : BP_CHECKBOX; int state = (part == BP_CHECKBOX) ? cb_states[ checkState ][ drawState ] : rb_states[ checkState ][ drawState ]; WCHAR *text = get_button_text(hwnd); GetClientRect(hwnd, &bgRect); GetThemeBackgroundContentRect(theme, hDC, part, state, &bgRect, &textRect); if (dtFlags & DT_SINGLELINE) /* Center the checkbox / radio button to the text. */ bgRect.top = bgRect.top + (textRect.bottom - textRect.top - cb_size) / 2; /* adjust for the check/radio marker */ bgRect.bottom = bgRect.top + cb_size; bgRect.right = bgRect.left + cb_size; textRect.left = bgRect.right + 6; if (IsThemeBackgroundPartiallyTransparent(theme, part, state)) DrawThemeParentBackground(hwnd, hDC, NULL); DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL); if (text) { DrawThemeText(theme, hDC, part, state, text, lstrlenW(text), dtFlags, 0, &textRect); HeapFree(GetProcessHeap(), 0, text); } if (hPrevFont) SelectObject(hDC, hPrevFont); }
LRESULT CStaticEx::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) { // TODO: 在此添加专用代码和/或调用基类 if (message == WM_SETTEXT) { CRect rect; CDC* pDC = GetDC(); GetClientRect(rect); DrawThemeParentBackground(m_hWnd, pDC->GetSafeHdc(), &rect); ReleaseDC(pDC); } return CStatic::DefWindowProc(message, wParam, lParam); }
//************************************************************************************************** void LTDrawToolBar::PaintToolButtonState( int iState, CDC* pDC, CRect rArea, LTVirtualButton* pButton, void* pContext ) { int iColor; int iIndex = 0; LTDrawToolBar* pDrawToobalr = (LTDrawToolBar*) pContext; if (iState == BTN_STATE_NORMAL) iColor = RGB(200,200,200); else if (iState == BTN_STATE_HOT) iColor = RGB(220,200,200); else if (iState == BTN_STATE_PRESSED) iColor = RGB(200,200,200); else if (iState == BTN_STATE_DISABLED) iColor = RGB(200,200,200); if (pButton == pDrawToobalr->p_PenButton) iIndex = 0; else if (pButton == pDrawToobalr->p_RectButton) iIndex = 1; else if (pButton == pDrawToobalr->p_ArrowButton) iIndex = 2; int iHeight = pDrawToobalr->p_ActiveIcons->GetHeight(); Gdiplus::Image* pImage = pDrawToobalr->p_DisabledIcons; if (iState == BTN_STATE_PRESSED) pImage = pDrawToobalr->p_ActiveIcons; Gdiplus::RectF rSource(0 * iIndex, 0, iHeight, iHeight); Gdiplus::RectF rTarget((rArea.left + (rArea.Width() - iHeight) / 2) , (rArea.top + (rArea.Height() - iHeight) / 2), iHeight, iHeight); //pDC->FillSolidRect(rArea, iColor); Gdiplus::Graphics oGraphics(pDC->m_hDC); //oGraphics.DrawImage(&imgBack, rTarget, 0, 0, // iHeight, iHeight, Gdiplus::UnitPixel); CRect rAreaEx = rArea; rAreaEx.right += 1; DrawThemeParentBackground(pDrawToobalr->m_hWnd, pDC->m_hDC, rAreaEx); //DrawThemeBackground(pDrawToobalr->h_Theme, pDC->m_hDC, BP_PUSHBUTTON, iState, rAreaEx, NULL); oGraphics.DrawImage(pImage, rTarget, iHeight * iIndex, 0, iHeight, iHeight, Gdiplus::UnitPixel); }
static void GB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags) { static const int states[] = { GBS_NORMAL, GBS_DISABLED, GBS_NORMAL, GBS_NORMAL, GBS_NORMAL }; RECT bgRect, textRect, contentRect; HFONT font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0); HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL; int state = states[ drawState ]; WCHAR *text = get_button_text(hwnd); GetClientRect(hwnd, &bgRect); textRect = bgRect; if (text) { SIZE textExtent; GetTextExtentPoint32W(hDC, text, lstrlenW(text), &textExtent); bgRect.top += (textExtent.cy / 2); textRect.left += 10; textRect.bottom = textRect.top + textExtent.cy; textRect.right = textRect.left + textExtent.cx + 4; ExcludeClipRect(hDC, textRect.left, textRect.top, textRect.right, textRect.bottom); } GetThemeBackgroundContentRect(theme, hDC, BP_GROUPBOX, state, &bgRect, &contentRect); ExcludeClipRect(hDC, contentRect.left, contentRect.top, contentRect.right, contentRect.bottom); if (IsThemeBackgroundPartiallyTransparent(theme, BP_GROUPBOX, state)) DrawThemeParentBackground(hwnd, hDC, NULL); DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL); SelectClipRgn(hDC, NULL); if (text) { textRect.left += 2; textRect.right -= 2; DrawThemeText(theme, hDC, BP_GROUPBOX, state, text, lstrlenW(text), 0, 0, &textRect); HeapFree(GetProcessHeap(), 0, text); } if (hPrevFont) SelectObject(hDC, hPrevFont); }
LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { HDC hdc = (HDC) wParam; if (!TrayTheme) { bHandled = FALSE; return 0; } RECT rect; GetClientRect(&rect); if (IsThemeBackgroundPartiallyTransparent(TrayTheme, TNP_BACKGROUND, 0)) DrawThemeParentBackground(m_hWnd, hdc, &rect); DrawThemeBackground(TrayTheme, hdc, TNP_BACKGROUND, 0, &rect, 0); return TRUE; }
/* Draw themed border */ static void nc_paint (HTHEME theme, HWND hwnd, HRGN region) { HRGN cliprgn = region; DWORD exStyle = GetWindowLongW (hwnd, GWL_EXSTYLE); if (exStyle & WS_EX_CLIENTEDGE) { HDC dc; RECT r; int cxEdge = GetSystemMetrics (SM_CXEDGE), cyEdge = GetSystemMetrics (SM_CYEDGE); int part = EP_EDITTEXT; int state = ETS_NORMAL; DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE); if (!IsWindowEnabled (hwnd)) state = ETS_DISABLED; else if (dwStyle & ES_READONLY) state = ETS_READONLY; else if (GetFocus() == hwnd) state = ETS_FOCUSED; GetWindowRect(hwnd, &r); /* New clipping region passed to default proc to exclude border */ cliprgn = CreateRectRgn (r.left + cxEdge, r.top + cyEdge, r.right - cxEdge, r.bottom - cyEdge); if (region != (HRGN)1) CombineRgn (cliprgn, cliprgn, region, RGN_AND); OffsetRect(&r, -r.left, -r.top); dc = GetDCEx(hwnd, region, DCX_WINDOW|DCX_INTERSECTRGN); OffsetRect(&r, -r.left, -r.top); if (IsThemeBackgroundPartiallyTransparent (theme, part, state)) DrawThemeParentBackground(hwnd, dc, &r); DrawThemeBackground (theme, dc, part, state, &r, 0); ReleaseDC(hwnd, dc); } /* Call default proc to get the scrollbars etc. also painted */ DefWindowProcW (hwnd, WM_NCPAINT, (WPARAM)cliprgn, 0); }
static void PB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused) { static const int states[] = { PBS_NORMAL, PBS_DISABLED, PBS_HOT, PBS_PRESSED, PBS_DEFAULTED }; RECT bgRect, textRect; HFONT font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0); HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL; int state = states[ drawState ]; WCHAR *text = get_button_text(hwnd); GetClientRect(hwnd, &bgRect); GetThemeBackgroundContentRect(theme, hDC, BP_PUSHBUTTON, state, &bgRect, &textRect); if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state)) DrawThemeParentBackground(hwnd, hDC, NULL); DrawThemeBackground(theme, hDC, BP_PUSHBUTTON, state, &bgRect, NULL); if (text) { DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect); HeapFree(GetProcessHeap(), 0, text); } if (focused) { MARGINS margins; RECT focusRect = bgRect; GetThemeMargins(theme, hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, NULL, &margins); focusRect.left += margins.cxLeftWidth; focusRect.top += margins.cyTopHeight; focusRect.right -= margins.cxRightWidth; focusRect.bottom -= margins.cyBottomHeight; DrawFocusRect( hDC, &focusRect ); } if (hPrevFont) SelectObject(hDC, hPrevFont); }
BOOL AFX_GLOBAL_DATA::DrawParentBackground(CWnd* pWnd, CDC* pDC, LPRECT rectClip) { ASSERT_VALID(pDC); ASSERT_VALID(pWnd); BOOL bRes = FALSE; CRgn rgn; if (rectClip != NULL) { rgn.CreateRectRgnIndirect(rectClip); pDC->SelectClipRgn(&rgn); } CWnd* pParent = pWnd->GetParent(); ASSERT_VALID(pParent); // In Windows XP, we need to call DrawThemeParentBackground function to implement // transparent controls bRes = DrawThemeParentBackground(pWnd->GetSafeHwnd(), pDC->GetSafeHdc(), rectClip) == S_OK; if (!bRes) { CPoint pt(0, 0); pWnd->MapWindowPoints(pParent, &pt, 1); pt = pDC->OffsetWindowOrg(pt.x, pt.y); bRes = (BOOL) pParent->SendMessage(WM_ERASEBKGND, (WPARAM)pDC->m_hDC); pDC->SetWindowOrg(pt.x, pt.y); } pDC->SelectClipRgn(NULL); return bRes; }
static void PB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags) { static const int states[] = { PBS_NORMAL, PBS_DISABLED, PBS_HOT, PBS_PRESSED, PBS_DEFAULTED }; RECT bgRect, textRect; HFONT font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0); HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL; int state = states[ drawState ]; WCHAR *text = get_button_text(hwnd); GetClientRect(hwnd, &bgRect); GetThemeBackgroundContentRect(theme, hDC, BP_PUSHBUTTON, state, &bgRect, &textRect); if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state)) DrawThemeParentBackground(hwnd, hDC, NULL); DrawThemeBackground(theme, hDC, BP_PUSHBUTTON, state, &bgRect, NULL); if (text) { DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect); HeapFree(GetProcessHeap(), 0, text); } if (hPrevFont) SelectObject(hDC, hPrevFont); }
static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { TRichUtil *ru; EnterCriticalSection(&csRich); ru = rlist_find(slist, hwnd); LeaveCriticalSection(&csRich); switch(msg) { case WM_THEMECHANGED: case WM_STYLECHANGED: RichUtil_ClearUglyBorder(ru); break; case WM_NCPAINT: { LRESULT ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); if (ru->hasUglyBorder && IsThemeActive()) { HANDLE hTheme = OpenThemeData(ru->hwnd, L"EDIT"); if (hTheme) { RECT rcBorder; RECT rcClient; int nState; HDC hdc = GetWindowDC(ru->hwnd); GetWindowRect(hwnd, &rcBorder); rcBorder.right -= rcBorder.left; rcBorder.bottom -= rcBorder.top; rcBorder.left = rcBorder.top = 0; CopyRect(&rcClient, &rcBorder); rcClient.left += ru->rect.left; rcClient.top += ru->rect.top; rcClient.right -= ru->rect.right; rcClient.bottom -= ru->rect.bottom; ExcludeClipRect(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); if(IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL)) DrawThemeParentBackground(hwnd, hdc, &rcBorder); if (!IsWindowEnabled(hwnd)) nState = ETS_DISABLED; else if(SendMessage(hwnd, EM_GETOPTIONS, 0, 0) & ECO_READONLY) nState = ETS_READONLY; else nState = ETS_NORMAL; DrawThemeBackground(hTheme, hdc, EP_EDITTEXT, nState, &rcBorder, NULL); CloseThemeData(hTheme); ReleaseDC(hwnd, hdc); return 0; } } return ret; } case WM_NCCALCSIZE: { LRESULT ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); NCCALCSIZE_PARAMS *ncsParam = (NCCALCSIZE_PARAMS*)lParam; if (ru->hasUglyBorder && IsThemeActive()) { HANDLE hTheme = OpenThemeData(hwnd, L"EDIT"); if (hTheme) { RECT rcClient; HDC hdc = GetDC(GetParent(hwnd)); ZeroMemory(&rcClient, sizeof(RECT)); if(GetThemeBackgroundContentRect(hTheme, hdc, EP_EDITTEXT, ETS_NORMAL, &ncsParam->rgrc[0], &rcClient) == S_OK) { ru->rect.left = rcClient.left-ncsParam->rgrc[0].left; ru->rect.top = rcClient.top-ncsParam->rgrc[0].top; ru->rect.right = ncsParam->rgrc[0].right-rcClient.right; ru->rect.bottom = ncsParam->rgrc[0].bottom-rcClient.bottom; CopyRect(&ncsParam->rgrc[0], &rcClient); CloseThemeData(hTheme); ReleaseDC(GetParent(hwnd), hdc); return WVR_REDRAW; } ReleaseDC(GetParent(hwnd), hdc); CloseThemeData(hTheme); } } return ret; } case WM_ENABLE: RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE|RDW_NOCHILDREN|RDW_UPDATENOW|RDW_FRAME); break; case WM_DESTROY: { LRESULT ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); EnterCriticalSection(&csRich); slist = rlist_remove(slist, ru); LeaveCriticalSection(&csRich); if (ru) free(ru); return ret; } } return mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); }
bool playlist_view::draw_items(HDC dc, int start_item, int count) { // profiler(draw_items); if (!drawing_enabled) return false; static_api_ptr_t<playlist_manager> playlist_api; HDC hdc_mem = 0; RECT rect, item, item_area, bk, draw/*,text*/; GetClientRect(wnd_playlist, &rect); rect.top += get_header_height(); int item_height = get_item_height(); HBRUSH br = 0; HBITMAP hbm_mem = 0, hbm_old = 0; pfc::array_t<int, pfc::alloc_fast_aggressive> widths; int total_width = get_column_widths(widths); int t = columns.get_count(); const bit_array & p_mask = g_cache.active_get_columns_mask(); item_area.left = rect.left; item_area.right = rect.right; item_area.top = rect.top + (item_height*start_item); item_area.bottom = item_area.top + (item_height*count); item.left = 0 - horizontal_offset; item.right = item.left + total_width; item.top = 0; item.bottom = item.top + item_height; bk.top = 0; bk.left = 0; bk.bottom = item_height*count; bk.right = rect.right - rect.left; /*static */pfc::string8_fast_aggressive temp; temp.prealloc(512); /* edit01 */ hdc_mem = CreateCompatibleDC(dc); COLORREF colourfore = 0xff; hbm_mem = CreateCompatibleBitmap(dc, rect.right - rect.left, item_height*count); hbm_old = (HBITMAP)SelectObject(hdc_mem, hbm_mem); HGDIOBJ font_old = SelectObject(hdc_mem, g_font); cui::colours::helper p_helper(appearance_client_pv_impl::g_guid); //fill entire area with back colour br = CreateSolidBrush(p_helper.get_colour(cui::colours::colour_background)); FillRect(hdc_mem, &bk, br); DeleteObject(br); //need checks here because of filling background { int total = playlist_api->activeplaylist_get_item_count(); if (start_item + count + scroll_item_offset > total) //end item is NOT inclusive { count -= (start_item + count + scroll_item_offset) - total; } } int end_item = start_item + count; //draw each item int n, focus = playlist_api->activeplaylist_get_focus_item(); // static int pcount; t_size playing_index, playing_playlist; playlist_api->get_playing_item_location(&playing_playlist, &playing_index); bool b_playback = static_api_ptr_t<play_control>()->is_playing(); if (g_cache.get_active_playlist() != playing_playlist) playing_index = pfc_infinite; for (n = start_item; n < end_item; n++) { bool sel = playlist_api->activeplaylist_is_item_selected(n + scroll_item_offset); bool b_focused = GetFocus() == wnd_playlist || IsChild(wnd_playlist, GetFocus()); bool b_playing = b_playback && playing_index == (n + scroll_item_offset); //draw each column of each item int theme_state = NULL; if (sel) theme_state = (b_playing ? LISS_HOTSELECTED : (b_focused ? LISS_SELECTED : LISS_SELECTEDNOTFOCUS)); else if (b_playing) theme_state = LISS_HOT; bool b_themed = m_theme && p_helper.get_themed() && IsThemePartDefined(m_theme, LVP_LISTITEM, theme_state); if (b_themed && theme_state) { if (IsThemeBackgroundPartiallyTransparent(m_theme, LVP_LISTITEM, theme_state)) DrawThemeParentBackground(get_wnd(), hdc_mem, &item); DrawThemeBackground(m_theme, hdc_mem, LVP_LISTITEM, theme_state, &item, NULL); } //int total = playlist_api->activeplaylist_get_item_count(); int c, offset = 0, i = 0; for (c = 0; c < t; c++) { if (p_mask[c]) { draw.left = item.left + offset; draw.top = item.top; offset += widths[i]; draw.right = item.left + offset; draw.bottom = item.bottom; { // profiler_debug(draw_item_get_string); g_cache.active_get_display_name(n + scroll_item_offset, i, temp); } colourinfo colours(0x000000, 0x000000, 0xFF, 0xFF, 0, 0xFF); g_cache.active_get_colour(n + scroll_item_offset, i, colours); if (b_themed) { //COLORREF cr_back= get_default_colour(colours::COLOUR_BACK); //colourfore = get_default_colour(colours::COLOUR_TEXT); //GetThemeColor(m_theme, LVP_LISTITEM, sel ? (GetFocus() == wnd_playlist ? LIS_SELECTED : LIS_SELECTEDNOTFOCUS) : LIS_NORMAL, TMT_WINDOWTEXT, &colourfore); colourfore = GetThemeSysColor(m_theme, sel ? COLOR_BTNTEXT : COLOR_WINDOWTEXT); //GetThemeColor(m_theme, LVP_LISTITEM, sel ? (GetFocus() == wnd_playlist ? LIS_SELECTED : LIS_SELECTEDNOTFOCUS) : LIS_NORMAL, TMT_TEXTCOLOR, &colourfore); if (!theme_state) { //GetThemeColor(m_theme, LVP_LISTITEM, LIS_NORMAL, TMT_FILLCOLOR, &colourfore); br = CreateSolidBrush(colours.background_colour); FillRect(hdc_mem, &draw, br); } } else { if (sel) { /* TEST */ if (GetFocus() == wnd_playlist) { colourfore = colours.selected_text_colour; br = CreateSolidBrush(colours.selected_background_colour); } else { colourfore = colours.selected_text_colour_non_focus; br = CreateSolidBrush(colours.selected_background_colour_non_focus); } } else { colourfore = colours.text_colour; br = CreateSolidBrush(colours.background_colour); } //draw cell background //if (!b_themed) FillRect(hdc_mem, &draw, br); } if (br) { DeleteObject(br); br = 0; } //render text //if (b_themed) // DrawThemeText(m_theme, hdc_mem, LVP_LISTITEM, sel ? (GetFocus() == wnd_playlist ? LIS_SELECTED : LIS_SELECTEDNOTFOCUS) : LIS_NORMAL, L"test", 4, 0, 0, &draw); //else ui_helpers::text_out_colours_tab(hdc_mem, temp, temp.length(), 2, 1, &draw, sel, colourfore, TRUE, true, (cfg_ellipsis != 0), (ui_helpers::alignment)columns[c]->align); if (colours.use_frame_left) { HPEN pen = CreatePen(PS_SOLID, 1, colours.frame_left); HPEN pen_old = (HPEN)SelectObject(hdc_mem, pen); MoveToEx(hdc_mem, draw.left, draw.top, 0); LineTo(hdc_mem, draw.left, draw.bottom); SelectObject(hdc_mem, pen_old); DeleteObject(pen); } if (colours.use_frame_top) { HPEN pen = CreatePen(PS_SOLID, 1, colours.frame_top); HPEN pen_old = (HPEN)SelectObject(hdc_mem, pen); MoveToEx(hdc_mem, draw.left, draw.top, 0); LineTo(hdc_mem, draw.right, draw.top); SelectObject(hdc_mem, pen_old); DeleteObject(pen); } if (colours.use_frame_right) { HPEN pen = CreatePen(PS_SOLID, 1, colours.frame_right); HPEN pen_old = (HPEN)SelectObject(hdc_mem, pen); MoveToEx(hdc_mem, draw.right - 1, draw.top, 0); LineTo(hdc_mem, draw.right - 1, draw.bottom); SelectObject(hdc_mem, pen_old); DeleteObject(pen); } if (colours.use_frame_bottom) { HPEN pen = CreatePen(PS_SOLID, 1, colours.frame_bottom); HPEN pen_old = (HPEN)SelectObject(hdc_mem, pen); MoveToEx(hdc_mem, draw.right - 1, draw.bottom - 1, 0); LineTo(hdc_mem, draw.left - 1, draw.bottom - 1); SelectObject(hdc_mem, pen_old); DeleteObject(pen); } i++; } } //draw focus frame if ((n + scroll_item_offset) == focus) { if (m_always_show_focus || (!(SendMessage(get_wnd(), WM_QUERYUISTATE, NULL, NULL) & UISF_HIDEFOCUS) && b_focused)) { RECT rc_focus = item; if (m_theme && p_helper.get_themed() && IsThemePartDefined(m_theme, LVP_LISTITEM, LISS_SELECTED)) InflateRect(&rc_focus, -1, -1); if (!p_helper.get_bool(cui::colours::bool_use_custom_active_item_frame)) { DrawFocusRect(hdc_mem, &rc_focus); } else { br = CreateSolidBrush(p_helper.get_colour(cui::colours::colour_active_item_frame)); FrameRect(hdc_mem, &rc_focus, br); DeleteObject(br); } } } item.top += item_height; item.bottom += item_height; } BitBlt(dc, item_area.left, item_area.top, item_area.right - item_area.left, item_area.bottom - item_area.top, hdc_mem, 0, 0, SRCCOPY); if (font_old) SelectObject(hdc_mem, font_old); SelectObject(hdc_mem, hbm_old); DeleteObject(hbm_mem); DeleteDC(hdc_mem); return true; }
static void CB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused) { static const int cb_states[3][5] = { { CBS_UNCHECKEDNORMAL, CBS_UNCHECKEDDISABLED, CBS_UNCHECKEDHOT, CBS_UNCHECKEDPRESSED, CBS_UNCHECKEDNORMAL }, { CBS_CHECKEDNORMAL, CBS_CHECKEDDISABLED, CBS_CHECKEDHOT, CBS_CHECKEDPRESSED, CBS_CHECKEDNORMAL }, { CBS_MIXEDNORMAL, CBS_MIXEDDISABLED, CBS_MIXEDHOT, CBS_MIXEDPRESSED, CBS_MIXEDNORMAL } }; static const int rb_states[2][5] = { { RBS_UNCHECKEDNORMAL, RBS_UNCHECKEDDISABLED, RBS_UNCHECKEDHOT, RBS_UNCHECKEDPRESSED, RBS_UNCHECKEDNORMAL }, { RBS_CHECKEDNORMAL, RBS_CHECKEDDISABLED, RBS_CHECKEDHOT, RBS_CHECKEDPRESSED, RBS_CHECKEDNORMAL } }; static const int cb_size = 13; RECT bgRect, textRect; HFONT font, hPrevFont = NULL; LRESULT checkState = SendMessageW(hwnd, BM_GETCHECK, 0, 0); DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE); int part = ((dwStyle & BUTTON_TYPE) == BS_RADIOBUTTON) || ((dwStyle & BUTTON_TYPE) == BS_AUTORADIOBUTTON) ? BP_RADIOBUTTON : BP_CHECKBOX; int state = (part == BP_CHECKBOX) ? cb_states[ checkState ][ drawState ] : rb_states[ checkState ][ drawState ]; WCHAR *text = get_button_text(hwnd); LOGFONTW lf; BOOL created_font = FALSE; HRESULT hr = GetThemeFont(theme, hDC, part, state, TMT_FONT, &lf); if (SUCCEEDED(hr)) { font = CreateFontIndirectW(&lf); if (!font) TRACE("Failed to create font\n"); else { TRACE("font = %s\n", debugstr_w(lf.lfFaceName)); hPrevFont = SelectObject(hDC, font); created_font = TRUE; } } else font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0); GetClientRect(hwnd, &bgRect); GetThemeBackgroundContentRect(theme, hDC, part, state, &bgRect, &textRect); if (dtFlags & DT_SINGLELINE) /* Center the checkbox / radio button to the text. */ bgRect.top = bgRect.top + (textRect.bottom - textRect.top - cb_size) / 2; /* adjust for the check/radio marker */ bgRect.bottom = bgRect.top + cb_size; bgRect.right = bgRect.left + cb_size; textRect.left = bgRect.right + 6; DrawThemeParentBackground(hwnd, hDC, NULL); DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL); if (text) { DrawThemeText(theme, hDC, part, state, text, lstrlenW(text), dtFlags, 0, &textRect); if (focused) { RECT focusRect; focusRect = textRect; DrawTextW(hDC, text, lstrlenW(text), &focusRect, dtFlags | DT_CALCRECT); if (focusRect.right < textRect.right) focusRect.right++; focusRect.bottom = textRect.bottom; DrawFocusRect( hDC, &focusRect ); } HeapFree(GetProcessHeap(), 0, text); } if (created_font) DeleteObject(font); if (hPrevFont) SelectObject(hDC, hPrevFont); }
void CClosableTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS) { CRect rect(lpDIS->rcItem); int nTabIndex = lpDIS->itemID; if (nTabIndex < 0) return; TCHAR szLabel[256]; TC_ITEM tci; tci.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_STATE; tci.pszText = szLabel; tci.cchTextMax = _countof(szLabel); tci.dwStateMask = TCIS_HIGHLIGHTED; if (!GetItem(nTabIndex, &tci)) return; szLabel[_countof(szLabel) - 1] = _T('\0'); //TRACE("CClosableTabCtrl::DrawItem: item=%u, state=%08x, color=%08x, rc=%3d,%3d,%3dx%3d\n", nTabIndex, tci.dwState, GetTextColor(lpDIS->hDC), lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right - lpDIS->rcItem.left, lpDIS->rcItem.bottom - lpDIS->rcItem.top); CDC* pDC = CDC::FromHandle(lpDIS->hDC); if (!pDC) return; CRect rcFullItem(lpDIS->rcItem); bool bSelected = (lpDIS->itemState & ODS_SELECTED) != 0; /////////////////////////////////////////////////////////////////////////////////////// // Adding support for XP Styles (Vista Themes) for owner drawn tab controls simply // does *not* work under Vista. Maybe it works under XP (did not try), but that is // meaningless because under XP a owner drawn tab control is already rendered *with* // the proper XP Styles. So, for XP there is no need to care about the theme API at all. // // However, under Vista, a tab control which has the TCS_OWNERDRAWFIXED // style gets additional 3D-borders which are applied by Vista *after* WM_DRAWITEM // was processed. Thus, there is no known workaround available to prevent Vista from // adding those old fashioned 3D-borders. We can render the tab control items within // the WM_DRAWITEM handler in whatever style we want, but Vista will in each case // overwrite the borders of each tab control item with old fashioned 3D-borders... // // To complete this experience, tab controls also do not support NMCUSTOMDRAW. So, the // only known way to customize a tab control is by using TCS_OWNERDRAWFIXED which does // however not work properly under Vista. // // The "solution" which is currently implemented to prevent Vista from drawing those // 3D-borders is by using "ExcludeClipRect" to reduce the drawing area which is used // by Windows after WM_DRAWITEM was processed. This "solution" is very sensitive to // the used rectangles and offsets in general. Incrementing/Decrementing one of the // "rcItem", "rcFullItem", etc. rectangles makes the entire "solution" flawed again // because some borders would become visible again. // HTHEME hTheme = NULL; int iPartId = TABP_TABITEM; int iStateId = TIS_NORMAL; bool bVistaHotTracked = false; bool bVistaThemeActive = theApp.IsVistaThemeActive(); if (bVistaThemeActive) { // To determine if the current item is in 'hot tracking' mode, we need to evaluate // the current foreground color - there is no flag which would indicate this state // more safely. This applies only for Vista and for tab controls which have the // TCS_OWNERDRAWFIXED style. bVistaHotTracked = pDC->GetTextColor() == GetSysColor(COLOR_HOTLIGHT); hTheme = OpenThemeData(m_hWnd, L"TAB"); if (hTheme) { if (bSelected) { // get the real tab item rect rcFullItem.left += 1; rcFullItem.right -= 1; rcFullItem.bottom -= 1; } else rcFullItem.InflateRect(2, 2); // get the real tab item rect CRect rcBk(rcFullItem); if (bSelected) { iStateId = TTIS_SELECTED; if (nTabIndex == 0) { // First item if (nTabIndex == GetItemCount() - 1) iPartId = TABP_TOPTABITEMBOTHEDGE; // First & Last item else iPartId = TABP_TOPTABITEMLEFTEDGE; } else if (nTabIndex == GetItemCount() - 1) { // Last item iPartId = TABP_TOPTABITEMRIGHTEDGE; } else { iPartId = TABP_TOPTABITEM; } } else { rcBk.top += 2; iStateId = bVistaHotTracked ? TIS_HOT : TIS_NORMAL; if (nTabIndex == 0) { // First item if (nTabIndex == GetItemCount() - 1) iPartId = TABP_TABITEMBOTHEDGE; // First & Last item else iPartId = TABP_TABITEMLEFTEDGE; } else if (nTabIndex == GetItemCount() - 1) { // Last item iPartId = TABP_TABITEMRIGHTEDGE; } else { iPartId = TABP_TABITEM; } } if (IsThemeBackgroundPartiallyTransparent(hTheme, iPartId, iStateId)) DrawThemeParentBackground(m_hWnd, *pDC, &rcFullItem); DrawThemeBackground(hTheme, *pDC, iPartId, iStateId, &rcBk, NULL); } } // Following background clearing is needed for: // WinXP/Vista (when used without an application theme) // Vista (when used with an application theme but without a theme for the tab control) if ( (!IsThemeActive() || !IsAppThemed()) || (hTheme == NULL && bVistaThemeActive) ) pDC->FillSolidRect(&lpDIS->rcItem, GetSysColor(COLOR_BTNFACE)); int iOldBkMode = pDC->SetBkMode(TRANSPARENT); // Draw image on left side CImageList *piml = GetImageList(); if (tci.iImage >= 0 && piml && piml->m_hImageList) { IMAGEINFO ii; piml->GetImageInfo(0, &ii); rect.left += bSelected ? 8 : 4; piml->Draw(pDC, tci.iImage, CPoint(rect.left, rect.top + 2), ILD_TRANSPARENT); rect.left += (ii.rcImage.right - ii.rcImage.left); if (!bSelected) rect.left += 4; } bool bCloseable = m_bCloseable; if (bCloseable && GetParent()->SendMessage(UM_QUERYTAB, nTabIndex)) bCloseable = false; // Draw 'Close button' at right side if (bCloseable && m_ImgLstCloseButton.m_hImageList) { CRect rcCloseButton; GetCloseButtonRect(nTabIndex, rect, rcCloseButton, bSelected, bVistaThemeActive); HTHEME hThemeNC = bVistaThemeActive ? OpenThemeData(m_hWnd, _T("WINDOW")) : NULL; if (hThemeNC) { // Possible "Close" parts: WP_CLOSEBUTTON, WP_SMALLCLOSEBUTTON, WP_MDICLOSEBUTTON int iPartId = WP_SMALLCLOSEBUTTON; int iStateId = (bSelected || bVistaHotTracked) ? CBS_NORMAL : CBS_DISABLED; if (IsThemeBackgroundPartiallyTransparent(hTheme, iPartId, iStateId)) DrawThemeParentBackground(m_hWnd, *pDC, &rcCloseButton); DrawThemeBackground(hThemeNC, *pDC, iPartId, iStateId, rcCloseButton, NULL); CloseThemeData(hThemeNC); } else { m_ImgLstCloseButton.Draw(pDC, (bSelected || bVistaHotTracked) ? 0 : 1, rcCloseButton.TopLeft(), ILD_TRANSPARENT); } rect.right = rcCloseButton.left - 2; if (bSelected) rect.left += hTheme ? 4 : 2; } COLORREF crOldColor = CLR_NONE; if (tci.dwState & TCIS_HIGHLIGHTED) crOldColor = pDC->SetTextColor(RGB(192, 0, 0)); else if (bVistaHotTracked) crOldColor = pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT)); rect.top += bSelected ? 4 : 3; // Vista: Tab control has troubles with determining the width of a tab if the // label contains one '&' character. To get around this, we use the old code which // replaces one '&' character with two '&' characters and we do not specify DT_NOPREFIX // here when drawing the text. // // Vista: "DrawThemeText" can not be used in case we need a certain foreground color. Thus we always us // "DrawText" to always get the same font and metrics (just for safety). pDC->DrawText(szLabel, rect, DT_SINGLELINE | DT_TOP | DT_CENTER /*| DT_NOPREFIX*/); if (crOldColor != CLR_NONE) pDC->SetTextColor(crOldColor); pDC->SetBkMode(iOldBkMode); if (hTheme) { CRect rcClip(rcFullItem); if (bSelected) { rcClip.left -= 2 + 1; rcClip.right += 2 + 1; } else { rcClip.top += 2; } pDC->ExcludeClipRect(&rcClip); CloseThemeData(hTheme); } }
static INT_PTR CALLBACK PhotoDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { const unsigned long iPageId = 3; TCHAR szAvatarFileName[MAX_PATH], szTempPath[MAX_PATH], szTempFileName[MAX_PATH]; PhotoDlgProcData* dat = (PhotoDlgProcData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: if (!lParam) break; // Launched from userinfo TranslateDialogDefault(hwndDlg); SendDlgItemMessage(hwndDlg, IDC_LOAD, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_OPEN), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); SendDlgItemMessage(hwndDlg, IDC_LOAD, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hwndDlg, IDC_DELETE, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DELETE), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); SendDlgItemMessage(hwndDlg, IDC_DELETE, BUTTONSETASFLATBTN, TRUE, 0); ShowWindow(GetDlgItem(hwndDlg, IDC_SAVE), SW_HIDE); { dat = new PhotoDlgProcData; dat->ppro = (CJabberProto*)lParam; dat->hBitmap = NULL; dat->ppro->m_bPhotoChanged = FALSE; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); dat->ppro->WindowSubscribe(hwndDlg); } SendMessage(hwndDlg, WM_JABBER_REFRESH_VCARD, 0, 0); break; case WM_JABBER_REFRESH_VCARD: if (dat->hBitmap) { DeleteObject(dat->hBitmap); dat->hBitmap = NULL; DeleteFile(dat->ppro->m_szPhotoFileName); dat->ppro->m_szPhotoFileName[0] = '\0'; } EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE); dat->ppro->GetAvatarFileName(NULL, szAvatarFileName, _countof(szAvatarFileName)); if (_taccess(szAvatarFileName, 0) == 0) { if (GetTempPath(_countof(szTempPath), szTempPath) <= 0) mir_tstrcpy(szTempPath, _T(".\\")); if (GetTempFileName(szTempPath, _T("jab"), 0, szTempFileName) > 0) { dat->ppro->debugLog(_T("Temp file = %s"), szTempFileName); if (CopyFile(szAvatarFileName, szTempFileName, FALSE) == TRUE) { if ((dat->hBitmap = Bitmap_Load(szTempFileName)) != NULL) { FIP->FI_Premultiply(dat->hBitmap); mir_tstrcpy(dat->ppro->m_szPhotoFileName, szTempFileName); EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE); } else DeleteFile(szTempFileName); } else DeleteFile(szTempFileName); } } dat->ppro->m_bPhotoChanged = FALSE; InvalidateRect(hwndDlg, NULL, TRUE); UpdateWindow(hwndDlg); break; case WM_JABBER_CHANGED: dat->ppro->SetServerVcard(dat->ppro->m_bPhotoChanged, dat->ppro->m_szPhotoFileName); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_DELETE: if (dat->hBitmap) { DeleteObject(dat->hBitmap); dat->hBitmap = NULL; DeleteFile(dat->ppro->m_szPhotoFileName); dat->ppro->m_szPhotoFileName[0] = '\0'; dat->ppro->m_bPhotoChanged = TRUE; EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), FALSE); InvalidateRect(hwndDlg, NULL, TRUE); UpdateWindow(hwndDlg); dat->ppro->m_vCardUpdates |= (1UL << iPageId); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; case IDC_LOAD: TCHAR szFilter[512], szFileName[MAX_PATH]; Bitmap_GetFilter(szFilter, _countof(szFilter)); OPENFILENAME ofn = { 0 }; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwndDlg; ofn.lpstrFilter = szFilter; ofn.lpstrCustomFilter = NULL; ofn.lpstrFile = szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_FILEMUSTEXIST | OFN_DONTADDTORECENT; szFileName[0] = '\0'; if (GetOpenFileName(&ofn)) { struct _stat st; HBITMAP hNewBitmap; dat->ppro->debugLog(_T("File selected is %s"), szFileName); if (_tstat(szFileName, &st) < 0 || st.st_size > 40 * 1024) { MessageBox(hwndDlg, TranslateT("Only JPG, GIF, and BMP image files smaller than 40 KB are supported."), TranslateT("Jabber vCard"), MB_OK | MB_SETFOREGROUND); break; } if (GetTempPath(_countof(szTempPath), szTempPath) <= 0) mir_tstrcpy(szTempPath, _T(".\\")); if (GetTempFileName(szTempPath, _T("jab"), 0, szTempFileName) > 0) { dat->ppro->debugLog(_T("Temp file = %s"), szTempFileName); if (CopyFile(szFileName, szTempFileName, FALSE) == TRUE) { if ((hNewBitmap = Bitmap_Load(szTempFileName)) != NULL) { if (dat->hBitmap) { DeleteObject(dat->hBitmap); DeleteFile(dat->ppro->m_szPhotoFileName); } dat->hBitmap = hNewBitmap; mir_tstrcpy(dat->ppro->m_szPhotoFileName, szTempFileName); dat->ppro->m_bPhotoChanged = TRUE; EnableWindow(GetDlgItem(hwndDlg, IDC_DELETE), TRUE); InvalidateRect(hwndDlg, NULL, TRUE); UpdateWindow(hwndDlg); dat->ppro->m_vCardUpdates |= (1UL << iPageId); SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } else DeleteFile(szTempFileName); } else DeleteFile(szTempFileName); } } break; } break; case WM_PAINT: if (dat->hBitmap) { BITMAP bm; POINT ptSize, ptOrg, pt, ptFitSize; RECT rect; HWND hwndCanvas = GetDlgItem(hwndDlg, IDC_CANVAS); HDC hdcCanvas = GetDC(hwndCanvas); HDC hdcMem = CreateCompatibleDC(hdcCanvas); SelectObject(hdcMem, dat->hBitmap); SetMapMode(hdcMem, GetMapMode(hdcCanvas)); GetObject(dat->hBitmap, sizeof(BITMAP), (LPVOID)&bm); ptSize.x = bm.bmWidth; ptSize.y = bm.bmHeight; DPtoLP(hdcCanvas, &ptSize, 1); ptOrg.x = ptOrg.y = 0; DPtoLP(hdcMem, &ptOrg, 1); GetClientRect(hwndCanvas, &rect); InvalidateRect(hwndCanvas, NULL, TRUE); UpdateWindow(hwndCanvas); if (ptSize.x <= rect.right && ptSize.y <= rect.bottom) { pt.x = (rect.right - ptSize.x) / 2; pt.y = (rect.bottom - ptSize.y) / 2; ptFitSize = ptSize; } else { if (((float)(ptSize.x - rect.right)) / ptSize.x > ((float)(ptSize.y - rect.bottom)) / ptSize.y) { ptFitSize.x = rect.right; ptFitSize.y = (ptSize.y*rect.right) / ptSize.x; pt.x = 0; pt.y = (rect.bottom - ptFitSize.y) / 2; } else { ptFitSize.x = (ptSize.x*rect.bottom) / ptSize.y; ptFitSize.y = rect.bottom; pt.x = (rect.right - ptFitSize.x) / 2; pt.y = 0; } } RECT rc; GetClientRect(hwndCanvas, &rc); if (IsThemeActive()) DrawThemeParentBackground(hwndCanvas, hdcCanvas, &rc); else FillRect(hdcCanvas, &rc, (HBRUSH)GetSysColorBrush(COLOR_BTNFACE)); if (bm.bmBitsPixel == 32) { BLENDFUNCTION bf = { 0 }; bf.AlphaFormat = AC_SRC_ALPHA; bf.BlendOp = AC_SRC_OVER; bf.SourceConstantAlpha = 255; GdiAlphaBlend(hdcCanvas, pt.x, pt.y, ptFitSize.x, ptFitSize.y, hdcMem, ptOrg.x, ptOrg.y, ptSize.x, ptSize.y, bf); } else { SetStretchBltMode(hdcCanvas, COLORONCOLOR); StretchBlt(hdcCanvas, pt.x, pt.y, ptFitSize.x, ptFitSize.y, hdcMem, ptOrg.x, ptOrg.y, ptSize.x, ptSize.y, SRCCOPY); } DeleteDC(hdcMem); } break; case WM_NOTIFY: if (((LPNMHDR)lParam)->idFrom == 0) { switch (((LPNMHDR)lParam)->code) { case PSN_PARAMCHANGED: SendMessage(hwndDlg, WM_INITDIALOG, 0, ((PSHNOTIFY*)lParam)->lParam); break; case PSN_APPLY: dat->ppro->m_vCardUpdates &= ~(1UL << iPageId); dat->ppro->SaveVcardToDB(hwndDlg, iPageId); if (!dat->ppro->m_vCardUpdates) dat->ppro->SetServerVcard(dat->ppro->m_bPhotoChanged, dat->ppro->m_szPhotoFileName); break; } } break; case WM_DESTROY: DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_LOAD, BM_SETIMAGE, IMAGE_ICON, 0)); DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_DELETE, BM_SETIMAGE, IMAGE_ICON, 0)); dat->ppro->WindowUnsubscribe(hwndDlg); if (dat->hBitmap) { dat->ppro->debugLogA("Delete bitmap"); DeleteObject(dat->hBitmap); DeleteFile(dat->ppro->m_szPhotoFileName); } delete dat; break; } return FALSE; }
/** * name: PaintThemeButton * desc: Draws the themed button * param: ctl - BTNCTRL structure for the button * hdcMem - device context to draw to * rcClient - rectangle of the whole button * return: nothing **/ static void __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) { RECT rcText = { 0, 0, 0, 0 }; WCHAR wszText[MAX_PATH] = { 0 }; WORD ccText; // Draw the flat button if ((ctl->dwStyle & MBS_FLAT) && ctl->hThemeToolbar) { int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED; if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) { if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient))) DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient); } DrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), rcClient, rcClient); } else { // draw themed button background if (ctl->hThemeButton) { int state = IsWindowEnabled(ctl->hwnd) ? (ctl->stateId == PBS_NORMAL && ctl->defbutton ? PBS_DEFAULTED : ctl->stateId) : PBS_DISABLED; if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) { if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient))) DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient); } DrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, rcClient, rcClient); } } // calculate text rect { RECT sizeText; HFONT hOldFont; ccText = GetWindowTextW(ctl->hwnd, wszText, _countof(wszText)); if (ccText > 0) { hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); GetThemeTextExtent( ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, wszText, ccText, DST_PREFIXTEXT, NULL, &sizeText); if (ctl->cHot) { RECT rcHot; GetThemeTextExtent(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, L"&", 1, DST_PREFIXTEXT, NULL, &rcHot); sizeText.right -= (rcHot.right - rcHot.left); } SelectObject(hdcMem, hOldFont); rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - (sizeText.right - sizeText.left)) / 2; rcText.top = (rcClient->bottom - rcClient->top - (sizeText.bottom - sizeText.top)) / 2; rcText.right = rcText.left + (sizeText.right - sizeText.left); rcText.bottom = rcText.top + (sizeText.bottom - sizeText.top); if (ctl->stateId == PBS_PRESSED) { OffsetRect(&rcText, 1, 1); } } } PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText); // draw text if (ccText > 0 && ctl->hThemeButton) { HFONT hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); DrawThemeText(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, wszText, ccText, DST_PREFIXTEXT, 0, &rcText); SelectObject(hdcMem, hOldFont); } }
static int CALLBACK CheckboxWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { CCheckboxData *dat = (CCheckboxData*)GetWindowLongPtr(hWnd, GWLP_USERDATA); if (!dat) return 0; switch (Msg) { case UM_INITCHECKBOX: { HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); if (!hFont) hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); LOGFONT lf; GetObject(hFont, sizeof(lf), &lf); lf.lfWeight = FW_BOLD; dat->hFont = CreateFontIndirect(&lf); SendMessage(hWnd, UM_AUTOSIZE, 0, 0); } return 0; case UM_AUTOSIZE: { HTHEME hTheme = OpenThemeData(hWnd, L"BUTTON"); int Len = GetWindowTextLength(hWnd) + 1; HDC hdc = GetDC(hWnd); HFONT hOldFont = (HFONT)SelectObject(hdc, dat->hFont); RECT rcText = { 0 }; if (hTheme) { WCHAR *szText = (WCHAR*)_alloca(Len * sizeof(WCHAR)); GetWindowTextW(hWnd, szText, Len); GetThemeTextExtent(hTheme, hdc, BP_GROUPBOX, IsWindowEnabled(hWnd) ? GBS_NORMAL : GBS_DISABLED, szText, -1, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE, nullptr, &rcText); } else { SIZE size; wchar_t *szText = (wchar_t*)_alloca(Len * sizeof(wchar_t)); GetWindowText(hWnd, szText, Len); GetTextExtentPoint32(hdc, szText, (int)mir_wstrlen(szText), &size); rcText.right = size.cx; rcText.bottom = size.cy; } SelectObject(hdc, hOldFont); ReleaseDC(hWnd, hdc); if (hTheme) CloseThemeData(hTheme); OffsetRect(&rcText, CG_CHECKBOX_INDENT + CG_CHECKBOX_WIDTH + CG_TEXT_INDENT, 0); RECT rc; GetClientRect(hWnd, &rc); SetWindowPos(hWnd, nullptr, 0, 0, rcText.right + CG_ADDITIONAL_WIDTH, rc.bottom, SWP_NOMOVE | SWP_NOZORDER); } break; case BM_CLICK: SendMessage(hWnd, WM_LBUTTONDOWN, 0, 0); SendMessage(hWnd, WM_LBUTTONUP, 0, 0); return 0; case BM_GETCHECK: return dat->State & CGSM_ISCHECKED; case BM_SETCHECK: if ((wParam != BST_UNCHECKED && wParam != BST_CHECKED && wParam != BST_INDETERMINATE) || (wParam == BST_INDETERMINATE && dat->Style != BS_3STATE && dat->Style != BS_AUTO3STATE)) wParam = BST_CHECKED; dat->State &= ~CGSM_ISCHECKED; dat->State |= wParam; InvalidateRect(hWnd, nullptr, false); SendMessage(GetParent(hWnd), WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(hWnd), BN_CLICKED), (LPARAM)hWnd); return 0; case BM_SETSTATE: if (wParam) dat->State |= CGS_PRESSED; else dat->State &= ~CGS_PRESSED; InvalidateRect(hWnd, nullptr, false); return 0; case BM_GETSTATE: return (dat->State & CGSM_GETSTATE) | ((GetFocus() == hWnd) ? BST_FOCUS : 0); case WM_GETDLGCODE: return DLGC_BUTTON; case WM_THEMECHANGED: case WM_ENABLE: InvalidateRect(hWnd, nullptr, false); return 0; case WM_SETTEXT: if (CallWindowProc(dat->OldWndProc, hWnd, Msg, wParam, lParam)) SendMessage(hWnd, UM_AUTOSIZE, 0, 0); return 0; case WM_KEYDOWN: if (wParam == VK_SPACE) SendMessage(hWnd, BM_SETSTATE, true, 0); return 0; case WM_KEYUP: if (wParam == VK_SPACE) { SendMessage(hWnd, BM_SETCHECK, (SendMessage(hWnd, BM_GETCHECK, 0, 0) + 1) % ((dat->Style == BS_AUTO3STATE) ? 3 : 2), 0); SendMessage(hWnd, BM_SETSTATE, false, 0); } return 0; case WM_CAPTURECHANGED: SendMessage(hWnd, BM_SETSTATE, false, 0); return 0; case WM_ERASEBKGND: return true; case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: SetFocus(hWnd); SendMessage(hWnd, BM_SETSTATE, true, 0); SetCapture(hWnd); return 0; case WM_LBUTTONUP: if (GetCapture() == hWnd) ReleaseCapture(); SendMessage(hWnd, BM_SETSTATE, false, 0); if (dat->State & CGS_HOVERED && (dat->Style == BS_AUTOCHECKBOX || dat->Style == BS_AUTO3STATE)) SendMessage(hWnd, BM_SETCHECK, (SendMessage(hWnd, BM_GETCHECK, 0, 0) + 1) % ((dat->Style == BS_AUTO3STATE) ? 3 : 2), 0); return 0; case WM_MOUSEMOVE: { TRACKMOUSEEVENT tme = { 0 }; tme.cbSize = sizeof(tme); tme.dwFlags = TME_LEAVE; tme.dwHoverTime = HOVER_DEFAULT; tme.hwndTrack = hWnd; _TrackMouseEvent(&tme); } POINT pt; GetCursorPos(&pt); if ((WindowFromPoint(pt) == hWnd) ^ ((dat->State & CGS_HOVERED) != 0)) { dat->State ^= CGS_HOVERED; InvalidateRect(hWnd, nullptr, false); } return 0; case WM_MOUSELEAVE: if (dat->State & CGS_HOVERED) { dat->State &= ~CGS_HOVERED; InvalidateRect(hWnd, nullptr, false); } return 0; case WM_SETFOCUS: case WM_KILLFOCUS: case WM_SYSCOLORCHANGE: InvalidateRect(hWnd, nullptr, false); return 0; case WM_PAINT: { HDC hdc; PAINTSTRUCT ps; hdc = BeginPaint(hWnd, &ps); RECT rc; GetClientRect(hWnd, &rc); HDC hdcMem = CreateCompatibleDC(hdc); HBITMAP hbmMem = CreateCompatibleBitmap(hdc, rc.right, rc.bottom); HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem); HTHEME hTheme = OpenThemeData(hWnd, L"BUTTON"); if (hTheme) DrawThemeParentBackground(hWnd, hdcMem, nullptr); else FillRect(hdcMem, &rc, GetSysColorBrush(COLOR_3DFACE)); int StateID = 0; switch (SendMessage(hWnd, BM_GETCHECK, 0, 0)) { case BST_CHECKED: StateID += CBSCHECK_CHECKED; break; case BST_UNCHECKED: StateID += CBSCHECK_UNCHECKED; break; case BST_INDETERMINATE: StateID += CBSCHECK_MIXED; break; } if (!IsWindowEnabled(hWnd)) StateID += CBSSTATE_DISABLED; else if (dat->State & CGS_PRESSED && (GetCapture() != hWnd || dat->State & CGS_HOVERED)) StateID += CBSSTATE_PRESSED; else if (dat->State & CGS_PRESSED || dat->State & CGS_HOVERED) StateID += CBSSTATE_HOT; rc.left += CG_CHECKBOX_INDENT; rc.right = rc.left + CG_CHECKBOX_WIDTH; // left-align the image in the client area rc.top += CG_CHECKBOX_VERTINDENT; rc.bottom = rc.top + CG_CHECKBOX_WIDTH; // exact rc dimensions are necessary for DrawFrameControl to draw correctly if (hTheme) DrawThemeBackground(hTheme, hdcMem, BP_CHECKBOX, StateID, &rc, &rc); else { int dfcStates[] = { 0, 0, DFCS_PUSHED, DFCS_INACTIVE, DFCS_CHECKED, DFCS_CHECKED, DFCS_CHECKED | DFCS_PUSHED, DFCS_CHECKED | DFCS_INACTIVE, DFCS_BUTTON3STATE | DFCS_CHECKED, DFCS_BUTTON3STATE | DFCS_CHECKED, DFCS_BUTTON3STATE | DFCS_INACTIVE | DFCS_CHECKED | DFCS_PUSHED, DFCS_BUTTON3STATE | DFCS_INACTIVE | DFCS_CHECKED | DFCS_PUSHED }; _ASSERT(StateID >= 1 && StateID <= _countof(dfcStates)); DrawFrameControl(hdcMem, &rc, DFC_BUTTON, dfcStates[StateID - 1]); } GetClientRect(hWnd, &rc); rc.left += CG_CHECKBOX_INDENT + CG_CHECKBOX_WIDTH + CG_TEXT_INDENT; int Len = GetWindowTextLength(hWnd) + 1; wchar_t *szTextT = (wchar_t*)_alloca(Len * sizeof(wchar_t)); GetWindowText(hWnd, szTextT, Len); HFONT hOldFont = (HFONT)SelectObject(hdcMem, dat->hFont); SetBkMode(hdcMem, TRANSPARENT); if (hTheme) DrawThemeText(hTheme, hdcMem, BP_GROUPBOX, IsWindowEnabled(hWnd) ? GBS_NORMAL : GBS_DISABLED, szTextT, -1, DT_LEFT | DT_VCENTER | DT_SINGLELINE, 0, &rc); else DrawText(hdcMem, szTextT, -1, &rc, DT_LEFT | DT_VCENTER | DT_SINGLELINE); if (GetFocus() == hWnd) { RECT rcText = { 0 }; if (hTheme) GetThemeTextExtent(hTheme, hdcMem, BP_GROUPBOX, IsWindowEnabled(hWnd) ? GBS_NORMAL : GBS_DISABLED, szTextT, -1, DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE, nullptr, &rcText); else { SIZE size; GetTextExtentPoint32(hdcMem, szTextT, (int)mir_wstrlen(szTextT), &size); rcText.right = size.cx; rcText.bottom = size.cy; } rcText.bottom = rc.bottom; OffsetRect(&rcText, rc.left, 0); InflateRect(&rcText, 1, -1); DrawFocusRect(hdcMem, &rcText); } SelectObject(hdcMem, hOldFont); if (hTheme) CloseThemeData(hTheme); BitBlt(hdc, 0, 0, rc.right, rc.bottom, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hbmOld); DeleteObject(hbmMem); DeleteDC(hdcMem); EndPaint(hWnd, &ps); } return 0; case WM_DESTROY: if (dat->hFont) DeleteObject(dat->hFont); SetWindowLongPtr(hWnd, GWLP_USERDATA, 0); CallWindowProc(dat->OldWndProc, hWnd, Msg, wParam, lParam); delete dat; return 0; } return CallWindowProc(dat->OldWndProc, hWnd, Msg, wParam, lParam); }
static void on_draw_item(HWND hDlg, WPARAM wParam, LPARAM lParam) { static HBRUSH black_brush = 0; LPDRAWITEMSTRUCT draw_info = (LPDRAWITEMSTRUCT)lParam; if (!black_brush) black_brush = CreateSolidBrush(0); if (draw_info->CtlID == IDC_SYSPARAM_COLOR) { UINT state; HTHEME theme; RECT buttonrect; theme = OpenThemeData(NULL, WC_BUTTONW); if (theme) { MARGINS margins; if (draw_info->itemState & ODS_DISABLED) state = PBS_DISABLED; else if (draw_info->itemState & ODS_SELECTED) state = PBS_PRESSED; else state = PBS_NORMAL; if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state)) DrawThemeParentBackground(draw_info->hwndItem, draw_info->hDC, NULL); DrawThemeBackground(theme, draw_info->hDC, BP_PUSHBUTTON, state, &draw_info->rcItem, NULL); buttonrect = draw_info->rcItem; GetThemeMargins(theme, draw_info->hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, &draw_info->rcItem, &margins); buttonrect.left += margins.cxLeftWidth; buttonrect.top += margins.cyTopHeight; buttonrect.right -= margins.cxRightWidth; buttonrect.bottom -= margins.cyBottomHeight; if (draw_info->itemState & ODS_FOCUS) DrawFocusRect(draw_info->hDC, &buttonrect); CloseThemeData(theme); } else { state = DFCS_ADJUSTRECT | DFCS_BUTTONPUSH; if (draw_info->itemState & ODS_DISABLED) state |= DFCS_INACTIVE; else state |= draw_info->itemState & ODS_SELECTED ? DFCS_PUSHED : 0; DrawFrameControl(draw_info->hDC, &draw_info->rcItem, DFC_BUTTON, state); buttonrect = draw_info->rcItem; } if (!(draw_info->itemState & ODS_DISABLED)) { HBRUSH brush; int index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETCURSEL, 0, 0); index = SendDlgItemMessageW(hDlg, IDC_SYSPARAM_COMBO, CB_GETITEMDATA, index, 0); brush = CreateSolidBrush(metrics[index].color); InflateRect(&buttonrect, -1, -1); FrameRect(draw_info->hDC, &buttonrect, black_brush); InflateRect(&buttonrect, -1, -1); FillRect(draw_info->hDC, &buttonrect, brush); DeleteObject(brush); } } }
static LRESULT IPADDRESS_Draw (const IPADDRESS_INFO *infoPtr, HDC hdc) { static const WCHAR dotW[] = { '.', 0 }; RECT rect, rcPart; COLORREF bgCol, fgCol; HTHEME theme; int i, state = ETS_NORMAL; TRACE("\n"); GetClientRect (infoPtr->Self, &rect); theme = OpenThemeData(infoPtr->Self, WC_EDITW); if (theme) { DWORD dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE); if (!infoPtr->Enabled) state = ETS_DISABLED; else if (dwStyle & ES_READONLY) state = ETS_READONLY; else if (GetFocus() == infoPtr->Self) state = ETS_FOCUSED; GetThemeColor(theme, EP_EDITTEXT, state, TMT_FILLCOLOR, &bgCol); GetThemeColor(theme, EP_EDITTEXT, state, TMT_TEXTCOLOR, &fgCol); if (IsThemeBackgroundPartiallyTransparent (theme, EP_EDITTEXT, state)) DrawThemeParentBackground(infoPtr->Self, hdc, &rect); DrawThemeBackground (theme, hdc, EP_EDITTEXT, state, &rect, 0); } else { if (infoPtr->Enabled) { bgCol = comctl32_color.clrWindow; fgCol = comctl32_color.clrWindowText; } else { bgCol = comctl32_color.clr3dFace; fgCol = comctl32_color.clrGrayText; } FillRect (hdc, &rect, (HBRUSH)(DWORD_PTR)(bgCol+1)); DrawEdge (hdc, &rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); } SetBkColor (hdc, bgCol); SetTextColor(hdc, fgCol); for (i = 0; i < 3; i++) { GetWindowRect (infoPtr->Part[i].EditHwnd, &rcPart); MapWindowPoints( 0, infoPtr->Self, (POINT *)&rcPart, 2 ); rect.left = rcPart.right; GetWindowRect (infoPtr->Part[i+1].EditHwnd, &rcPart); MapWindowPoints( 0, infoPtr->Self, (POINT *)&rcPart, 2 ); rect.right = rcPart.left; if (theme) DrawThemeText(theme, hdc, EP_EDITTEXT, state, dotW, 1, DT_SINGLELINE | DT_CENTER | DT_BOTTOM, 0, &rect); else DrawTextW(hdc, dotW, 1, &rect, DT_SINGLELINE | DT_CENTER | DT_BOTTOM); } if (theme) CloseThemeData(theme); return 0; }
static void CB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused, LPARAM prfFlag) { static const int cb_states[3][5] = { { CBS_UNCHECKEDNORMAL, CBS_UNCHECKEDHOT, CBS_UNCHECKEDPRESSED, CBS_UNCHECKEDDISABLED, CBS_UNCHECKEDNORMAL }, { CBS_CHECKEDNORMAL, CBS_CHECKEDHOT, CBS_CHECKEDPRESSED, CBS_CHECKEDDISABLED, CBS_CHECKEDNORMAL }, { CBS_MIXEDNORMAL, CBS_MIXEDHOT, CBS_MIXEDPRESSED, CBS_MIXEDDISABLED, CBS_MIXEDNORMAL } }; static const int rb_states[2][5] = { { RBS_UNCHECKEDNORMAL, RBS_UNCHECKEDHOT, RBS_UNCHECKEDPRESSED, RBS_UNCHECKEDDISABLED, RBS_UNCHECKEDNORMAL }, { RBS_CHECKEDNORMAL, RBS_CHECKEDHOT, RBS_CHECKEDPRESSED, RBS_CHECKEDDISABLED, RBS_CHECKEDNORMAL } }; SIZE sz; RECT bgRect, textRect; HFONT font, hPrevFont = NULL; LRESULT checkState = get_button_state(hwnd) & 3; DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE); int part = ((dwStyle & BUTTON_TYPE) == BS_RADIOBUTTON) || ((dwStyle & BUTTON_TYPE) == BS_AUTORADIOBUTTON) ? BP_RADIOBUTTON : BP_CHECKBOX; int state = (part == BP_CHECKBOX) ? cb_states[ checkState ][ drawState ] : rb_states[ checkState ][ drawState ]; WCHAR *text; LOGFONTW lf; BOOL created_font = FALSE; HWND parent; HBRUSH hBrush; DWORD cdrf; HRESULT hr = GetThemeFont(theme, hDC, part, state, TMT_FONT, &lf); if (SUCCEEDED(hr)) { font = CreateFontIndirectW(&lf); if (!font) TRACE("Failed to create font\n"); else { TRACE("font = %s\n", debugstr_w(lf.lfFaceName)); hPrevFont = SelectObject(hDC, font); created_font = TRUE; } } else { font = get_button_font(hwnd); hPrevFont = SelectObject(hDC, font); } if (FAILED(GetThemePartSize(theme, hDC, part, state, NULL, TS_DRAW, &sz))) sz.cx = sz.cy = 13; GetClientRect(hwnd, &bgRect); if (prfFlag == 0) { DrawThemeParentBackground(hwnd, hDC, NULL); } parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd); if (!hBrush) /* did the app forget to call defwindowproc ? */ hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd ); FillRect( hDC, &bgRect, hBrush ); cdrf = BUTTON_SendCustomDraw(hwnd, hDC, CDDS_PREERASE, &bgRect); if (cdrf == CDRF_SKIPDEFAULT) goto cleanup; GetThemeBackgroundContentRect(theme, hDC, part, state, &bgRect, &textRect); if (dtFlags & DT_SINGLELINE) /* Center the checkbox / radio button to the text. */ bgRect.top = bgRect.top + (textRect.bottom - textRect.top - sz.cy) / 2; /* adjust for the check/radio marker */ bgRect.bottom = bgRect.top + sz.cy; bgRect.right = bgRect.left + sz.cx; textRect.left = bgRect.right + 6; DrawThemeBackground(theme, hDC, part, state, &bgRect, NULL); if (cdrf == CDRF_NOTIFYPOSTERASE) BUTTON_SendCustomDraw(hwnd, hDC, CDDS_POSTERASE, &bgRect); cdrf = BUTTON_SendCustomDraw(hwnd, hDC, CDDS_PREPAINT, &bgRect); if (cdrf == CDRF_SKIPDEFAULT) goto cleanup; text = get_button_text(hwnd); if (text) { DrawThemeText(theme, hDC, part, state, text, lstrlenW(text), dtFlags, 0, &textRect); if (focused) { RECT focusRect; focusRect = textRect; DrawTextW(hDC, text, lstrlenW(text), &focusRect, dtFlags | DT_CALCRECT); if (focusRect.right < textRect.right) focusRect.right++; focusRect.bottom = textRect.bottom; DrawFocusRect( hDC, &focusRect ); } HeapFree(GetProcessHeap(), 0, text); } if (cdrf == CDRF_NOTIFYPOSTPAINT) BUTTON_SendCustomDraw(hwnd, hDC, CDDS_POSTPAINT, &bgRect); cleanup: if (created_font) DeleteObject(font); if (hPrevFont) SelectObject(hDC, hPrevFont); }
static LRESULT CALLBACK OptionsFilterSubclassProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { if (message != WM_PAINT && message != WM_PRINT) return mir_callNextSubclass(hWnd, OptionsFilterSubclassProc, message, wParam, lParam); if (GetFocus() == hWnd || GetWindowTextLength(hWnd)) return mir_callNextSubclass(hWnd, OptionsFilterSubclassProc, message, wParam, lParam); RECT rc; GetClientRect(hWnd, &rc); HDC hdc; PAINTSTRUCT paint; if (message == WM_PAINT) hdc = BeginPaint(hWnd, &paint); else hdc = (HDC)wParam; TCHAR buf[255]; if (bSearchState == 1 && FilterLoadProgress < 100 && FilterLoadProgress > 0) mir_sntprintf(buf, SIZEOF(buf), TranslateT("Loading... %d%%"), FilterLoadProgress); else mir_sntprintf(buf, SIZEOF(buf), TranslateT("Search")); BOOL bDrawnByTheme = FALSE; int oldMode = SetBkMode(hdc, TRANSPARENT); HTHEME hTheme = OpenThemeData(hWnd, L"EDIT"); if (hTheme) { if (IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL)) DrawThemeParentBackground(hWnd, hdc, &rc); RECT rc2; GetThemeBackgroundContentRect(hTheme, hdc, EP_EDITTEXT, ETS_NORMAL, &rc, &rc2); rc2.top = 2 * rc.top - rc2.top; rc2.left = 2 * rc.left - rc2.left; rc2.bottom = 2 * rc.bottom - rc2.bottom; rc2.right = 2 * rc.right - rc2.right; DrawThemeBackground(hTheme, hdc, EP_EDITTEXT, ETS_NORMAL, &rc2, &rc); HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); HFONT oldFont = (HFONT)SelectObject(hdc, hFont); wchar_t *bufW = mir_t2u(buf); DrawThemeText(hTheme, hdc, EP_EDITTEXT, ETS_DISABLED, bufW, -1, 0, 0, &rc); mir_free(bufW); SelectObject(hdc, oldFont); CloseThemeData(hTheme); bDrawnByTheme = TRUE; } SetBkMode(hdc, oldMode); if (!bDrawnByTheme) { HFONT hFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0); HFONT oldFont = (HFONT)SelectObject(hdc, hFont); SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); FillRect(hdc, &rc, GetSysColorBrush(COLOR_WINDOW)); int oldMode = SetBkMode(hdc, TRANSPARENT); DrawText(hdc, buf, -1, &rc, 0); SetBkMode(hdc, oldMode); SelectObject(hdc, oldFont); } if (message == WM_PAINT) EndPaint(hWnd, &paint); return 0; }
void CWBButton::DrawBitmap(CDC * pDC, int mode) { if (m_State < FileLoaded) return; CRect rc; GetClientRect(rc); COLORREF crOldText = pDC->SetTextColor(RGB(0, 0, 0)); CDC dcImage, dcTrans, dcOffScr; // Create two memory dcs for the image and the mask dcImage.CreateCompatibleDC(pDC); dcTrans.CreateCompatibleDC(pDC); dcOffScr.CreateCompatibleDC(pDC); // Select the image into the appropriate dc CBitmap* pOldBitmapImage; switch (mode) { case normal: pOldBitmapImage = dcImage.SelectObject(&NormalBitmap); break; case select: pOldBitmapImage = dcImage.SelectObject(&SelectBitmap); break; case focus: pOldBitmapImage = dcImage.SelectObject(&FocusBitmap); break; case disable: pOldBitmapImage = dcImage.SelectObject(&DisableBitmap); break; default: return; } // Create the mask bitmap CBitmap bitmapTrans, OffScr; CBitmap* pOldBitmapOffScr; int nWidth = rc.Width(); int nHeight = rc.Height(); OffScr.CreateBitmap(nWidth, nHeight, (BYTE)pDC->GetDeviceCaps(PLANES), (BYTE)pDC->GetDeviceCaps(BITSPIXEL), NULL); pOldBitmapOffScr = dcOffScr.SelectObject(&OffScr); // Select the mask bitmap into the appropriate dc bitmapTrans.CreateBitmap(nWidth, nHeight, 1, 1, NULL); CBitmap* pOldBitmapTrans = dcTrans.SelectObject(&bitmapTrans); DrawThemeParentBackground(GetSafeHwnd(), dcOffScr.GetSafeHdc(), rc); // Build mask based on transparent colour COLORREF oldColor = dcImage.SetBkColor(m_TransparentColor); dcTrans.BitBlt(0, 0, nWidth, nHeight, &dcImage, 0, 0, SRCCOPY); // create monochrome bitmap dcOffScr.SetBkColor(oldColor); dcOffScr.BitBlt(0, 0, nWidth, nHeight, &dcImage, 0, 0, SRCINVERT); dcOffScr.BitBlt(0, 0, nWidth, nHeight, &dcTrans, 0, 0, SRCAND); dcOffScr.BitBlt(0, 0, nWidth, nHeight, &dcImage, 0, 0, SRCINVERT); pDC->BitBlt(0, 0, nWidth, nHeight, &dcOffScr, 0, 0, SRCCOPY); // Restore settings dcImage.SelectObject(pOldBitmapImage); dcTrans.SelectObject(pOldBitmapTrans); dcOffScr.SelectObject(pOldBitmapOffScr); //pDC->SetTextColor(crOldText); }
static void PB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused, LPARAM prfFlag) { static const int states[] = { PBS_NORMAL, PBS_HOT, PBS_PRESSED, PBS_DISABLED, PBS_DEFAULTED }; RECT bgRect, textRect; HFONT font = get_button_font(hwnd); HFONT hPrevFont = font ? SelectObject(hDC, font) : NULL; int state = states[ drawState ]; WCHAR *text; PBUTTON_DATA pdata = _GetButtonData(hwnd); HWND parent; DWORD cdrf; GetClientRect(hwnd, &bgRect); GetThemeBackgroundContentRect(theme, hDC, BP_PUSHBUTTON, state, &bgRect, &textRect); if (prfFlag == 0) { if (IsThemeBackgroundPartiallyTransparent(theme, BP_PUSHBUTTON, state)) DrawThemeParentBackground(hwnd, hDC, NULL); } parent = GetParent(hwnd); if (!parent) parent = hwnd; SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd ); cdrf = BUTTON_SendCustomDraw(hwnd, hDC, CDDS_PREERASE, &bgRect); if (cdrf == CDRF_SKIPDEFAULT) goto cleanup; DrawThemeBackground(theme, hDC, BP_PUSHBUTTON, state, &bgRect, NULL); if (cdrf == CDRF_NOTIFYPOSTERASE) BUTTON_SendCustomDraw(hwnd, hDC, CDDS_POSTERASE, &bgRect); cdrf = BUTTON_SendCustomDraw(hwnd, hDC, CDDS_PREPAINT, &bgRect); if (cdrf == CDRF_SKIPDEFAULT) goto cleanup; BUTTON_DrawIml(hDC, &pdata->imlData, &textRect, FALSE, drawState); text = get_button_text(hwnd); if (text) { DrawThemeText(theme, hDC, BP_PUSHBUTTON, state, text, lstrlenW(text), dtFlags, 0, &textRect); HeapFree(GetProcessHeap(), 0, text); } if (focused) { MARGINS margins; RECT focusRect = bgRect; GetThemeMargins(theme, hDC, BP_PUSHBUTTON, state, TMT_CONTENTMARGINS, NULL, &margins); focusRect.left += margins.cxLeftWidth; focusRect.top += margins.cyTopHeight; focusRect.right -= margins.cxRightWidth; focusRect.bottom -= margins.cyBottomHeight; DrawFocusRect( hDC, &focusRect ); } if (cdrf == CDRF_NOTIFYPOSTPAINT) BUTTON_SendCustomDraw(hwnd, hDC, CDDS_POSTPAINT, &bgRect); cleanup: if (hPrevFont) SelectObject(hDC, hPrevFont); }
void CButtonExtn::DrawButton(HWND hWnd, HDC hDC, RECT *pRect, BOOL fChecked, BOOL fHot, BOOL fFocus) { // Code originally by Nikita Leontiev in answer to "Change checkBox text color Win32" // in MS's Forum: "Visual Studio Developer Center > Visual Studio vNext Forums > Visual C++ General" // Modified for MFC, Checkbox and Radio buttons by DK int nWidth = pRect -> right - pRect -> left; int nHeight = pRect -> bottom - pRect -> top; HDC hMemDC = CreateCompatibleDC(hDC); HBITMAP hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight); SelectObject(hMemDC, hBitmap); RECT rFillRect = {0, 0, nWidth, nHeight}; HTHEME hTheme = OpenThemeData(hWnd, L"BUTTON"); int nStateID(0); if (m_type == BS_AUTOCHECKBOX) { nStateID = (fChecked) ? CBS_CHECKEDNORMAL : CBS_UNCHECKEDNORMAL; if (fHot) nStateID = (fChecked) ? CBS_CHECKEDHOT : CBS_UNCHECKEDHOT; } else { nStateID = (fChecked) ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL; if (fHot) nStateID = (fChecked) ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT; } //If bg color isn't set, try get backgroung color from current theme if (m_bUseBkgColour) { FillRect(hMemDC, &rFillRect, CreateSolidBrush(GetSysColor(m_icolour))); } else { // Don't check IsThemeBackgroundPartiallyTransparent because it return false for BP_CHECKBOX DrawThemeParentBackground(hWnd, hMemDC, &rFillRect); } RECT rIconRect = {0, 0, 13, nHeight}; DrawThemeBackground(hTheme, hMemDC, m_type == BS_AUTOCHECKBOX ? BP_CHECKBOX : BP_RADIOBUTTON, nStateID, &rIconRect, NULL); CloseThemeData(hTheme); RECT rTextRect = {16, 0, nWidth - 16, nHeight}; SetBkMode(hMemDC, TRANSPARENT); if (m_bUseTextColour) SetTextColor(hMemDC, m_crfText); SelectObject(hMemDC, (HFONT)GetStockObject(DEFAULT_GUI_FONT)); if (m_caption.IsEmpty()) { GetWindowText(m_caption); SetWindowText(L""); } DrawText(hMemDC, m_caption, m_caption.GetLength(), &rTextRect, DT_SINGLELINE | DT_VCENTER); if (fFocus){ DrawText(hMemDC, m_caption, m_caption.GetLength(), &rTextRect, DT_SINGLELINE | DT_VCENTER | DT_CALCRECT); rTextRect.left--; rTextRect.right++; DrawFocusRect(hMemDC, &rTextRect); } BitBlt(hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY); DeleteObject(hBitmap); DeleteDC(hMemDC); }
static void GB_draw(HTHEME theme, HWND hwnd, HDC hDC, ButtonState drawState, UINT dtFlags, BOOL focused) #endif { static const int states[] = { GBS_NORMAL, GBS_NORMAL, GBS_NORMAL, GBS_DISABLED, GBS_NORMAL }; RECT bgRect, textRect, contentRect; int state = states[ drawState ]; WCHAR *text = get_button_text(hwnd); LOGFONTW lf; HFONT font, hPrevFont = NULL; BOOL created_font = FALSE; #ifdef __REACTOS__ /* r74406 */ HWND parent; HBRUSH hBrush; RECT clientRect; #endif HRESULT hr = GetThemeFont(theme, hDC, BP_GROUPBOX, state, TMT_FONT, &lf); if (SUCCEEDED(hr)) { font = CreateFontIndirectW(&lf); if (!font) TRACE("Failed to create font\n"); else { hPrevFont = SelectObject(hDC, font); created_font = TRUE; } } else { #ifdef __REACTOS__ /* r73885 */ font = get_button_font(hwnd); #else font = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0); #endif hPrevFont = SelectObject(hDC, font); } GetClientRect(hwnd, &bgRect); textRect = bgRect; if (text) { SIZE textExtent; GetTextExtentPoint32W(hDC, text, lstrlenW(text), &textExtent); bgRect.top += (textExtent.cy / 2); textRect.left += 10; textRect.bottom = textRect.top + textExtent.cy; textRect.right = textRect.left + textExtent.cx + 4; ExcludeClipRect(hDC, textRect.left, textRect.top, textRect.right, textRect.bottom); } GetThemeBackgroundContentRect(theme, hDC, BP_GROUPBOX, state, &bgRect, &contentRect); ExcludeClipRect(hDC, contentRect.left, contentRect.top, contentRect.right, contentRect.bottom); #ifdef __REACTOS__ /* r73885 & r74149 */ if (prfFlag == 0) { if (IsThemeBackgroundPartiallyTransparent(theme, BP_GROUPBOX, state)) DrawThemeParentBackground(hwnd, hDC, NULL); } #else if (IsThemeBackgroundPartiallyTransparent(theme, BP_GROUPBOX, state)) DrawThemeParentBackground(hwnd, hDC, NULL); #endif #ifdef __REACTOS__ /* r74406 */ parent = GetParent(hwnd); if (!parent) parent = hwnd; hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd); if (!hBrush) /* did the app forget to call defwindowproc ? */ hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC, (WPARAM)hDC, (LPARAM)hwnd ); GetClientRect(hwnd, &clientRect); FillRect( hDC, &clientRect, hBrush ); #endif DrawThemeBackground(theme, hDC, BP_GROUPBOX, state, &bgRect, NULL); SelectClipRgn(hDC, NULL); if (text) { InflateRect(&textRect, -2, 0); DrawThemeText(theme, hDC, BP_GROUPBOX, state, text, lstrlenW(text), 0, 0, &textRect); HeapFree(GetProcessHeap(), 0, text); } if (created_font) DeleteObject(font); if (hPrevFont) SelectObject(hDC, hPrevFont); }
static LRESULT CALLBACK RichUtil_Proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { TRichUtil *ru = NULL, tru; int idx; LRESULT ret; tru.hwnd = hwnd; { mir_cslock lck(csRich); if (List_GetIndex(&sListInt, &tru, &idx)) ru = (TRichUtil *)sListInt.items[idx]; } switch (msg) { case WM_THEMECHANGED: case WM_STYLECHANGED: RichUtil_ClearUglyBorder(ru); break; case WM_NCPAINT: ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); if (ru->hasUglyBorder && IsThemeActive()) { HANDLE hTheme = OpenThemeData(ru->hwnd, L"EDIT"); if (hTheme) { RECT rcBorder; RECT rcClient; int nState; HDC hdc = GetWindowDC(ru->hwnd); GetWindowRect(hwnd, &rcBorder); rcBorder.right -= rcBorder.left; rcBorder.bottom -= rcBorder.top; rcBorder.left = rcBorder.top = 0; CopyRect(&rcClient, &rcBorder); rcClient.left += ru->rect.left; rcClient.top += ru->rect.top; rcClient.right -= ru->rect.right; rcClient.bottom -= ru->rect.bottom; ExcludeClipRect(hdc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); if (IsThemeBackgroundPartiallyTransparent(hTheme, EP_EDITTEXT, ETS_NORMAL)) DrawThemeParentBackground(hwnd, hdc, &rcBorder); if (!IsWindowEnabled(hwnd)) nState = ETS_DISABLED; else if (SendMessage(hwnd, EM_GETOPTIONS, 0, 0) & ECO_READONLY) nState = ETS_READONLY; else nState = ETS_NORMAL; DrawThemeBackground(hTheme, hdc, EP_EDITTEXT, nState, &rcBorder, NULL); CloseThemeData(hTheme); ReleaseDC(hwnd, hdc); return 0; } } return ret; case WM_NCCALCSIZE: { ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); NCCALCSIZE_PARAMS *ncsParam = (NCCALCSIZE_PARAMS *)lParam; if (ru->hasUglyBorder && IsThemeActive()) { HANDLE hTheme = OpenThemeData(hwnd, L"EDIT"); if (hTheme) { RECT rcClient = {0}; HDC hdc = GetDC(GetParent(hwnd)); if (GetThemeBackgroundContentRect(hTheme, hdc, EP_EDITTEXT, ETS_NORMAL, &ncsParam->rgrc[0], &rcClient) == S_OK) { ru->rect.left = rcClient.left - ncsParam->rgrc[0].left; ru->rect.top = rcClient.top - ncsParam->rgrc[0].top; ru->rect.right = ncsParam->rgrc[0].right - rcClient.right; ru->rect.bottom = ncsParam->rgrc[0].bottom - rcClient.bottom; ncsParam->rgrc[0] = rcClient; CloseThemeData(hTheme); ReleaseDC(GetParent(hwnd), hdc); return WVR_REDRAW; } ReleaseDC(GetParent(hwnd), hdc); CloseThemeData(hTheme); } } } return ret; case WM_ENABLE: RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_NOCHILDREN | RDW_UPDATENOW | RDW_FRAME); break; case WM_GETDLGCODE: return mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam) & ~DLGC_HASSETSEL; case WM_NCDESTROY: ret = mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); { mir_cslock lck(csRich); List_Remove(&sListInt, idx); } mir_free(ru); return ret; } return mir_callNextSubclass(hwnd, RichUtil_Proc, msg, wParam, lParam); }
/** * paints the background for a switchbar item. It can paint aero, visual styles, skins or * classic buttons (depending on os and current plugin settings). * * @param hdc HDC: target device context * @param rc RECT*: target rectangle * @param stateId the state identifier (normal, pressed, hot, disabled etc.) */ void __fastcall CSideBar::m_DefaultBackgroundRenderer(const HDC hdc, const RECT *rc, const CSideBarButton *item) { UINT id = item->getID(); int stateId = item->m_buttonControl->stateId; bool fIsActiveItem = (item->m_sideBar->getActiveItem() == item); if (CSkin::m_skinEnabled) { TContainerData *pContainer = const_cast<TContainerData *>(item->m_sideBar->getContainer()); int ctrlId = stateId == PBS_PRESSED || fIsActiveItem ? ID_EXTBKBUTTONSPRESSED : (stateId == PBS_HOT ? ID_EXTBKBUTTONSMOUSEOVER : ID_EXTBKBUTTONSNPRESSED); CSkinItem *skinItem = &SkinItems[ctrlId]; HWND hwnd = item->m_buttonControl->hwnd; CSkin::SkinDrawBG(hwnd, pContainer->hwnd, pContainer, const_cast<RECT *>(rc), hdc); CSkin::DrawItem(hdc, rc, skinItem); } else if (M.isAero() || PluginConfig.m_fillColor) { if (id == IDC_SIDEBARUP || id == IDC_SIDEBARDOWN) { if (M.isAero()) ::FillRect(hdc, const_cast<RECT *>(rc), CSkin::m_BrushBack); else CSkin::FillBack(hdc, const_cast<RECT *>(rc)); if (stateId == PBS_HOT || stateId == PBS_PRESSED) DrawAlpha(hdc, const_cast<RECT *>(rc), 0xf0f0f0, 70, 0x000000, 0, 9, 31, 4, 0); else DrawAlpha(hdc, const_cast<RECT *>(rc), 0xf0f0f0, 30, 0x707070, 0, 9, 31, 4, 0); } else { if (PluginConfig.m_fillColor) FillTabBackground(hdc, stateId, item->getDat(), const_cast<RECT *>(rc)); CSkin::m_switchBarItem->setAlphaFormat(AC_SRC_ALPHA, (stateId == PBS_HOT && !fIsActiveItem) ? 250 : (fIsActiveItem || stateId == PBS_PRESSED ? 250 : 230)); CSkin::m_switchBarItem->Render(hdc, rc, true); if (stateId == PBS_HOT || stateId == PBS_PRESSED || fIsActiveItem) { RECT rcGlow = *rc; rcGlow.top += 1; rcGlow.bottom -= 2; CSkin::m_tabGlowTop->setAlphaFormat(AC_SRC_ALPHA, (stateId == PBS_PRESSED || fIsActiveItem) ? 180 : 100); CSkin::m_tabGlowTop->Render(hdc, &rcGlow, true); } } } else if (M.isVSThemed()) { RECT *rcDraw = const_cast<RECT *>(rc); if (id == IDC_SIDEBARUP || id == IDC_SIDEBARDOWN) { ::FillRect(hdc, rc, stateId == PBS_HOT ? ::GetSysColorBrush(COLOR_HOTLIGHT) : ::GetSysColorBrush(COLOR_3DFACE)); ::InflateRect(rcDraw, -2, 0); ::DrawEdge(hdc, rcDraw, EDGE_ETCHED, BF_SOFT | BF_RECT | BF_FLAT); } else { CSkin::FillBack(hdc, rcDraw); if (IsThemeBackgroundPartiallyTransparent(item->m_buttonControl->hThemeToolbar, TP_BUTTON, stateId)) DrawThemeParentBackground(item->getHwnd(), hdc, rcDraw); if (M.isAero() || PluginConfig.m_WinVerMajor >= 6) { stateId = (fIsActiveItem ? PBS_PRESSED : PBS_HOT); DrawThemeBackground(item->m_buttonControl->hThemeToolbar, hdc, 8, RBStateConvert2Flat(stateId), rcDraw, rcDraw); } else { stateId = (fIsActiveItem ? PBS_PRESSED : PBS_HOT); DrawThemeBackground(item->m_buttonControl->hThemeToolbar, hdc, TP_BUTTON, TBStateConvert2Flat(stateId), rcDraw, rcDraw); } } } else { RECT *rcDraw = const_cast<RECT *>(rc); if (!(id == IDC_SIDEBARUP || id == IDC_SIDEBARDOWN)) { HBRUSH br = (stateId == PBS_HOT && !fIsActiveItem) ? ::GetSysColorBrush(COLOR_BTNSHADOW) : (fIsActiveItem || stateId == PBS_PRESSED ? ::GetSysColorBrush(COLOR_HOTLIGHT) : ::GetSysColorBrush(COLOR_3DFACE)); ::FillRect(hdc, rc, br); ::DrawEdge(hdc, rcDraw, (stateId == PBS_HOT && !fIsActiveItem) ? EDGE_ETCHED : (fIsActiveItem || stateId == PBS_PRESSED) ? EDGE_BUMP : EDGE_ETCHED, BF_RECT | BF_SOFT | BF_FLAT); } else { ::FillRect(hdc, rc, stateId == PBS_HOT ? ::GetSysColorBrush(COLOR_HOTLIGHT) : ::GetSysColorBrush(COLOR_3DFACE)); ::InflateRect(rcDraw, -2, 0); ::DrawEdge(hdc, rcDraw, EDGE_ETCHED, BF_SOFT | BF_RECT | BF_FLAT); } } }
void CTTCheckBtnGroup::OnPaint() { CPaintDC dc(this); CRect clientRect; GetClientRect(clientRect); if (clientRect.Width() <= 0 || clientRect.Height() <= 0) return; CMemDC memDC(dc, clientRect); CDC* pDC = &memDC.GetDC(); DrawThemeParentBackground(GetSafeHwnd(), memDC.GetDC().GetSafeHdc(), clientRect); Graphics graphics(pDC->GetSafeHdc()); graphics.SetSmoothingMode(SmoothingModeAntiAlias); graphics.SetInterpolationMode(InterpolationModeHighQualityBicubic); graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixel); // clear background CRgn bkgndRgn; CRect bkgndRect(clientRect); bkgndRect.left += 1; bkgndRect.top += 1; CreateRectRgnInDevicePoints(pDC, &bkgndRgn, bkgndRect, m_CornerRadius); pDC->SelectClipRgn(&bkgndRgn); pDC->FillSolidRect(&clientRect, RGB(255, 255, 255)); CRgn clientRgn; CreateRectRgnInDevicePoints(pDC, &clientRgn, clientRect); pDC->SelectClipRgn(&clientRgn); // Whole border Gdiplus::Rect borderRect(clientRect.left, clientRect.top, clientRect.Width(), clientRect.Height()); borderRect.Inflate(-1, -1); if (m_Buttons.size() == 0) { COLORREF borderColor = m_ColorMap.GetColor(Normal, Border); DrawRectArea(borderRect, graphics, borderColor, m_CornerRadius, m_BorderPenWidth); } for (int btnId = 0; btnId < m_Buttons.size(); ++btnId) { BtnInfo* pBtnInfo = &m_Buttons[btnId]; CRgn btnRgn; CRect t(pBtnInfo->m_rect); t.right += 1; t.bottom += 1; CreateRectRgnInDevicePoints(pDC, &btnRgn, t); btnRgn.CombineRgn(&btnRgn, &bkgndRgn, RGN_AND); pDC->SelectClipRgn(&btnRgn); ControlState buttonState = GetButtonState(pBtnInfo); // Highlight if (buttonState != Press) pDC->FillSolidRect(pBtnInfo->m_rect, m_ColorMap.GetColor(buttonState, BorderLight)); // Border graphics.SetClip(btnRgn); COLORREF borderColor = m_ColorMap.GetColor(buttonState, Border); DrawRectArea(borderRect, graphics, borderColor, m_CornerRadius, m_BorderPenWidth); graphics.ResetClip(); CRgn offsetRgn1; offsetRgn1.CreateRectRgn(0, 0, 0, 0); offsetRgn1.CopyRgn(&btnRgn); offsetRgn1.OffsetRgn(m_BorderPenWidth + 1, m_BorderPenWidth + 1); CRgn offsetRgn2; offsetRgn2.CreateRectRgn(0, 0, 0, 0); offsetRgn2.CopyRgn(&btnRgn); offsetRgn2.OffsetRgn(-(m_BorderPenWidth + 1), -(m_BorderPenWidth + 1)); CRgn backRgn; backRgn.CreateRectRgn(0, 0, 0, 0); backRgn.CombineRgn(&offsetRgn1, &offsetRgn2, RGN_AND); pDC->SelectClipRgn(&backRgn); if (buttonState != Mouseover) { DrawGradient(pDC, t); /*Draw4ColorsGradientRect(t, *pDC, m_ColorMap.GetColor(buttonState, BackgroundTopGradientStart), m_ColorMap.GetColor(buttonState, BackgroundTopGradientFinish), m_ColorMap.GetColor(buttonState, BackgroundBottomGradientStart), m_ColorMap.GetColor(buttonState, BackgroundBottomGradientFinish), m_CornerRadius, TRUE);*/ } COLORREF textColor = RGB(80,80,80);//COLOR_GRAYTEXT;//COLOR_BTNTEXT; /*if (buttonState == Press) textColor = RGB(0, 122, 224);*/ pDC->SelectClipRgn(&btnRgn); CFont* pFont = GetFont(); int nFormat = DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS; CTTButton::DrawCaptionText(pDC, &pBtnInfo->m_rect, &pBtnInfo->m_rect, pBtnInfo->m_text, nFormat, pFont, textColor); } pDC->SelectClipRgn(&clientRgn); for (int btnId = 1; btnId < m_Buttons.size(); ++btnId) { BtnInfo* pPrevBtnInfo = &m_Buttons[btnId - 1]; BtnInfo* pCurBtnInfo = &m_Buttons[btnId]; ControlState prevBtnState = GetButtonState(pPrevBtnInfo); ControlState curBtnState = GetButtonState(pCurBtnInfo); ControlState state = Normal; if (prevBtnState == Press || curBtnState == Press) state = Press; else if (prevBtnState == Mouseover || curBtnState == Mouseover) state = Mouseover; COLORREF borderColor = m_ColorMap.GetColor(state, Border); CPen borderPen(PS_SOLID, m_BorderPenWidth, borderColor); pDC->SelectObject(borderPen); pDC->MoveTo(pPrevBtnInfo->m_rect.right, pPrevBtnInfo->m_rect.top); pDC->LineTo(pPrevBtnInfo->m_rect.right, pPrevBtnInfo->m_rect.bottom); } }