NCPAINT

Bonjour,

J'essaye sous Windows 8 de changer la couleur du titre et du fond d'une fenêtre (Zone non client) . J'ai repris du code trouvé sur le net.

Voici les éléments :

BEGIN_MESSAGE_MAP(CPersoMessageBoxTimer,CDialog)
ON_WM_CTLCOLOR()
ON_MESSAGE(WM_NCPAINT,OnNCPaint)
ON_MESSAGE(WM_NCACTIVATE,OnNCActivate)
END_MESSAGE_MAP()

afx_msg LRESULT CPersoMessageBoxTimer::OnNCPaint (WPARAM wParam, LPARAM lParam)
{
char P_lpTitleText[100];

//DefWindowProc(WM_NCPAINT, wParam, lParam);

this->GetWindowText(P_lpTitleText, 100);

if (wParam)
DrawCaptionBar(this->m_hWnd,GetWindowLong(this->m_hWnd, GWL_STYLE), P_lpTitleText,D_ACTIVEBAR);
else
DrawCaptionBar(this->m_hWnd,GetWindowLong(this->m_hWnd, GWL_STYLE),P_lpTitleText,D_INACTIVEBAR);


return TRUE;
}

void CPersoMessageBoxTimer::DrawCaptionBar(HWND P_hWnd, DWORD P_dwStyle, LPSTR P_lpTitleText,WORD P_ActiveBar)
{
HDC hDC;
RECT rc2, rc3;
LOGBRUSH lb;
HBRUSH hbr, hbrOld;
LOGPEN lp;
COLORREF crRGBValue = NULL;
COLORREF crRGBValue2 = NULL;

HPEN pen,penOld;

hDC = ::GetWindowDC(P_hWnd);

::GetWindowRect(P_hWnd, &rc2);

//------------------------------- dessin encadrement fenêtre

crRGBValue = (P_ActiveBar == D_ACTIVEBAR) ?
couleur_fenetre_tour_MD2i : RGB(235, 235, 235);

lb.lbStyle = BS_SOLID;
lb.lbColor = crRGBValue;
lb.lbHatch = NULL;

hbr = CreateBrushIndirect(&lb);

lp.lopnColor = crRGBValue;
lp.lopnStyle = PS_SOLID;
lp.lopnWidth.x = 1;

pen = CreatePenIndirect(&lp);

hbrOld = (HBRUSH) ::SelectObject(hDC, hbr);
penOld = (HPEN) ::SelectObject(hDC,pen);

Rectangle(hDC, 0, 0, rc2.right - rc2.left, 31);
Rectangle(hDC, 0, 31, 8, rc2.bottom - rc2.top);
Rectangle(hDC, rc2.right - rc2.left-8, 31, rc2.right - rc2.left, rc2.bottom - rc2.top);
Rectangle(hDC, 8, rc2.bottom - rc2.top-8, rc2.right-8, rc2.bottom - rc2.top);

hbr = (HBRUSH) ::SelectObject(hDC, hbrOld);
pen = (HPEN) ::SelectObject(hDC,penOld);

DeleteObject(hbr);
DeleteObject(pen);

crRGBValue2 = (P_ActiveBar == D_ACTIVEBAR) ?
couleur_fenetre_cadre_MD2i : RGB(235, 235, 235);

lp.lopnColor = crRGBValue2;
lp.lopnStyle = PS_SOLID;
lp.lopnWidth.x = 1;

pen = CreatePenIndirect(&lp);
penOld = (HPEN) ::SelectObject(hDC,pen);

MoveToEx(hDC,8, 31,(LPPOINT) NULL);
LineTo(hDC,rc2.right - rc2.left-8, 31);
LineTo(hDC,rc2.right - rc2.left-8, rc2.bottom - rc2.top - 8);
LineTo(hDC,8, rc2.bottom - rc2.top - 8);
LineTo(hDC,8,31);

pen = (HPEN) ::SelectObject(hDC,penOld);

DeleteObject(pen);


SetBkColor(hDC, crRGBValue);

rc3.left=0;
rc3.top=0;
rc3.right=rc2.right - rc2.left;
rc3.bottom=rc2.bottom - rc2.top;

DrawText(hDC, P_lpTitleText, -1, (LPRECT)&rc3, DT_CENTER);

::ReleaseDC(P_hWnd, hDC);

return;
}

Mon souci est que la fenêtre retrouve un look vista avec les bords hauts arrondis.
Merci

Topic archived. No new replies allowed.