正文

VC动态自定义桌面背景(关键代码)2010-11-14 11:27:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lym51/52016.html

分享到:

// VS2005 //head file #include <wininet.h> #include<shlobj.h>   // define IActiveDesktop* m_pADesktop;   /////////////////////////////////// // init com env HRESULT hr; CoInitialize(NULL); m_pADesktop = NULL; hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&m_pADesktop); if (FAILED(hr)) {          return FALSE; }   CstringArray m_strArr; /// 图片路径 CString strPath; for(int i=0; i<10; ++i) {         strPath.Format(_T("%d.bmp"), i); // 0.bmp, 1.bmp  and so on, for test         m_str.Add(strPath); }   SetTimer(1, 5000, NULL); //每5s更换一次桌布 ////////////////////////////////////////////////////////////   // /// key code   //// HRESULT hr; // for test,在定时器中,间隔指定时间,设置桌布 OnTimer(UINT_PTR nIDEvent) static int index = 0;  if (index >= m_strArr.GetCount())  {   index = 0;   return;  }  hr = m_pADesktop->SetWallpaper(m_strArr.GetAt(index), 0);  if(FAILED(hr)) return;  WALLPAPEROPT wpo;  wpo.dwSize = sizeof(wpo);  wpo.dwStyle = WPSTYLE_STRETCH;  hr = m_pADesktop->SetWallpaperOptions(&wpo, 0);  if (FAILED(hr))  {   return;  }  hr = m_pADesktop->ApplyChanges(AD_APPLY_ALL);  if (FAILED(hr))  {   return;  }  index++; ////////////////////////////////////////////   // clean KillTimer(1);  m_pADesktop->Release();  CoUninitialize(); //////////////////////////////////////////////

阅读(3258) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册