2 * Copyright (C) 5/11/2002 Carlos Harvey Perez
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject
10 * to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * IN NO EVENT SHALL CARLOS HARVEY PEREZ BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Except as contained in this notice, the name of Carlos Harvey Perez
25 * shall not be used in advertising or otherwise to promote the sale,
26 * use or other dealings in this Software without prior written
27 * authorization from Carlos Harvey Perez.
32 using System.Runtime.InteropServices;
34 using System.Diagnostics;
36 //using UtilityLibrary.WinControls;
38 //namespace UtilityLibrary.Win32
39 namespace System.Windows.Forms{
41 /// Windows API Functions
46 // No need to construct this object
49 #region Constans values
50 internal const string TOOLBARCLASSNAME = "ToolbarWindow32";
51 internal const string REBARCLASSNAME = "ReBarWindow32";
52 internal const string PROGRESSBARCLASSNAME = "msctls_progress32";
53 internal const string SCROLLBAR = "SCROLLBAR";
57 internal delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
58 internal delegate int CompareFunc(IntPtr param1, IntPtr param2, IntPtr sortParam);
59 internal delegate int WinProc(IntPtr hWnd, int message, int wParam, int lParam);
62 #region Kernel32.dll functions
63 [DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
64 internal static extern int GetCurrentThreadId();
65 [DllImport("kernel32.dll")]
66 internal static extern int GetDriveType(string rootPathName);
67 [DllImport("kernel32.dll")]
68 internal static extern int GetVolumeInformation(string drivePath,
69 StringBuilder volumeNameBuffer,
70 int driveNameBufferSize,
72 out int maxFileNameLength,
73 out int fileSystemFlags,
74 StringBuilder systemNameBuffer,
75 int systemNameBufferSize);
76 [DllImport("kernel32.dll")]
77 internal static extern void OutputDebugString(string message);
80 #region Gdi32.dll functions
81 [DllImport("gdi32.dll")]
82 static internal extern bool StretchBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
83 IntPtr hDCSrc, int XOriginScr, int YOriginSrc, int WidthScr, int HeightScr, PatBltTypes Rop);
84 [DllImport("gdi32.dll")]
85 static internal extern IntPtr CreateCompatibleDC(IntPtr hDC);
86 [DllImport("gdi32.dll")]
87 static internal extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int Width, int Heigth);
88 [DllImport("gdi32.dll")]
89 static internal extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
90 [DllImport("gdi32.dll")]
91 static internal extern bool BitBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
92 IntPtr hDCSrc, int XOriginScr, int YOriginSrc, PatBltTypes flags);
93 [DllImport("gdi32.dll")]
94 static internal extern IntPtr DeleteDC(IntPtr hDC);
95 [DllImport("gdi32.dll")]
96 static internal extern bool PatBlt(IntPtr hDC, int XLeft, int YLeft, int Width, int Height, int Rop);
97 [DllImport("gdi32.dll")]
98 static internal extern bool DeleteObject(IntPtr hObject);
99 [DllImport("gdi32.dll")]
100 static internal extern int GetPixel(IntPtr hDC, int XPos, int YPos);
101 [DllImport("gdi32.dll")]
102 static internal extern int SetMapMode(IntPtr hDC, int fnMapMode);
103 [DllImport("gdi32.dll")]
104 static internal extern int GetObjectType(IntPtr handle);
106 internal static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO_FLAT bmi,
107 int iUsage, ref int ppvBits, IntPtr hSection, int dwOffset);
109 internal static extern int GetDIBits(IntPtr hDC, IntPtr hbm, int StartScan, int ScanLines, int lpBits, BITMAPINFOHEADER bmi, int usage);
111 internal static extern int GetDIBits(IntPtr hdc, IntPtr hbm, int StartScan, int ScanLines, int lpBits, ref BITMAPINFO_FLAT bmi, int usage);
113 internal static extern IntPtr GetPaletteEntries(IntPtr hpal, int iStartIndex, int nEntries, byte[] lppe);
115 internal static extern IntPtr GetSystemPaletteEntries(IntPtr hdc, int iStartIndex, int nEntries, byte[] lppe);
117 internal static extern int SetDCBrushColor(IntPtr hdc, int crColor);
119 internal static extern IntPtr CreateSolidBrush(int crColor);
121 internal static extern int SetBkMode(IntPtr hDC, BackgroundMode mode);
123 internal static extern int SetViewportOrgEx(IntPtr hdc, int x, int y, int param);
125 internal static extern int SetTextColor(IntPtr hDC, int colorRef);
127 internal static extern int SetStretchBltMode(IntPtr hDC, StrechModeFlags StrechMode);
129 internal static extern int SetPixel(IntPtr hDC, int x, int y, int color);
131 internal static extern IntPtr CreatePen(PenStyle penStyle, int width, int color);
133 internal static extern int GetClipRgn(IntPtr hDC, ref IntPtr region);
135 internal static extern IntPtr CreateRectRgn(int nLeftRect, int TopRect, int nRightRect, int nBottomRect);
137 internal static extern int GetRgnBox(IntPtr hRegion, ref RECT rc);
140 #region Uxtheme.dll functions
141 [DllImport("uxtheme.dll")]
142 static public extern int SetWindowTheme(IntPtr hWnd, StringBuilder AppID, StringBuilder ClassID);
143 static public void DisableWindowsXPTheme(IntPtr hWnd)
145 // Disable using the Window XP Theme for the Window handle
146 // passed as a parameter
147 StringBuilder applicationName = new StringBuilder(" ", 1);
148 StringBuilder classIDs = new StringBuilder(" " , 1);
149 Win32.SetWindowTheme(hWnd, applicationName, classIDs);
153 #region User32.dll functions
154 [DllImport("user32.dll", CharSet=CharSet.Auto)]
155 static internal extern IntPtr GetDesktopWindow();
156 [DllImport("user32.dll", CharSet=CharSet.Auto)]
157 static internal extern bool ShowWindow(IntPtr hWnd, ShowWindowStyles State);
158 [DllImport("user32.dll", CharSet=CharSet.Auto)]
159 static internal extern bool SetForegroundWindow(IntPtr hWnd);
160 [DllImport("user32.dll", CharSet=CharSet.Auto)]
161 static internal extern bool OpenClipboard(IntPtr hWndNewOwner);
162 [DllImport("user32.dll", CharSet=CharSet.Auto)]
163 static internal extern bool CloseClipboard();
164 [DllImport("user32.dll", CharSet=CharSet.Auto)]
165 static internal extern bool EmptyClipboard();
166 [DllImport("user32.dll", CharSet=CharSet.Auto)]
167 static internal extern IntPtr SetClipboardData( int Format, IntPtr hData);
168 [DllImport("user32.dll", CharSet=CharSet.Auto)]
169 static internal extern bool GetMenuItemRect(IntPtr hWnd, IntPtr hMenu, int Item, ref RECT rc);
170 [DllImport("user32.dll", CharSet=CharSet.Auto)]
171 internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
172 [DllImport("user32.dll", CharSet=CharSet.Auto)]
173 internal static extern int SendMessage(IntPtr hWnd, Msg msg, int wParam, int lParam);
174 [DllImport("user32.dll", CharSet=CharSet.Auto)]
175 internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);
176 [DllImport("user32.dll", CharSet=CharSet.Auto)]
177 internal static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref RECT lParam);
178 [DllImport("user32.dll", CharSet=CharSet.Auto)]
179 internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref POINT lParam);
180 [DllImport("user32.dll", CharSet=CharSet.Auto)]
181 internal static extern void SendMessage(IntPtr hWnd, ToolBarMessages msg, int wParam, ref TBBUTTON lParam);
182 [DllImport("user32.dll", CharSet=CharSet.Auto)]
183 internal static extern void SendMessage(IntPtr hWnd, ToolBarMessages msg, int wParam, ref TBBUTTONINFO lParam);
184 [DllImport("user32.dll", CharSet=CharSet.Auto)]
185 internal static extern int SendMessage(IntPtr hWnd, RebarMessages msg, int wParam, ref REBARBANDINFO lParam);
186 [DllImport("user32.dll", CharSet=CharSet.Auto)]
187 internal static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVITEM lParam);
188 [DllImport("user32.dll", CharSet=CharSet.Auto)]
189 internal static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVINSERTSTRUCT lParam);
190 [DllImport("user32.dll", CharSet=CharSet.Auto)]
191 internal static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVSORTCB lParam);
192 [DllImport("user32.dll", CharSet=CharSet.Auto)]
193 internal static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVHITTESTINFO hti);
194 [DllImport("user32.dll", CharSet=CharSet.Auto)]
195 internal static extern void SendMessage(IntPtr hWnd, ListViewMessages msg, int wParam, ref LVITEM lParam);
196 [DllImport("user32.dll", CharSet=CharSet.Auto)]
197 internal static extern void SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, ref HDITEM lParam);
198 [DllImport("user32.dll", CharSet=CharSet.Auto)]
199 internal static extern void SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, ref HD_HITTESTINFO hti);
200 [DllImport("user32.dll", CharSet=CharSet.Auto)]
201 internal static extern int SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, int lParam);
202 [DllImport("user32.dll", CharSet=CharSet.Auto)]
203 internal static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
204 [DllImport("user32.dll", CharSet=CharSet.Auto)]
205 internal static extern IntPtr PostMessage(IntPtr hWnd, Msg msg, int wParam, int lParam);
206 [DllImport("user32.dll", CharSet=CharSet.Auto)]
207 internal static extern IntPtr SetWindowsHookEx(WindowsHookCodes hookid, HookProc pfnhook, IntPtr hinst, int threadid);
208 [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
209 internal static extern bool UnhookWindowsHookEx(IntPtr hhook);
210 [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
211 internal static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, IntPtr lparam);
212 [DllImport("user32.dll", CharSet=CharSet.Auto)]
213 internal extern static int DrawText(IntPtr hdc, string lpString, int nCount, ref RECT lpRect, DrawTextFormatFlags flags);
214 [DllImport("user32.dll", CharSet=CharSet.Auto)]
215 internal extern static IntPtr GetDlgItem(IntPtr hDlg, int nControlID);
216 [DllImport("user32.dll", CharSet=CharSet.Auto)]
217 internal extern static int InvalidateRect(IntPtr hWnd, ref RECT rc, int bErase);
218 [DllImport("user32.dll", CharSet=CharSet.Auto)]
219 internal extern static int InvalidateRect(IntPtr hWnd, IntPtr rc, int bErase);
220 [DllImport("User32.dll", CharSet=CharSet.Auto)]
221 internal static extern bool WaitMessage();
223 [DllImport("User32.dll", CharSet=CharSet.Auto)]
224 internal static extern bool PeekMessage(ref MESSAGE msg, int hWnd, int wFilterMin, int wFilterMax, PeekMessageFlags flags);
226 [DllImport("User32.dll", CharSet=CharSet.Auto)]
227 internal static extern bool GetMessage(ref MESSAGE msg, int hWnd, int wFilterMin, int wFilterMax);
229 [DllImport("User32.dll", CharSet=CharSet.Auto)]
230 internal static extern bool TranslateMessage(ref MESSAGE msg);
232 [DllImport("User32.dll", CharSet=CharSet.Auto)]
233 internal static extern bool DispatchMessage(ref MESSAGE msg);
235 [DllImport("User32.dll", CharSet=CharSet.Auto)]
236 internal static extern IntPtr LoadCursor(IntPtr hInstance, CursorType cursor);
238 [DllImport("User32.dll", CharSet=CharSet.Auto)]
239 internal static extern IntPtr SetCursor(IntPtr hCursor);
241 [DllImport("User32.dll", CharSet=CharSet.Auto)]
242 internal static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
244 [DllImport("User32.dll", CharSet=CharSet.Auto)]
245 internal static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
247 [DllImport("User32.dll", CharSet=CharSet.Auto)]
248 internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize,
249 IntPtr hdcSrc, ref POINT pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, UpdateLayeredWindowFlags dwFlags);
251 [DllImport("User32.dll", CharSet=CharSet.Auto)]
252 internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);
254 [DllImport("User32.dll", CharSet=CharSet.Auto)]
255 internal static extern bool TrackMouseEvent(ref TRACKMOUSEEVENTS tme);
257 [DllImport("User32.dll", CharSet=CharSet.Auto)]
258 internal static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
260 [DllImport("User32.dll", CharSet=CharSet.Auto)]
261 internal static extern short GetKeyState(int virtKey);
263 [DllImport("User32.dll", CharSet=CharSet.Auto)]
264 internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
266 [DllImport("User32.dll", CharSet=CharSet.Auto)]
267 internal static extern int GetClassName(IntPtr hWnd, StringBuilder ClassName, int nMaxCount);
269 [DllImport("User32.dll", CharSet=CharSet.Auto)]
270 internal static extern int SetWindowLong(IntPtr hWnd, GetWindowLongFlag flag, int dwNewLong);
272 [DllImport("User32.dll", CharSet=CharSet.Auto)]
273 internal static extern int SetWindowLong(IntPtr hWnd, GetWindowLongFlag flag, WinProc winProc);
275 [DllImport("User32.dll", CharSet=CharSet.Auto)]
276 internal static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hRegion, int flags);
278 [DllImport("User32.dll", CharSet=CharSet.Auto)]
279 internal static extern IntPtr GetWindowDC(IntPtr hWnd);
281 [DllImport("User32.dll", CharSet=CharSet.Auto)]
282 internal static extern int FillRect(IntPtr hDC, ref RECT rect, IntPtr hBrush);
284 [DllImport("User32.dll", CharSet=CharSet.Auto)]
285 internal static extern int SetWindowText(IntPtr hWnd, string text);
287 [DllImport("User32.dll", CharSet=CharSet.Auto)]
288 internal static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int maxCount);
290 [DllImport("user32.dll", CharSet=CharSet.Auto)]
291 static internal extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
293 [DllImport("user32.dll", CharSet=CharSet.Auto)]
294 static internal extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
296 [DllImport("user32.dll", CharSet=CharSet.Auto)]
297 static internal extern int ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
299 [DllImport("user32.dll", CharSet=CharSet.Auto)]
300 static internal extern int GetSystemMetrics(SystemMetricsCodes code);
302 [DllImport("user32.dll", CharSet=CharSet.Auto)]
303 static internal extern int SetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si, int fRedraw);
305 [DllImport("user32.dll", CharSet=CharSet.Auto)]
306 static internal extern int ShowScrollBar(IntPtr hWnd, int bar, int show);
308 [DllImport("user32.dll", CharSet=CharSet.Auto)]
309 static internal extern int EnableScrollBar(IntPtr hWnd, int flags, int arrows);
311 [DllImport("user32.dll", CharSet=CharSet.Auto)]
312 static internal extern int BringWindowToTop(IntPtr hWnd);
314 [DllImport("user32.dll", CharSet=CharSet.Auto)]
315 static internal extern int GetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si);
317 [DllImport("user32.dll", CharSet=CharSet.Auto)]
318 static internal extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy,
319 ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion, ref RECT rcInvalidated, int flags);
321 [DllImport("user32.dll", CharSet=CharSet.Auto)]
322 static internal extern bool IsWindow(IntPtr hWnd);
324 [DllImport("user32.dll", CharSet=CharSet.Auto)]
325 static internal extern int LockWindowUpdate(IntPtr hWnd);
327 [DllImport("user32.dll", CharSet=CharSet.Auto)]
328 static internal extern bool ValidateRect(IntPtr hWnd, ref RECT rcInvalidated);
330 [DllImport("user32.dll", CharSet=CharSet.Auto)]
331 static internal extern bool ValidateRect(IntPtr hWnd, IntPtr rc);
333 [DllImport("user32.dll", CharSet=CharSet.Auto)]
334 static internal extern int GetScrollBarInfo(IntPtr hWnd, SystemObject id, ref SCROLLBARINFO sbi);
336 [DllImport("user32.dll", CharSet=CharSet.Auto)]
337 static internal extern IntPtr GetWindowLong(IntPtr hWnd, GetWindowLongFlag flag);
339 [DllImport("user32.dll", CharSet=CharSet.Auto)]
340 static internal extern int SetProp(IntPtr hWnd, IntPtr atom, IntPtr hData);
342 [DllImport("user32.dll", CharSet=CharSet.Auto)]
343 static internal extern int CallWindowProc(IntPtr hOldProc, IntPtr hWnd, int message, int wParam, int lParam);
345 [DllImport("user32.dll", CharSet=CharSet.Auto)]
346 static internal extern int EndMenu();
348 [DllImport("user32.dll", CharSet=CharSet.Auto)]
349 static internal extern int DefWindowProc(IntPtr hWnd, int message, int wParam, int lParam);
353 #region Shell32.dll functions
355 [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
356 internal static extern IntPtr SHGetFileInfo(string drivePath, int fileAttributes,
357 out SHFILEINFO fileInfo, int countBytesFileInfo, ShellFileInfoFlags flags);
359 [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
360 internal static extern IntPtr SHGetFileInfo(IntPtr idl, int fileAttributes,
361 out SHFILEINFO fileInfo, int countBytesFileInfo, ShellFileInfoFlags flags);
363 [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
364 internal static extern int SHGetSpecialFolderLocation(IntPtr hwndOwner, ShellSpecialFolder folder, out IntPtr idl);
366 [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
367 internal static extern int SHGetMalloc(out IMalloc alloc);
369 [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
370 internal static extern int SHGetDesktopFolder(out IShellFolder folder);
372 [DllImport("Shell32.dll", CharSet=CharSet.Auto)]
373 internal static extern int SHGetPathFromIDList(IntPtr idl, StringBuilder path);
375 internal static void SHFreeMalloc(IntPtr handle)
377 IMalloc alloc = null;
380 Win32.SHGetMalloc(out alloc);
381 Debug.Assert(alloc != null);
383 // Free allocator itself
384 IUnknown iUnknown = (IUnknown)alloc;
389 // In case the Garbage collector is trying to free
390 // this memory from its own thread
391 Debug.WriteLine(e.Message);
397 #region Common Controls functions
399 [DllImport("comctl32.dll")]
400 internal static extern bool InitCommonControlsEx(INITCOMMONCONTROLSEX icc);
402 [DllImport("comctl32.dll")]
403 internal static extern bool InitCommonControls();
405 [DllImport("comctl32.dll", EntryPoint="DllGetVersion")]
406 internal extern static int GetCommonControlDLLVersion(ref DLLVERSIONINFO dvi);
408 [DllImport("comctl32.dll")]
409 internal static extern IntPtr ImageList_Create(int width, int height, int flags, int count, int grow);
411 [DllImport("comctl32.dll")]
412 internal static extern bool ImageList_Destroy(IntPtr handle);
414 [DllImport("comctl32.dll")]
415 internal static extern int ImageList_Add(IntPtr imageHandle, IntPtr hBitmap, IntPtr hMask);
417 [DllImport("comctl32.dll")]
418 internal static extern bool ImageList_Remove(IntPtr imageHandle, int index);
420 [DllImport("comctl32.dll")]
421 internal static extern bool ImageList_BeginDrag(IntPtr imageHandle, int imageIndex, int xHotSpot, int yHotSpot);
423 [DllImport("comctl32.dll")]
424 internal static extern bool ImageList_DragEnter(IntPtr hWndLock, int x, int y);
426 [DllImport("comctl32.dll")]
427 internal static extern bool ImageList_DragMove(int x, int y);
429 [DllImport("comctl32.dll")]
430 internal static extern bool ImageList_DragLeave(IntPtr hWndLock);
432 [DllImport("comctl32.dll")]
433 internal static extern void ImageList_EndDrag();
435 [DllImport("comctl32.dll")]
436 internal static extern bool ImageList_Draw(IntPtr hImageList, int imageIndex,
437 IntPtr hDCDest, int x, int y, ImageListDrawFlags flags);
439 [DllImport("comctl32.dll")]
440 internal static extern int ImageList_DrawEx(
441 IntPtr hImageList, int imageIndex, IntPtr hDCDest, int x, int y, int dx, int dy,
442 uint backColor, uint foregColor, ImageListDrawFlags flags);
444 [DllImport("comctl32.dll")]
445 internal static extern int ImageList_DragShowNolock(int show);
447 [DllImport("comctl32.dll")]
448 internal static extern int ImageList_AddMasked(IntPtr hImageList, IntPtr hBitmap, int crMask);
450 [DllImport("comctl32.dll")]
451 internal static extern int ImageList_SetDragCursorImage(IntPtr himlDrag, int iDrag, int dxHotspot, int dyHotspot);
453 internal static int ImageList_DrawEx(IntPtr hImageList, int imageIndex, IntPtr hDCDest, int x, int y, int dx, int dy,
454 ImageListDrawColor backColor, ImageListDrawColor foreColor, ImageListDrawFlags flags)
456 uint bColor = (uint)ImageListDrawColors.CLR_NONE;
457 if ( backColor == ImageListDrawColor.Default )
458 bColor = (uint)ImageListDrawColors.CLR_DEFAULT;
460 uint fColor = (uint)ImageListDrawColors.CLR_NONE;
461 if ( foreColor == ImageListDrawColor.Default )
462 fColor = (uint)ImageListDrawColors.CLR_DEFAULT;
464 // Call actual function
465 return ImageList_DrawEx(hImageList, imageIndex, hDCDest, x, y, dx, dy, bColor, fColor, flags);
469 static internal bool IsCommonCtrl6()
471 DLLVERSIONINFO dllVersion = new DLLVERSIONINFO();
472 // We are assummng here that anything greater or equal than 6
473 // will have the new XP theme drawing enable
474 dllVersion.cbSize = Marshal.SizeOf(typeof(DLLVERSIONINFO));
475 Win32.GetCommonControlDLLVersion(ref dllVersion);
476 return (dllVersion.dwMajorVersion >= 6);
481 #region Win32 Macro-Like helpers
482 internal static int X_LPARAM(int lParam)
484 return (lParam & 0xffff);
487 internal static int Y_LPARAM(int lParam)
489 return (lParam >> 16);
492 internal static Point GetPointFromLPARAM(int lParam)
494 return new Point(X_LPARAM(lParam), Y_LPARAM(lParam));
497 internal static int LOW_ORDER(int param)
499 return (param & 0xffff);
502 internal static int HIGH_ORDER(int param)
504 return (param >> 16);
507 internal static int INDEXTOOVERLAYMASK(int index)
509 return (int)((uint)index << 8);
512 internal static int OVERLAYMASKTOINDEX(int index)
514 return (int)((uint)index >> 8);
517 internal static int INDEXTOSTATEIMAGEMASK(int i)
519 return (int)((uint)i << 12);
522 internal static int STATEIMAGEMASKTOINDEX(int i)
524 return (int)((uint)i >> 12);
527 internal static short HRESULT_CODE(int hr)
529 return (short)(hr & 0xFFFF);
532 internal static bool SUCCEEDED(int status)
534 return (status >= 0);
537 internal static bool FAILED(int status)
542 internal static int MAKEINTRESOURCE(int res)
544 return 0x0000FFFF & res;
549 #region Mono win32 Fuinctions
551 internal delegate IntPtr WndProc (IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
553 [DllImport ("user32.dll",
554 CallingConvention = CallingConvention.StdCall,
555 CharSet = CharSet.Ansi, EntryPoint = "RegisterClassA")]
556 internal static extern uint RegisterClass(ref WNDCLASS wndClass);
558 #region Added by Dennis hayes 10-20-2002
560 [DllImport ("user32.dll",
561 CallingConvention = CallingConvention.StdCall,
562 CharSet = CharSet.Auto)]
563 internal static extern uint SendMessage(
564 IntPtr hWnd, uint Msg,
565 IntPtr wParam, IntPtr lParam);
567 [DllImport ("user32.dll",
568 CallingConvention = CallingConvention.StdCall,
569 CharSet = CharSet.Auto)]
570 internal static extern bool GetWindowPlacement(
572 ref WINDOWPLACEMENT lpwndpl // position data
576 [DllImport ("user32.dll",
577 CallingConvention = CallingConvention.StdCall,
578 CharSet = CharSet.Ansi, EntryPoint = "CreateWindowExA")]
579 internal static extern IntPtr CreateWindowEx (
580 uint dwExStyle, string lpClassName,
581 string lpWindowName, uint dwStyle,
582 int x, int y, int nWidth, int nHeight,
583 IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance,
586 [DllImport ("user32.dll",
587 CallingConvention = CallingConvention.StdCall,
588 CharSet = CharSet.Auto)]
589 internal static extern IntPtr CreateMenu ();
591 [DllImport ("user32.dll",
592 CallingConvention = CallingConvention.StdCall,
593 CharSet = CharSet.Ansi)]
594 internal static extern bool AppendMenuA(IntPtr hMenu, uint uflags, IntPtr NewItem, string item);
596 [DllImport ("user32.dll",
597 CallingConvention = CallingConvention.StdCall)]
598 internal static extern bool DestroyMenu (IntPtr hMenu);
600 [DllImport ("user32.dll", CallingConvention =
601 CallingConvention.StdCall, CharSet = CharSet.Auto)]
602 internal extern static IntPtr DefWindowProcA (
603 IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
605 [DllImport ("user32.dll", CallingConvention =
606 CallingConvention.StdCall, CharSet = CharSet.Auto)]
607 internal extern static int DestroyWindow (IntPtr hWnd);
609 [DllImport ("user32.dll", CallingConvention =
610 CallingConvention.StdCall, CharSet = CharSet.Auto)]
611 internal static extern int ShowWindow (IntPtr hWnd,
614 [DllImport ("user32.dll", CallingConvention =
615 CallingConvention.StdCall,CharSet = CharSet.Auto)]
616 internal static extern int GetMessageA (ref MSG msg, int hwnd,
617 int msgFrom, int msgTo);
619 [DllImport ("user32.dll", CallingConvention =
620 CallingConvention.StdCall, CharSet = CharSet.Auto)]
621 internal static extern int TranslateMessage (ref MSG msg);
623 [DllImport ("user32.dll", CallingConvention =
624 CallingConvention.StdCall, CharSet = CharSet.Auto)]
625 internal static extern int DispatchMessageA (ref MSG msg);
627 [DllImport ("user32.dll", CallingConvention =
628 CallingConvention.StdCall, CharSet = CharSet.Auto)]
629 internal static extern int PeekMessageA (
630 ref MSG msg, IntPtr hWnd, uint wMsgFilterMin,
631 uint wMsgFilterMax, uint wRemoveMsg);
633 [DllImport ("user32.dll", CallingConvention =
634 CallingConvention.StdCall,
635 CharSet = CharSet.Auto)]
636 internal extern static void PostQuitMessage (int nExitCode);
638 [DllImport ("user32.dll", CallingConvention =
639 CallingConvention.StdCall,
640 CharSet = CharSet.Auto)]
641 internal extern static IntPtr SetActiveWindow (IntPtr hWnd);
643 [DllImport ("user32.dll", CallingConvention =
644 CallingConvention.StdCall,
645 CharSet = CharSet.Auto)]
646 internal extern static int CloseWindow (IntPtr hWnd);
648 [DllImport ("user32.dll", CallingConvention =
649 CallingConvention.StdCall,
650 CharSet = CharSet.Auto)]
651 internal extern static int SetWindowPos (
652 IntPtr hWnd, SetWindowPosZOrder pos,
653 int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
655 [DllImport ("user32.dll",
656 CallingConvention = CallingConvention.StdCall,
657 CharSet = CharSet.Auto)]
658 internal static extern int MessageBoxA (
659 IntPtr hWnd, string pText, string pCaption, uint uType);
661 [DllImport ("user32.dll",
662 CallingConvention = CallingConvention.StdCall,
663 CharSet = CharSet.Auto)]
664 internal static extern IntPtr SetParent (
665 IntPtr hWndChild, IntPtr hWndNewParent);
667 [DllImport ("user32.dll",
668 CallingConvention = CallingConvention.StdCall,
669 CharSet = CharSet.Auto)]
670 internal static extern IntPtr GetParent (IntPtr hWnd);
672 [DllImport ("user32.dll",
673 CallingConvention = CallingConvention.StdCall,
674 CharSet = CharSet.Auto)]
675 internal static extern bool SetWindowTextA (
676 IntPtr hWnd, string lpString);
678 [DllImport ("user32.dll",
679 CallingConvention = CallingConvention.StdCall,
680 CharSet = CharSet.Auto)]
681 internal static extern bool UpdateWindow (IntPtr hWnd);
683 [DllImport ("user32.dll",
684 CallingConvention = CallingConvention.StdCall,
685 CharSet = CharSet.Auto)]
686 internal static extern uint GetBkColor (IntPtr hdc);
688 [DllImport ("user32.dll",
689 CallingConvention = CallingConvention.StdCall,
690 CharSet = CharSet.Auto)]
691 internal static extern uint SetBkColor (IntPtr hdc, uint crColor);
693 [DllImport ("user32.dll",
694 CallingConvention = CallingConvention.StdCall,
695 CharSet = CharSet.Auto)]
696 internal static extern IntPtr GetDC (IntPtr hWnd);
698 [DllImport ("user32.dll",
699 CallingConvention = CallingConvention.StdCall,
700 CharSet = CharSet.Auto)]
701 internal static extern int ReleaseDC (IntPtr hWnd, IntPtr hDC);
703 [DllImport ("user32.dll",
704 CallingConvention = CallingConvention.StdCall,
705 CharSet = CharSet.Auto)]
706 internal static extern IntPtr GetFocus();
708 [DllImport ("user32.dll",
709 CallingConvention = CallingConvention.StdCall,
710 CharSet = CharSet.Auto)]
711 internal static extern IntPtr SetFocus (IntPtr hWnd);
713 [DllImport ("user32.dll",
714 CallingConvention = CallingConvention.StdCall,
715 CharSet = CharSet.Auto)]
716 internal static extern bool IsWindowEnabled (IntPtr hWnd);
718 [DllImport ("user32.dll",
719 CallingConvention = CallingConvention.StdCall,
720 CharSet = CharSet.Auto)]
721 internal static extern bool IsMenu (IntPtr hWnd);
724 [DllImport ("user32.dll",
725 CallingConvention = CallingConvention.StdCall,
726 CharSet = CharSet.Auto)]
727 internal static extern bool EnableWindow (
728 IntPtr hWnd, bool bEnable);
730 [DllImport ("user32.dll",
731 CallingConvention = CallingConvention.StdCall,
732 CharSet = CharSet.Auto)]
733 internal static extern bool GetWindowRect (
734 IntPtr hWnd, ref RECT lpRect);
736 [DllImport ("user32.dll",
737 CallingConvention = CallingConvention.StdCall,
738 CharSet = CharSet.Auto)]
739 internal static extern bool GetClientRect (
740 IntPtr hWnd, ref RECT lpRect);
742 [DllImport ("user32.dll",
743 CallingConvention = CallingConvention.StdCall,
744 CharSet = CharSet.Auto)]
745 internal static extern bool InvalidateRect (
746 IntPtr hWnd, ref RECT lpRect, bool bErase);
748 [DllImport ("user32.dll",
749 CallingConvention = CallingConvention.StdCall,
750 CharSet = CharSet.Auto)]
751 internal static extern IntPtr GetCapture ();
753 [DllImport ("user32.dll",
754 CallingConvention = CallingConvention.StdCall,
755 CharSet = CharSet.Auto)]
756 internal static extern IntPtr SetCapture (IntPtr hWnd);
758 [DllImport ("user32.dll",
759 CallingConvention = CallingConvention.StdCall,
760 CharSet = CharSet.Auto)]
761 internal static extern bool ReleaseCapture ();
763 [DllImport ("user32.dll",
764 CallingConvention = CallingConvention.StdCall,
765 CharSet = CharSet.Auto)]
766 internal static extern int GetWindowTextA (
767 IntPtr hWnd, ref String lpString, int nMaxCount);
769 [DllImport ("user32.dll",
770 CallingConvention = CallingConvention.StdCall,
771 CharSet = CharSet.Auto)]
772 internal static extern int GetWindowTextLengthA (IntPtr hWnd);
774 [DllImport ("user32.dll",
775 CallingConvention = CallingConvention.StdCall,
776 CharSet = CharSet.Auto)]
777 internal static extern bool GetCursorPos (ref POINT lpPoint);
781 [DllImport ("user32.dll",
782 CallingConvention = CallingConvention.StdCall,
783 CharSet = CharSet.Auto)]
784 internal static extern IntPtr GetMenu (IntPtr hWnd);
786 [DllImport ("user32.dll",
787 CallingConvention = CallingConvention.StdCall,
788 CharSet = CharSet.Auto)]
789 internal static extern int SetMenu (IntPtr hWnd, IntPtr hMenu);
791 [DllImport ("user32.dll",
792 CallingConvention = CallingConvention.StdCall,
793 CharSet = CharSet.Ansi)]
794 internal static extern int InsertMenuA(IntPtr hMenu, uint pos, uint uflags, IntPtr NewItem, string item);
796 [DllImport ("user32.dll",
797 CallingConvention = CallingConvention.StdCall,
798 CharSet = CharSet.Ansi)]
799 internal static extern int RemoveMenu(IntPtr hMenu, uint pos, uint uflags);
801 [DllImport ("user32.dll",
802 CallingConvention = CallingConvention.StdCall)]
803 internal static extern int DrawMenuBar (IntPtr hWnd);
807 [DllImport ("user32.dll", CallingConvention =
808 CallingConvention.StdCall,
809 CharSet = CharSet.Auto)]
810 internal extern static int AdjustWindowRect (
811 ref RECT rc, int dwStyle, int bMenu);
815 [DllImport ("kernel32.dll", CallingConvention =
816 CallingConvention.StdCall,
817 CharSet = CharSet.Auto)]
818 internal extern static uint GetLastError ();
820 [DllImport ("kernel32.dll", CallingConvention =
821 CallingConvention.StdCall,
822 CharSet = CharSet.Auto)]
823 internal extern static uint FormatMessage (
824 uint flags, IntPtr lpSource,
825 uint messageId, uint languageId,
826 StringBuilder lpBuffer, int nSize,
829 internal static string FormatMessage(uint error) {
830 StringBuilder sb = new StringBuilder(2048);
831 Win32.FormatMessage( (uint)(FM_.FORMAT_MESSAGE_FROM_SYSTEM | FM_.FORMAT_MESSAGE_IGNORE_INSERTS),
832 IntPtr.Zero, error, 0, sb, sb.Capacity, IntPtr.Zero);
833 return sb.ToString();