Change Text of a CText Static

Posted on 2003-02-24
Medium Priority
Last Modified: 2013-11-20
I have several CText static text areas on a dialog in my application.  I'm trying to change the text contained within them when certain events occur.  Specifically, I'm trying to print the name of the file opened to the static text control.  I have all the code in place to give me the filename from CFileDialog, but cannot implement the change to the static text controls.  I previously did this with edit boxes, but I would like to convert to static texts for a more polished look.  I was thinking along the lines of getting a pointer to the control and using *ptr->SetWindowText(str_Text) but was unable to do it.  I would appreciate any help offered.  Thanks in advance.
Question by:klax33
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 48

Accepted Solution

AlexFM earned 400 total points
ID: 8008891
GetDlgItem(IDC_STATIC_TEXT)->SetWindowText(_T("New text"));

Author Comment

ID: 8008960
That code compiles and builds but gives a "memory could not be read" error.  Also, when you try to just type the first part GetDlgItem(STATIC_TEXT)-> the listbox with all the possible functions does not pop up as it normally does.  [I am using Visual C++ 6.0].  

Author Comment

ID: 8009002
Thanks for your quick response AlexFM.  You are correct in your code fragment.  However I did not use a unique identifier to my static control and since IDC_STATIC is shared, it was causing a memory error.  jhance who answered my identical double post mentioned that I needed a unique identifier.  You code works and is the most concise so you get the points.  Thanks again.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question