Aplikasi ini digunakan untuk mensetting background desktop. Logika jalannya aplikasi:
- Mendapatkan alamat wallpaper yang dipilih, kemudian di wallpaper tersebut disalin ke folder Windows dengan nama file Background.bmp
- Kemudian path wallpaper yang di folder windows, dimasukan ke dalam registry.
HKEY_CURRENT_USER\Control Panel\Desktop
- Setelah komputer dinyalakan. Buka aplikasi VBnya, bila belum ada aplikasi VBnya silakan diinstall terlebih dahulu. Kemudian pilih standard.exe. Kemudian design interfacenya terlebih dulu di form1, seperti di bawah ini.
- setelah itu atur propertinya, biar lebih mudah ikuti properti dibawah ini.
Object | Properties | Value |
Form1 | BorderStyle Caption MinButton | 1 – Fixed Single Set Wallpaper True |
Drive1 | - | - |
Dir1 | - | - |
File1 | Pattern | *.bmp;*.jpg;*.jpeg;*.gif |
Image1 | BorderStyle Stretch | 1 – Fixed Single True |
Label1 | Caption | Set Position Wallpaper |
OptionButton1 | Caption | Tile |
OptionButton2 | Caption | Center |
Command1 | Name Caption | cmdApply Apply |
- setelah properti diatur semua. kemudian masukan coding di bawah ini di form1.
‘<—salin dari sini (Begin)—>
Option ExplicitDim FileDipilihPrivate Sub cmdApply_Click()On Error Resume Next‘Save gambar yang dipilih ke WindowsSavePicture Image1.Picture, GetWindowsPath & “Background.bmp”‘Panggil sub ubahUbahEnd SubPrivate Sub Drive1_Change()‘Memilih DriveDir1.Path = Drive1.DriveEnd SubPrivate Sub Dir1_Change()‘Mengaitkan daftar file dengan daftar directoryFile1.Path = Dir1.PathEnd SubPrivate Sub File1_Click()‘Klik File1, tampilkan gambarClsFileDipilih = File1.Path & “/” & File1.FileNameImage1.Picture = LoadPicture(FileDipilih)End SubPrivate Sub Ubah()‘Perintah ubah wallpaper (Setting di Registry)Dim rtn As LongDim KeyName As StringDim Nilai As StringDim hKey As LongDim KeyValueLength As LongIf Tile.Value = True ThenNilai = 1ElseNilai = 0End IfKeyName = “desktop\TileWallpaper”KeyValueLength = Len(Nilai) + 1rtn = RegOpenKey(HKEY_CURRENT_USER, “Control Panel\desktop”, hKey)rtn = RegSetValueEx(hKey, “TileWallpaper”, 0, REG_SZ, Nilai, KeyValueLength)rtn = RegCloseKey(hKey)rtn = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, _“Background.bmp”,SPIF_UPDATEINIFILE Or _SPIF_SENDWININICHANGE)End Sub‘<—sampai sini (End)—>
- setelah coding di atas dicopy di form1. Kemudian buat satu module. caranya, klik project di menubar, pilih add module.
- setelah module dibuat. Kemudian masukan coding di bawah ini. di module1.
‘<—salin dari sini (Begin)—>
‘—Api code yang dibutuhkan—Public Declare Function GetWindowsDirectory Lib “kernel32.dll” Alias _“GetWindowsDirectoryA” (ByVal lpBuffer As String, ByVal nSize As Long) _As LongDeclare Function SystemParametersInfo& Lib “user32″ Alias _“SystemParametersInfoA” (ByVal uAction&, ByVal uParam&, ByVal lpvParam _As Any, ByVal fuWinIni&)Declare Function RegCloseKey Lib “advapi32.dll” (ByVal hKey As Long) As LongDeclare Function RegCreateKey Lib “advapi32.dll” Alias “RegCreateKeyA” _(ByVal hKey As Long, ByVal ipSubKey As String, phkResult As Long) As LongDeclare Function RegOpenKey Lib “advapi32.dll” Alias “RegOpenKeyA” _(ByVal hKey As Long, ByVal ipSubKey As String, phkResult As Long) As LongDeclare Function RegQueryValue Lib “advapi32.dll” Alias “RegQueryValueA” _(ByVal hKey As Long, ByVal ipSubKey As String, ByVal ipValue As String, _ipcbValue As Long) As LongDeclare Function RegSetValueEx Lib “advapi32.dll” Alias “RegSetValueExA” _(ByVal hKey As Long, ByVal ipValueName As String, ByVal Reserved As Long, _ByVal dwType As Long, ByVal ipData As String, ByVal cbData As Long) As LongPublic Const REG_SZ = 1Public Const HKEY_CURRENT_USER = &H80000001Public Const SPIF_UPDATEINIFILE = &H1Public Const SPI_SETDESKWALLPAPER = 20Public Const SPIF_SENDWININICHANGE = &H2‘—Dapatkan path Windows—Public Function GetWindowsPath() As StringOn Error Resume NextDim Buffer As String * 255Dim x As Longx = GetWindowsDirectory(Buffer, 255)GetWindowsPath = Left(Buffer, x) & “\”End Function‘<—sampai sini(End)—>
- Setelah diketik semua codingnya di form1 dan di module1 yang diatas, Silakan jalankan project untuk mengetahui hasilnya.
- Pilih drive melalui DriveListBox,
- Pilih directory melalui DirListBox,
- Pilih file gambar yang berformat *.bmp melalui FileListBox,
- Pilih posisi gambar (Tile atau Center),
- Klik tombol Apply.
Catatan:Anda dapat memodifikasi sendiri codingnya atau tampilan form1 sesuai dengan kreatif masing-masing. (—Selamat Mencoba—)
Tidak ada komentar:
Posting Komentar