#region Uxtheme.dll functions
[DllImport("uxtheme.dll")]
static public extern int SetWindowTheme(IntPtr hWnd, StringBuilder AppID, StringBuilder ClassID);
static public void DisableWindowsXPTheme(IntPtr hWnd)
{
// Disable using the Window XP Theme for the Window handle
// passed as a parameter
StringBuilder applicationName = new StringBuilder(" ", 1);
StringBuilder classIDs = new StringBuilder(" " , 1);
WindowsAPI.SetWindowTheme(hWnd, applicationName, classIDs);
}
#endregion
#region Shell32.dll functions
[DllImport("Shell32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SHGetFileInfo(string drivePath, uint fileAttributes,
out SHFILEINFO fileInfo, uint countBytesFileInfo, ShellFileInfoFlags flags);
[DllImport("Shell32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr SHGetFileInfo(IntPtr idl, uint fileAttributes,
out SHFILEINFO fileInfo, uint countBytesFileInfo, ShellFileInfoFlags flags);
[DllImport("Shell32.dll", CharSet=CharSet.Auto)]
public static extern int SHGetSpecialFolderLocation(IntPtr hwndOwner, ShellSpecialFolder folder, out IntPtr idl);
[DllImport("Shell32.dll", CharSet=CharSet.Auto)]
public static extern int SHGetMalloc(out IMalloc alloc);
[DllImport("Shell32.dll", CharSet=CharSet.Auto)]
public static extern int SHGetDesktopFolder(out IShellFolder folder);
[DllImport("Shell32.dll", CharSet=CharSet.Auto)]
public static extern int SHGetPathFromIDList(IntPtr idl, StringBuilder path);
public static void SHFreeMalloc(IntPtr handle)
{
IMalloc alloc = null;
try
{
WindowsAPI.SHGetMalloc(out alloc);
Debug.Assert(alloc != null);
alloc.Free(handle);
// Free allocator itself
IUnknown iUnknown = (IUnknown)alloc;
iUnknown.Release();
}
catch (Exception e)
{
// In case the Garbage collector is trying to free
// this memory from its own thread
Debug.WriteLine(e.Message);
}
}
#endregion
#region Common Controls functions
[DllImport("comctl32.dll")]
public static extern bool InitCommonControlsEx(INITCOMMONCONTROLSEX icc);
[DllImport("comctl32.dll")]
public static extern bool InitCommonControls();
[DllImport("comctl32.dll", EntryPoint="DllGetVersion")]
public extern static int GetCommonControlDLLVersion(ref DLLVERSIONINFO dvi);
[DllImport("comctl32.dll")]
public static extern IntPtr ImageList_Create(int width, int height, uint flags, int count, int grow);
[DllImport("comctl32.dll")]
public static extern bool ImageList_Destroy(IntPtr handle);
[DllImport("comctl32.dll")]
public static extern int ImageList_Add(IntPtr imageHandle, IntPtr hBitmap, IntPtr hMask);
[DllImport("comctl32.dll")]
public static extern bool ImageList_Remove(IntPtr imageHandle, int index);
[DllImport("comctl32.dll")]
public static extern bool ImageList_BeginDrag(IntPtr imageHandle, int imageIndex, int xHotSpot, int yHotSpot);
[DllImport("comctl32.dll")]
public static extern bool ImageList_DragEnter(IntPtr hWndLock, int x, int y);
[DllImport("comctl32.dll")]
public static extern bool ImageList_DragMove(int x, int y);
[DllImport("comctl32.dll")]
public static extern bool ImageList_DragLeave(IntPtr hWndLock);
[DllImport("comctl32.dll")]
public static extern void ImageList_EndDrag();
[DllImport("comctl32.dll")]
public static extern bool ImageList_Draw(IntPtr hImageList, int imageIndex,
IntPtr hDCDest, int x, int y, ImageListDrawFlags flags);
[DllImport("comctl32.dll")]
public static extern int ImageList_DrawEx(IntPtr hImageList, int imageIndex,
IntPtr hDCDest, int x, int y, int dx, int dy,
ImageListDrawColors backColor, ImageListDrawColors foregColor, ImageListDrawFlags flags);
static public bool IsCommonCtrl6()
{
DLLVERSIONINFO dllVersion = new DLLVERSIONINFO();
// We are assummng here that anything greater or equal than 6
// will have the new XP theme drawing enable
dllVersion.cbSize = Marshal.SizeOf(typeof(DLLVERSIONINFO));
WindowsAPI.GetCommonControlDLLVersion(ref dllVersion);
return (dllVersion.dwMajorVersion >= 6);
}
我沒間鍋
不過你可以看看UtilityLibrary的員代碼
裡面有許多例子,我給你貼一部分,希望有所啟發
#region Kernel32.dll functions
[DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
public static extern int GetCurrentThreadId();
[DllImport("kernel32.dll")]
public static extern uint GetDriveType(string rootPathName);
[DllImport("kernel32.dll")]
public static extern int GetVolumeInformation(string drivePath,
StringBuilder volumeNameBuffer,
uint driveNameBufferSize,
out uint serialNumber,
out uint maxFileNameLength,
out uint fileSystemFlags,
StringBuilder systemNameBuffer,
uint systemNameBufferSize);
#endregion
#region Gdi32.dll functions
[DllImport("gdi32.dll")]
static public extern bool StretchBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
IntPtr hDCSrc, int XOriginScr, int YOriginSrc, int WidthScr, int HeightScr, PatBltTypes Rop);
[DllImport("gdi32.dll")]
static public extern IntPtr CreateCompatibleDC(IntPtr hDC);
[DllImport("gdi32.dll")]
static public extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int Width, int Heigth);
[DllImport("gdi32.dll")]
static public extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
[DllImport("gdi32.dll")]
static public extern bool BitBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
IntPtr hDCSrc, int XOriginScr, int YOriginSrc, PatBltTypes flags);
[DllImport("gdi32.dll")]
static public extern IntPtr DeleteDC(IntPtr hDC);
[DllImport("gdi32.dll")]
static public extern bool PatBlt(IntPtr hDC, int XLeft, int YLeft, int Width, int Height, uint Rop);
[DllImport("gdi32.dll")]
static public extern bool DeleteObject(IntPtr hObject);
[DllImport("gdi32.dll")]
static public extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
[DllImport("gdi32.dll")]
static public extern int SetMapMode(IntPtr hDC, int fnMapMode);
[DllImport("gdi32.dll")]
static public extern int GetObjectType(IntPtr handle);
[DllImport("gdi32")]
public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO_FLAT bmi,
int iUsage, ref int ppvBits, IntPtr hSection, int dwOffset);
[DllImport("gdi32")]
public static extern int GetDIBits(IntPtr hDC, IntPtr hbm, int StartScan, int ScanLines, int lpBits, BITMAPINFOHEADER bmi, int usage);
[DllImport("gdi32")]
public static extern int GetDIBits(IntPtr hdc, IntPtr hbm, int StartScan, int ScanLines, int lpBits, ref BITMAPINFO_FLAT bmi, int usage);
[DllImport("gdi32")]
public static extern IntPtr GetPaletteEntries(IntPtr hpal, int iStartIndex, int nEntries, byte[] lppe);
[DllImport("gdi32")]
public static extern IntPtr GetSystemPaletteEntries(IntPtr hdc, int iStartIndex, int nEntries, byte[] lppe);
[DllImport("gdi32")]
public static extern uint SetDCBrushColor(IntPtr hdc, uint crColor);
[DllImport("gdi32")]
public static extern IntPtr CreateSolidBrush(uint crColor);
[DllImport("gdi32")]
public static extern int SetBkMode(IntPtr hDC, BackgroundMode mode);
[DllImport("gdi32")]
public static extern int SetViewportOrgEx(IntPtr hdc, int x, int y, int param);
[DllImport("gdi32")]
public static extern uint SetTextColor(IntPtr hDC, uint colorRef);
[DllImport("gdi32")]
public static extern int SetStretchBltMode(IntPtr hDC, StrechModeFlags StrechMode);
[DllImport("gdi32")]
public static extern uint SetPixel(IntPtr hDC, int x, int y, uint color);
#endregion