C++ 生成桌面的问题 20
用IActiveDesktop接口生成桌面,第一次可以成功,第二次之后之前生成为桌面的图片文件无法删除和覆盖。这个是什么问题。BOOLCTDDesktopCalendar...
用IActiveDesktop接口生成桌面,第一次可以成功,第二次之后之前生成为桌面的图片文件无法删除和覆盖。这个是什么问题。
BOOL CTDDesktopCalendar::SetMyWallpaper(CString strPicFile, DWORD dwStyle)
{
IActiveDesktop *pActiveDesktop;
HRESULT hr;
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
COMPONENTSOPT comps;
comps.dwSize = sizeof comps;
comps.fEnableComponents = TRUE;
comps.fActiveDesktop = TRUE;
pActiveDesktop->SetDesktopItemOptions(&comps,0);
//下面是使用固定path的文件的方法
if (FAILED(pActiveDesktop->SetWallpaper(strPicFile,dwStyle)))
return false;
pActiveDesktop->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);
pActiveDesktop->Release();
CoUninitialize();
return TRUE;
}
……
void CTDDesktopCalendar::SaveSelectBmp(void)
{
CDC dcSave;
dcSave.CreateCompatibleDC(NULL);
CBitmap bitmap;
BITMAP bm;
m_bmpScreen.GetObject(sizeof(bm), &bm);
bm.bmWidth = m_size.cx;
bm.bmHeight = m_size.cy;
bitmap.CreateBitmapIndirect(&bm);
CBitmap* pOldBmp = dcSave.SelectObject(&bitmap);
DrawDesktop();
DrawScreenShape(&m_dcMem);
dcSave.StretchBlt(0,0, m_size.cx, m_size.cy,
&m_dcMem,0, 0,m_size.cx, m_size.cy, SRCCOPY);
HBITMAP hBmp = (HBITMAP)bitmap.Detach();
dcSave.SelectObject(pOldBmp);
PBITMAPINFO pbmp;
if(!CTDUtility::CreateBitmapInfoStruct(hBmp, pbmp))
{
return;
}
CTime time;
time=CTime::GetCurrentTime();
CString strTime=time.Format("%H%M%S");
::DeleteFile(_T("\\desktop.bmp"));
CString strBmpFile=CTDUtility::GetModuleFileDir()+_T("desktop.bmp");
if(CTDUtility::CreateBMPFile(strBmpFile.GetBuffer(strBmpFile.GetLength()), pbmp, hBmp, GetDC()->GetSafeHdc()))
{
//AfxMessageBox("Save image file successfully!");
SetMyWallpaper(strBmpFile,WPSTYLE_CENTER);
}
} 展开
BOOL CTDDesktopCalendar::SetMyWallpaper(CString strPicFile, DWORD dwStyle)
{
IActiveDesktop *pActiveDesktop;
HRESULT hr;
CoInitialize(NULL);
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
COMPONENTSOPT comps;
comps.dwSize = sizeof comps;
comps.fEnableComponents = TRUE;
comps.fActiveDesktop = TRUE;
pActiveDesktop->SetDesktopItemOptions(&comps,0);
//下面是使用固定path的文件的方法
if (FAILED(pActiveDesktop->SetWallpaper(strPicFile,dwStyle)))
return false;
pActiveDesktop->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);
pActiveDesktop->Release();
CoUninitialize();
return TRUE;
}
……
void CTDDesktopCalendar::SaveSelectBmp(void)
{
CDC dcSave;
dcSave.CreateCompatibleDC(NULL);
CBitmap bitmap;
BITMAP bm;
m_bmpScreen.GetObject(sizeof(bm), &bm);
bm.bmWidth = m_size.cx;
bm.bmHeight = m_size.cy;
bitmap.CreateBitmapIndirect(&bm);
CBitmap* pOldBmp = dcSave.SelectObject(&bitmap);
DrawDesktop();
DrawScreenShape(&m_dcMem);
dcSave.StretchBlt(0,0, m_size.cx, m_size.cy,
&m_dcMem,0, 0,m_size.cx, m_size.cy, SRCCOPY);
HBITMAP hBmp = (HBITMAP)bitmap.Detach();
dcSave.SelectObject(pOldBmp);
PBITMAPINFO pbmp;
if(!CTDUtility::CreateBitmapInfoStruct(hBmp, pbmp))
{
return;
}
CTime time;
time=CTime::GetCurrentTime();
CString strTime=time.Format("%H%M%S");
::DeleteFile(_T("\\desktop.bmp"));
CString strBmpFile=CTDUtility::GetModuleFileDir()+_T("desktop.bmp");
if(CTDUtility::CreateBMPFile(strBmpFile.GetBuffer(strBmpFile.GetLength()), pbmp, hBmp, GetDC()->GetSafeHdc()))
{
//AfxMessageBox("Save image file successfully!");
SetMyWallpaper(strBmpFile,WPSTYLE_CENTER);
}
} 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询