MFC static text

I was wondering how to hide static text and change it.

Im working on my first MFC app for homework and Im using a combo box with the selection of six shapes such as (Square, Rectangle, Circle, Cube, etc.) So when I select Square I want just the static text to say side: with a edit box next to it and if I select Rectangle the static text to say length: width: with two edit boxes

So I was wondering how to use my combo box to get the correct static text and edit boxes. I don't know if I need tabs or not.

this is my combobox handler but I can only change one static text
and I dont know how to hide it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

void CTestDlg::OnCbnSelchangeCombo1()
{
	// TODO: Add your control notification handler code here
	CComboBox* object = (CComboBox*)GetDlgItem(IDC_COMBO1); 
    int n = object->GetCurSel();

// 0=Square, 1=Rectangle, 2=Circle, 3=Cube, 4=Prism, 5=Cylinder 

	if (n == 0)
	  SetDlgItemText(IDC_STATIC, "side:");
	
	else if (n == 1)
	{
	  SetDlgItemText(IDC_STATIC, "length:"); // don't set
	  SetDlgItemText(IDC_STATIC, "width:"); // this one sets only

	}


}


thanks for any help in advance.
Last edited on
To hide/show any type of window, you use the ShowWindow method of CWnd (or the equiv Win32 call, if not using MFC).

1
2
3
CWnd* pWnd = GetDlgItem(IDC_STATIC_ONE); // NOT just IDC_STATIC (see below)

pWnd->ShowWindow(SW_HIDE); // or SW_SHOW 


You should not use IDC_STATIC for static windows you want to update. It's a special resource ID (-1) for all static controls with fixed labels, to avoid having to define resource IDs which will never be used to update controls.

Instead, each static you need to change should be given it's own unique ID (well, unique for a given dialog)
Last edited on
Sorry but Im new to MFC this is my first time dealing with MFC. But when I try this it don't work.

is IDC_STATIC_ONE does this need to be declared,

my static texts are named IDC_STATIC1 IDC_STATIC2
but when I try to refer to them it says they are undefined.

thanks for any help and sorry for being a dumb beginner.
but my teacher assigned this and it isn't part of are book.
Im in a OOP class
Of course IDC_STATIC_ONE (or whatever you want to name it) must be created first using the resource editor.
Topic archived. No new replies allowed.