GetParent( ) 和AfxGetMainWnd( )

The GetParent function retrieves a handle to the specified window's parent or owner.

To retrieve a handle to a specified ancestor, use theGetAncestorfunction.

//该函数返回的是指定子窗口的父窗口的句柄,其中,参数hWnd为子窗口的句柄

Syntax

HWND GetParent(      

    HWND hWnd );

Parameters

hWnd[in] Handle to the window whose parent window handle is to be retrieved.  

举个例子来说:你在对话框中添加了一个Edit的控件,通过GetDlgItem( int ID)你能获得该控件的句柄,如果你想获得该对话框的句柄,就能以GetParent( GetDlgItem(ID))来实现,也就是说,获得的是子窗口所在的父窗口的句柄。

原文地址:https://www.cnblogs.com/CBDoctor/p/2520249.html