#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先拜各位大人~~~~~~~~~
解决方案 »
- 自制的软件调用WINOOWS系统程序“附件”里的“计算器”这一功能,请问这在MFC中是怎样实现的?
- MFC中关于 结束工作线程的棘手问题!
- 收集垃圾代码
- 循环到5000多此出现如下状况
- 如何让ATL控件大小始终与容器窗口客户区大小一致
- 超级难题!!如果在同一太机器上,知道第二个网关是否可以上网?两个网关在同一网段?
- 求解一款韩国软件的时间变换算法(附例子数据供研究)
- 算法求解!给分!!!
- 【求助】困扰了我20小时的小问题,解决了但是想问问原因。(关于编译器不同)
- 如何将一个图标资源存为一个图标文件(.ico)?
- 用ADO已经打开VFP的DBF文件,也正确取到了数据库的表名和字段名,但是执行查询语句的时候就是出错?忘高手帮忙,重谢
- 如何将DWORD类型转换成时间类型?
调用SendMessage的函数的声明中的static关键字去掉。看不出有什么必要。
如何在静态函数中把参数传出去??
在类中定义的线程,不用static,该如何操作??
static UINT ThreadA(LPVOID pParam);
str = "abxcdfsa";
SendMessage(WM_MYSTRING, 0, (LPARAM)(&str))我不知道你的错误出自何处但是以上语句即使编译没错,结果也是不对的str是局部变量,退出函数好,里面的内容就改变了
所以myFunc()里不能得出正确结果
改为::SendMessage()
他有四个参数,第一个参数是窗口句柄,将MyFunc()所在类的窗口句柄给他就行了
试一试
应该有效
主要意思:
如何在线程中把参数传递到窗口,我的线程定义为static.感谢楼上的,我接着试。
发消息时,使用:
pWnd->SendMessage();
pWnd就是作为参数传进来的窗口指针,这样就没有任何问题了。
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;
}