Home > Software engineering >  C how MFC in another class to change the main window of the static text color
C how MFC in another class to change the main window of the static text color

Time:11-06

Through this can change OnCtlColor within the main window, then how to call in another class methods change his color?

CodePudding user response:

Another pointer to a class in the main window, then calls the function under the main window

CodePudding user response:

reference 1st floor zyrr159487 response:
pointer to another class in the main window, and then call the main window function under

Call this function, do not work, it seems that this function to initialize the execution, there is no other method can simulate signal changes, red green dots

CodePudding user response:

OnCtlColor is sent to the main window of the news!

CodePudding user response:

Want to buy first state
Invalidate InvalidateRect trigger controls such as window to redraw



CodePudding user response:

reference 4 floor zgl7903 response:
want to buy first state
Invalidate InvalidateRect trigger controls such as window to redraw

Color always dynamic change, only have been redrawn the form

CodePudding user response:

OnCtlColor is by the framework to call (ask) using what color, can return different values through dynamic child controls to change color,
So you shouldn't try to "call" it, and should give it different return value to indirect rendering of different colors,

CodePudding user response:

The timer + static redraw

CodePudding user response:

Other classes return different values, change different color, how to change this function?

CodePudding user response:

reference 4 floor zgl7903 response:
want to buy first state
Invalidate InvalidateRect trigger controls such as window to redraw

This not line, I become a second basic four or five times, not too practical, will shine

CodePudding user response:

refer to 7th floor schlafenhamster response:
timer + static redraw

Can't use event triggers? I have a higher frequency

CodePudding user response:

Timon, 9/f,
references - laozhao response:
Quote: refer to 4th floor zgl7903 response:
want to buy first state
Invalidate InvalidateRect trigger controls such as window to redraw

This not line, I become a second basic four or five times, not too practical, blinking


To avoid flicker is double buffer

CodePudding user response:

11 references zgl7903 response:
Quote: Timon, 9/f, reference - laozhao response:
Quote: refer to 4th floor zgl7903 response:
want to buy first state
Invalidate InvalidateRect trigger controls such as window to redraw

This not line, I become a second basic four or five times, not too practical, blinking


To avoid flicker is double buffer


Is there a simple, like in c # can not directly change the color

CodePudding user response:

Invalidate control after four or five times a second

CodePudding user response:

CStatic derived from a new class, form a can change the font, background color and font color of the control class


CodePudding user response:

SendMessage

CodePudding user response:

reference 13 floor schlafenhamster reply:
change after four or five times a second Invalidate control

4 ~ 5 times, 1 SEC 200 ms/time, the timer will be enough

CodePudding user response:

refer to 12th floor Timon - laozhao response:
Quote: reference 11 floor zgl7903 response:
Quote: Timon, 9/f, reference - laozhao response:
Quote: refer to 4th floor zgl7903 response:
want to buy first state
Invalidate InvalidateRect trigger controls such as window to redraw

This not line, I become a second basic four or five times, not too practical, blinking


To avoid flicker is double buffer


Is there a simple, can not directly change the color like in c #



C # is a BMW, MFC is a bullock carts, not
The original poster to find, take charge, can help you to make

CodePudding user response:

Suggest that class to invoke the static text invalidate, OnCtlColor invokes the RGB values of a class at the same time; Send WM_CTLCOLOR postmessage/sendmessage, useless my success, to find the information also didn't see successful including high and low

CodePudding user response:

I didn't see with 30 milliseconds to invalidate a refresh the main window, in the evening to back up the code,

CodePudding user response:

Thread the
Thread the
 void ChangeColorFunction: : ChangeColor () 
{
If (MainDlg==NULL)
return;
RandColor ();
CWnd * CWnd=CWnd: : FromHandle (GetDlgItem (MainDlg StaticID));
The CWND - & gt; Invalidate (1);
}

Void ChangeColorFunction: : RandColor ()
{
ColorChange=RGB (rand () % 256, 256 rand () %, the rand () % 256);
}

Window
 void CStaticTestDlg: : OnTimer (UINT_PTR nIDEvent) 
{
//TODO: add the message handler code and/or invoke the default
If (nIDEvent==1)
{
ChangeFunction - & gt; ChangeColor ();
}
CDialogEx: : OnTimer (nIDEvent);
}


HBRUSH CStaticTestDlg: : OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
{
HBRUSH gets=CDialogEx: : OnCtlColor (pDC, pWnd, nCtlColor);

//TODO: any features in this change DC

If (pWnd - & gt; GetDlgCtrlID ())
{
//pDC - & gt; SetBkColor (changeFunction - & gt; ColorChange);//the background color for the green
PDC - & gt; SetTextColor (changeFunction - & gt; ColorChange);//words in red
}

//TODO: if the default brush is not required, it returns another brush
Return gets;
}
  • Related