15,979
社区成员
发帖
与我相关
我的任务
分享
#include <dwmapi.h>
#pragma comment (lib , "dwmapi.lib" )
MARGINS margins = {-1};
DwmExtendFrameIntoClientArea(m_hWnd, &margins);
void Ctestaero4Dlg::OnPaint()
{
CPaintDC dc(this);
CRect rc;
GetClientRect(&rc);
dc.FillSolidRect(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, RGB(0,0,0));
CDialogEx::OnPaint();
}
#pragma comment (lib , "UxTheme.lib" )
void CMyButton::OnPaint()
{
PAINTSTRUCT ps;
HDC hdc = ::BeginPaint(m_hWnd, &ps);
if(hdc)
{
LONG_PTR dwStyle = GetWindowLongPtr(m_hWnd, GWL_STYLE);
LONG_PTR dwButtonStyle = LOWORD(dwStyle);
LONG_PTR dwButtonType = dwButtonStyle&0xF;
CRect rcClient;
VERIFY(::GetClientRect(m_hWnd, &rcClient));
if(BS_PUSHBUTTON==dwButtonType || BS_DEFPUSHBUTTON==dwButtonType)
{
HTHEME hTheme = OpenThemeData(m_hWnd, L"Button");
if(hTheme)
{
HDC hdcPaint = NULL;
BP_PAINTPARAMS params = { sizeof(BP_PAINTPARAMS) };
params.dwFlags = BPPF_ERASE;
HPAINTBUFFER hBufferedPaint = BeginBufferedPaint(hdc, &rcClient, BPBF_TOPDOWNDIB, ¶ms, &hdcPaint);
if (hdcPaint)
{
VERIFY(PatBlt(hdcPaint, 0, 0, rcClient.Width(), rcClient.Height(), BLACKNESS));
VERIFY(S_OK==BufferedPaintSetAlpha(hBufferedPaint, &ps.rcPaint, 0x00));
LRESULT dwCheckState = ::SendMessage(m_hWnd, BM_GETCHECK, 0, NULL);
POINT pt;
RECT rc;
::GetWindowRect(m_hWnd, &rc);
GetCursorPos(&pt);
BOOL bHot = PtInRect(&rc, pt);
BOOL bFocus = ::GetFocus()==m_hWnd;
int iPartId = BP_PUSHBUTTON;
if(dwButtonStyle==BS_RADIOBUTTON || dwButtonStyle==BS_AUTORADIOBUTTON)
iPartId = BP_RADIOBUTTON;
int iState;
iState = PBS_NORMAL;
if (dwStyle&WS_DISABLED)
iState = PBS_DISABLED;
else
{
if(dwStyle&BS_DEFPUSHBUTTON)
iState = PBS_DEFAULTED;
if(::GetCapture()==m_hWnd && bHot)
iState = PBS_PRESSED;
else if (::GetCapture()==m_hWnd || bHot)
iState = PBS_HOT;
}
RECT rcPaint = rcClient;
VERIFY(S_OK==DrawThemeBackground(hTheme, hdcPaint, iPartId, iState, &rcPaint, NULL));
VERIFY(S_OK==GetThemeBackgroundContentRect(hTheme, hdcPaint, iPartId, iState, &rcPaint, &rc));
DTTOPTS DttOpts = {sizeof(DTTOPTS)};
DttOpts.dwFlags = DTT_COMPOSITED | DTT_GLOWSIZE;
DttOpts.crText = RGB(255, 255, 255);
DttOpts.iGlowSize = 12; // Default value
HFONT hFontOld = (HFONT)::SendMessage(m_hWnd, WM_GETFONT, 0L, NULL);
if(hFontOld)
hFontOld = (HFONT) SelectObject(hdcPaint, hFontOld);
int iLen = ::GetWindowTextLength(m_hWnd);
if(iLen)
{
iLen+=5;
LPWSTR szText = (LPWSTR)LocalAlloc(LPTR, sizeof(WCHAR)*iLen);
if(szText)
{
iLen = ::GetWindowTextW(m_hWnd, szText, iLen);
if(iLen)
{
DWORD dwFlags = DT_SINGLELINE | DT_CENTER | DT_VCENTER;
VERIFY(S_OK==DrawThemeTextEx(hTheme, hdcPaint,
iPartId, iState, szText, -1, dwFlags, &rc, &DttOpts));
}
VERIFY(!LocalFree(szText));
}
}
if (hFontOld)
{
SelectObject(hdcPaint, hFontOld);
hFontOld = NULL;
}
VERIFY(S_OK==EndBufferedPaint(hBufferedPaint, TRUE));
}
VERIFY(S_OK==CloseThemeData(hTheme));
}
}
}
::EndPaint(m_hWnd, &ps);
}