How to clear text of static text mfc?

Asked By 20 points N/A Posted on -
qa-featured

Hello experts,

How to clear text of static text mfc? I don’t know how to perform this kind of clearing text. I need your guidance or step by step instruction to get this done properly. There are some instances that it will not be cleared but I hope this time it will.

SHARE
Answered By 10 points N/A #172108

How to clear text of static text mfc?

qa-featured

 

Hi Debra, 

You can use following method to clear the text.

First get the item by calling GetDlgItem method. For example

  CWnd* pWindow = GetDlgItem(IDC_Label_STATIC);

Then Setting its text my using the following code

 pWindow->SetDlgItemTextW(IDC_Label_STATIC, _T(""));

Other way to do this is to declare the variable as static, then initializing it as static control and then changing the value.

CStatic *Static_text;  

Static_text = new CStatic; 

Static_text->Create("I'm a static", WS_CHILD | WS_VISIBLE,

         CRect(3, 4, 11, 18), this, 900); 

 void CPlotDlg::OnBnClickedButton1()

{

Static_text->SetWindowText("I'm changed");

}

I hope it will help you.

Thank you

Related Questions