Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: Legacy dll interoperability problem Pin
Adam Plucinski4-Oct-02 0:37
Adam Plucinski4-Oct-02 0:37 
GeneralRe: Legacy dll interoperability problem Pin
Stephane Rodriguez.4-Oct-02 0:46
Stephane Rodriguez.4-Oct-02 0:46 
QuestionArrayList Problem? Pin
Nick Parker3-Oct-02 18:19
protectorNick Parker3-Oct-02 18:19 
AnswerRe: ArrayList Problem? Pin
Stephane Rodriguez.3-Oct-02 18:40
Stephane Rodriguez.3-Oct-02 18:40 
GeneralRe: ArrayList Problem? Pin
David Stone3-Oct-02 18:50
sitebuilderDavid Stone3-Oct-02 18:50 
GeneralRe: ArrayList Problem? Pin
Nick Parker4-Oct-02 13:01
protectorNick Parker4-Oct-02 13:01 
GeneralRe: ArrayList Problem? Pin
Paul Riley4-Oct-02 13:23
Paul Riley4-Oct-02 13:23 
GeneralStill having problems with IActiveDesktop Pin
Wjousts3-Oct-02 16:38
Wjousts3-Oct-02 16:38 
Okay, I think I've almost cracked this one. I got some more help by looking at Carlos Perez's explorer tree control which also uses some interfaces from Shell32. This is what I now have:


using System;
using Microsoft;
using Microsoft.Win32;
using System.Runtime.InteropServices;


namespace ShellTypeLib
{
// Component structure for IActiveDeskTop
[StructLayout(LayoutKind.Sequential)]
struct COMPONENT
{
uint dwSize;
uint dwID;
int iComponentType;
bool fChecked;
bool fDirty;
bool fNoScroll;
COMPPOS cpPos;
char[] wszFriendlyName;
char[] wszSource;
}

[StructLayout(LayoutKind.Sequential)]
struct COMPPOS
{
uint dwSize;
int iLeft;
int iTop;
uint dwWidth;
uint dwHeight;
int izIndex;
bool fCanResize;
bool fCanResizeX;
bool fCanResizeY;
int iPreferredLeftPercent;
int iPreferredTopPercent;
}

[StructLayout(LayoutKind.Sequential)]
struct COMPONENTSOPT
{
uint dwSize;
bool fEnableComponents;
bool fActiveDesktop;
}

[StructLayout(LayoutKind.Sequential)]
struct WALLPAPEROPT
{
uint dwSize;
uint dwStyle;
}


// Declare IActiveDesktop interface
[Guid("F490EB00-1240-11D1-9888-006097DEACF9")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IActiveDesktop
{
[PreserveSig]
uint ApplyChanges(uint dwFlags);

[PreserveSig]
uint GetWallpaper([MarshalAs(UnmanagedType.LPWStr)]out string pwszWallpaper, uint cchWallpaper, uint dwReserved);

[PreserveSig]
uint SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string pwszWallpaper, uint dwReserved);

[PreserveSig]
uint GetWallpaperOptions(ref WALLPAPEROPT pwpo,uint dwReserved);

[PreserveSig]
uint SetWallpaperOptions(ref WALLPAPEROPT pwpo, uint dwReserved);

[PreserveSig]
uint GetPattern([MarshalAs(UnmanagedType.LPWStr)] string pwszPattern, uint cchPattern, uint dwReserved);

[PreserveSig]
uint SetPattern([MarshalAs(UnmanagedType.LPWStr)] string pwszPattern, uint dwReserved);

[PreserveSig]
uint GetDesktopItemOptions(ref COMPONENTSOPT pco, uint dwReserved);

[PreserveSig]
uint SetDesktopItemOptions(ref COMPONENTSOPT pcomp, uint dwReserved);

[PreserveSig]
uint AddDesktopItem(ref COMPONENT pcomp, uint dwReserved);

[PreserveSig]
uint AddDesktopItemWithUI(IntPtr hwnd, ref COMPONENT pcomp, uint dwReserved);

[PreserveSig]
uint ModifyDesktopItem(ref COMPONENT pcomp, uint dwFlags);

[PreserveSig]
uint RemoveDesktopItem(ref COMPONENT pcomp, uint dwReserved);

[PreserveSig]
uint GetDesktopItemCount(out int lpiCount, [MarshalAs(UnmanagedType.U4)]uint dwReserved);

[PreserveSig]
uint GetDesktopItem(int nComponent, ref COMPONENT pcomp, uint dwReserved);

[PreserveSig]
uint GetDesktopItemByID(uint dwID, ref COMPONENT pcomp, uint dwReserved);

[PreserveSig]
uint GenerateDesktopItemHtml([MarshalAs(UnmanagedType.LPWStr)] string pwszFileName, ref COMPONENT pcomp, uint dwReserved);

[PreserveSig]
uint AddUrl(IntPtr hwnd, [MarshalAs(UnmanagedType.LPWStr)] string pszSource, ref COMPONENT pcomp, uint dwFlags);

[PreserveSig]
uint GetDesktopItemBySource([MarshalAs(UnmanagedType.LPWStr)] string pszSource, ref COMPONENT pcomp, uint dwReserved);
}

// Declare ActiveDesktop as a COM coclass
[ComImport, Guid("75048700-EF1F-11D0-9888-006097DEACF9")]
class ActiveDesktop
{

}
}

namespace Wallpaper_test
{
///
/// Summary description for Class1.
///

class Class1
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
System.Console.WriteLine("Windows Wallpaper Tester\n");

ShellTypeLib.ActiveDesktop MyDesktop = new ShellTypeLib.ActiveDesktop();
Type objType = typeof(ShellTypeLib.IActiveDesktop);
System.Console.WriteLine(objType.IsInstanceOfType(MyDesktop));

ShellTypeLib.IActiveDesktop IDesk = (ShellTypeLib.IActiveDesktop) MyDesktop;

uint hresult;

hresult = IDesk.SetWallpaper(@"C:\Documents and Settings\Wjousts\My Documents\My Pictures\Test.jpg",0);
Console.WriteLine("Result from SetWallpaper: " + hresult.ToString("X"));

uint flags = 4;
hresult = IDesk.ApplyChanges(flags);
Console.WriteLine("Result from ApplyChanges: " + hresult.ToString("X"));

int count = 10;
uint reserved = 0;
hresult = IDesk.GetDesktopItemCount(out count,reserved);

System.Console.WriteLine(count);
Console.WriteLine("Result from GetDesktopItemCount: " + hresult.ToString("X"));

}
}
}

So now all three of the IActiveDesktop methods that I call return 0, which is good. Also GetDesktopItemCount is now returning the correct value. SetWallpaper returns zero and if I look at my registry with regedit I can see it has changed the ConvertedWallpaper key, but, and this is a big but, the wallpaper hasn't actually changed! What's more I could have changed that key a lot easier with Registry class in .NET. So I still have the problem of how do I get windows to actually act on the updated registry and CHANGE THE FREAKING WALLPAPER!!! Mad | :mad:
GeneralRe: Still having problems with IActiveDesktop Pin
David Stone3-Oct-02 16:46
sitebuilderDavid Stone3-Oct-02 16:46 
GeneralRe: Still having problems with IActiveDesktop Pin
Wjousts4-Oct-02 1:54
Wjousts4-Oct-02 1:54 
GeneralRe: Still having problems with IActiveDesktop Pin
David Stone4-Oct-02 10:40
sitebuilderDavid Stone4-Oct-02 10:40 
GeneralRe: Still having problems with IActiveDesktop Pin
Stephane Rodriguez.3-Oct-02 18:43
Stephane Rodriguez.3-Oct-02 18:43 
GeneralRe: Still having problems with IActiveDesktop Pin
Nathan Tran5-Mar-03 16:29
Nathan Tran5-Mar-03 16:29 
Questionapi available for this purpose? Pin
imran_rafique3-Oct-02 16:12
imran_rafique3-Oct-02 16:12 
AnswerRe: api available for this purpose? Pin
Furty3-Oct-02 16:22
Furty3-Oct-02 16:22 
GeneralDate Controlled Content -- Basic C# Pin
yakfreek3-Oct-02 13:58
yakfreek3-Oct-02 13:58 
GeneralRe: Date Controlled Content -- Basic C# Pin
Paul Riley3-Oct-02 15:26
Paul Riley3-Oct-02 15:26 
GeneralRe: Date Controlled Content -- Basic C# Pin
4-Oct-02 5:40
suss4-Oct-02 5:40 
GeneralRe: Date Controlled Content -- Basic C# Pin
Paul Riley4-Oct-02 7:30
Paul Riley4-Oct-02 7:30 
Questionwhat can cause DB_E_ABOTLIMITREACHED? Pin
Anonymous3-Oct-02 5:04
Anonymous3-Oct-02 5:04 
AnswerRe: what can cause DB_E_ABOTLIMITREACHED? Pin
leppie3-Oct-02 9:25
leppie3-Oct-02 9:25 
GeneralRe: what can cause DB_E_ABOTLIMITREACHED? Pin
David Stone3-Oct-02 9:58
sitebuilderDavid Stone3-Oct-02 9:58 
GeneralRe: what can cause DB_E_ABOTLIMITREACHED? Pin
Anonymous4-Oct-02 2:45
Anonymous4-Oct-02 2:45 
GeneralRe: what can cause DB_E_ABOTLIMITREACHED? Pin
leppie4-Oct-02 8:04
leppie4-Oct-02 8:04 
AnswerRe: what can cause DB_E_ABOTLIMITREACHED? Pin
James T. Johnson3-Oct-02 9:55
James T. Johnson3-Oct-02 9:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.