Home > Software engineering >  How to refresh the dialog interface
How to refresh the dialog interface

Time:12-12

I wrote a program, can change the font color by color button
 

//I'm in pDC OnCtlColor function - & gt; SetTextColor (m_color1); Implementation of font changes color
GetDlgItem (CMFCColorButton m_color1=(*) (IDC_MFCCOLORBUTTON2)) - & gt; GetColor ();

Use color button control color, font color of the interface will not refresh; Controls can be dragged in my program, after I drag controls, font color will change

So I want to use a timer to refresh interface

O bosses give directions

CodePudding user response:

 

Void CEditTestDlg: : OnBnClickedBtnTimerUpdate ()
{
This - & gt; The SetTimer (1, 1, NULL);
This - & gt; The SetTimer (2, 1, NULL);
}

Void CEditTestDlg: : OnTimer (UINT_PTR nIDEvent)
{
The switch (nIDEvent)
{
Case 1:
If ( TMP & gt;
=100){
This - & gt; KillTimer (1);
MessageBox (_T (" timer 1 stop!" ), NULL, NULL);
return;
}
Sleep (20);
TMP +=1;
m_value . The Format (_T (" % d "), TMP);
The UpdateData (FALSE);
break;
Case 2:
If (tmp1 & gt;
=200){
This - & gt; KillTimer (2);
MessageBox (_T (" timer 2 stop!" ), NULL, NULL);
return;
}
Sleep (20);
Tmp1 +=1;
m_value2 . The Format (_T (" % d "), tmp1);
The UpdateData (FALSE);
Default:
break;
}
CDialog: : OnTimer (nIDEvent);
}

Red mark of several variables is what kind of?

CodePudding user response:

Some people have done something like that before

CodePudding user response:

Can be used to Invalidate trigger redraws
 if (GetDlgItem (IDC_MFCCOLORBUTTON2)) 
{
GetDlgItem (IDC_MFCCOLORBUTTON2) - & gt; Invalidate ().
}



CodePudding user response:

From the code to guess int TMP; Cstrings m_value m_value2;

CodePudding user response:

If (GetDlgItem (IDC_MFCCOLORBUTTON2))
{
GetDlgItem (IDC_MFCCOLORBUTTON2) - & gt; Invalidate ().
}

How to use it? In the OnPaint, or on the OnCtlColor, or used in other functions?

CodePudding user response:

 

Void ButtonCreatePad: : OnPaint ()
{
//CPaintDC dc (this);//device context for painting
//TODO: add message handler code here
//no message calls for drawing CDialogEx: : OnPaint ()

CPaintDC dc (this);
CRect rect1;
GetClientRect (& amp; Rect1);
The CDC dcMem.
DcMem. CreateCompatibleDC (& amp; Dc);
CBitmap bmpBackground;
BmpBackground. LoadBitmapW (IDB_BITMAP7);
BITMAP BITMAP.
BmpBackground. GetBitmap (& amp; Bitmap);
CBitmap * pbmpOld=dcMem. SelectObject (& amp; BmpBackground);
Dc. StretchBlt (0, 0, rect1 Width (), rect1. Height (), & amp; DcMem, 0, 0, bitmap bmWidth, bitmap. BmHeight, SRCCOPY);
}


HBRUSH ButtonCreatePad: : OnCtlColor (CDC * pDC, CWnd * pWnd, UINT nCtlColor)
{
HBRUSH gets=CDialogEx: : OnCtlColor (pDC, pWnd, nCtlColor);
GetDlgItem (CMFCColorButton m_color1=(*) (IDC_MFCCOLORBUTTON2)) - & gt; GetColor ();
//TODO: any features in this change DC
UINT id=pWnd - & gt; GetDlgCtrlID ();
If (id==IDC_RADIO_SQUARE | | id==IDC_RADIO_ROUND)
{
PDC - & gt; SetBkMode (TRANSPARENT);

CRect rc;
PWnd - & gt; GetWindowRect (& amp; Rc);
The ScreenToClient (& amp; Rc);

The CDC * dc GetDC ();

PDC - & gt; BitBlt (0, 0, rc. Width (), rc, Height (), dc, rc, left, rc, top, SRCCOPY);//the parent window background images onto a button on the first
ReleaseDC (dc);

Gets=(HBRUSH) : : GetStockObject (NULL_BRUSH);

}

If (nCtlColor==CTLCOLOR_STATIC)
{
PDC - & gt; SetBkMode (TRANSPARENT);//set the background transparent language
PDC - & gt; SetTextColor (m_color1);//set the font to white
Return (HBRUSH) : : GetStockObject (NULL_BRUSH);
}
PDC - & gt; SetTextColor (m_color1);
PDC - & gt; SetBkMode (TRANSPARENT);//set the background transparent controls (don't forget the control setting for transparent, or changes in the properties of the controls, it is too hard)
The switch (nCtlColor)
{
Case CTLCOLOR_BTN:
Gets=(HBRUSH) : : GetStockObject (NULL_BRUSH);//return an empty brush can make static background transparent font
Default: break;
}

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


You said Invalidate re-paint is how to get the

CodePudding user response:

CodePudding user response:

Use color button control color,
control. Invalidate ();

CodePudding user response:

I just added a button directly, and then click the function inside the
Invalidate ().
  • Related