ocx:定义一个firework(short a)事件,定义一个线程,定义一个函数
如果在函数中调用firework正常影应,使用线程会就调不出来了。请问大家怎么改呢?
DWORD WINAPI MSG(LPVOID para)
{
CTest2Ctrl *ctr = (CTest2Ctrl*)para;
ctr->tt();
return 1;
}
int CTest2Ctrl::tt()
{
int a = 0;
int b = 1;
int c = a +b;
SendMessage((WM_USER+1),FireRes,c,0); //此处应该怎么写呢?
//FireRes(c);   //在线程函数直接调会出问题。在一般函数中正常
return c;
}

解决方案 »

  1.   

    SyntaxLRESULT SendMessage(          HWND hWnd,
        UINT Msg,
        WPARAM wParam,
        LPARAM lParam
    );
    ParametershWnd
    [in] 
    Handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST, the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.Microsoft Windows Vista and later. Message sending is subject to User Interface Privilege Isolation (UIPI). The thread of a process can send messages only to message queues of threads in processes of lesser or equal integrity level.Msg
    [in] Specifies the message to be sent.
    wParam
    [in] Specifies additional message-specific information.
    lParam
    [in] Specifies additional message-specific information.
    你看清楚SendMessage的参数,第一个是句柄,第二个是消息ID即WM_USER+1,后面两个是需要传递的数据,可以为NULL
      

  2.   

    这个倒没错,他是调用的CTest2Ctrl::SendMessage
      

  3.   

    到底怎么改就可以呢?郁闷啊。只看到网上说多线程调用事件,不能直接调。要用sendMessage。我那fireRes事件是void 型、参数是short 
      

  4.   

    线程中的函数:
    #define WM_SETSLIDERPOS WM_USER+10int CTest2Ctrl::tt()
    {
    int a = 0;
    int b = 1;
    int c = a +b;
    AfxMessageBox("tt");
    SendMessage(WM_SETSLIDERPOS,0,0); AfxMessageBox("tt5");
    return c;
    }
    BEGIN_MESSAGE_MAP(CTest2Ctrl, COleControl)
    //{{AFX_MSG_MAP(CTest2Ctrl)
    // NOTE - ClassWizard will add and remove message map entries// DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG_MAP
    ON_MESSAGE(WM_SETSLIDERPOS, OnSetSliderPos) //对应关系 ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)END_MESSAGE_MAP()
    LRESULT CTest2Ctrl::OnSetSliderPos( WPARAM wparam, LPARAM lParam )
    {
    AfxMessageBox("fdafdzjb");
    return 0;
    } .h中定义
    // Message maps
    //{{AFX_MSG(CTest2Ctrl)
    // NOTE - ClassWizard will add and remove member functions here.
    // DO NOT EDIT what you see in these blocks of generated code !
    afx_msg LRESULT OnSetSliderPos( WPARAM wparam, LPARAM lParam ); //}}AFX_MSGDECLARE_MESSAGE_MAP()