为什么在调用SetClassWindow(在CFrame中的一个命令响应中)来改变图标,运行后却显示的图标是个白色的框.而是用SetIcon就可以成功加载?

解决方案 »

  1.   

    不好意思,一时手误,是SetClassLong。
      

  2.   

    SetClassLong函数可以改变程序的图标。在CMainFrame类的OnCreate函数里面添加
    SetClassLong(m_hWnd,GCL_HICON,(LONG)LoadIcon(NULL,IDI_ERROR));
    (IDI_ERROR可以改成你需要的图标去,自己设置)
    或者添加自定义的图标都可以的。或者在CMainFrame的PreCreateWindow函数中添加
    cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,0,0,LoadIcon(NULL,IDI_WARNING));
    一样的可以更改图标
      

  3.   

    我想问的是  为什么在一个命令响应中用SetClassLong改变的图标竟然变成无效的图标,而CWnd::SetIcon函数却可以?这两个函数的实现到底有什么样的区别呢?
      

  4.   

    MSDN上有一个说法,你可以参考下:
    Use the SetClassLong function with care. For example, it is possible to change the background color for a class by using SetClassLong, but this change does not immediately repaint all windows belonging to the class. 
      

  5.   

    我好想记得有个教程里有说到过用SetClassLong改图标的,记得好想是很成功...图标是封装在窗口类中的,感觉SetIcon内部应该也是用SetClassLong实现的吧...子类化都是使用的SetClassLong与SetWindowLong实现的,没见过用其他函数实现的,也许我孤陋寡闻了
      

  6.   

    调用完SetClassLong之后用UpdateWindow更新一下应该就行了。
      

  7.   

    我不知道你的代码是如何写的,刚才我试了一下,能成功啊!
    代码:void CMainFrame::On32771()
    {
    ::SetClassLong(GetSafeHwnd(),GCL_HICON,(LONG)LoadIcon(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON1)));}