Chapter 15: Fundamental Controls Visual C++ and MFC Fundamentals
BOOL CClientAreaDlg::OnInitDialog()
{
CDialog::OnInitDialog();SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon// TODO: Add extra initialization hereCWnd* stcLogo = new CWnd;stcLogo->CreateEx(WS_EX_DLGMODALFRAME, "STATIC", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
240, 90, 90, 40, m_hWnd, 0x1888);return TRUE; // return TRUE unless you set the focus to a control
}In the same way, to get a handle to any control of your application, access its m_hWnd
member variable.If you had created a window using the Win32 API’s CreateWindow() or
CreateWindowEx() function, or if for any reason an HWND object exists in your
application, you can convert such a window to a CWnd pointer using the
CWnd::FromHandle() method. Its syntax is:static CWnd* PASCAL FromHandle(HWND hWnd);Here is an example:BOOL CDialog1Dlg::OnInitDialog()
{
CDialog::OnInitDialog();// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon// TODO: Add extra initialization here
HWND ThisWnd;ThisWnd = CreateWindow("EDIT", NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER,
20, 100, 140, 200, m_hWnd, NULL, AfxGetInstanceHandle(), NULL);CWnd *NewWnd;NewWnd->FromHandle(ThisWnd);return TRUE; // return TRUE unless you set the focus to a control
}