Click here to Skip to main content
15,903,362 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Serial Port Question Pin
palbano9-Aug-04 18:01
palbano9-Aug-04 18:01 
GeneralRe: Serial Port Question Pin
shultas9-Aug-04 15:26
shultas9-Aug-04 15:26 
GeneralRe: Serial Port Question Pin
Tom Wright10-Aug-04 3:43
Tom Wright10-Aug-04 3:43 
GeneralRe: Serial Port Question Pin
shultas10-Aug-04 5:46
shultas10-Aug-04 5:46 
GeneralRe: Serial Port Question Pin
shultas10-Aug-04 5:50
shultas10-Aug-04 5:50 
GeneralAutomation +Get the active projet of visual studio .net Pin
nicgendron9-Aug-04 5:45
nicgendron9-Aug-04 5:45 
GeneralMFC / VisualC++ 7.0 / accelerators problem Pin
Member 130853379-Aug-04 5:28
Member 130853379-Aug-04 5:28 
GeneralColoring Text Pin
act_x9-Aug-04 5:22
act_x9-Aug-04 5:22 
In an SDI app , I m trying to do the following :
My View creates a Wnd and I am trying to dynamically create some controls ( CStatics)


Something like this


Test Test status

test 1 Running ....
test 2 Untested
test 3 Untested

All text are within their CStatics . I was trying to Color Code the Test Status
Like blue while running
red for failed
green for passed
grey for untested .


So I create a Class that inherits from CStatics and according to the article
HOWTO: Change the Color of an MFC Child Control Class
ID: Q132080

I overrode the OnChildNotify method

Here is what I do .
<br />
int value = 0; <br />
#define BACKCOLOR RGB(190,190,190)<br />
<br />
<br />
const COLORREF colors [] = { <br />
	                         RGB(255,0,0),<br />
							 RGB(0,255,0),<br />
							 RGB(0,0,255)<br />
};<br />
<br />
<br />
#define VALUECOLOR  colors[value]<br />
<br />
BOOL CColoredStatic::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult) <br />
{<br />
	// If "message" is not the message you're after, do default processing:<br />
<br />
   // For 16-bit applications change WM_CTLCOLOREDIT to WM_CTLCOLOR<br />
      if (message != WM_CTLCOLORSTATIC)<br />
      {<br />
         return CStatic::OnChildNotify(message,wParam,lParam,pLResult);<br />
      }<br />
<br />
	  //Set the text foreground to red:<br />
          HDC hdcChild = (HDC)wParam;<br />
	  COLORREF   oldTextColor = GetTextColor(hdcChild);<br />
	  COLORREF   oldBkColor = GetBkColor(hdcChild);<br />
   // <br />
      SetTextColor(hdcChild, VALUECOLOR );<br />
<br />
   // Set the text background to green:<br />
      SetBkColor(hdcChild, BACKCOLOR);<br />
<br />
   // Send what would have been the return value of OnCtlColor() - the<br />
   // brush handle - back in pLResult:<br />
      *pLResult = (LRESULT)(m_brush.GetSafeHandle());<br />
<br />
	  <br />
<br />
   // Return TRUE to indicate that the message was handled:<br />
      return TRUE;<br />
<br />
}<br />
<br />
void CColoredStatic::ChangeValue(const int &newVal)<br />
{<br />
 value = newVal;<br />
 Invalidate();<br />
}<br />



What I find is that after changing the value of "value" externally for the first CColorStatic object , all the CStatics get painted with the same color . Where the desired effect is to just update that Object .


My questions


when i do this
 // <br />
      SetTextColor(hdcChild, VALUECOLOR );<br />
<br />
   // Set the text background to green:<br />
      SetBkColor(hdcChild, BACKCOLOR);



So I have to restore the Color setting for the remaining controls ?
If yes what is that Call ? Something like a restoreObject !!!!!!!!
GeneralRe: Coloring Text Pin
John R. Shaw9-Aug-04 5:52
John R. Shaw9-Aug-04 5:52 
GeneralRe: Coloring Text Pin
act_x9-Aug-04 5:54
act_x9-Aug-04 5:54 
GeneralHtmlHelp inside DLLs Pin
brdavid9-Aug-04 5:17
brdavid9-Aug-04 5:17 
GeneralRe: HtmlHelp inside DLLs Pin
Blake Miller9-Aug-04 8:15
Blake Miller9-Aug-04 8:15 
GeneralRe: HtmlHelp inside DLLs Pin
brdavid9-Aug-04 10:30
brdavid9-Aug-04 10:30 
GeneralRe: HtmlHelp inside DLLs Pin
Blake Miller10-Aug-04 5:08
Blake Miller10-Aug-04 5:08 
GeneralRe: HtmlHelp inside DLLs Pin
brdavid10-Aug-04 6:33
brdavid10-Aug-04 6:33 
GeneralCustom Appwizard in VC.Net Pin
BlackDice9-Aug-04 4:40
BlackDice9-Aug-04 4:40 
GeneralSQL Server Connection String Pin
shultas9-Aug-04 4:27
shultas9-Aug-04 4:27 
GeneralCPU usage going to 100% full from running a DDE using VC++ Pin
swerajan9-Aug-04 3:53
swerajan9-Aug-04 3:53 
GeneralRe: CPU usage going to 100% full from running a DDE using VC++ Pin
David Crow9-Aug-04 4:00
David Crow9-Aug-04 4:00 
GeneralRe: CPU usage going to 100% full from running a DDE using VC++ Pin
swerajan9-Aug-04 4:03
swerajan9-Aug-04 4:03 
QuestionHow do I read .cda file from a CD? /w Win 32 API Pin
Link26009-Aug-04 3:34
Link26009-Aug-04 3:34 
Generalselection problem --- Pin
nainakhawaja9-Aug-04 2:35
nainakhawaja9-Aug-04 2:35 
GeneralRe: selection problem --- Pin
David Crow9-Aug-04 2:44
David Crow9-Aug-04 2:44 
GeneralRe: selection problem --- Pin
nainakhawaja9-Aug-04 2:52
nainakhawaja9-Aug-04 2:52 
GeneralRe: selection problem --- Pin
Stlan9-Aug-04 3:07
Stlan9-Aug-04 3:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.