Click here to Skip to main content
15,909,242 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC Textbox unable to be displayed in CFrameWnd? Pin
Michael Dunn7-Jun-07 20:01
sitebuilderMichael Dunn7-Jun-07 20:01 
QuestionCDC DrawText Pin
gurucplusplus7-Jun-07 8:04
gurucplusplus7-Jun-07 8:04 
AnswerRe: CDC DrawText Pin
Matthew Faithfull7-Jun-07 8:19
Matthew Faithfull7-Jun-07 8:19 
AnswerRe: CDC DrawText [modified] Pin
Mark Salsbery7-Jun-07 8:19
Mark Salsbery7-Jun-07 8:19 
GeneralRe: CDC DrawText Pin
gurucplusplus7-Jun-07 8:28
gurucplusplus7-Jun-07 8:28 
GeneralRe: CDC DrawText Pin
Mark Salsbery7-Jun-07 8:35
Mark Salsbery7-Jun-07 8:35 
GeneralRe: CDC DrawText Pin
gurucplusplus7-Jun-07 8:52
gurucplusplus7-Jun-07 8:52 
GeneralRe: CDC DrawText Pin
Mark Salsbery7-Jun-07 9:11
Mark Salsbery7-Jun-07 9:11 
gurucplusplus wrote:
If my text drawn changes I have to call invalidateRect to mark invalid for the next WM_PAINT message to update the text. Where should I call invalidaterect then?


Right. If the text characters never change (like pDC->DrawText("Text") then there's no reason
to ever call InvalidateRect() because every time the window needs repainting the text will
just be redrawn.
Now suppose you are drawing the text of a string that changes (pDC->DrawText(str)). The user
does something that causes the value of str to change and you want to reflect that change in the
window. Any time after you change str, call InvalidateRect() to mark the area as invalid. When
the resulting WM_PAINT is received by the window, CView::OnPaint() will call OnDraw(). In your
OnDraw() override, you call pDC->DrawText(str), drawing the new text on the window.

Also remember, WM_PAINT messages are LOW priority (they can get bumped to the back of the message
queue). If you need an instant update, like if the text string is changing as the result of a
timer (like in a clock implementation), then you can add a call to UpdateWindow() right after
the call to InvalidateRect(). This will cause a WM_PAINT to be sent immediately.

Remember that, when responding to WM_PAINT, it is your responsibility to validate the region
of the window that is invalid to prevent repeated WM_PAINT messages. Most of the time this
is done for us by MFC or the default window message handling. So if you invalidate regions of
a window while it's trying to validate it, the WM_PAINT messages keep coming.

If you want to see the recursive action/result of doing this in your OnDraw(), try this in your
OnDraw(). This consumes all the CPU time of one of my processors and renders dialog controls
useless:

Invalidate();
UpdateWindow();
return;

I'm actually surprised it doesn't crash Smile | :)

Mark


"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

GeneralRe: CDC DrawText Pin
gurucplusplus7-Jun-07 9:57
gurucplusplus7-Jun-07 9:57 
QuestionCToolBar disable/enable buttons Pin
Romiks7-Jun-07 7:45
Romiks7-Jun-07 7:45 
AnswerRe: CToolBar disable/enable buttons Pin
Mark Salsbery7-Jun-07 7:52
Mark Salsbery7-Jun-07 7:52 
GeneralRe: CToolBar disable/enable buttons Pin
Romiks7-Jun-07 19:41
Romiks7-Jun-07 19:41 
GeneralRe: CToolBar disable/enable buttons Pin
Nelek8-Jun-07 3:09
protectorNelek8-Jun-07 3:09 
GeneralRe: CToolBar disable/enable buttons Pin
Mark Salsbery8-Jun-07 4:32
Mark Salsbery8-Jun-07 4:32 
GeneralRe: CToolBar disable/enable buttons Pin
Romiks8-Jun-07 18:54
Romiks8-Jun-07 18:54 
GeneralRe: CToolBar disable/enable buttons Pin
Mark Salsbery9-Jun-07 7:51
Mark Salsbery9-Jun-07 7:51 
GeneralRe: CToolBar disable/enable buttons Pin
Romiks11-Jun-07 20:38
Romiks11-Jun-07 20:38 
QuestionRe: CToolBar disable/enable buttons Pin
Mark Salsbery12-Jun-07 6:28
Mark Salsbery12-Jun-07 6:28 
AnswerRe: CToolBar disable/enable buttons Pin
Romiks16-Jun-07 23:37
Romiks16-Jun-07 23:37 
GeneralRe: CToolBar disable/enable buttons Pin
Mark Salsbery17-Jun-07 7:29
Mark Salsbery17-Jun-07 7:29 
GeneralRe: CToolBar disable/enable buttons Pin
Mark Salsbery17-Jun-07 8:09
Mark Salsbery17-Jun-07 8:09 
GeneralRe: CToolBar disable/enable buttons Pin
Romiks17-Jun-07 18:58
Romiks17-Jun-07 18:58 
GeneralRe: CToolBar disable/enable buttons Pin
Mark Salsbery18-Jun-07 4:29
Mark Salsbery18-Jun-07 4:29 
GeneralRe: CToolBar disable/enable buttons Pin
Romiks18-Jun-07 5:52
Romiks18-Jun-07 5:52 
QuestionMerge Modules Pin
bob169727-Jun-07 7:42
bob169727-Jun-07 7:42 

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.