Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to update the dialog value inside a thread?(Visual C++)

Status
Not open for further replies.

dperez79

Member level 1
Member level 1
Joined
Feb 10, 2004
Messages
35
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
299
Threads Visual C++

Hi,
I am using several threads in my application, each thread can execute a global or a member function(static).
Now I can set the member variable value executing a function include in the App class. But I can't update the View ( UpdateData() is not possible in any function that belongs the thread).
Could you recommend me some way of update the dialog values inside the thread execution?
Thanks.
 

Re: Threads Visual C++

Perhaps you could use messages

in the dialog thread add the parts to the cpp file:
Code:
// This should be declared somewhere, add only the ON_MESSAGE part!
BEGIN_MESSAGE_MAP(CFacManDlg, CDialog)
  //{{AFX_MSG_MAP(CFacManDlg)
  ON_WM_PAINT()
  //}}AFX_MSG_MAP
  ON_MESSAGE(WM_MY_MESSAGE, OnMyMessage)
END_MESSAGE_MAP()

// implementation of the OnMyMessage method!
LRESULT CMyDlg::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
  // do whatever you want and use the wParam and the lParam if needed

  return 0; // I handled this message
}

In the header file of the dialog thread add the declaration of the method
Code:
protected:
  LRESULT OnMyMessage (WPARAM wParam, LPARAM lParam);
  ...

And create a header file with message ID's
Code:
#ifndef MyMessages_h_
#define MyMessages_h_

#include <windows.h>

#define WM_MY_MESSAGE(WM_USER + 100)

#endif //MyMessages_h_

Now you send messages from another thread like this in case you know your window's handle (hWnd_). :
Code:
SendMessage(hWnd_, WM_MY_MESSAGE, My_wParam, My_lParam);
You can pass the window handle to your thread's class by passing m_hWnd to your constructor from within the BOOL CMyDlg::OnInitDialog() method:
Code:
myThread_ = new myThread(m_hWnd);
Probably you can find other/better solutions for this too. Be creative ;-)
 

Re: Threads Visual C++

One more Way,

If you want to refresh Dlg then pass the Handle of the Window(Dlg) to Thread or keep it global.

Using the Cwnd::Fromhandle() method create the local pointer to dlg and do the update.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top