CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2014
    Location
    Las Vegas, NV
    Posts
    85

    CStatic doesn't work in CTab in MFC

    Hello
    I'm trying to change the text of a CStatic from a thread. I have a pointer to man dialog:
    Code:
    MDialog* MainDialog = (MDialog*)AfxGetApp()->m_pMainWnd;
    then i try to change the text like this:
    Code:
    MainDialog->text1.SetWindowTextW(L"test1");
    it will work if the text1 is placed in the dialog but not if its placed inside a tab but i can't figure out why ?
    The code is in tab dialog .cpp not in main dialog but doesn't work anyway. I tried both ways
    Any help would be greatly appreciated!

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: CStatic doesn't work in CTab in MFC

    You must not use window-related MFC classes in worker threads. This is a limitation of MFC architecture: you use MFC in the thread that the window was created in. If you want to interact with windows/controls from other thread, use plain Win32 API.
    Best regards,
    Igor

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: CStatic doesn't work in CTab in MFC

    Can you be more specific about what you mean by "inside a tab".

  4. #4
    Join Date
    Sep 2014
    Location
    Las Vegas, NV
    Posts
    85

    Re: CStatic doesn't work in CTab in MFC

    Quote Originally Posted by GCDEF View Post
    Can you be more specific about what you mean by "inside a tab".
    I have a Tab Control in main dialog. In Tab i have 4 pages:
    Code:
    	m_DialogID[0] = IDD_DIALOG1;
    	m_DialogID[1] = IDD_DIALOG2;
    	m_DialogID[2] = IDD_DIALOG3;
    	m_DialogID[3] = IDD_DIALOG4;
    Code:
    void tabClass::InitDialogs()
    {
    	m_Dialog[0]->Create(m_DialogID[0], GetParent());
    	m_Dialog[1]->Create(m_DialogID[1], GetParent());
    	m_Dialog[2]->Create(m_DialogID[2], GetParent());
    	m_Dialog[3]->Create(m_DialogID[3], GetParent());
    }
    Every tab page has a separate dialog created, when i change tabs it changes the page. I want to be able to change a static text inside one of those dialogs, each of it has its own .cpp file and dialog resource. I'm only able to change static text that is placed inside the main dialog but not inside any of those dialogs inside tabs

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: CStatic doesn't work in CTab in MFC

    Quote Originally Posted by eclessiastes View Post
    I want to be able to change a static text inside one of those dialogs
    So what is your real problem? You have dialog array, so you can access dialog's m_hWnd, so you can GetDlgItem for the static, and finally you can SetWindowText for the static. Please note my comment above about not trying to do that MFC way being in a worker thread.

    Or you can send custom message to your main dialog, which dialog is to re-send the message to its subordinate dialog(s), where target dialog is to apply the text to the static.
    Best regards,
    Igor

  6. #6
    Join Date
    Sep 2014
    Location
    Las Vegas, NV
    Posts
    85

    Re: CStatic doesn't work in CTab in MFC

    Quote Originally Posted by Igor Vartanov View Post
    So what is your real problem? You have dialog array, so you can access dialog's m_hWnd, so you can GetDlgItem for the static, and finally you can SetWindowText for the static. Please note my comment above about not trying to do that MFC way being in a worker thread.

    Or you can send custom message to your main dialog, which dialog is to re-send the message to its subordinate dialog(s), where target dialog is to apply the text to the static.
    Thanks, works now
    Last edited by eclessiastes; November 13th, 2015 at 04:23 AM.

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