x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

Windows CE 1.0 MFC CFormView background color won't change

wmundstock Page Icon Posted 2023-01-20 12:41 AM
#
Avatar image of wmundstock
H/PC Newbie

Posts:
23
Location:
Brazil 
Status:
Hi!
I am trying to create a simple MFC app for WinCE1.0.

I created a single document form using CFormView. For some reason MFC makes this form white, which could be ok, except that the Static label gets a grey background and end up looking like this.

Things I have tried:
1. Set the static control to Transparent - nothing changed
2. Create a OnEraseBkgnd event handler with code as below - the event is triggered but view continues white.

 
BOOL CMFCFormViewView::OnEraseBkgnd(CDC* pDC)  
{
CBrush backBrush(GRAY_BRUSH);
CRect rect;
pDC->GetClipBox(&rect);
pDC->FillRect(rect,&backBrush);
return TRUE;
}


Any clue what could be wrong?



(CFormView.PNG)



Attachments
----------------
Attachments CFormView.PNG (4KB - 1 downloads)
 Top of the page
stingraze Page Icon Posted 2023-01-20 1:21 AM
#
Avatar image of stingraze
H/PC Vanguard

Posts:
3,273
Location:
Japan
Status:
Are you using Visual C++ 6.0?

From my experience in using Embedded Visual Basic 3.0 long time ago, I remember the form color / label color is a little strange.
Can you try making the form gray instead?

I remember transparent didn't really work, but I'm not too sure because I don't have the environment.

-stingraze
 Top of the page
torch Page Icon Posted 2023-01-20 5:57 AM
#
Avatar image of torch
Subscribers
H/PC Vanguard

Posts:
4,462
Location:
United States 
Status:
Quote
stingraze - 2023-01-19 6:21 PM

Are you using Visual C++ 6.0?


Was Visual Studio C++ 5.0 the last version that supported CE 1.0?

Obviously what you suggested still stands, I just mean I'm not sure if 6.0 supported CE1.0

Edited by torch 2023-01-20 7:46 AM
 Top of the page
Citgo Page Icon Posted 2023-01-20 6:58 AM
#
Avatar image of Citgo
Factor Fanatic

Posts:
63
Location:
Germany 
Status:
Quote
stingraze - 2023-01-20 2:21 AM

Are you using Visual C++ 6.0?

From my experience in using Embedded Visual Basic 3.0 long time ago, I remember the form color / label color is a little strange.
Can you try making the form gray instead?

I remember transparent didn't really work, but I'm not too sure because I don't have the environment.

-stingraze


It's different in EVB because you can change the background on the properties pages. The default background color of labels are shown different...
Anyway... in MFC did u try to overlay the form with a rectangle?
Long time ago I read that you need a class and iverride the background. Don't know..
 Top of the page
wmundstock Page Icon Posted 2023-01-20 11:47 AM
#
Avatar image of wmundstock
H/PC Newbie

Posts:
23
Location:
Brazil 
Status:
The environment is Windows CE1 SDK + Visual C++ 5.0. VC++ 6 is not supported.

I tried using transparent label and tried making the form gray. That is what the OnEraseBkgnd was supposed to do. Just fill the client rectangle with gray brush.

I tried different brush colors, but nothing seems to work.

The event is triggered though.
 Top of the page
Citgo Page Icon Posted 2023-01-20 1:11 PM
#
Avatar image of Citgo
Factor Fanatic

Posts:
63
Location:
Germany 
Status:
Whats about thisbackground color

As I said...something with a class.
 Top of the page
C:Amie Page Icon Posted 2023-01-20 2:19 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
17,175
Location:
United Kingdom
Status:
Can you post your full source?

According to MFC, CDC::FIllRect
Quote
The brush needs to either be created using the CBrush memberfunctions CreateHatchBrush, CreatePatternBrush, and CreateSolidBrush or retrieved by the ::GetStockObject Windows function


From what I can see, GRAY_BRUSH is an index of SelectStockObject and not a COLORREF long int.

Also can't you use SetBkColor to do it?
 Top of the page
wmundstock Page Icon Posted 2023-01-20 6:42 PM
#
Avatar image of wmundstock
H/PC Newbie

Posts:
23
Location:
Brazil 
Status:
I tried the sample code with the custom class CColorFormView. It does not work, plus the code actually do a similar thing that I attempted manually which is to implement the OnEraseBkgnd message handler. Again, its triggered, but it does not paint the screen. I am thinking something else comes after and repaint with white.

Attachment with full code.

 
///////////////////////////////////////////////////////////////////////////// 
// CColorFormView message handlers
void CColorFormView::SetBackgroundColor(COLORREF crBackground)
{
m_crBackground = crBackground;

if(m_wndbkBrush.GetSafeHandle())
m_wndbkBrush.DeleteObject();

m_wndbkBrush.CreateSolidBrush(m_crBackground);
}

BOOL CColorFormView::OnEraseBkgnd(CDC* pDC)
{
CFormView::OnEraseBkgnd(pDC);

CRect rect;
GetClientRect(rect);

pDC->FillRect(&rect, &m_wndbkBrush);

return TRUE;
}


Edited by wmundstock 2023-01-20 6:43 PM




Attachments
----------------
Attachments MFC FormViewExample.zip (0KB - 0 downloads)
 Top of the page
wmundstock Page Icon Posted 2023-01-21 12:20 AM
#
Avatar image of wmundstock
H/PC Newbie

Posts:
23
Location:
Brazil 
Status:
"If you can't beat them, join tem."

Allright, I could not find a way to make the form gray, but I found a way to make the label white. Fair enough...

Even though the ClassWizard don't seem to offer the WM_CTLCOLOR message event handler, it is possible to manually add it and it works.

 
HBRUSH CMFCFormViewView::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor ) 
{
CBrush backBrush(RGB(255,255,255));
if (nCtlColor == CTLCOLOR_STATIC)
return backBrush;
else
return CColorFormView::OnCtlColor(pDC,pWnd,nCtlColor);
}




(CFormViewResolved.PNG)



Attachments
----------------
Attachments CFormViewResolved.PNG (4KB - 0 downloads)
 Top of the page
wmundstock Page Icon Posted 2023-01-25 11:47 PM
#
Avatar image of wmundstock
H/PC Newbie

Posts:
23
Location:
Brazil 
Status:
Small correction to my own code.
Even though the MSDN documentation says I should return the brush my control should be painted with, this does not work. If you add anything that is not 255,255,255 for RGB it will set it to white anyway.

Documentation says I should set the background color and return the brush. The 2 code snippets below work:

This one will set the static to transparent which is what I needed.

	switch (nCtlColor) 
	{ 
case CTLCOLOR_STATIC:
pDC->SetBkMode(TRANSPARENT);
return CColorFormView::OnCtlColor(pDC,pWnd,nCtlColor);
break;
default:
return CColorFormView::OnCtlColor(pDC,pWnd,nCtlColor);
}


This will set the static to any color you like:

	switch (nCtlColor) 
{
case CTLCOLOR_STATIC:
This would work too.
pDC->SetBkColor(GetSysColor(COLOR_WINDOW));
return (HBRUSH)GetStockObject(NULL_BRUSH);
break;
default:
return CColorFormView::OnCtlColor(pDC,pWnd,nCtlColor);
}


Edited by wmundstock 2023-01-25 11:47 PM
 Top of the page
Jump to forum:
Seconds to generate: 0.234 - Cached queries : 50 - Executed queries : 29
Server Time now is: Saturday, 28 January 2023 - 17:23