CWnd* pMyParentWnd = GetParent(); if (pMyParentWnd != NULL) { // Do something with the parent window }
CWnd* pParentWnd = pChildWnd->GetParent(); if (pParentWnd != NULL && pParentWnd->SendMessage(WM_MY_MESSAGE, 0, 0)) { // Parent window handled message successfully }In this example, GetParent() is used to retrieve a pointer to the parent of a child window. The SendMessage() function is then called on the parent window, passing a custom message code and two parameters. If the parent window handles the message and returns a non-zero value, further actions are taken in the child window. Overall, the CWnd GetParent function is a useful tool in MFC programming for retrieving and manipulating parent windows.