Functions.cs
上传用户:nnpulika
上传日期:2013-02-15
资源大小:597k
文件大小:21k
源码类别:

状态条

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4. using System.Text;
  5. using System.Diagnostics;
  6. namespace UtilityLibrary.Win32
  7. {
  8. /// <summary>
  9. /// Windows API Functions
  10. /// </summary>
  11. public class WindowsAPI
  12. {
  13. #region Constructors
  14. // No need to construct this object
  15. private WindowsAPI()
  16. {
  17. }
  18. #endregion
  19. #region Constans values
  20. public const string TOOLBARCLASSNAME = "ToolbarWindow32";
  21. public const string REBARCLASSNAME = "ReBarWindow32";
  22. public const string PROGRESSBARCLASSNAME = "msctls_progress32";
  23. public const string SCROLLBAR = "SCROLLBAR";
  24. #endregion
  25. #region CallBacks
  26. public delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
  27. public delegate int CompareFunc(IntPtr param1, IntPtr param2, IntPtr sortParam);
  28. public delegate int WinProc(IntPtr hWnd, uint message, int wParam, int lParam);
  29. #endregion
  30. #region Kernel32.dll functions
  31. [DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
  32. public static extern int GetCurrentThreadId();
  33. [DllImport("kernel32.dll")]
  34. public static extern uint GetDriveType(string rootPathName);
  35. [DllImport("kernel32.dll")]
  36. public static extern int GetVolumeInformation(string drivePath,
  37. StringBuilder volumeNameBuffer,
  38. uint driveNameBufferSize,
  39. out uint serialNumber,
  40. out uint maxFileNameLength,
  41. out uint fileSystemFlags,
  42. StringBuilder systemNameBuffer,
  43. uint systemNameBufferSize);
  44. #endregion
  45. #region Gdi32.dll functions
  46. [DllImport("gdi32.dll")]
  47. static public extern bool StretchBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
  48. IntPtr hDCSrc,  int XOriginScr, int YOriginSrc, int WidthScr, int HeightScr, PatBltTypes Rop);
  49. [DllImport("gdi32.dll")]
  50. static public extern IntPtr CreateCompatibleDC(IntPtr hDC);
  51. [DllImport("gdi32.dll")]
  52. static public extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int Width, int Heigth);
  53. [DllImport("gdi32.dll")]
  54. static public extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
  55. [DllImport("gdi32.dll")]
  56. static public extern bool BitBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
  57. IntPtr hDCSrc,  int XOriginScr, int YOriginSrc, PatBltTypes flags);
  58. [DllImport("gdi32.dll")]
  59. static public extern IntPtr DeleteDC(IntPtr hDC);
  60. [DllImport("gdi32.dll")]
  61. static public extern bool PatBlt(IntPtr hDC, int XLeft, int YLeft, int Width, int Height, uint Rop);
  62. [DllImport("gdi32.dll")]
  63. static public extern bool DeleteObject(IntPtr hObject);
  64. [DllImport("gdi32.dll")]
  65. static public extern uint GetPixel(IntPtr hDC, int XPos, int YPos);
  66. [DllImport("gdi32.dll")]
  67. static public extern int SetMapMode(IntPtr hDC, int fnMapMode);
  68. [DllImport("gdi32.dll")]
  69. static public extern int GetObjectType(IntPtr handle);
  70. [DllImport("gdi32")]
  71. public static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO_FLAT bmi, 
  72. int iUsage, ref int ppvBits, IntPtr hSection, int dwOffset);
  73. [DllImport("gdi32")]
  74. public static extern int GetDIBits(IntPtr hDC, IntPtr hbm, int StartScan, int ScanLines, int lpBits, BITMAPINFOHEADER bmi, int usage);
  75. [DllImport("gdi32")]
  76. public static extern int GetDIBits(IntPtr hdc, IntPtr hbm, int StartScan, int ScanLines, int lpBits, ref BITMAPINFO_FLAT bmi, int usage);
  77. [DllImport("gdi32")]
  78. public static extern IntPtr GetPaletteEntries(IntPtr hpal, int iStartIndex, int nEntries, byte[] lppe);
  79. [DllImport("gdi32")]
  80. public static extern IntPtr GetSystemPaletteEntries(IntPtr hdc, int iStartIndex, int nEntries, byte[] lppe);
  81. [DllImport("gdi32")]
  82. public static extern uint SetDCBrushColor(IntPtr hdc,  uint crColor);
  83. [DllImport("gdi32")]
  84. public static extern IntPtr CreateSolidBrush(uint crColor);
  85. [DllImport("gdi32")]
  86. public static extern int SetBkMode(IntPtr hDC, BackgroundMode mode);
  87. [DllImport("gdi32")]
  88. public static extern int SetViewportOrgEx(IntPtr hdc,  int x, int y,  int param);
  89. [DllImport("gdi32")]
  90.         public static extern uint SetTextColor(IntPtr hDC, uint colorRef);
  91. [DllImport("gdi32")]
  92. public static extern int SetStretchBltMode(IntPtr hDC, StrechModeFlags StrechMode);
  93. [DllImport("gdi32")]
  94. public static extern uint SetPixel(IntPtr hDC, int x, int y, uint color);
  95. #endregion
  96. #region Uxtheme.dll functions
  97. [DllImport("uxtheme.dll")]
  98. static public extern int SetWindowTheme(IntPtr hWnd, StringBuilder AppID, StringBuilder ClassID);
  99. static public void DisableWindowsXPTheme(IntPtr hWnd)
  100. {
  101. // Disable using the Window XP Theme for the Window handle
  102. // passed as a parameter
  103. StringBuilder applicationName = new StringBuilder(" ", 1); 
  104. StringBuilder classIDs = new StringBuilder(" " , 1); 
  105. WindowsAPI.SetWindowTheme(hWnd, applicationName, classIDs);
  106. }
  107. #endregion
  108. #region User32.dll functions
  109. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  110. static public extern IntPtr GetDC(IntPtr hWnd);
  111. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  112. static public extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
  113. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  114. static public extern IntPtr GetDesktopWindow();
  115. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  116. static public extern bool ShowWindow(IntPtr hWnd, ShowWindowStyles State);
  117. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  118. static public extern bool UpdateWindow(IntPtr hWnd);
  119. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  120. static public extern bool SetForegroundWindow(IntPtr hWnd);
  121. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  122. static public extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int Width, int Height, uint flags);
  123. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  124. static public extern bool OpenClipboard(IntPtr hWndNewOwner);
  125. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  126. static public extern bool CloseClipboard();
  127. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  128. static public extern bool EmptyClipboard();
  129. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  130. static public extern IntPtr SetClipboardData( uint Format, IntPtr hData);
  131. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  132. static public extern bool GetMenuItemRect(IntPtr hWnd, IntPtr hMenu, uint Item, ref RECT rc);
  133. [DllImport("user32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
  134. public static extern IntPtr GetParent(IntPtr hWnd);
  135. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  136. public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
  137. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  138. public static extern int SendMessage(IntPtr hWnd, Msg msg, int wParam, int lParam);
  139. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  140. public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);
  141. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  142. public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref RECT lParam);
  143. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  144. public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref POINT lParam);
  145. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  146. public static extern void SendMessage(IntPtr hWnd, ToolBarMessages msg, int wParam, ref TBBUTTON lParam);
  147. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  148. public static extern void SendMessage(IntPtr hWnd, ToolBarMessages msg, int wParam, ref TBBUTTONINFO lParam);
  149. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  150. public static extern int SendMessage(IntPtr hWnd, RebarMessages msg, int wParam, ref REBARBANDINFO lParam);
  151. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  152. public static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVITEM lParam);
  153. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  154. public static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVINSERTSTRUCT lParam);
  155. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  156. public static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVSORTCB lParam);
  157. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  158. public static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVHITTESTINFO hti);
  159. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  160. public static extern void SendMessage(IntPtr hWnd, ListViewMessages msg, int wParam, ref LVITEM lParam);
  161. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  162. public static extern void SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, ref HDITEM lParam);
  163. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  164. public static extern void SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, ref HD_HITTESTINFO hti);
  165. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  166. public static extern int SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, int lParam);
  167. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  168. public static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
  169. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  170. public static extern IntPtr PostMessage(IntPtr hWnd, Msg msg, int wParam, int lParam);
  171. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  172. public static extern IntPtr SetWindowsHookEx(WindowsHookCodes hookid, HookProc pfnhook, IntPtr hinst, int threadid);
  173. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  174. public static extern bool UnhookWindowsHookEx(IntPtr hhook);
  175. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  176. public static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, IntPtr lparam);
  177. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  178. public static extern IntPtr SetFocus(IntPtr hWnd);
  179. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  180. public extern static int DrawText(IntPtr hdc, string lpString, int nCount, ref RECT lpRect, DrawTextFormatFlags flags);
  181. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  182. public extern static IntPtr SetParent(IntPtr hChild, IntPtr hParent);
  183. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  184. public extern static IntPtr GetDlgItem(IntPtr hDlg, int nControlID);
  185. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  186. public extern static int GetClientRect(IntPtr hWnd, ref RECT rc);
  187. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  188.         public extern static int InvalidateRect(IntPtr hWnd,  ref RECT rc, int bErase);
  189. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  190. public extern static int InvalidateRect(IntPtr hWnd,  IntPtr rc, int bErase);
  191. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  192. public static extern bool WaitMessage();
  193. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  194. public static extern bool PeekMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax, PeekMessageFlags flags);
  195. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  196. public static extern bool GetMessage(ref MSG msg, int hWnd, uint wFilterMin, uint wFilterMax);
  197. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  198. public static extern bool TranslateMessage(ref MSG msg);
  199. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  200. public static extern bool DispatchMessage(ref MSG msg);
  201. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  202. public static extern IntPtr LoadCursor(IntPtr hInstance, CursorType cursor);
  203. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  204. public static extern IntPtr SetCursor(IntPtr hCursor);
  205. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  206. public static extern IntPtr GetFocus();
  207. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  208. public static extern bool ReleaseCapture();
  209. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  210. public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
  211. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  212. public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
  213. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  214. public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize, 
  215. IntPtr hdcSrc, ref POINT pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, UpdateLayeredWindowFlags dwFlags);
  216. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  217. public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
  218. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  219. public static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);
  220. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  221. public static extern bool TrackMouseEvent(ref TRACKMOUSEEVENTS tme);
  222. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  223. public static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
  224. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  225. public static extern ushort GetKeyState(int virtKey);
  226. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  227. public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
  228. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  229. public static extern int GetClassName(IntPtr hWnd,  StringBuilder ClassName, int nMaxCount);
  230. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  231. public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
  232. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  233. public static extern int SetWindowLong(IntPtr hWnd, int nIndex, WinProc winProc);
  234. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  235. public static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hRegion, uint flags);
  236. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  237. public static extern IntPtr GetWindowDC(IntPtr hWnd);
  238. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  239. public static extern int FillRect(IntPtr hDC, ref RECT rect, IntPtr hBrush);
  240. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  241. public static extern int GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT wp);
  242. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  243. public static extern int SetWindowText(IntPtr hWnd, string text);
  244. [DllImport("User32.dll", CharSet=CharSet.Auto)]
  245. public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int maxCount);
  246. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  247. static public extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); 
  248. [DllImport("user32.dll", CharSet=CharSet.Auto)] 
  249. static public extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer); 
  250. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  251. static public extern int ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
  252. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  253. static public extern int GetSystemMetrics(SystemMetricsCodes code);
  254. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  255. static public extern int SetScrollInfo(IntPtr hwnd,  int bar, ref SCROLLINFO si, int fRedraw);
  256. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  257. static public extern int ShowScrollBar(IntPtr hWnd, int bar,  int show);
  258. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  259. static public extern int EnableScrollBar(IntPtr hWnd, uint flags, uint arrows);
  260. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  261. static public extern int BringWindowToTop(IntPtr hWnd);
  262. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  263. static public extern int GetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si);
  264. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  265. static public extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy, 
  266. ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion, ref RECT rcInvalidated, uint flags);
  267. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  268. static public extern bool IsWindow(IntPtr hWnd);
  269. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  270. static public extern int LockWindowUpdate(IntPtr hWnd);
  271. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  272. static public extern bool ValidateRect(IntPtr hWnd, ref RECT rcInvalidated);
  273. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  274. static public extern bool ValidateRect(IntPtr hWnd, IntPtr rc);
  275. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  276. static public extern int GetScrollBarInfo(IntPtr hWnd, SystemObject id, ref SCROLLBARINFO sbi);
  277. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  278. static public extern IntPtr GetWindowLong(IntPtr hWnd, GetWindowLongFlag flag);
  279. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  280. static public extern int SetProp(IntPtr hWnd, IntPtr atom, IntPtr hData);
  281. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  282. static public extern int CallWindowProc(IntPtr hOldProc, IntPtr hWnd, uint message, int wParam, int lParam);
  283. #endregion
  284. #region Shell32.dll functions
  285. [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
  286. public static extern IntPtr SHGetFileInfo(string drivePath, uint fileAttributes, 
  287. out SHFILEINFO fileInfo, uint countBytesFileInfo, ShellFileInfoFlags flags);
  288. [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
  289. public static extern IntPtr SHGetFileInfo(IntPtr idl, uint fileAttributes, 
  290. out SHFILEINFO fileInfo, uint countBytesFileInfo, ShellFileInfoFlags flags);
  291. [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
  292. public static extern int SHGetSpecialFolderLocation(IntPtr hwndOwner, ShellSpecialFolder folder, out IntPtr idl);
  293. [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
  294. public static extern int SHGetMalloc(out IMalloc alloc);
  295. [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
  296. public static extern int SHGetDesktopFolder(out IShellFolder folder);
  297. [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
  298. public static extern int SHGetPathFromIDList(IntPtr idl, StringBuilder path);
  299. public static void SHFreeMalloc(IntPtr handle)
  300. {
  301. IMalloc alloc = null;
  302. try 
  303. {
  304. WindowsAPI.SHGetMalloc(out alloc);
  305. Debug.Assert(alloc != null);
  306. alloc.Free(handle);
  307. // Free allocator itself
  308. IUnknown iUnknown = (IUnknown)alloc;
  309. iUnknown.Release();
  310. }
  311. catch (Exception e)
  312. {
  313. // In case the Garbage collector is trying to free
  314. // this memory from its own thread
  315. Debug.WriteLine(e.Message);
  316. }
  317. }
  318. #endregion
  319. #region Common Controls functions
  320. [DllImport("comctl32.dll")]
  321. public static extern bool InitCommonControlsEx(INITCOMMONCONTROLSEX icc);
  322. [DllImport("comctl32.dll")]
  323. public static extern bool InitCommonControls();
  324. [DllImport("comctl32.dll", EntryPoint="DllGetVersion")]
  325. public extern static int GetCommonControlDLLVersion(ref DLLVERSIONINFO dvi);
  326. [DllImport("comctl32.dll")]
  327. public static extern IntPtr ImageList_Create(int width, int height, uint flags, int count, int grow);
  328. [DllImport("comctl32.dll")]
  329. public static extern bool ImageList_Destroy(IntPtr handle);
  330. [DllImport("comctl32.dll")]
  331. public static extern int ImageList_Add(IntPtr imageHandle, IntPtr hBitmap, IntPtr hMask);
  332. [DllImport("comctl32.dll")]
  333. public static extern bool ImageList_Remove(IntPtr imageHandle, int index);
  334. [DllImport("comctl32.dll")]
  335. public static extern bool ImageList_BeginDrag(IntPtr imageHandle, int imageIndex, int xHotSpot, int yHotSpot);
  336. [DllImport("comctl32.dll")]
  337. public static extern bool ImageList_DragEnter(IntPtr hWndLock, int x, int y);
  338. [DllImport("comctl32.dll")]
  339. public static extern bool ImageList_DragMove(int x, int y);
  340. [DllImport("comctl32.dll")]
  341. public static extern bool ImageList_DragLeave(IntPtr hWndLock);
  342. [DllImport("comctl32.dll")]
  343. public static extern void ImageList_EndDrag();
  344. [DllImport("comctl32.dll")]
  345. public static extern bool ImageList_Draw(IntPtr hImageList, int imageIndex, 
  346. IntPtr hDCDest, int x, int y, ImageListDrawFlags flags);
  347. [DllImport("comctl32.dll")]
  348. public static extern int ImageList_DrawEx(IntPtr hImageList, int imageIndex,
  349. IntPtr hDCDest, int x, int y, int dx, int dy, 
  350. ImageListDrawColors backColor, ImageListDrawColors foregColor, ImageListDrawFlags flags);
  351. static public bool IsCommonCtrl6()
  352. {
  353. DLLVERSIONINFO dllVersion = new DLLVERSIONINFO();
  354. // We are assummng here that anything greater or equal than 6
  355. // will have the new XP theme drawing enable
  356. dllVersion.cbSize = Marshal.SizeOf(typeof(DLLVERSIONINFO));
  357. WindowsAPI.GetCommonControlDLLVersion(ref dllVersion);
  358. return (dllVersion.dwMajorVersion >= 6);
  359. }
  360. #endregion
  361. #region Win32 Macro-Like helpers
  362. public static int X_LPARAM(int lParam)
  363. {
  364. return (lParam & 0xffff);
  365. }
  366.  
  367. public static int Y_LPARAM(int lParam)
  368. {
  369. return (lParam >> 16);
  370. }
  371. public static Point GetPointFromLPARAM(int lParam)
  372. {
  373. return new Point(X_LPARAM(lParam), Y_LPARAM(lParam));
  374. }
  375. public static int LOW_ORDER(int param)
  376. {
  377. return (param & 0xffff);
  378. }
  379. public static int HIGH_ORDER(int param)
  380. {
  381. return (param >> 16);
  382. }
  383. public static uint INDEXTOOVERLAYMASK(uint index)
  384. {
  385. return (index << 8); 
  386. }
  387. public static short HRESULT_CODE(int hr)
  388. {
  389.              return (short)(hr & 0xFFFF);
  390. }
  391. public static bool SUCCEEDED(int status)
  392. {
  393. return (status >= 0);
  394. }
  395. public static bool FAILED(int status)
  396. {
  397. return (status < 0);
  398. }
  399. public static int  MAKEINTRESOURCE(int res)
  400. {
  401. return 0x0000FFFF & res;
  402. }
  403. #endregion
  404. }
  405. }