Proper way to add item to ListCtrl
-
tell me proper way to add an item to ListCtrl. Here is my code:-
// stdafx.h
#define WM_MYMESSAGE (WM_USER+1)
// MyThread.h
class CMyThread : public CWinThread
{
DECLARE_DYNCREATE(CMyThread)
.
.
.
public:
unsigned int f0ll, f1ll, f2ll, f3ll;
unsigned int f0ul, f1ul, f2ul, f3ul;public:
afx_msg void MyMessageHandler(WPARAM, LPARAM);
// MyThread.cpp
.
.
.
afx_msg void CMyThread::MyMessageHandler(WPARAM, LPARAM)
{
// I have to add an item to ListCtrl here
}
BEGIN_MESSAGE_MAP(CMyThread, CWinThread)
ON_THREAD_MESSAGE(WM_MYMESSAGE, MyMessageHandler)
END_MESSAGE_MAP()
// IPMDlg.cpp
.
.
.
void CIPMDlg::OnBnClickedBrefreshdevices()
{
.
.
.
pRefreshThread = AfxBeginThread(RUNTIME_CLASS(CMyThread));
pRefreshThread->PostThreadMessage(WM_MYMESSAGE, 0, 0);
}Future Lies in Present. Manmohan Bishnoi
-
tell me proper way to add an item to ListCtrl. Here is my code:-
// stdafx.h
#define WM_MYMESSAGE (WM_USER+1)
// MyThread.h
class CMyThread : public CWinThread
{
DECLARE_DYNCREATE(CMyThread)
.
.
.
public:
unsigned int f0ll, f1ll, f2ll, f3ll;
unsigned int f0ul, f1ul, f2ul, f3ul;public:
afx_msg void MyMessageHandler(WPARAM, LPARAM);
// MyThread.cpp
.
.
.
afx_msg void CMyThread::MyMessageHandler(WPARAM, LPARAM)
{
// I have to add an item to ListCtrl here
}
BEGIN_MESSAGE_MAP(CMyThread, CWinThread)
ON_THREAD_MESSAGE(WM_MYMESSAGE, MyMessageHandler)
END_MESSAGE_MAP()
// IPMDlg.cpp
.
.
.
void CIPMDlg::OnBnClickedBrefreshdevices()
{
.
.
.
pRefreshThread = AfxBeginThread(RUNTIME_CLASS(CMyThread));
pRefreshThread->PostThreadMessage(WM_MYMESSAGE, 0, 0);
}Future Lies in Present. Manmohan Bishnoi
If "MyThread" is not the thread that owns the ListCtrl, then you will have problems. You must add items to the ListCtrl only from the thread that created the ListCtrl.
-
If "MyThread" is not the thread that owns the ListCtrl, then you will have problems. You must add items to the ListCtrl only from the thread that created the ListCtrl.
CIPMDlg class created the ListCtrl should I post a message back to the main thread's message pump to add item to ListCtrl
Future Lies in Present. Manmohan Bishnoi
-
CIPMDlg class created the ListCtrl should I post a message back to the main thread's message pump to add item to ListCtrl
Future Lies in Present. Manmohan Bishnoi
Manmohan29 wrote:
should I post a message back to the main thread's message pump to add item to ListCtrl
Yes.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius