-
November 10th, 2015, 04:38 PM
#1
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!
-
November 11th, 2015, 04:35 AM
#2
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
-
November 11th, 2015, 08:10 AM
#3
Re: CStatic doesn't work in CTab in MFC
Can you be more specific about what you mean by "inside a tab".
-
November 11th, 2015, 02:04 PM
#4
Re: CStatic doesn't work in CTab in MFC
Originally Posted by GCDEF
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
-
November 12th, 2015, 04:11 AM
#5
Re: CStatic doesn't work in CTab in MFC
Originally Posted by eclessiastes
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
-
November 13th, 2015, 04:14 AM
#6
Re: CStatic doesn't work in CTab in MFC
Originally Posted by Igor Vartanov
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|