GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Sep-2004, 17:07
Pandiani Pandiani is offline
New Member
 
Join Date: May 2004
Location: The Balkans
Posts: 16
Pandiani is on a distinguished road

changing caption of static text control


Is it possible to change caption of static text control in Visual C++ .Net in runtime. For example if user click on button caption on some static text control is changed. I declared CStatic variable named m_Text but dont know what to do next. Static text field has ID: IDC_TEXT
Code:
void CPlotDlg::OnBnClickedButton1() { m_Text.??? }

Thanks for help!
  #2  
Old 20-Sep-2004, 02:38
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,032
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough
Quote:
Originally Posted by Pandiani
Is it possible to change caption of static text control in Visual C++ .Net in runtime. For example if user click on button caption on some static text control is changed. I declared CStatic variable named m_Text but dont know what to do next. Static text field has ID: IDC_TEXT
Code:
void CPlotDlg::OnBnClickedButton1() { m_Text.??? }

Thanks for help!

You can go 2 ways about this.
1. Do what you did, and than add this line in the data exchange section of your dialog:
CPP / C++ / C Code:
DDX_Control(pDX, IDC_TEXT, m_text);

Now your dialog is ready to exchange data with your control.
Than, in your button's OnClick event:
CPP / C++ / C Code:
void CPlotDlg::OnBnClickedButton1()
{
	m_Text.SetWindowText("I'm a static control");
}

However, IDC_TEXT might be defined as -1. In this case, define it in Resource.h with a different value - don't cae what that is, just something you didn't use for another control (>0, howerver).

2.(Recommended)
Declare a member variable of your dialog as a pointer to CStatic:
CPP / C++ / C Code:
CStatic *Label; 

Then, in your OnInitDialog, attach it to your dialog:
CPP / C++ / C Code:
Label = new CStatic;

Label->Create("I'm a static control too", WS_CHILD | WS_VISIBLE,
	          CRect(10, 40, 160, 80), this, 90210); //Beverly Hills :D

Change it's caption:
CPP / C++ / C Code:
void CPlotDlg::OnBnClickedButton1()
{
	Label->SetWindowText("I'm a changed static control");
}

Mental Note: I should write a small tutor about data exchange and populating text controls sometime, since many people don't find it obvious the way that VC treats this controls. As a side note, I completely understand this, since I found it too confusing, and I think MS didn't find the best and most user-friendly way to handle the implementation of this controls.

Hope this is what you were looking for.

Best regards,
Luci
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD Burner Help - Power Calibration Error.... JonBoy420 Computer Hardware Forum 111 19-Feb-2009 04:54
How to add progress text to an MFC progress control? m_dale MS Visual C++ / MFC Forum 3 07-Jan-2005 03:25
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:50.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.