David wrote:
hello...
how can i use IActiveDesktop COM interface from shell32.dll?
Hi David,
you can use the IActiveDesktop-Wrapper provided by Mattias Sjögren:
using System;
using System.Runtime. InteropServices ;
enum WPSTYLE
{
CENTER = 0,
TILE = 1,
STRETCH = 2,
MAX = 3
}
struct WALLPAPEROPT
{
public int dwSize;
public WPSTYLE dwStyle;
}
struct COMPONENTSOPT
{
public int dwSize;
[MarshalAs(Unman agedType.Bool)]
public bool fEnableComponen ts;
[MarshalAs(Unman agedType.Bool)]
public bool fActiveDesktop;
}
struct COMPPOS
{
public const int COMPONENT_TOP = 0x3FFFFFFF;
public const int COMPONENT_DEFAU LT_LEFT = 0xFFFF;
public const int COMPONENT_DEFAU LT_TOP = 0xFFFF;
public int dwSize;
public int iLeft;
public int iTop;
public int dwWidth;
public int dwHeight;
public int izIndex;
[MarshalAs(Unman agedType.Bool)]
public bool fCanResize;
[MarshalAs(Unman agedType.Bool)]
public bool fCanResizeX;
[MarshalAs(Unman agedType.Bool)]
public bool fCanResizeY;
public int iPreferredLeftP ercent;
public int iPreferredTopPe rcent;
}
[Flags]
enum ITEMSTATE
{
NORMAL = 0x00000001,
FULLSCREEN = 00000002,
SPLIT = 0x00000004,
VALIDSIZESTATEB ITS =
NORMAL | SPLIT | FULLSCREEN,
VALIDSTATEBITS =
NORMAL | SPLIT | FULLSCREEN |
unchecked((int) 0x80000000) | 0x40000000
}
struct COMPSTATEINFO
{
public int dwSize;
public int iLeft;
public int iTop;
public int dwWidth;
public int dwHeight;
public int dwItemState;
}
enum COMP_TYPE
{
HTMLDOC = 0,
PICTURE = 1,
WEBSITE = 2,
CONTROL = 3,
CFHTML = 4,
MAX = 4
}
[StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Unicode)]
struct COMPONENT
{
private const int INTERNET_MAX_UR L_LENGTH = 2084;
public int dwSize;
public int dwID;
public COMP_TYPE iComponentType;
[MarshalAs(Unman agedType.Bool)]
public bool fChecked;
[MarshalAs(Unman agedType.Bool)]
public bool fDirty;
[MarshalAs(Unman agedType.Bool)]
public bool fNoScroll;
public COMPPOS cpPos;
[MarshalAs(Unman agedType.ByValT Str, SizeConst=260)]
public string wszFriendlyName ;
[MarshalAs(Unman agedType.ByValT Str,SizeConst=I NTERNET_MAX_URL _LENGTH)]
public string wszSource;
[MarshalAs(Unman agedType.ByValT Str,SizeConst=I NTERNET_MAX_URL _LENGTH)]
public string wszSubscribedUR L;
#if AD_IE5
public int dwCurItemState;
public COMPSTATEINFO csiOriginal;
public COMPSTATEINFO csiRestored;
#endif
}
enum DTI_ADTIWUI
{
DTI_ADDUI_DEFAU LT = 0x00000000,
DTI_ADDUI_DISPS UBWIZARD = 0x00000001,
DTI_ADDUI_POSIT IONITEM = 0x00000002,
}
[Flags]
enum AD_APPLY
{
SAVE = 0x00000001,
HTMLGEN = 0x00000002,
REFRESH = 0x00000004,
ALL = SAVE | HTMLGEN | REFRESH,
FORCE = 0x00000008,
BUFFERED_REFRES H = 0x00000010,
DYNAMICREFRESH = 0x00000020
}
[Flags]
enum COMP_ELEM
{
TYPE = 0x00000001,
CHECKED = 0x00000002,
DIRTY = 0x00000004,
NOSCROLL = 0x00000008,
POS_LEFT = 0x00000010,
POS_TOP = 0x00000020,
SIZE_WIDTH = 0x00000040,
SIZE_HEIGHT = 0x00000080,
POS_ZINDEX = 0x00000100,
SOURCE = 0x00000200,
FRIENDLYNAME = 0x00000400,
SUBSCRIBEDURL = 0x00000800,
ORIGINAL_CSI = 0x00001000,
RESTORED_CSI = 0x00002000,
CURITEMSTATE = 0x00004000,
ALL = TYPE | CHECKED | DIRTY | NOSCROLL | POS_LEFT |
SIZE_WIDTH | SIZE_HEIGHT | POS_ZINDEX | SOURCE |
FRIENDLYNAME | POS_TOP | SUBSCRIBEDURL | ORIGINAL_CSI |
RESTORED_CSI | CURITEMSTATE
}
[Flags]
enum ADDURL
{
SILENT = 0x0001
}
[
ComImport(),
Guid("F490EB00-1240-11D1-9888-006097DEACF9"),
InterfaceType(C omInterfaceType .InterfaceIsIUn known)
]
interface IActiveDesktop
{
void ApplyChanges(AD _APPLY dwFlags);
void GetWallpaper([MarshalAs(Unman agedType.LPWStr )]
System.Text.Str ingBuilder pwszWallpaper, int cchWallpaper, int
dwReserved);
void SetWallpaper([MarshalAs(Unman agedType.LPWStr )]
string pwszWallpaper, int dwReserved);
void GetWallpaperOpt ions(ref WALLPAPEROPT pwpo, int dwReserved);
void SetWallpaperOpt ions([In] ref WALLPAPEROPT pwpo, int
dwReserved);
void GetPattern([MarshalAs(Unman agedType.LPWStr )]
System.Text.Str ingBuilder pwszPattern, int cchPattern, int
dwReserved);
void SetPattern([MarshalAs(Unman agedType.LPWStr )] string
pwszPattern, int dwReserved);
void GetDesktopItemO ptions(ref COMPONENTSOPT pco, int dwReserved);
void SetDesktopItemO ptions([In] ref COMPONENTSOPT pco, int
dwReserved);
void AddDesktopItem([In] ref COMPONENT pcomp, int dwReserved);
void AddDesktopItemW ithUI(IntPtr hwnd, [In] ref COMPONENT pcomp,
DTI_ADTIWUI dwFlags);
void ModifyDesktopIt em([In] ref COMPONENT pcomp, COMP_ELEM
dwFlags);
void RemoveDesktopIt em([In] ref COMPONENT pcomp, int dwReserved);
void GetDesktopItemC ount(out int lpiCount, int dwReserved);
void GetDesktopItem( int nComponent, ref COMPONENT pcomp, int
dwReserved);
void GetDesktopItemB yID(IntPtr dwID, ref COMPONENT pcomp, int
dwReserved);
void GenerateDesktop ItemHtml([MarshalAs(Unman agedType.LPWStr )]
string pwszFileName, [In] ref COMPONENT pcomp, int dwReserved);
void AddUrl(IntPtr hwnd, [MarshalAs(Unman agedType.LPWStr )]
string pszSource, [In] ref COMPONENT pcomp, ADDURL dwFlags);
void GetDesktopItemB ySource([MarshalAs(Unman agedType.LPWStr )]
string pwszSource, ref COMPONENT pcomp, int dwReserved);
}
[
ComImport(),
Guid("75048700-EF1F-11D0-9888-006097DEACF9")
]
class ActiveDesktop /* : IActiveDesktop */ {}
Cheers
Arne Janning