Click to See Complete Forum and Search --> : Changing static text


July 15th, 1999, 09:34 AM
I wrote a small dialog box with one static text control and wanted to change the static text on the LMouseDown and the LMouseUp. I made a call to SetDlgItem( IDC_STATIC, CString) but the text didn't change. Do I need to repaint the screen? How do I make the text appear when the Left Mouse buton is down?

A sample of my code is:

void CMyDialog::OnLMouseButtonDown()
{
CString myString("Mouse button is down");
SetDlgItem( IDC_STATIC, myString);

CDialog::OnLMouseButtonDown();
}

Any help is appreciated...

-Dave

Wayne Fuller
July 15th, 1999, 09:50 AM
Rename the Ctrl ID to something else besides IDC_STATIC. Like IDC_MYSTATIC or
something like that. It will work then.

Wayne

July 15th, 1999, 10:31 AM
Wayne,

Why does changing the name make that much of a difference. The exact name if I recal was IDC_STATIC1. What does MFC do with the default given names? Do they do something different than they would do with user provided names for controls?

-Dave

chiuyan
July 15th, 1999, 10:42 AM
The default name for all static controls is IDC_STATIC. They all get the same ID, because they are supposed to be static (i.e. not changing), so Visual C assumes that you are not going to want (or need) to uniquely identify any on these controls, so he gives them all IDC_STATIC. MFC probably just returns if ID == IDC_STATIC or something.

HTH
--michael

Paul McKenzie
July 15th, 1999, 11:09 AM
The IDC_STATIC is shared by multiple controls in the dialog. To get another look at what you're trying to do, here is an alternate solution:

CStatic *pStatic = (CStatic *)GetDlgItem(IDC_STATIC);
if ( pStatic != NULL )
pStatic->SetWindowText("string of text");



If pStatic is NULL, this means that there was a problem identifying which control is IDC_STATIC.

Regards,

Paul McKenzie

Black Racer
July 16th, 1999, 09:21 PM
Hi,
first I would gave the Static-text a memberVariable (STRG-W) called m_staticedit then I would do this with the onclick. Don't forget the UpdateData(FALSE); //thats mostly the problem, when a text should change

Black Racer