#define WM_MYSTRING  WM_USER+102afx_msg LRESULT myFunc(WPARAM wParam, LPARAM lParam);ON_MESSAGE(WM_MYSTRING, myFunc)CString str;
str = "abxcdfsa";
SendMessage(WM_MYSTRING, 0, (LPARAM)(&str))
LRESULT myFunc(WPARAM wParam, LPARAM lParam)
{
   CString *pStr;
   pStr = (CString*)lParam;}编译:error C2352: 'CWnd::SendMessageA' : illegal call of non-static member function先拜各位大人~~~~~~~~~

解决方案 »

  1.   

    应该是在静态函数中你调用了SendMessage,静态函数中不能调用非全局的非静态函数!
      

  2.   

    楼上说的有道理,建议把
    调用SendMessage的函数的声明中的static关键字去掉。看不出有什么必要。
      

  3.   

    我快疯了。
    如何在静态函数中把参数传出去??
    在类中定义的线程,不用static,该如何操作??
    static UINT ThreadA(LPVOID pParam);
      

  4.   

    CString str;
    str = "abxcdfsa";
    SendMessage(WM_MYSTRING, 0, (LPARAM)(&str))我不知道你的错误出自何处但是以上语句即使编译没错,结果也是不对的str是局部变量,退出函数好,里面的内容就改变了
    所以myFunc()里不能得出正确结果
      

  5.   

    SendMessage()
    改为::SendMessage()
    他有四个参数,第一个参数是窗口句柄,将MyFunc()所在类的窗口句柄给他就行了
    试一试
    应该有效
      

  6.   

    是不是我表达的不清楚?
    主要意思:
       如何在线程中把参数传递到窗口,我的线程定义为static.感谢楼上的,我接着试。
      

  7.   

    这样的问题啊,我的解决办法是,在启动线程时,把窗口的指针作为参数传给线程。
    发消息时,使用:
    pWnd->SendMessage();
    pWnd就是作为参数传进来的窗口指针,这样就没有任何问题了。
      

  8.   

    // CConnectorDlg dialog
    class CConnectorDlg : public CDialog
    {
    // Construction
    public:
    CConnectorDlg(CWnd* pParent = NULL); // standard constructor
    ~CConnectorDlg(void);// Dialog Data
    enum { IDD = IDD_CONNECTOR_DIALOG };
    protected:
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    // Implementation
    protected:
    // Generated message map functions
    virtual BOOL OnInitDialog();
    DECLARE_MESSAGE_MAP()
    public:
    HANDLE m_hConnectionControlThread;
    DWORD m_dwConnectionControlThreadId;
    HANDLE m_hConnectionControlIndicator[3]; /* 0:Connect Indicator; 1:Disconnect Indicator; 2:Exit indicator */
    static DWORD WINAPI ConnectionControlThreadEntry(LPVOID lpParameter);
    };BOOL CConnectorDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hMainIconBig, TRUE); // Set big icon
    SetIcon(m_hMainIconSmall, FALSE); // Set small icon // TODO: Add extra initialization here m_hConnectionControlIndicator[0] = CreateEvent(NULL, FALSE, FALSE, NULL);
    m_hConnectionControlIndicator[1] = CreateEvent(NULL, FALSE, FALSE, NULL);
    m_hConnectionControlIndicator[2] = CreateEvent(NULL, FALSE, FALSE, NULL);
    m_hConnectionControlThread = CreateThread(NULL, 0, ConnectionControlThreadEntry, this, 0, &m_dwConnectionControlThreadId); return TRUE;  // return TRUE  unless you set the focus to a control
    }DWORD WINAPI CConnectorDlg::ConnectionControlThreadEntry(LPVOID lpParameter)
    {
    CConnectorDlg * pConnectorDlg = (CConnectorDlg*)lpParameter; while(TRUE)
    {
    DWORD dwWaitResult = WaitForMultipleObjects(3, pConnectorDlg->m_hConnectionControlIndicator, FALSE, INFINITE); switch (dwWaitResult - WAIT_OBJECT_0)
    {
    case 0:
    if (TRUE == DoConnect(pConnectorDlg))
    {
    ::PostMessage(pConnectorDlg->m_hWnd, UM_CONNECT_SUCCESS, 0, 0);
    }
    else
    {
    ::PostMessage(pConnectorDlg->m_hWnd, UM_CONNECT_FAILURE, 0, 0);
    }
    break;
    case 1:
    if (TRUE == DoDisconnect(pConnectorDlg))
    {
    ::PostMessage(pConnectorDlg->m_hWnd, UM_DISCONNECT_SUCCESS, 0, 0);
    }
    else
    {
    ::PostMessage(pConnectorDlg->m_hWnd, UM_DISCONNECT_FAILURE, 0, 0);
    }
    break;
    case 2:
    ExitThread(0);
    break;
    }
    } return 0;
    }