Home > Software engineering >  (MFC) CStatusBar thread calls the collapse problem
(MFC) CStatusBar thread calls the collapse problem

Time:09-22

I had a solution, for the sake of convenience in each dialog box (Child) Style: call the CStatusBar, I defined it in the App files (CStatusBar m_statusBar),
I first in the main dialog to m_statusBar do initialization operation, no problem, but when I was a child in the dialog box thread (I need in this thread to manipulate) the m_statusBar call but collapsed,

Followed by the code:
//thread information structure of the definition of 
Struct struct_MyInfo
{
.
StatusBar CStatusBar *;
};

//dialog OnInitDialog () 
BOOL CXXXDlg: : OnInitDialog ()
{
CDialogEx: : OnInitDialog ();

.
TheApp. M_statusBar. SetPaneText (0, L "is for version information... ");//& lt; Here - nothing
Struct_MyInfo * p=new struct_MyInfo;
.
p-> StatusBar=& amp; (theApp m_statusBar);//& lt; - m_statusBar I is defined in the App
CWinThread * pThread=AfxBeginThread (MyThread (LPVOID), p);
.

return TRUE;//return TRUE unless you set the focus to a control
//exception: OCX property page should return FALSE
}


//threadUINT MyThread (LPVOID lpParam) 
{
LpParam struct_MyInfo * p=(struct_MyInfo *);
.
p-> StatusBar - & gt; SetPaneText (0, L "ready");//& lt; - this will collapse
return 0;
}

CodePudding user response:

I try to use in the thread main dialog pointer SetTimer (... ), and then the OnTimer (... ) m_statusBar can operation

CodePudding user response:

To set breakpoints, and see if the pointer is normal, whether the call stack with other information
Struct_MyInfo * p=new struct_MyInfo; Suggested that the p as a class variable, otherwise when the delete bad management

CodePudding user response:

p-> StatusBar=0?

CodePudding user response:

refer to the original poster qq_30866987 response:
I had a solution, for the convenience of in each dialog box (Child) Style: call CStatusBar, I defined it in the App files (CStatusBar m_statusBar),
I first in the main dialog to m_statusBar do initialization operation, no problem, but when I was a child in the dialog box thread (I need in this thread to manipulate) the m_statusBar call but collapsed,

Followed by the code:
//thread information structure of the definition of 
Struct struct_MyInfo
{
.
StatusBar CStatusBar *;
};

//dialog OnInitDialog () 
BOOL CXXXDlg: : OnInitDialog ()
{
CDialogEx: : OnInitDialog ();

.
TheApp. M_statusBar. SetPaneText (0, L "is for version information... ");//& lt; Here - nothing
Struct_MyInfo * p=new struct_MyInfo;
.
p-> StatusBar=& amp; (theApp m_statusBar);//& lt; - m_statusBar I is defined in the App
CWinThread * pThread=AfxBeginThread (MyThread (LPVOID), p);
.

return TRUE;//return TRUE unless you set the focus to a control
//exception: OCX property page should return FALSE
}


//threadUINT MyThread (LPVOID lpParam) 
{
LpParam struct_MyInfo * p=(struct_MyInfo *);
.
p-> StatusBar - & gt; SetPaneText (0, L "ready");//& lt; - this will collapse
return 0;
}



Don't work in operation in the UI thread, PostThreadMessage, let the UI thread processing the message

CodePudding user response:

"The definition in the App file (CStatusBar m_statusBar),"
With the int CMainFrame: : OnCreate (LPCREATESTRUCT LPCREATESTRUCT) in the
if (! M_wndStatusBar. Create (this) | |
! M_wndStatusBar. SetIndicators (indicators,
Sizeof (indicators)/sizeof (UINT)))
{
TRACE0 (" Failed to create the status bar \ n ");
return -1;//fail to create
};
has nothing to do!

CodePudding user response:

reference 5 floor schlafenhamster reply:
"defined in the App file (CStatusBar m_statusBar),"
With the int CMainFrame: : OnCreate (LPCREATESTRUCT LPCREATESTRUCT) in the
if (! M_wndStatusBar. Create (this) | |
! M_wndStatusBar. SetIndicators (indicators,
Sizeof (indicators)/sizeof (UINT)))
{
TRACE0 (" Failed to create the status bar \ n ");
return -1;//fail to create
};
has nothing to do!

Creation is successful, is just a thread in the call, modify the collapse

I look at the https://bbs.csdn.net/topics/110192663, find the reason

CodePudding user response:

"The definition in the App file (CStatusBar m_statusBar)," is another m_statusBar
And the MainFrame m_statusBar irrelevant!
Do a function in the MainFrame, the inline CStatusBar * GetstSatusBar () {return & amp; M_statusBar; }

CodePudding user response:

Work not to directly manipulate the UI thread in the thread created in the controls

CodePudding user response:

Don't manipulate controls in the thread, send a message to the main thread to complete the operation
  • Related