threads.. a beginner's agony..

2»

Comments

  • I am just wondering,

    if there is any particular reason, that PostMessage() should be used, but not SendMessage(). In my multi-threaded application, I have always used SendMessage() and check the return value for successfully corresponding function calls. In my knowledge, it is safe to manipulate variables/objects (via function calls) between threads using it. Is it correct?

    J.B.

    : I haven't been following this conversation completely, but I thought I would try to give a suggestion. I have a CFormView which executes a thread every minute. If a certain situation occurs, I update a text box on the CFormView. Here is how I do it.
    :
    : Thread that will post a message to CMainFrame
    : [code]
    : UINT MyThread(LPVOID pParam)
    : {
    : ::PostMessage(AfxGetMainWnd()->m_hWnd, WM_MY_MSG, NULL, pParam);
    : return 0;
    : }
    : [/code]
    :
    :
    : Thread that will post a message to CFormView
    : [code]
    : LRESULT CMainFrame::OnMyMsg(WPARAM wParam, LPARAM lParam)
    : {
    : GetActiveView()->PostMessage(WM_MY_MSG, wParam, lParam);
    : return 0;
    : }
    : [/code]
    :
    : CFormView
    : [code]
    : LRESULT CMyFormView::OnMyMsg(WPARAM wParam, LPARAM lParam)
    : {
    : // Update text box
    : ....
    : ....
    : ....
    : return 0
    : }
    : [/code]
    :
    : I hope this helps. If not, just ignore me.:-)

  • : I am just wondering,
    :
    : if there is any particular reason, that PostMessage() should be used, but not SendMessage(). In my multi-threaded application, I have always used SendMessage() and check the return value for successfully corresponding function calls. In my knowledge, it is safe to manipulate variables/objects (via function calls) between threads using it. Is it correct?
    :
    : J.B.

    [blue]
    check the following article b4 comin to any conclusion..
    http://www.codeproject.com/dialog/messagemgmt.asp
    [/blue]
    [email protected]
    __________________________________________
    [red]greatest thing is to do wot others think you can't..
    [/red]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories