在对话框中中建立按钮的函数  void CMy1Dlg::OnBnClickedTest(){
// TODO: 在此添加控件通知处理程序代码
HWND hWnd=GetSafeHwnd();
   CWnd *pWnd=CWnd::FromHandle(hWnd);
   CString strText=_T("");
   strText.Format("pWnd=0x%x\nthis=0x%\n",pWnd,this);
   AfxMessageBox(strText);
}
红字那行编译提示""怎么是与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换"
应该怎么处理呀???

解决方案 »

  1.   


    strText.Format("pWnd=0x%x\nthis=0x%\n",pWnd->m_hWnd,this->m_hWnd);
      

  2.   

    还是提示,
    "d:\我的文档\visual studio 2008\projects\1\1\1dlg.cpp(160) : error C2664: “void ATL::CStringT<BaseType,StringTraits>::Format(const wchar_t *,...)”: 不能将参数 1 从“const char [20]”转换为“const wchar_t *”
    1>        with
    1>        [
    1>            BaseType=wchar_t,
    1>            StringTraits=StrTraitMFC_DLL<wchar_t>
    1>        ]
    1>        与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
    "
      

  3.   

    strText.Format("pWnd=0x%x\nthis=0x%\n",pWnd,this);
    ========
    改成:strText.Format(L"pWnd=0x%x\nthis=0x%\n",pWnd,this);
      

  4.   

    strText.Format(_T("pWnd=0x%x\nthis=0x%\n"),pWnd,this);
      

  5.   

    这样写没有问题,但是调试运行时点击button后会提示debug assertion failed!!!
      

  6.   

    这个和上面的问题没关系,加L是因为工程要求字符用UNICODE,如果不加L或是_T的话,用的是ANSI字符,所以会报错,至于执行期错误,应该是别的地方的问题,你给的代码太少看不清楚。
      

  7.   

    楼主,你的strText.Format(L"pWnd=0x%x\nthis=0x%\n",pWnd,this);红字部分少了一个x,所以会报错。我调试的时候发现的,呵呵
      

  8.   

    strText.Format(_T("pWnd=0x%x\nthis=0x%x\n"),pWnd,this);