Windows/MFC

wallpaper

aucd29 2013. 10. 2. 18:16
void CSetWallpaperDlg::OnSetWallpaper()
{
    TCHAR szWindowsPath[MAX_PATH + 1];
    GetWindowsDirectory(szWindowsPath, MAX_PATH+1);

    CString strWallpaperFile = "\\My_Wallpaper.BMP";
    
    CHAR szBuf[100];

    CString strFile;
    CString strFileName = m_strFilePath;

    strFile = strFileName;
/////////////윈도우 디렉토리에 비트맵 파일 생성 시작///////////////////////////////////////    
    CFile file;

    if(!file.Open(strFile, CFile::modeRead))
        return;
    
    DWORD dwLength = file.GetLength();
    
    void* pBuff = GlobalAlloc(GMEM_FIXED, dwLength);
    file.ReadHuge(pBuff, dwLength);
    
    CFile newfile;

    if(!newfile.Open(szWindowsPath+strWallpaperFile, CFile::modeCreate | CFile::modeWrite))
        return;

    newfile.WriteHuge(pBuff, dwLength);

    file.Close();
    newfile.Close();
////////////윈도우 디렉토리에 비트맵 파일 생성 끝////////////////////////////////////////////

    CString strPath = szWindowsPath+strWallpaperFile;
    strcpy(szBuf, strPath);

    SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (LPSTR)(LPCTSTR)strPath, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}