allstar Posted September 9, 2004 Posted September 9, 2004 I've been searching the forum and I've cobbled together the following code: Imports Microsoft.Win32 Imports System Public Class Form1 Inherits System.Windows.Forms.Form Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoA" _ (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As String, ByVal fuWinIni As Long) As Long Private Const SPI_SETDESKWALLPAPER As Integer = 20 Private Const SPIF_UPDATEINIFILE As Integer = &H1 #Region " Windows Form Designer generated code " #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SystemParametersInfo _(SPI_SETDESKWALLPAPER,0, "C:\boxes_1024.bmp", SPIF_UPDATEINIFILE) End Sub End Class But it doesn't seem to do anything, can anyone tell me why? Quote
Administrators PlausiblyDamp Posted September 9, 2004 Administrators Posted September 9, 2004 You probably need to change the longs to integers with .Net and IIRC you also need to set the final parameter to SPIF_SENDCHANGE. Try the following - it should work. Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, ByVal lpvParam As String, ByVal fuWinIni As Integer) As Long Private Const SPI_SETDESKWALLPAPER As Integer = 20 Private Const SPIF_SENDCHANGE As Integer = &H2 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "C:\windows\Coffee Bean.bmp", SPIF_SENDCHANGE) End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
allstar Posted September 9, 2004 Author Posted September 9, 2004 Thats great that fixed it straight away. Thanks. I have another question though... If I wanted to change the desktop wallpaper to a web page for example, so it would have to be an active desktop, how could I go about it? Thats my ultimate goal, what I posted above is the first thing I have found that approaches what I want to do. Quote
allstar Posted September 10, 2004 Author Posted September 10, 2004 does anyone have a pointer in the right direction perhaps? Quote
Administrators PlausiblyDamp Posted September 10, 2004 Administrators Posted September 10, 2004 These may be worth a look http://www.xtremedotnettalk.com/showthread.php?t=86674&highlight=IActiveDesktop http://www.xtremedotnettalk.com/showthread.php?t=86675&highlight=IActiveDesktop Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
allstar Posted September 10, 2004 Author Posted September 10, 2004 Yeah, I've tried that, but the code he gives doesn't allow me to put an html page as the desktop background. Just jpgs and bmps. I'll try playing with the code though. Quote
Leaders dynamic_sysop Posted September 10, 2004 Leaders Posted September 10, 2004 you would first need to create a bitmap / some sort of image of the html page , then you can use the above mentioned methods of setting as desktop background. here's an example i built a long time ago ( been digging through my cd archives ) it's based on the screenshot application i did in C++ to capture the mouse but thats another story . the form ( Form1 ) ... [color=Green]/// in a Form with 2 buttons ...[/color] [color=Gray]/// <summary> ///[/color] [color=Green]the code to use the class ( in this case it's button clicks in Form1 )[/color] [color=Gray] /// </summary>[/color] private void button1_Click(object sender, System.EventArgs e) { Process.Start("IEXPLORE.EXE" , textBox1.Text ); /// textBox1.Text contains a valid url to snapshot. button1.Enabled = false; } private void button2_Click(object sender, System.EventArgs e) { this.Visible=false; while(this.Visible) { Application.DoEvents(); } System.Threading.Thread.Sleep(75); /// give the form chance to hide. _win32 bmpShot = new _win32(); /// the snapshot takes place upon creating this class. bmpShot.bmp.Save( @"C:\imgWeb.bmp" ); /// in this case i save the image as a bitmap to the C drive. button1.Enabled = true; this.Visible=true; } the class that takes the html screen and makes an image of it... [color=Gray]/// <summary> ///[/color] [color=Green]the class that performs the snapshot of your html page.[/color] [color=Gray]/// </summary>[/color] [color=Blue]public class[/color] _win32 { [color=Blue]#region[/color] " Api Calls " [color=Blue]private const int[/color] SRCCOPY = 0xCC0020; [DllImport("gdi32.dll")] [color=Blue]private static extern[/color] IntPtr BitBlt (IntPtr hDestDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop); [DllImport("gdi32.dll")] [color=Blue]private static extern[/color] IntPtr CreateCompatibleBitmap (IntPtr hdc, int nWidth, int nHeight); [DllImport("gdi32.dll")] [color=Blue]private static extern[/color] IntPtr CreateCompatibleDC (IntPtr hdc); [DllImport("gdi32.dll")] [color=Blue]private static extern[/color] IntPtr DeleteDC (IntPtr hdc); [DllImport("gdi32.dll")] [color=Blue]private static extern[/color] IntPtr DeleteObject (IntPtr hObject); [DllImport("user32.dll")] [color=Blue]private static extern[/color] IntPtr GetDC (IntPtr hwnd); [DllImport("user32.dll")] [color=Blue]private static extern int[/color] GetWindowRect (IntPtr hwnd, ref Rectangle lpRect); [DllImport("user32.dll")] [color=Blue]private static extern[/color] IntPtr ReleaseDC (IntPtr hwnd, IntPtr hdc); [DllImport("gdi32.dll")] [color=Blue]private static extern[/color] IntPtr SelectObject (IntPtr hdc, IntPtr hObject); [DllImport("user32.dll", EntryPoint="FindWindowA")] [color=Blue]private static extern[/color] IntPtr FindWindow (string lpClassName, string lpWindowName); [DllImport("user32.dll", EntryPoint="FindWindowExA")] [color=Blue]private static extern[/color] IntPtr FindWindowEx (IntPtr hWnd1,IntPtr hWnd2, string lpsz1, string lpsz2); [color=Blue]#endregion[/color] [color=Blue]public[/color] Rectangle clientRect=new Rectangle(); [color=Blue]public[/color] Bitmap bmp; [color=Blue]public[/color] _win32() { IntPtr val = this.WebHandle(); if(val!=IntPtr.Zero) { this.dcHandle( val ); } } [color=Blue]public[/color] IntPtr WebHandle() { IntPtr hwnd = FindWindow( "IEFRAME" , null ); IntPtr hwndSrc = IntPtr.Zero; if(hwnd != IntPtr.Zero) { hwndSrc = FindWindowEx( hwnd , IntPtr.Zero , "Shell DocObject View" , null ); hwndSrc = FindWindowEx( hwndSrc , IntPtr.Zero , "InterNet Explorer_Server" , null ); GetWindowRect( hwndSrc , ref clientRect ); } return hwndSrc; } [color=Blue]public void[/color] dcHandle(IntPtr hHandle) { IntPtr srcHdc = gDc( hHandle ); IntPtr destHdc = CreateCompatibleDC( srcHdc ); IntPtr bmpDc = CreateCompatibleBitmap( srcHdc , clientRect.Width , clientRect.Height - 145 ); CreateImageCanvas( destHdc , srcHdc , bmpDc , clientRect , SRCCOPY ); bmp = bMap( bmpDc ); /// create the bitmap to save. CleanDcs( hHandle , destHdc , srcHdc , bmpDc ); return; } [color=Blue]public[/color] IntPtr gDc(IntPtr hHandle) { return GetDC( hHandle ); } [color=Blue]public void[/color] CreateImageCanvas(IntPtr dest , IntPtr source , IntPtr bDc , Rectangle rct , int dwRop ) { IntPtr objDc = SelectObject( dest , bDc ); BitBlt( dest , 0 , 0 , clientRect.Width , clientRect.Height - 145 , source, 0 , 0 , SRCCOPY ); SelectObject( dest , objDc ); return; } [color=Blue]public[/color] Bitmap bMap(IntPtr b) { return Bitmap.FromHbitmap(b); } [color=Blue]public void[/color] CleanDcs(IntPtr hHandle , IntPtr dest , IntPtr source , IntPtr bDc ) { ReleaseDC( hHandle , source ); DeleteDC( dest ); DeleteObject( bDc ); return; } } hope it helps :) Quote
allstar Posted September 13, 2004 Author Posted September 13, 2004 Thanks dynamic, but that won't help me unfortunately. I have a flash sequence embedded in an html page. At the moment I can make it my desktop background by adding the html page as an active desktop. By doing a right click, properties etc. Basically I want a way to automate this so that I can avoid having to go through all the windows menus. I presume that I should be able to just change the relevent registry settings to get it to work, but I have several problems... mainly that I don't really know what I'm doing. I'm more of a Java programmer than any other language. Work have had me start doing VB .Net but I'm only scratching the surface with that. Obviously my Java experience means I can understand c# pretty well, but again I just don't know enough about the api to be confident to approach this project on my own. Added to this is the fact that I have searched high and low on the Internet for information on how to do this and can't find anything, despite all the googling! I think my next step is going to have to be buying a load of c# books and sitting down with them until I can do it myself! Quote
Recommended Posts