在 CMainFrame::PreCreateWindow 添加如下代码:WNDCLASS wndcls;
wndcls.cbClsExtra =0;
wndcls.cbWndExtra =0;
wndcls.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_HELP);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=::AfxGetInstanceHandle ();            wndcls.lpfnWndProc=::DefWindowProc ;       
 
wndcls.lpszClassName=TEXT("unhappyless");
wndcls.lpszMenuName=NULL;

wndcls.style=CS_HREDRAW | CS_VREDRAW;
 
RegisterClass(&wndcls); cs.lpszName=TEXT("unhappyless");
在 view 类的PreCreateWindow 中加如下代码:cs.lpszName=TEXT("unhappyless");

解决方案 »

  1.   

    参照MSDN:TN001TN001: Window Class Registration
    This note describes the MFC routines that register the special WNDCLASSes needed by Microsoft Windows. Specific WNDCLASS attributes used by MFC and Windows are discussed.The ProblemThe attributes of a CWnd object, like an HWND in Windows, are stored in two places: the window object and the WNDCLASS. A WNDCLASS is different than a C++ class. The name of the WNDCLASS is passed to general window creation functions such as CWnd::Create and CFrameWnd::Create in the lpszClassName parameter.This WNDCLASS must be registered via one of four means: Implicitly by MFC provided WNDCLASSes
    Implicitly by subclassing a Windows control (or some other control)
    Explicitly by calling the MFC AfxRegisterWndClass or AfxRegisterClass
    Explicitly by calling the Windows routine RegisterClass
      

  2.   

    哦,我不知道你在何处调用的,我单独新建一个MDI,把这些加进去,没有调用,看不出什么效果
      

  3.   


    嘿嘿,你是注册了一个你自己的窗口类,可是呢,你没有用上啊,
    cs.lpszName=TEXT("unhappyless");//这不是类名!是下面:
    cs.lpszClass=TEXT("unhappyless");//lpszClass这个才是类的名字啊,不要看走眼啦,呵呵
      

  4.   

    一般呢,你想想看,注册一个类是比较简单的吧,都是先填充一个结构,再用RegisterClass或者RegisterClassEx去注册,一旦注册后,哪个类名啊,就相当重要了,一旦你类名写不对所做的一切是徒劳的,比如在注册时用一个类名,用CreateWindow创建窗口时却又误用了另一个类名(CreateWindow是个API函数,MFC中已经不常用了)所以有很多初学者问题都是出在这里,为什么老是显示不了窗口啊等这些问题就出来了。所以检查时要切记:类名是不能错的,编译时也不会报错(因为它不知道你想用哪个类名)。
      

  5.   

    cs.lpszName  是什么意思? 和cs.lpszClass 有什么关系没?