Jump to content
Xtreme .Net Talk

i need to send a bitmap to my client and set it as wallpaper how can i do it in c#??


Recommended Posts

Posted

Edit-Just realised you wanted to know how to send it and how to set it. See this thread for sending binary files. http://www.xtremedotnettalk.com/showthread.php?t=93025

 

This is how I do it in Visual Basic, it shouldn't be very dificult to convert.

 

You may also need to delete this file after calling the function.

 

C:\Documents and Settings\**CURRENTUSERNAME**\Local Settings\Application Data\Microsoft\Wallpaper1.bmp

 

 


'CONSTANTS
   Private Const SPI_SETDESKWALLPAPER As Integer = &H14
   Private Const SPIF_UPDATEINIFILE As Integer = &H1
   Private Const SPIF_SENDWININICHANGE As Integer = &H2
   'API Declares
   Private Declare Auto Function SystemParametersInfo Lib "user32.dll" ( _
       ByVal uAction As Integer, ByVal uParam As Integer, _
       ByVal lpvParam As String, ByVal fuWinIni As Integer) As Integer

   Friend Sub SetWallpaper(ByVal img As Image, ByVal PathToImage As String)
       Dim imageLocation As String
       Dim FileName As String

       imageLocation = PathToImage
       Dim tmp = Split(imageLocation, "\")
       FileName = tmp(UBound(tmp))
       Try
           img.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) & FileName, System.Drawing.Imaging.ImageFormat.Bmp)
           SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, imageLocation, _
               SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
       Catch Ex As Exception
           MsgBox("There was an error setting the wallpaper: " & Ex.Message)
       End Try
   End Sub

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...