Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: BlessCity en 27 Marzo 2016, 23:32 pm



Título: Ayuda por favor;)
Publicado por: BlessCity en 27 Marzo 2016, 23:32 pm
Hola, estoy desarrollando un programa en visual basic..

Pero hay algo que quiero hacer osea..

Cambiar el fondo de la pantalla principal del escritorio por un fondo que yo quiera al momento de dar aceptar



alguien me ayuda?

Gracias..


Título: Re: Ayuda por favor;)
Publicado por: 79137913 en 29 Marzo 2016, 16:37 pm
HOLA!!!

Espero que te sirva...

Forma de siempre:
Código
  1. Private Const SPIF_UPDATEINIFILE = &H1
  2. Private Const SPI_SETDESKWALLPAPER = 20
  3. Private Const SPIF_SENDWININICHANGE = &H2
  4.  
  5. Private Declare Function SystemParametersInfo Lib "user32" Alias _
  6. "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, _
  7. ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
  8.  
  9.  
  10. Public Enum REG_TOPLEVEL_KEYS
  11. HKEY_CLASSES_ROOT = &H80000000
  12. HKEY_CURRENT_CONFIG = &H80000005
  13. HKEY_CURRENT_USER = &H80000001
  14. HKEY_DYN_DATA = &H80000006
  15. HKEY_LOCAL_MACHINE = &H80000002
  16. HKEY_PERFORMANCE_DATA = &H80000004
  17. HKEY_USERS = &H80000003
  18. End Enum
  19.  
  20.  
  21. Private Declare Function RegCreateKey Lib _
  22.   "advapi32.dll" Alias "RegCreateKeyA" _
  23.   (ByVal Hkey As Long, ByVal lpSubKey As _
  24.   String, phkResult As Long) As Long
  25.  
  26. Private Declare Function RegCloseKey Lib _
  27.   "advapi32.dll" (ByVal Hkey As Long) As Long
  28.  
  29. Private Declare Function RegSetValueEx Lib _
  30.   "advapi32.dll" Alias "RegSetValueExA" _
  31.   (ByVal Hkey As Long, ByVal _
  32.   lpValueName As String, ByVal _
  33.   Reserved As Long, ByVal dwType _
  34.   As Long, lpData As Any, ByVal _
  35.   cbData As Long) As Long
  36.  
  37. Private Const REG_SZ = 1
  38.  
  39.  
  40. Public Function ChangeWallPaper(ImageFile As String, Tile As Boolean)
  41.  
  42. 'Pass Full Path of .BMP to this function
  43. 'Returns true if successful, false otherwise
  44. 'If you want to tile, set Tile to True
  45.  
  46. Dim lRet As Long
  47. On Error Resume Next
  48.  
  49. If Tile Then WriteStringToRegistry HKEY_CURRENT_USER, _
  50.  "Control Panel\desktop", "TileWallpaper", "1"
  51.  
  52. lRet = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, ImageFile, _
  53.   SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
  54. ChangeWallPaper = lRet <> 0 And Err.LastDllError = 0
  55. End Function
  56.  
  57. Private Function WriteStringToRegistry(Hkey As _
  58.  REG_TOPLEVEL_KEYS, strPath As String, strValue As String, _
  59.  strdata As String) As Boolean
  60.  
  61.  
  62. Dim bAns As Boolean
  63.  
  64. On Error GoTo ErrorHandler
  65.   Dim keyhand As Long
  66.   Dim r As Long
  67.   r = RegCreateKey(Hkey, strPath, keyhand)
  68.   If r = 0 Then
  69. r = RegSetValueEx(keyhand, strValue, 0, _
  70.   REG_SZ, ByVal strdata, Len(strdata))
  71. r = RegCloseKey(keyhand)
  72. End If
  73.  
  74.   WriteStringToRegistry = (r = 0)
  75.  
  76. Exit Function
  77.  
  78. ErrorHandler:
  79. WriteStringToRegistry = False
  80. Exit Function
  81.  
  82. End Function
  83.  
  84.  
  85.  
  86.  
  87. Private Sub Form_Load()
  88. Dim x, sourcef
  89. sourcef = "c:\tuimagen.bmp" 'PATH DE LA IMAGEN PARA EL FONDO DE PANTALLA
  90. x = ChangeWallPaper(sourcef, False)
  91. Unload Me
  92. End Sub
  93.  

Forma reducida con otro metodo no tan usado:
Código
  1. 'general declaration in the module or change scope to Private if you declare this in the form
  2. Option Explicit
  3.  
  4. Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
  5.                        (ByVal uAction As Long, ByVal uParam As Long, _
  6.                         ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
  7.  
  8. Public Const SPI_SETDESKWALLPAPER = 20
  9. Public Const SPIF_SENDWININICHANGE = &H2
  10. Public Const SPIF_UPDATEINIFILE = &H1
  11.  
  12. 'typical usage
  13. Dim strImagePath As String
  14.  
  15. strImagePath = "c:\tuimagen.bmp"
  16. Call SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, strImagePath, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

GRACIAS POR LEER!!!