CWnd :: CreateControl function completed successfully, but m_hWnd is NULL

I run the code with VC ++ 6.0, everything is in order. But when you run the same code in Visual C ++ 2010, the wnd descriptor (namely m_hWnd ) is always NULL. In addition, the return value of bRet is TRUE (i.e., Success).

Here is my code:

 BOOL CDemoDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application 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 CRect rect; GetClientRect(rect); CWnd wnd; BOOL bRet = wnd.CreateControl(_T("WMPlayer.OCX"), NULL, WS_VISIBLE, rect, this, 19089); return TRUE; // return TRUE unless you set the focus to a control } 
+4
source share
1 answer

The wnd object goes out of scope - try to make it a member and check what happens next. Also, if you try to assign a different handle to your m_hWnd object for your dialog, you make a mistake, since m_hWnd must be valid for your dialog by the time OnInitDialog is called (in response to the Create call), so you should not reassign the window handle member of the dialog box, but rather create a separate element for it. Hope this helps.

0
source

Source: https://habr.com/ru/post/1442263/


All Articles