RE: How to send user defined Message and Handle it
Hi,
"muktang@gmail.com" wrote:
Hi I am new to VC++ MFC Prog.
I want to know how I can define my own Message and use it
I want to call a function using sendMessage,process this function and
get the result
Specifically
I want to send a CString object to the current dialog's window
the message should be handle by the dialogbox function and entire
string should be converted in UPPERCASE
If you mean a modal dialog, then it's impossible to send messages to
it as a modal dialog has its own message dispatching mechanism...
For a modeless dialog you can do:
// Declare a handler in the window class:
afx_msg LRESULT OnMyHandler(WPARAM wp, LPARAM lp);
// Define it:
LRESULT CModelessDlg::OnMyHandler(WPARAM wp, LPARAM lp)
{
LPTSTR lpsz = (LPTSTR) wp;
::CharUpper(lpsz);
return 0;
}
// Define a user message (likely globally):
const UINT UM_MYMSG = WM_APP + 1;
// Associate the message with the handler in the message map:
ON_MESSAGE(UM_MYMSG, OnMyHandler)
// Now you can use your handler like so:
void CMyView::SomeFunction()
{
CString str;
str = "my string";
// Do not use PostMessage
m_pMyDlg->SendMessage(UM_MYMSG, (UINT)(LPCTSTR)str, 0);
// Now str is in UPPER CASE
}
--
======
Arman