Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

580 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