http://www.codeproject.com/KB/dialog/messagehandling.aspx
Sending Messages:
Besides receiving messages, you will often find your self sending messages. You might want to send messages to communicate between to windows in your program, or to communicate between different programs. In order to send a message you need a pointer to a c++ window class. This can be retrieved using various functions, including CWnd::FindWindow, GetDlgItem(), GetParent(), and more. The CWnd class has a SendMessage() member function which allows you to send messages to it's window. For example, Let’s say you have a CWnd pointer to the Calculator, and you want to close it. What you should do is send a WM_CLOSE message, which will notify the Calculator that it should close. You can use the following code. In order to get a pointer to Calculator, I use the static CWnd::FindWindow() function and pass the title of the window, which in our case is "Calculator".
CWnd* pCalc;
pCalc = CWnd::FindWindow(NULL, _T("Calculator"));
if (pCalc == NULL)
{
}
else
{
pCalc->SendMessage(WM_CLOSE);
}
Sending Messages:
Besides receiving messages, you will often find your self sending messages. You might want to send messages to communicate between to windows in your program, or to communicate between different programs. In order to send a message you need a pointer to a c++ window class. This can be retrieved using various functions, including CWnd::FindWindow, GetDlgItem(), GetParent(), and more. The CWnd class has a SendMessage() member function which allows you to send messages to it's window. For example, Let’s say you have a CWnd pointer to the Calculator, and you want to close it. What you should do is send a WM_CLOSE message, which will notify the Calculator that it should close. You can use the following code. In order to get a pointer to Calculator, I use the static CWnd::FindWindow() function and pass the title of the window, which in our case is "Calculator".
CWnd* pCalc;
pCalc = CWnd::FindWindow(NULL, _T("Calculator"));
if (pCalc == NULL)
{
}
else
{
pCalc->SendMessage(WM_CLOSE);
}
'Windows > MFC' 카테고리의 다른 글
CXMLFile - A Simple C++ XML Parser (0) | 2013.10.02 |
---|---|
클라이언트 프로그램에서 Global IME를 구현하는 방법 (0) | 2013.10.02 |
Context Menu Drawing (컨텍스트 메뉴에 그리기) (0) | 2013.10.02 |
scroll bar 처리.. (0) | 2013.10.02 |
스크롤바-기초05 (0) | 2013.10.02 |