我想用一个窗口来接收PCM的消息,所以想从CWnd中继承一个类,这个窗口类的父窗口是现在的主窗口(对话框),我有如下代码:    WNDCLASS wndcls;
    HINSTANCE hInst = AfxGetInstanceHandle();    if (!(::GetClassInfo(hInst, _T("MyClass"), &wndcls)))
    {
        // otherwise we need to register a new class
        wndcls.style            = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
        wndcls.lpfnWndProc      = ::DefWindowProc;
        wndcls.cbClsExtra       = wndcls.cbWndExtra = 0;
        wndcls.hInstance        = hInst;
        wndcls.hIcon            = NULL;
        wndcls.hCursor          = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
        wndcls.hbrBackground    = (HBRUSH) (COLOR_3DFACE + 1);
        wndcls.lpszMenuName     = NULL;
        wndcls.lpszClassName    = _T("MyClass") ;        if (!AfxRegisterClass(&wndcls))
        {
            AfxThrowResourceException();
        }
    }
int a = m_pSouChat->Create(_T("MyClass"),_T(""),WS_OVERLAPPED|WS_VISIBLE,CRect(0,0,100,100),pDlg,1234) ;a的返回值总为0,请问这段代码该放在哪里好??
谢谢了!!

解决方案 »

  1.   

    要用CreateEx
    Create只用于child窗口
      

  2.   

    CWnd::Create  
    virtual BOOL Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
    ResCreates a Windows child window and attaches it to the CWnd object. You construct a child window in two steps. First, call the constructor, which constructs the CWnd object. Then call Create, which creates the Windows child window and attaches it to CWnd. Create initializes the window’s class name and window name and registers values for its style, parent, and ID.
      

  3.   

    CWnd::CreateEx  
    BOOL CreateEx( DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hwndParent, HMENU nIDorHMenu, LPVOID lpParam = NULL );BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, LPVOID lpParam = NULL);
    ResCreates an overlapped, pop-up, or child window with the extended style specified in dwExStyle. The CreateEx parameters specify the WNDCLASS, window title, window style, and (optionally) initial position and size of the window. CreateEx also specifies the window’s parent (if any) and ID. 
      

  4.   

    你要重载CWnd的Create函数,系统有WM_CREATE消息,会调用到你的Create函数,在你的函数最后,用return CWnd::Create(....),就会创建新窗口了!你这样不行的!
      

  5.   

    谢谢楼上的各位兄台,MSDN 我都看过了,代码也试过好几次,但总是不行。 mintwlf(Programmer) :请问该如何重载Create()函数?? 谢谢了!!!
      

  6.   

    你用AppWizard直接添加vitrual function Create,然后响应WM_CREATE消息就行了。
      

  7.   

    你把你要创建的窗口的属性传给Create的那些参数就行啦,通常情况下这样的窗口是要你自己画的,也就是你需要自己重载OnDraw函数,你可以看看MFC源码,应该说是比较痛苦的过程吧!如果没有什么特别大的必要,你还是从已有的MFC控件派生自己的控件,这样会舒服许多。