mfc >> Trying to change txt color from message map function

by b2RpZXNiYWNr » Tue, 01 Feb 2005 03:25:02 GMT

HI,

My menu has a option that changes the text color.

so I have my OnPaint() function but I am trying to call the DC from another
function in same class.. what am I doing wrong?

void CChildView::OnTextBlack()
{
// TODO: Add your command handler code here
CDC* pDC = GetDC();
pDC->SetTextColor(RGB(0,0,0));
pDC->TextOut(mPt.x, mPt.y, mStr);

ReleaseDC(pDC);

mCount = 1;
Invalidate();
}


mfc >> RE: Trying to change txt color from message map function

by b2RpZXNiYWNr » Tue, 01 Feb 2005 03:49:05 GMT


I changed my approach to ON_COMMAND_RANGE...
and came up with this... it worked... but why not the first code?

void CChildView::OnTextColor(UINT nID)
{
CClientDC dc(this);

switch(nID)
{
case ID_TEXT_BLACK:
dc.SetTextColor(RGB(0,0,0));
dc.TextOut(mPt.x, mPt.y, mStr);
break;

case ID_TEXT_GREEN:
dc.SetTextColor(RGB(0,255,0));
dc.TextOut(mPt.x, mPt.y, mStr);
break;

case ID_TEXT_BLUE:
dc.SetTextColor(RGB(0,0,255));
dc.TextOut(mPt.x, mPt.y, mStr);
break;

default:
break;
}
}





mfc >> Trying to change txt color from message map function

by Scott McPhillips [MVP] » Tue, 01 Feb 2005 08:06:22 GMT





You can't just paint when you feel like it. Do all your painting in
OnDraw. Otherwise your window will not repaint properly when it is
covered then uncovered, minimized/restored, etc.

Your call to Invalidate() will cause OnDraw to be called. What color
does your OnDraw() use? You should simply save the color in a variable
and call Invalidate(). Then the one-and-only painting code in OnDraw
should use the saved color.

--
Scott McPhillips [VC++ MVP]



Similar Threads

1. [*map/map_all_coml11.txt||10||r||1|| @],[*map/map_all_coml11.txt||10||r||1|| @] - CSharp/C#

2. [*map/map_all_ag2.txt||10||r||1|| @],[*map/map_all_ag2.txt||10||r||1|| @]

[*map/map_all_ag2.txt||10||r||1|| @],[*map/map_all_ag2.txt||10||r||1|| @],[*map/map_all_ag2.txt||10||r||1|| @]

3. [*map/map_all_coml10.txt||10||r||1|| @],[*map/map_all_coml10.txt||10||r||1|| @] - CSharp/C#

4. Mapping Notify Messages to a function

Hi.

I have writen a C# Com object which interacts with a piece of hardware
via a C library. At the moment I poll this hardware from within my C#
assembly to see when new messages are received. The C library also
contains a function called setNotify() which posts a
WM__HARDWARELIBRARY message when new messages are recieved by the
hardware. But how do I map WM__HARDWARELIBRARY to a function in my C#
code so that this function is called when messages arrive at the
hardware?

Thanks,

Barry.

5. Message Map functions called twice?

6. Changing the function color covertion (unsafe)

hello,

the code below make a bitmap greyscale.
how do I change the code that the result will be 16 colors/256 colors 
instead of greyscale?
somebody can explain the theory behind the calculations?

for (int y = 0; y < size.Y; y++)
{
PixelData* pPixel = PixelAt(0, y);
for (int x = 0; x < size.X; x++)
{
byte value = (byte) ((pPixel->red + pPixel->green + pPixel->blue) / 3);
pPixel->red =  value;
pPixel->green = value;
pPixel->blue = value;
pPixel++;
}
}


thx very much.

7. ComboBox->DrawItem problem...(global function to change selection-color) - Borland C++ Builder VCL Components

8. [*map/map_index_cne2_13.txt||10||r||1|| @]

[*map/map_index_cne2_13.txt||10||r||1|| @]