Thread: changing static text

  1. #1
    sockets mad
    Join Date
    Mar 2002

    Smile changing static text


    I'm a newbie to win32 c and I'm still getting to used to a lot of things. I was wondering whether there is a way to change the contents of static text controls during runtime on a DialogBox loaded from the resources rather than using a window class etc.

    I tried thinking that maybe you use SetWindowText or SetDlgItemText but i don't know how to find out the hwnd of the static text and it doesn't seem to have an indentifier like IDOK or whatever. I know you can use SetWindowText if you make the static text using CreateWindow as it returns the hwnd of it but i don't know how to change ones which have been drawn on the dialog at design time.

    I used to use vb which is probably why I'm approaching it in this way, if I'm totally looking in the wrong direction then please correct me!


    Daniel Briley

  2. #2
    Join Date
    Jan 2002
    Open up your resource script, either using a GUI editor if you have one, or in a text editor if you don't. Find the static control you wish to modify the text of and give it an id which you should give a numeric value (ie #define it) in your resource header.

    Now that the static control has a unique id you can use GetDlgItem to get the handle of the control for use with SetWindowText or just use SetDlgItemText.

    eg in resource header:
    #define IDC_MY_STATIC_CNTRL 500
    and then in the resource script:
    LTEXT "original static cntrl text", IDC_MY_STATIC_CNTRL, 0, 0, 200, 15
    Hope that helps.

  3. #3
    sockets mad
    Join Date
    Mar 2002
    Thanks for that, works exactly as i needed it too :-D

    greatly appreciated

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. uploading file to http server via multipart form data
    By Dynamo in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2008, 04:36 AM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. ADDING text to a STATIC control
    By Garfield in forum Windows Programming
    Replies: 2
    Last Post: 09-01-2003, 09:48 AM
  5. Changing the colour of static text.
    By -leech- in forum Windows Programming
    Replies: 2
    Last Post: 02-09-2003, 08:09 PM
Website Security Test