私はWorkerthreadからメインウィンドウ(ダイアログ)へデータを渡す方法についていくつかのスレッドを読んでいますが、まだ理解しておらず、まだ助けが必要です。 私のworkerthreadはいくつかの計算を処理し、各ループ中に結果をGUIの編集に表示する必要があります。私が知っているMFC - PostMessageを使用したPostMessageによるデータのGUIへの投稿
//CWorkerThreadMgr.h manages the second thread
HRESULT Start (HWND hWnd);// from where the workerthread will be started
HWND m_hWnd ; //Window handle to the UI ;
HANDLE m_hTread; //handle of the worker thread
static UINT WINAPI ThreadProc(LPVOID lptest);
static UINT WINAPI ThreadProc(LPVOID lptest)
{
CWorkerThreadMgr* pCalculateMgr = reinterpret_cast< CWorkerThreadMgr*(lptest);
//The following operation:rand() *m_Slider.GetPos() should
//should be calculated and the result displayed each time in the edit box in the gui
for(UINT uCount = 0; uCount < 40; uCount++){
pCalculateMgr->rand() *m_Slider.GetPos();//?don't allowed to touch the gui!!
PostMessage(pCalculateMgr-> m_hWnd, WM_SENDCALCULATED_VALUE,wparam(rand() *m_Slider.GetPos(),0);
}
}
LRESULT CStartCalculationDlg::OnSendCalculatedValue(WPARAM Result, LPARAM)
{
// The resut should be displayed in the edit box
m_Calculation.Format(_T("%d"),???);
SetDlgItemText(IDC_CALCULATION, m_Calculation);
return 1;
}
void CStartCalculationDlg::OnHScroll(UINT nSBCode, UINT nPos,CScrollBar* pScrollBar)
{
m_SliderValue.Format(_T("%d"),m_Slider.GetPos());
SetDlgItemText(IDC_SLIDER_VALUE,m_SliderValue);
}
// Implementation in the CStartCalculationDlg.h
CWorkerThreadMgr m_WorkerThreadMgr //instance of the WorkerThreadMgr
CSliderCtrl m_Slider //member variable of the slider control
CString m_SliderValue // member variable of the edit box, where the current value of the
//slider will be displayed
CString m_Calculation // member variable of the edit box where the calculated
//result from the workerthread will be displayed via PostMessage
afx_msg LRESULT OnSendCalculatedValue(WPARAM, LPARAM);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
次probemは...、私はのPostMessageを使用する必要がありますが、私がやっている計算は、制御要素を意味するので、私はこの問題を解決する方法がわからない、その時に私のスライダコントロールを新しい値を取得すると、スレッドプロシージャはそれを認識し、スライダの値を更新する必要があります。どうすればそれをすることができますか?
スライダの位置をパラメータとしてスレッドに渡すことはできますか? – Jeeva