CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Guest

    Changing static text

    I wrote a small dialog box with one static text control and wanted to change the static text on the LMouseDown and the LMouseUp. I made a call to SetDlgItem( IDC_STATIC, CString) but the text didn't change. Do I need to repaint the screen? How do I make the text appear when the Left Mouse buton is down?

    A sample of my code is:

    void CMyDialog::OnLMouseButtonDown()
    {
    CString myString("Mouse button is down");
    SetDlgItem( IDC_STATIC, myString);

    CDialog::OnLMouseButtonDown();
    }

    Any help is appreciated...

    -Dave


  2. #2
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Changing static text

    Rename the Ctrl ID to something else besides IDC_STATIC. Like IDC_MYSTATIC or
    something like that. It will work then.

    Wayne


  3. #3
    Guest

    Re: Changing static text

    Wayne,

    Why does changing the name make that much of a difference. The exact name if I recal was IDC_STATIC1. What does MFC do with the default given names? Do they do something different than they would do with user provided names for controls?

    -Dave


  4. #4
    Join Date
    May 1999
    Location
    Seattle, WA USA
    Posts
    423

    Re: Changing static text

    The default name for all static controls is IDC_STATIC. They all get the same ID, because they are supposed to be static (i.e. not changing), so Visual C assumes that you are not going to want (or need) to uniquely identify any on these controls, so he gives them all IDC_STATIC. MFC probably just returns if ID == IDC_STATIC or something.

    HTH
    --michael


  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Changing static text

    The IDC_STATIC is shared by multiple controls in the dialog. To get another look at what you're trying to do, here is an alternate solution:

    CStatic *pStatic = (CStatic *)GetDlgItem(IDC_STATIC);
    if ( pStatic != NULL )
    pStatic->SetWindowText("string of text");



    If pStatic is NULL, this means that there was a problem identifying which control is IDC_STATIC.

    Regards,

    Paul McKenzie



  6. #6
    Join Date
    Jul 1999
    Posts
    70

    Re: Changing static text

    Hi,
    first I would gave the Static-text a memberVariable (STRG-W) called m_staticedit then I would do this with the onclick. Don't forget the UpdateData(FALSE); //thats mostly the problem, when a text should change

    Black Racer


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