我是新手,请教一个问题:
CWnd wnd;
BOOL b=wnd.CreateEx(WS_POPUP,"CDialog","你好",WS_VISIBLE,100,100,300,300,NULL,IDR_MENU1,NULL);
为什么编译的时候显示WS_POPUP没有定义啊??哪位高手给个例子呀~~

解决方案 »

  1.   

    CreateEx的第一个参数是extended style of the CWnd。WS_POPUP不属于extended style吧?为什么不用Create,而用CreateEx呢
      

  2.   

    CWnd::CreateEx的第二个参数是lpszClassName,看MSDN的解释是:Points to a null-terminated character string that names the Windows class (a WNDCLASS structure). The class name can be any name registered with the global AfxRegisterWndClass function or any of the predefined control-class names. It must not be NULL. 可以看出必须用AfxRegisterWndClass注册窗口类或者是预定义的控件类。而你的程序中使用的是CDialog,这个显然不符合要求.看MSDN中的说明:void CMyDlg::OnCreateExtendedCtrl() 
    {
       CWnd* pWnd = new CStatic;
       pWnd->CreateEx(WS_EX_CLIENTEDGE, // Make a client edge label.
          _T("STATIC"), "Hi",
          WS_CHILD | WS_TABSTOP | WS_VISIBLE,
          5, 5, 30, 30, m_hWnd, (HMENU)1234);
    }^_^
      

  3.   

    BOOL COCWnd::PreCreateWindow(CREATESTRUCT& cs) 
    {
    // TODO: Add your specialized code here and/or call the base class
    // cs.style = WS_BORDER | WS_POPUPWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
    return CWnd::PreCreateWindow(cs);
    }BOOL COCWnd::Create(DWORD dwExStyle, DWORD dwStyle, const RECT& rect, 
    CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
    {
    // Register a class with no cursor
    if (m_lpszClassName == NULL)
    {
         m_lpszClassName = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW);
    }
    // TODO: Add your specialized code here and/or call the base class

    return CreateEx(dwExStyle, m_lpszClassName, _T("显示地籍图"), dwStyle, 
    rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, 
    pParentWnd->GetSafeHwnd(), NULL, NULL);
    }
      

  4.   

    // 打开地籍图窗口
    void WINAPI OpenCadaster(CWnd* pCLEMMWnd, HWND m_hwndMapWindow)
    {
    COCWnd* pOCWnd;
    CRect ChildRect, PRect;
    CString strCommand;

    pCLEMMWnd->GetClientRect(&PRect);
    ChildRect = PRect;
    ChildRect.left = PRect.left+PRect.Width()/2;
    ChildRect.top = PRect.top+50;
    ChildRect.bottom = PRect.bottom/2+50;
    pOCWnd = new COCWnd;
    pOCWnd->m_hMainhWndWindow = m_hwndMapWindow;
    pOCWnd->Create(WS_EX_OVERLAPPEDWINDOW|WS_EX_TOPMOST, WS_VISIBLE|WS_POPUP|WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN, ChildRect, NULL, 0, NULL);
    }
      

  5.   

    我再问一下,就是好多时候我看见应该填写字符串参数的地方,我一般就是写成  "STRING"的形式,好象也没有错误啊,怎么各位大多数时候都是写成_T("STRING")的形式,加一个括号还加一个T??好象MSDN中也是这样写的,哪位能解释一下吗??
      

  6.   

    怎么各位大多数时候都是写成_T("STRING")
    ----------------------
    _T是一个支持UNICODE字符的宏定义,使用了能起到安全的作用
      

  7.   

    程序定义了_UNICODE,那么_T中的就是宽字符(UNICODE)
    否则,就是ANSI字符_UNICODE宏决定了程序中的C、C++标准库函数是否编译成支持UNICODE的样子
    UNICODE宏决定了程序中的windows函数是否编程成支持UNICODE的样子以下是我写的,不是真正的定义,懒的找,呵呵~
    #ifdef _UNICODED
    #define _T(XX) wchar_t XX
    #else
    #define _T(XX) char XX
    #endif