我在程序中使用该函数时,发现一个问题就是该函数返回时,我原来的类的成员变量的值全没有了,变成了不可用的值。
在程序中该函数的调用形式为:
SendMessageTimeout(AfxGetMainWnd()->m_hWnd, WM_MY_MESSAGE, SMTO_NORMAL, (LPARAM)recvtemp, SMTO_BLOCK, 15000, 0);
(该涵数是在另外新建的一个线程里调用的)
搞不明白为什么会这样子! 谢谢!!
在程序中该函数的调用形式为:
SendMessageTimeout(AfxGetMainWnd()->m_hWnd, WM_MY_MESSAGE, SMTO_NORMAL, (LPARAM)recvtemp, SMTO_BLOCK, 15000, 0);
(该涵数是在另外新建的一个线程里调用的)
搞不明白为什么会这样子! 谢谢!!
This function sends a specified message to a window by calling the window procedure for the specified window, with the message as one of the parameters for the window procedure. If a specified window belongs to a different thread, SendMessageTimeout does not return until either the window procedure for that window processes the message or a specified time-out period elapses. If the window receiving the message belongs to the message queue of the current thread, SendMessageTimeout calls the window procedure directly and ignores the time-out value.LRESULT SendMessageTimeout(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam,
UINT fuFlags,
UINT uTimeout,
PDWORD_PTR lpdwResult
);
Parameters
hWnd
[in] Handle to the window to which SendMessageTimeout should send the message and for which SendMessageTimeout should call the window procedure. If the value of this parameter is HWND_BROADCAST, SendMessageTimeout sends the message to all top-level windows running on the operating system, including unavailable or hidden unowned windows. SendMessageTimeout does not return until each window times out. Therefore, the total delay can last up to uTimeout milliseconds times the number of top-level windows.
Msg
[in] Unsigned integer that specifies the message to be sent.
wParam
[in] WPARAM that specifies additional message-specific information.
lParam
[in] LPARAM that specifies additional message-specific information.
fuFlags
[in] Unsigned integer that specifies how to send the message. For Microsoft® Windows® CE, the only valid value is SMTO_NORMAL, which indicates that the calling thread can process other requests while waiting for SendMessageTimeout to return.
uTimeout
[in] Unsigned integer that specifies the duration, in milliseconds, of the time-out period. If you send a broadcast message, each window can use the full time-out period. For example, if you specify a 5 second time-out period and three top-level windows fail to process the message, your total delay can last up to 15 seconds.
lpdwResult
[out] Pointer to a DWORD that receives the result of the message processing. This value depends on the message that you send.
Return Values
A nonzero value indicates success. Zero indicates failure or that SendMessageTimeout timed out. To get extended error information, call GetLastError. If GetLastError returns 0, SendMessageTimeout timed out. If you call SendMessageTimeout with the HWND_BROADCAST handle, the return value does not indicate whether individual windows timed out.
线程是用AfxBeginThread(),运行类方法创建的。
SendMessageTimeout的消息处理函数是在工程中主对话框的类中,所涉及的处理,与该线程所在类的成员变量没有任何关系。3楼:
我会试一下,看行不行。 谢谢!
recvtemp的操作存在溢出。
把个参数信息列出来看看
还有主窗口中对这个消息的处理代码
供大家参考:
在我用客户端发送数据包的时间是发送了两个包(这是一个网络的多线程通讯程序),针对一个Socket数据包连接要建立一个处理子线程,所以在调用了该函数时,因为创建该线程的主线程的消息队列中还有消息(即下一个数据包),所以该函数调用被阻塞,而去处理消息队列中的消息。
简言之,就是因为切换到了不同的线程。