怎么样改变win2k、xp下的桌面壁纸,要实时的。

zaqizaba 2002-06-07 01:41:48
//---------------------------------------------------------------------------
// 设置墙纸
#include <shlobj.h>
void __stdcall SetWallPaper(AnsiString FileName, int WallpaperStyle) {
// WallpaperStyle:
// 1 -> 居中
// 2 -> 平铺
// 3 -> 拉伸
// 其它 -> 自动,使用系统当前设置
IActiveDesktop* pIADesk = NULL;
HRESULT hr = ::CoCreateInstance(Shlobj::CLSID_ActiveDesktop,
NULL,
CLSCTX_INPROC_SERVER,
IID_IActiveDesktop,
(void**)&pIADesk);
if(SUCCEEDED(hr)) {
WALLPAPEROPT WallpaperOpt;
WallpaperOpt.dwSize = sizeof(WALLPAPEROPT);
switch(WallpaperStyle) {
case 1: {
WallpaperOpt.dwStyle = WPSTYLE_CENTER;
break;
}
case 2: {
WallpaperOpt.dwStyle = WPSTYLE_TILE;
break;
}
case 3: {
WallpaperOpt.dwStyle = WPSTYLE_STRETCH;
break;
}
default: {
pIADesk->GetWallpaperOptions(&WallpaperOpt, 0);
break;
}
}
pIADesk->SetWallpaperOptions(&WallpaperOpt, 0);
pIADesk->SetWallpaper(WideString(FileName), 0);
pIADesk->ApplyChanges(AD_APPLY_ALL|AD_APPLY_FORCE);
pIADesk->Release();
}
else {
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, FileName.c_str(), SPIF_SENDCHANGE);
}
}

结果报错:
[C++ Error] shobjidl.h(2193): E2238 Multiple declaration for 'FOLDERSETTINGS'
[C++ Error] shobjidl.h(8095): E2238 Multiple declaration for 'DESKBANDINFO'
[C++ Error] shlobj.h(1422): E2238 Multiple declaration for 'FVSHOWINFO'
[C++ Error] shlobj.h(3457): E2238 Multiple declaration for 'SHELLFLAGSTATE'

这篇帖子我结的太快了:(
http://www.csdn.net/expert/topic/775/775824.xml?temp=.7685663
...全文
47 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
diabloyj 2002-06-10
  • 打赏
  • 举报
回复
2000 98 都可以
XP现在手头没有
用另外的文件打开对话框就可以了
zaqizaba 2002-06-10
  • 打赏
  • 举报
回复
OpenPictureDialog1不支持jpg格式
怪不的,呵呵
谢了
结帐~
zaqizaba 2002-06-10
  • 打赏
  • 举报
回复
不可以!
看清题目!是jpg格式哦
zaqizaba 2002-06-10
  • 打赏
  • 举报
回复
怎么得到xp下的壁纸路径?
richard_hu 2002-06-08
  • 打赏
  • 举报
回复
SystemParametersInfo的功能强大阿
zaqizaba 2002-06-08
  • 打赏
  • 举报
回复
是在win2k下的jpg也能改?
zaqizaba 2002-06-07
  • 打赏
  • 举报
回复
噢,好好检验,明明是一个问题,现在便宜你了~呵呵
diabloyj 2002-06-07
  • 打赏
  • 举报
回复
实际上是一回事
以上的两个程序编译通过
diabloyj 2002-06-07
  • 打赏
  • 举报
回复
有两种方法。
1如上
2写注册表
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetWallPaper()
{
Graphics::TBitmap *tmpBitmap=new Graphics::TBitmap();
tmpBitmap->Width=Form1->Image1->Width;
tmpBitmap->Height=Form1->Image1->Height;
tmpBitmap->Canvas->StretchDraw(Rect(0,0,tmpBitmap->Width,tmpBitmap->Height),Form1->Image1->Picture->Graphic);
char dir[50];
GetWindowsDirectory(dir,50);
tmpBitmap->SaveToFile(AnsiString(dir)+"\\myWallPaper.bmp");
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0,(AnsiString(dir)+"\\myWallPaper.bmp").c_str(), 0);
delete tmpBitmap;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
SetWallPaper();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(OpenPictureDialog1->Execute())
Edit1->Text = OpenPictureDialog1->FileName;
Image1->Picture->LoadFromFile(Edit1->Text);
}
//---------------------------------------------------------------------------



//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)
{
if (OpenPictureDialog1->Execute())
Edit1->Text = OpenPictureDialog1->FileName;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRegistry *RegEdit= new TRegistry;
try
{
RegEdit->RootKey=HKEY_CURRENT_USER;
RegEdit->OpenKey("Control Panel\\desktop",true);
String PicName = Edit1->Text;
int LayOut = RadioGroup1->ItemIndex;
//0:居中; 1:平辅;2:拉伸;
if( LayOut == 0)
{
RegEdit->WriteString("TileWallpaper",0 );
RegEdit->WriteString("WallpaperStyle",0 );
}
if( LayOut == 1)
{
RegEdit->WriteString("TileWallpaper",1 );
RegEdit->WriteString("WallpaperStyle",0 );
}
if( LayOut == 2)
{
RegEdit->WriteString("TileWallpaper",0 );
RegEdit->WriteString("WallpaperStyle",2 );
}
RegEdit->WriteString("Wallpaper",PicName);
SystemParametersInfo(SPI_SETDESKWALLPAPER,0,NULL,SPIF_SENDCHANGE);
}
__finally
{
RegEdit->CloseKey();
delete RegEdit;
}
}
//---------------------------------------------------------------------------
shally5 2002-06-07
  • 打赏
  • 举报
回复
一个API函数就行啦!
void __fastcall TForm1::Button1Click(TObject *Sender)
{
SystemParametersInfo(

20, // system parameter to query or set
0, // depends on action to be taken
"c:\\temp\\ok1.bmp", // depends on action to be taken
1 // user profile update flag
);
}
freejiang 2002-06-07
  • 打赏
  • 举报
回复
哈哈,我已经编译通过了,不过好像只能使用bmp格式的图片。
书生 2002-06-07
  • 打赏
  • 举报
回复
呵呵,我还正奇怪,好象前天才看见这个帖子的呢。
错误显示都是变量重复声明了,你检查一下其他地方有没有重复声明了该变量。
freejiang 2002-06-07
  • 打赏
  • 举报
回复
shlobj.h这个头文件中包含了很多Shell编程的定义,非常有用。但是在BCB中却有问题,一旦包含这个头文件,则会导致编译出错。解决方法很简单,如下。

在Project menu > Options > Directories/Conditionals里的Conditionals中加入NO_WIN32_LEAN_AND_MEAN 即可。

13,873

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧