SendMessage()
-
I am attempting to use SendMessage, and I need to pass a CString as one of the arguements. I can't seem to get this to work.
-
I am attempting to use SendMessage, and I need to pass a CString as one of the arguements. I can't seem to get this to work.
-
Pass string ( TCHAR * ) not CString. CString is an C++ object, and passing it may produce problems.
Wouldn't passing the (LPCTSTR) of the CString be the same thing? Using LPCTSTR I get "cannot convert parameter 2 from 'const char *' to 'unsigned int'" on compile. Using TCHAR I get "cannot convert parameter 2 from 'char [100]' to 'unsigned int'" on compile.
-
Pass string ( TCHAR * ) not CString. CString is an C++ object, and passing it may produce problems.
CString myString
SendMessage(MY_MESSAGE, *myString, 0);
void CMainFrm::OnMyMessage(WPARAM wParam, LPARAM)
{
CString test = wParam;
}This gives me only the first character of the string myString.
-
CString myString
SendMessage(MY_MESSAGE, *myString, 0);
void CMainFrm::OnMyMessage(WPARAM wParam, LPARAM)
{
CString test = wParam;
}This gives me only the first character of the string myString.
Try This put the address of the string in a DWORD and passes as the LPARAM; DWORD pdwAddress =(DWORD)&myString; SendMessage(MY_MESSAGE, 0, pdwAddress); void CMainFrm::OnMyMessage( WPARAM wParam, LPARAM lParam ) { CString s; s = *(CString *)lParam; }
-
Try This put the address of the string in a DWORD and passes as the LPARAM; DWORD pdwAddress =(DWORD)&myString; SendMessage(MY_MESSAGE, 0, pdwAddress); void CMainFrm::OnMyMessage( WPARAM wParam, LPARAM lParam ) { CString s; s = *(CString *)lParam; }
-
Try This put the address of the string in a DWORD and passes as the LPARAM; DWORD pdwAddress =(DWORD)&myString; SendMessage(MY_MESSAGE, 0, pdwAddress); void CMainFrm::OnMyMessage( WPARAM wParam, LPARAM lParam ) { CString s; s = *(CString *)lParam; }
Perfect! It worked great, but I realized that it would better fit my needs to use PostMessage, and now it doesn't work. So what's the difference between the way they are called then, they look awfully similar to me. Thanks John
-
Perfect! It worked great, but I realized that it would better fit my needs to use PostMessage, and now it doesn't work. So what's the difference between the way they are called then, they look awfully similar to me. Thanks John
PostMessage() puts the message in the windows message queue and then returns, no processing of the message is performed before the window's message pump gets to run. With SendMessage() you "forces" the imidiate processing of the message so the message is processed *before* SendMessage() returns. SendMessage() isn't usually a good idea since you can get weird recursive effects if you arn't careful. The most common problem people seem to have with PostMessage() is that they are passing pointers to stack-allocated objects which goes out of scope (are destroyed) before the window procedure gets hold of the pointer... As always, mind your allocations.