1。如何知道程序运行时的系统是否使用了ActiveDesktop?2。在使用了ActiveDesktop时,又如何设置墙纸?#include <wininet.h>
#include <shlobj.h>HRESULT hr;
CoInitialize(NULL);
IActiveDesktop *pActiveDesktop; //编译不通过,IActiveDesktop 不能识别hr = CoCreateInstance(CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pActiveDesktop);if(pActiveDesktop->SetWallpaper(L"wallpaper.bmp",0)!=S_OK)
return;
pActiveDesktop->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);pActiveDesktop->Release();
CoUninitialize();请高手指点,多谢了
#include <shlobj.h>HRESULT hr;
CoInitialize(NULL);
IActiveDesktop *pActiveDesktop; //编译不通过,IActiveDesktop 不能识别hr = CoCreateInstance(CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pActiveDesktop);if(pActiveDesktop->SetWallpaper(L"wallpaper.bmp",0)!=S_OK)
return;
pActiveDesktop->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);pActiveDesktop->Release();
CoUninitialize();请高手指点,多谢了
可以设置墙纸。
CComQIPtr<IActiveDesktop> pIActiveDesktop;如果要更详细的资料,msdn上有个例子testad,你可以去下载来看看.
地址http://msdn.microsoft.com/msdnmag/issues/01/05/code/CQA0105.exe
// MSDN Magazine -- May 2001
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual C++ 6.0. Runs on Win 98 and probably Win 2000 too.
//
#pragma once#include <atlbase.h> // ATL smart pointers
#include <shlguid.h> // shell GUIDs
#include <shlobj.h> // IActiveDesktop//////////////////
// Handy class to enable/disable Active Desktop. This class wraps only the
// IActiveDesktop functions needed to enable/disable and get the enabled
// status. You could improve it to encapsulate all of IActiveDesktop.
//
class CActiveDesktop {
protected:
// ATL smart pointers are the only way to go!!
CComQIPtr<IActiveDesktop> m_pIActiveDesktop;public:
HRESULT m_hr; // most recent return code // ctor: create IActiveDesktop interface instance
//
CActiveDesktop() {
m_hr = m_pIActiveDesktop.CoCreateInstance(CLSID_ActiveDesktop,
NULL, CLSCTX_INPROC_SERVER);
// If this bombs, you probably forgot to call call CoInitialize
ASSERT(SUCCEEDED(m_hr));
} // Determine if Active Desktop is enabled. SHGetSettings is apparently
// more reliable than IActiveDesktop::GetDesktopItemOptions, which can
// report incorrectly during the middle of ApplyChanges!
//
BOOL IsEnabled() {
SHELLFLAGSTATE shfs;
SHGetSettings(&shfs, SSF_DESKTOPHTML);
return shfs.fDesktopHTML;
}
// Enable/disable Active Desktop.
// Calls ApplyChanges to make it really happen.
//
void Enable(BOOL bEnable) {
ASSERT(m_pIActiveDesktop);
COMPONENTSOPT opt;
opt.dwSize = sizeof(opt);
opt.fActiveDesktop = opt.fEnableComponents = bEnable;
m_hr = m_pIActiveDesktop->SetDesktopItemOptions(&opt,0);
ASSERT(SUCCEEDED(m_hr));
ApplyChanges(AD_APPLY_REFRESH); // do it!
} // Apply the changes
//
void ApplyChanges(DWORD dwFlags) {
ASSERT(m_pIActiveDesktop);
m_hr = m_pIActiveDesktop->ApplyChanges(dwFlags);
ASSERT(SUCCEEDED(m_hr));
};
};
CComQIPtr<IActiveDesktop> m_pIActiveDesktop; //IActiveDesktop不能被识别