zoukankan      html  css  js  c++  java
  • VC++ 设置桌面壁纸

    Windows Shell API提供了接口IActiveDesktop来完成墙纸的设置。

    //IActiveDesktop 接口方法表 (详情参见MSDN)

    AddDesktopItem
    AddDesktopItemWithUI
    AddUrl
    ApplyChange
    GenerateDesktopItemHtml
    GetDesktopItem
    GetDesktopItemByID
    GetDesktopItemBySource
    GetDesktopItemCount
    GetDesktopItemOptions
    GetPattern
    GetWallpaper
    GetWallpaperOptions
    ModifyDesktopItem
    RemoveDesktopItem
    SetDesktopItemOptions
    SetPattern
    SetWallpaper
    SetWallpaperOptions

       C++ Code 
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
     
    BOOL SetWallpaper(CString &strPicFile, DWORD dwStyle)
    {
        HRESULT hr = S_OK;
        IActiveDesktop* pIAD = NULL;
        
        
    //创建接口的实例
        hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**) &pIAD );
        
    if (FAILED(hr))
        {
            
    return FALSE;
        }
        
        
    //将文件名改为宽字符串,这是IActiveDesktop::SetWallpaper的要求
        WCHAR wszWallpaper [MAX_PATH] = {0};
        LPTSTR lpStr = strPicFile.GetBuffer(strPicFile.GetLength() );
        MultiByteToWideChar(CP_ACP, 
    0, lpStr, -1, wszWallpaper, MAX_PATH);
        strPicFile.ReleaseBuffer();
        
        
    //设置墙纸
        hr = pIAD->SetWallpaper(wszWallpaper, 0);
        
    if (FAILED(hr))
        {
            
    return FALSE;
        }
        
        
    //设置墙纸的样式
        WALLPAPEROPT wpo;
        wpo.dwSize = 
    sizeof(wpo);
        wpo.dwStyle = dwStyle;
        hr = pIAD->SetWallpaperOptions(&wpo, 
    0);
        
    if(!SUCCEEDED(hr))
        {
            
    return FALSE;
        } 
        
        
    //应用墙纸的设置
        hr = pIAD->ApplyChanges(AD_APPLY_ALL);
        
    if(!SUCCEEDED(hr))
        {
            
    return FALSE;
        } 
        
        
    //读取墙纸的文件名并打印在debug窗口内
        hr = pIAD->GetWallpaper(wszWallpaper, MAX_PATH, 0);
        CString strFile = wszWallpaper;
        TRACE(strFile); 
        
        
    //释放接口的实例
        pIAD->Release();
        
    return TRUE;
    }

    BOOL EnableActiveDesktop(BOOL bEnable)
    {
        HRESULT hr = S_OK;
        IActiveDesktop* pIAD = 
    NULL;
        
        
    //创建接口的实例
        hr = CoCreateInstance ( CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**) &pIAD );
        
    if(!SUCCEEDED(hr))
        {
            
    return FALSE;
        } 
        
        
    //启用或关闭Active desktop
        COMPONENTSOPT comp;
        comp.dwSize = 
    sizeof(comp);
        comp.fEnableComponents = bEnable;
        comp.fActiveDesktop = bEnable;
        hr = pIAD->SetDesktopItemOptions(&comp, 
    0);
        
    if(!SUCCEEDED(hr))
        {
            
    return FALSE;
        } 
        
        
    //释放接口的实例
        pIAD->Release;
        
    return TRUE;
    }

      Demo下载http://pan.baidu.com/s/1bpjFyNX

  • 相关阅读:
    Django实现自定义template页面并在admin site的app模块中加入自定义跳转链接
    django中将model转换为dict的方法
    django后台显示图片 而不是图片地址
    Django admin 继承user表后密码为明文,继承UserAdmin,重写其方法
    Android API之Telephony.Sms
    com.android.providers.telephony.MmsSmsDatabaseHelper
    在发送信息时应用PendingIntent.FLAG_UPDATE_CURRENT
    Android开发之旅(吴秦)
    Android API之android.content.BroadcastReceiver
    Receiver not registered.
  • 原文地址:https://www.cnblogs.com/MakeView660/p/6922665.html
Copyright © 2011-2022 走看看