Post Message.
-
I asked this same question for SendMessage HERE once before. However, it appears as though the solution for SendMessage does not work for PostMessage. I want to pass a CString as one of the parameters of PostMessage. How is this done?
-
I asked this same question for SendMessage HERE once before. However, it appears as though the solution for SendMessage does not work for PostMessage. I want to pass a CString as one of the parameters of PostMessage. How is this done?
I want to pass a CString as one of the parameters of PostMessage. How is this done? Well, you can pass a pointer to a CString, however this will work only if the receiver of the message to is in the same process as the sender, otherwise the pointer will be meaningless. You also have to make sure that the CString object exists long enough for the receiver to use it. Since posted messages are handled asynchronously, you'll need to arrange this part yourself. --Mike-- http://home.inreach.com/mdunn/ You are the weakest link, GOODBYE!
-
I asked this same question for SendMessage HERE once before. However, it appears as though the solution for SendMessage does not work for PostMessage. I want to pass a CString as one of the parameters of PostMessage. How is this done?
Assuming the target window is in the same process, you can send a CString via PostMessage like this:
void SendTextToWindow(HWND hwndTarget, UINT uiMessage, LPCSTR lpszText);
{
CString* pText = new CString;
(*pText) = lpszText;::PostMessage(hwndTarget, uiMessage, (WPARAM)pText, 0);
}
Then, in the message handler for uiMessage,
LRESULT OnSomeMessage(WPARAM wParam, LPARAM lParam)
{
CString* pText = (CString*)wParam;
ASSERT(pText);// do something with pText delete pText; return 0;
}
I have used this, but I do not recommend it because there is a potential that the message could not make it to the target window and thus the CString never be destroyed. Also, this only works if the target window is in the same process. Ultimately, if you really need to do this often, I would recommend creating a manager class (something line CStringMessageManager), and have it be responspilble for deleting CString objects created and passed via PostMessage.
-
I asked this same question for SendMessage HERE once before. However, it appears as though the solution for SendMessage does not work for PostMessage. I want to pass a CString as one of the parameters of PostMessage. How is this done?
I went ahead and posted the code I use to deal with this situation. You can find it at http://www.codeproject.com/useritems/sendcstring.asp