我在win2000下有代码:IActiveDesktop* pIAD;  msdn提示IActiveDesktop“Declared in shlobj.h”,可是我无论是否添加#include "shlobj.h"都有出错信息说IActiveDesktop没有定义,这是为什么?

解决方案 »

  1.   

    In order to access Win2000 specific APIs etc, one needs the following #define in the application's stdafx.h (before any other #includes) 
    #define _WIN32_WINNT 0x0500
      

  2.   

    有没有Shell32.dll?
    #include <shlobj.h>
    #include <comdef.h>
      

  3.   

    Step 1:
    Add head files in stdafx.h like this:
    ...
    #include <afxwin.h>        // MFC core and standard components
    #include <afxext.h>        // MFC extensions
    #include "wininet.h"    //you should Add  
    #include <afxdisp.h>        // MFC Automation classes
    #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h> // MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT#include <afxconv.h>      //you should Add  
    ...Step 2:
    #include "Shlobj.h"
    HRESULT hr;
    USES_CONVERSION;
    IActiveDesktop *pActiveDesktop;hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
    IID_IActiveDesktop, (void**)&pActiveDesktop);
    if(hr==S_OK){
    LPCWSTR m_ActiveWallpaper=T2W(m_wallpaper);
    hr=pActiveDesktop->SetWallpaper(m_ActiveWallpaper,NULL);
    if(hr==S_OK)pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
    pActiveDesktop->Release();
    }
      

  4.   

    在StdAfx.中#include <afxwin.h>之前添加如下语句:#include <afx.h>#include <wininet.h> 即可。