我的主程序是对话框模式
为了给程序加上自己弄的屏保
新建了generic cwnd类(参考了网上的文章)
类中定义了 static LPCSTR lpszClassName;BOOL CMyScreenWnd::Create()中
if (lpszClassName==NULL) 

lpszClassName=AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, ::LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_NOCURSOR))); 


CreateEx(WS_EX_TOPMOST,lpszClassName,_T(""),WS_VISIBLE | WS_POPUP, 
rect.left,rect.top,rect.right-rect.left,rect.bottom-rect.top, 
GetSafeHwnd(),NULL,NULL); //创建一个全屏窗口 结果编译没问题,连接时候有错误如下:Linking...
MyScreenWnd.obj : error LNK2001: unresolved external symbol "public: static char const * const CMyScreenWnd::lpszClassName" (?lpszClassName@CMyScreenWnd@@2PBDB)
Debug/MyScreenSaver.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.请问是怎么回事

解决方案 »

  1.   

    要在.cpp中写static LPCSTR CMyScreenWnd::lpszClassName;
      

  2.   

    static LPCSTR CMyScreenWnd::lpszClassName;不是在头文件中的申明吗
      

  3.   

    .cpp中的if (lpszClassName==NULL) 

    lpszClassName=AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, ::LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_NOCURSOR))); 
    }函数里怎么写成static LPCSTR CMyScreenWnd::lpszClassName啊
      

  4.   

    你只是申明了,要在类的外面给它赋初值:
    LPCSTR CMyScreenWnd::lpszClassName = NULL;
      

  5.   

    我在cpp文件所有函数的最外面LPCSTR CMyScreenWnd::lpszClassName = NULL;了啊
      

  6.   

    Thank you mynamelj(隐姓埋名,从此绝迹在互联网之上)OK了