4

VC++ 6.0 でコードを実行しましたが、すべて問題ありません。しかし、Visual C++ 2010 で同じコードを実行すると、wnd(つまりm_hWnd) のハンドルは常に NULL になります。また、戻り値 bRet は TRUE (つまり、成功) です。

これが私のコードです:

BOOL CDemoDlg::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
    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

1 に答える 1

0

wndオブジェクトはスコープ外になります-それをメンバーにして、その後何が起こるかを確認してみてください。また、ダイアログのm_hWndオブジェクトに別のハンドルを割り当てようとしている場合は、間違いを犯しています。これは、OnInitDialogが呼び出されるまでに(Create呼び出しに応答して)m_hWndがダイアログに対して有効であるためです。ダイアログメンバーウィンドウハンドルを再割り当てするのではなく、別のメンバーを作成する必要があります。お役に立てれば。

于 2012-11-09T10:07:54.513 に答える