Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I found in internet to change color:

Add OnCtlColor and write this code

  //hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); //Commet it and add
  hbr = m_brush;



yes, but it's used a message, but I have already my message:

void CMFCApplication7Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{


so I don't know what I can write inside the event of OnLButtonDown

What I have tried:

I searched in internet, but there isn't a way
Posted
Updated 20-Sep-19 5:59am
v2
Comments
Member 14594285 20-Sep-19 11:22am    
I think I must write a similar thing:


BOOL CMFCApplication7Dlg::OnEraseBkgnd(CDC* pDC)
{
if (afx_msg == WM_MOUSEMOVE)
{
CRect rect;
GetClientRect(&rect);
CBrush myBrush(RGB(255, 255, 255)); // dialog background color
CBrush *pOld = pDC->SelectObject(&myBrush);
BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(pOld); // restore old brush
return bRes;
return CDialogEx::OnEraseBkgnd(pDC);
}

Can you help me?
Member 14594285 20-Sep-19 11:27am    
i tried :

BOOL CMFCApplication7Dlg::OnEraseBkgnd(CDC* pDC)
{
MSG* pMsg = new MSG;
// TODO: Add your message handler code here and/or call default
if (pMsg->message == WM_LBUTTONDOWN)
{
CRect rect;
GetClientRect(&rect);
CBrush myBrush(RGB(255, 255, 255)); // dialog background color
CBrush *pOld = pDC->SelectObject(&myBrush);
BOOL bRes = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(pOld); // restore old brush
return bRes;
return CDialogEx::OnEraseBkgnd(pDC);
}
}

but it doesn't work..dialog open white before I click mouse

1 solution

There are two steps to doing this. First, you write the code for OnEraseBkgnd() to draw the dialog background, as you did. Second, you have to cause it to be drawn. To do this you can call Invalidate() and pass true to cause the background to be redrawn.

In your drawing code, you should call GetStockObject and pass it WHITE_BRUSH. There are several "stock" objects that can be utilized so you don't have to create them yourself. There are several ways to draw a solid-colored rectangle. PatBlt is one way but I have never used it. Rectangle() is the one I usually use.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900