Home > Software engineering >  MFC change control color
MFC change control color

Time:11-06

Change is statictext color, in a class (the main form class), through the different events change static text font color,

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:

reference 1st floor zgl7903 response:
CStatic derived from a new class, form a can change the font, background color and font color of the control class

CMFCButton * MFCB=(CMFCButton *) GetDlgItem (IDC_MFCBUTTON1);

MFCB - & gt; SetFaceColor (RGB (0, 255, 0));
I call this in the main window class can change the color, but call this is an error in the other classes,

CodePudding user response:

GetDlgItem API prototype is HWND GetDlgItem ( HWND hDlg , int nIDDlgItem);
Thus gain control of other Windows, you have to specify a control of the parent window
You now that is the main window class (theApp m_pMainWnd=XXX registration window), you can use the AfxGetMainWnd ()

The CWnd * pMainWnd=AfxGetMainWnd ();
If (pMainWnd)
{
CMFCButton * MFCB=(CMFCButton *) pMainWnd - & gt; GetDlgItem (IDC_MFCBUTTON1);
If (MFCB)
{
.
}
}

CodePudding user response:

reference zgl7903 reply: 3/f
GetDlgItem API prototype is HWND GetDlgItem ( HWND hDlg , int nIDDlgItem);
Thus gain control of other Windows, you have to specify a control of the parent window
You now that is the main window class (theApp m_pMainWnd=XXX registration window), you can use the AfxGetMainWnd ()

The CWnd * pMainWnd=AfxGetMainWnd ();
If (pMainWnd)
{
CMFCButton * MFCB=(CMFCButton *) pMainWnd - & gt; GetDlgItem (IDC_MFCBUTTON1);
If (MFCB)
{
.
}
}

Other classes call I how to pass the HWND, can call the class, other class cannot call

CodePudding user response:

Timon
reference 4th floor - laozhao response:
Quote: reference zgl7903 reply: 3/f
GetDlgItem API prototype is HWND GetDlgItem ( HWND hDlg , int nIDDlgItem);
Thus gain control of other Windows, you have to specify a control of the parent window
You now that is the main window class (theApp m_pMainWnd=XXX registration window), you can use the AfxGetMainWnd ()

The CWnd * pMainWnd=AfxGetMainWnd ();
If (pMainWnd)
{
CMFCButton * MFCB=(CMFCButton *) pMainWnd - & gt; GetDlgItem (IDC_MFCBUTTON1);
If (MFCB)
{
.
}
}

Other classes call I how to pass the HWND, can call the class, other class cannot call


The code is not already here

  • Related