1

Topic: Problem with color setting of the text and a creeping line background

There is at me a flow hThread to which as the data the structure myStruct in which there is a field isthreadfinished type bool which shows is sent, whether this flow was completed or not. There is timer ID_TIMER_1 to which there corresponds function CMyClass:: OnTimer which deduces creeping line with an interval in half-seconds and completes a creeping line output as soon as the flow hThread completes the operation: void CMyClass:: OnTimer (UINT uTime) {if (myStruct.isthreadfinished == true)//if the flow is completed {KillTimer (ID_TIMER_1); timerTest = false; timerCount = 0; m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled"); CloseHandle (hThread);//other actions; return;} if (timerCount> =6) timerCount = 0; if (timerCount == 0) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled"); if (timerCount == 1) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled."); if (timerCount == 2) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled." ); if (timerCount == 3) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled..."); if (timerCount == 4) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled...."); if (timerCount == 5) m_IDC_STATIC1.SetWindowTextA ("calculation is fulfilled....."); timerCount ++;} usually when the variable m_IDC_STATIC1 concerns type CStatic, all works normally - the creeping line of black color appears against common dialog (a color shade of gray). But I wanted to replace text color and background color of creeping line - that this line was red color, and background color on which it appears - green color. For this purpose I created class CMyStatic2 as offspring of class CStatic in which I redefined method OnPaint (): file MyStatic2.h: #include <afxwin.h> class CMyStatic2: public CStatic {protected: void OnPaint (); DECLARE_MESSAGE_MAP () public://open members of class CMyStatic;} ; File MyStatic2.cpp: #include "stdafx.h" #include "MyStatic2.h" BEGIN_MESSAGE_MAP (CMyStatic2, CStatic) ON_WM_PAINT () END_MESSAGE_MAP () void CMyStatic2:: OnPaint () {const MSG *msg = GetCurrentMessage (); DefWindowProc (msg-> message, msg-> wParam, msg-> lParam); RECT rect; CClient dc (this); GetClientRect (&rect); CBrush brush (RGB (0,128,0));//green background color dc. SelectObject (&brush); dc. FillRect (&rect,&brush); dc. SetTextColor (RGB (255,0,0));//} And a variable m_IDC_STATIC1 in class CMyClass I replaced red text color from type CStatic with type CMyStatic2. Therefore at me at flow and timer start for one second appears  a field of green color, and then it changes on standard color of dialogue (a color shade of gray) and the creeping line in this static field has black color. In what the reason of it? How to rectify this error - that is how to make so that this static field always had green color, and the creeping line in it always had red color?

2

Re: Problem with color setting of the text and a creeping line background

Hello, RussianFellow, you wrote: RF> RF> void CMyClass:: OnTimer (UINT uTime) RF> {RF> if (myStruct.isthreadfinished == true) RF>//if the flow is completed RF> {RF> KillTimer (ID_TIMER_1); RF> timerTest = false; RF> timerCount = 0; RF> m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled"); RF> CloseHandle (hThread); RF>//other actions; RF> return; RF>} RF> if (timerCount> =6) timerCount = 0; RF> if (timerCount == 0) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled"); RF> if (timerCount == 1) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled."); RF> if (timerCount == 2) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled."); RF> if (timerCount == 3) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled..."); RF> if (timerCount == 4) m_IDC_STATIC1.SetWindowTextA ("Calculation is fulfilled...."); RF> if (timerCount == 5) m_IDC_STATIC1.SetWindowTextA ("calculation is fulfilled....." ); RF> timerCount ++; RF>} RF> Why not to make so:... std:: string sTextOut = "Calculation is fulfilled"; if (timerCount> =6) timerCount = 0; for (int i = 0; i <timerCount; i ++) sTextOut + = "."; m_IDC_STATIC1.SetWindowTextA (sTextOut.c_str ()); timerCount ++; On a specific question here an example: https://www.codeproject.com/Articles/10 … nd-CStatic

3

Re: Problem with color setting of the text and a creeping line background

Hello, RussianFellow, you wrote: Probably SetWindowTextA does not cause copying by function OnPaint. Very much to that it is similar. At  OnPaint it is caused once and draws a green rectangle. And as soon as works timer SetWindowTextA draws using system colors. You then should not SetWindowTextA cause, and to send the message for copying in which at you by the way the text is not deduced. P.S.Kstati, a line at you not running

4

Re: Problem with color setting of the text and a creeping line background

Hello, anatolym, you wrote: A> Hello, RussianFellow, you wrote: A> it is possible SetWindowTextA does not cause copying by function OnPaint. Very much to that it is similar. At  OnPaint it is caused once and draws a green rectangle. And as soon as works timer SetWindowTextA draws using system colors. A> you then should not SetWindowTextA cause, and to send the message for copying in which at you by the way the text is not deduced. P.S.Tajmery, inheritance, horror what And on WPF is all it is possible to make on a markup language. <DockPanel LastChildFill = "True" Margin = "5" TextBlock. FontSize = "20"> <TextBlock Panel. ZIndex = "1" Background = "Green" Foreground = "Yellow"> Operation in progress </TextBlock> <TextBlock Text = ".............." x:Name = "Dots" Margin = "-100 0 0 0" Background = "Green" Foreground = "Yellow"> <TextBlock. Triggers> <EventTrigger RoutedEvent = "TextBlock. Loaded"> <BeginStoryboard> <Storyboard TargetName = "Dots" TargetProperty = "Margin"> <ThicknessAnimation To = "0 0 0 0" RepeatBehavior = "Forever" Duration = "0:0:2"> </ThicknessAnimation> </Storyboard> </BeginStoryboard> </EventTrigger> </TextBlock. Triggers> </TextBlock> </DockPanel> Looks so the link

5

Re: Problem with color setting of the text and a creeping line background

Hello, anatolym, you wrote: A> Hello, RussianFellow, you wrote: A> it is possible SetWindowTextA does not cause copying by function OnPaint. Very much to that it is similar. At  OnPaint it is caused once and draws a green rectangle. And as soon as works timer SetWindowTextA draws using system colors. A> you then should not SetWindowTextA cause, and to send the message for copying in which at you by the way the text is not deduced. Yes, all is true - copying OnPaint was not caused in me on SetWindowTextA. I solved a problem as follows: in class CMyStatic2 added the following: public: char s [50]; void setText (char *s); void CMyStatic2:: setText (char *s) {strcpy (this-> s, s);} As CMyStatic:: OnPaint I wrote: CBrush brush (RGB (0,128,0));//background color - green dc. SelectObject (&brush); dc. FillRect (&rect,&brush); dc. SetTextColor (RGB (255,0,0));//text color - red dc. SetBkColor (RGB (0,128,0));//background color at the text - green dc. DrawTextA (s, strlen (s) ,&rect,0); And as CMyClass:: OnTimer instead of if (timeCount == 0) m_IDC_STATIC1.setWindowTextA ("Calculation is fulfilled"); I wrote: if (timeCount == 0) {m_IDC_STATIC1.setText ("Calculation is fulfilled"); m_IDC_STATIC1.RedrawWindow ();} (And so for all cases timeCount, and also for a case when it is necessary to deduce an inscription "Calculation it is fulfilled"). As a result all works for me correctly! P.S. Than differs CWnd:: RedrawWindow from CWnd:: UpdateWindow?

6

Re: Problem with color setting of the text and a creeping line background

Hello, RussianFellow, you wrote: RF> And as CMyClass:: OnTimer instead of RF> if (timeCount == 0) m_IDC_STATIC1.setWindowTextA ("Calculation is fulfilled"); RF> I wrote: RF> if (timeCount == 0) RF> {RF> m_IDC_STATIC1.setText ("Calculation is fulfilled"); RF> m_IDC_STATIC1.RedrawWindow (); RF>} RF> (And so for all cases timeCount, and also for a case when it is necessary to deduce an inscription "Calculation it is fulfilled"). It can be packed into a cycle as offered above AlexGin. For duplication not is a buzzing. RF> P.S. Than differs CWnd:: RedrawWindow from CWnd:: UpdateWindow? It I do not know, or I do not remember MFC the last time for a long time saw, and thank God.

7

Re: Problem with color setting of the text and a creeping line background

It is not forgotten dc. SetBkMode (TRANSPARENT) before plotting that did not overwrite a background the text.

8

Re: Problem with color setting of the text and a creeping line background

9

Re: Problem with color setting of the text and a creeping line background

Hello, RussianFellow, you wrote: RF> P.S. Than differs CWnd:: RedrawWindow from CWnd:: UpdateWindow? CWnd:: UpdateWindow - causes function API UpdateWindow () which stupidly sends to a window message WM_PAINT, and it  completely. CWnd:: RedrawWindow - causes function API RedrawWindow () at which it is some parameters and combinations of flags. MFC causes it with any values by default, probably such values do not cause the full copying of a window.

10

Re: Problem with color setting of the text and a creeping line background

Hello, RussianFellow, you wrote: RF> P.S. Than differs CWnd:: RedrawWindow from CWnd:: UpdateWindow? In MSDN to esteem feeblly?