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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "jpeg.hpp"
#include <registry.hpp>
#include "USpi.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
void __fastcall DefinirFondDecran ();
TForm1 *Form1;
String Addr="Winlog.jpg";
TRegistry *registre = new TRegistry();
AnsiString __fastcall GetUser();
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CentrerClick(TObject *Sender)
{
registre->WriteString("TileWallpaper", 0);
registre->WriteString("WallpaperStyle", 1); // 1=center 2=strech
DefinirFondDecran () ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TitleClick(TObject *Sender)
{
registre->WriteString("TileWallpaper", 1);
DefinirFondDecran () ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EtirerClick(TObject *Sender)
{
registre->WriteString("TileWallpaper", 0);
registre->WriteString("WallpaperStyle", 2);
DefinirFondDecran () ;
}
//---------------------------------------------------------------------------
void __fastcall DefinirFondDecran ()
{
//etablir comme fond decran
SystemParametersInfo( SPI_SETDESKWALLPAPER,Addr.Length(),Addr.c_str(),WM_SETTINGCHANGE);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//afficher limage au demarage
TJPEGImage *jp = new TJPEGImage();
jp->LoadFromFile(Addr);
Image1->Picture->Bitmap->Assign(jp);
//place le pointer sur le regristre pour changer laspect du fond decran
registre->RootKey = HKEY_CURRENT_USER ;
registre->OpenKey("\\Control Panel\\Desktop", true);
//converti jpg to bmp et la sauvegader
using Graphics::TBitmap;
Graphics::TBitmap* bmp;
TJPEGImage *jpg = new TJPEGImage();
bmp = new Graphics::TBitmap ();
jpg->LoadFromFile (Addr);
bmp->Assign(jpg);
bmp->SaveToFile (Addr.SetLength(Addr.Length() -3)+="bmp");
delete bmp;
delete jpg;
//copier le bmtp dans windows
String AddrWin="C:\\Documents and Settings\\"+GetUser()+"\\Local Settings\\Application Data\\Microsoft\\";
DeleteFile(AddrWin+"Wallpaper1.bmp");
CopyFile(Addr.c_str(),(AddrWin+"Wallpaper1.bmp").c_str(), true);
}
//---------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
registre->CloseKey(); //fermer le regristre
delete registre;
DeleteFile(Addr.SetLength(Addr.Length() -3)+="bmp"); // effacer limage bmp quon na cree au depart de laplication
}
//---------------------------------------------------------------------------
AnsiString __fastcall GetUser()
{
AnsiString user("");
DWORD t_user(256);
char *name_user=new char[t_user];
if( GetUserName(name_user, &t_user) )
{
user=AnsiString(name_user);
}
delete[] name_user;
return user;
} |
Partager