CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2007
    Posts
    186

    MFC static text control

    I have a static text control in an mfc application. I want to add some text and such to it. Im new to mfc but I thought I add a control variable to change the caption property. When I right click the control and pick add variable I just get a blank menu with no datatypes for control variable of value or control type. I tried adding a CString and typing that into the dataype box but it didnt work. Am I doing anything stupid?
    Last edited by abcdefgqwerty; March 22nd, 2007 at 03:48 PM.

  2. #2
    Join Date
    Jul 2001
    Posts
    703

    Re: MFC static text control

    Add a member variable to the control of type CString.

    if m_Edit is your member variable then,

    Code:
    UpdateData();
    m_Edit = "My first Text";
    UpdateData(FALSE);
    Thats it.

    Method 2:
    Code:
    CEdit* pEdit = (CEdit*) GetDlgItem(IDC_EDIT);
    pEdit->SetDlgItemText........
    Happy Coding
    "Dont Forget to rate if it helped"

  3. #3
    Join Date
    Feb 2007
    Posts
    186

    Re: MFC static text control

    Can I cast CWnd * to a pointer of any control type? Ive seen a CWnd* being cast into a listcontrol * once.

  4. #4
    Join Date
    Jul 2001
    Posts
    703

    Re: MFC static text control

    Dude,

    OOps! my mistake, i thought of Edit control but you are asking for just static text.

    Go to OnInitDialog() and just add this line

    Code:
    SetDlgItemText(IDC_STATIC,"My First Static Text");
    "Dont Forget to rate if it helped"

  5. #5
    Join Date
    Feb 2007
    Posts
    186

    Re: MFC static text control

    its ok thanks for the help. My problem was a bug in MFC where I guess the control didnt work right until I deleted it and put it back on the page. That or I did something stupid which is most likely I guess.
    That worked on setting the text, mfc is pretty confusing at first. C# is a lot more elegant and has less bugs.
    Last edited by abcdefgqwerty; March 22nd, 2007 at 04:39 PM.

  6. #6
    Join Date
    Apr 2005
    Posts
    221

    Re: MFC static text control

    Quote Originally Posted by abcdefgqwerty
    mfc is pretty confusing at first. C# is a lot more elegant and has less bugs.
    Well, C# has the benefit of the long history of C++ behind it, and, of course, C++ was built on the experience of C.

    Although I would also add that how confusing a language is to someone just learning it is often a combination of the learner's past experience and, more importantly, the teacher's effectiveness in teaching (or alternatively how well-written the book is that the learner is using). Unfortunately there are a lot of bad teachers and a lot of poorly written books out there.

  7. #7
    Join Date
    Apr 2025
    Posts
    1

    Re: MFC static text control

    Quote Originally Posted by VCVCVC View Post
    Dude,

    OOps! my mistake, i thought of Edit control but you are asking for just static text.

    Go to OnInitDialog() and just add this line

    Code:
    SetDlgItemText(IDC_STATIC,"My First Static Text");
    Yeah well, this is wrong as well.

    So go to your OnInitDialog() and in that, after all default initializations, give error due to My First Static Text. Also, its showing that IDC_STATIC is not declared.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,429

    Re: MFC static text control

    Quote Originally Posted by GURUKARTHI K C View Post
    Yeah well, this is wrong as well.

    So go to your OnInitDialog() and in that, after all default initializations, give error due to My First Static Text. Also, its showing that IDC_STATIC is not declared.
    Well, after 18+ years (the age of the thread)...
    Are you sure someone who posted to this thread still attends (sometimes) the CG?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured