win32functions.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400
  1. /*
  2. * Copyright (C) 5/11/2002 Carlos Harvey Perez
  3. * Modifcations and additons, Copyright Ximian 2002/3
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject
  11. * to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  18. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT.
  20. * IN NO EVENT SHALL CARLOS HARVEY PEREZ BE LIABLE FOR ANY CLAIM,
  21. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
  23. * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. * Except as contained in this notice, the name of Carlos Harvey Perez
  26. * shall not be used in advertising or otherwise to promote the sale,
  27. * use or other dealings in this Software without prior written
  28. * authorization from Carlos Harvey Perez.
  29. */
  30. using System;
  31. using System.Threading;
  32. using System.Drawing;
  33. using System.Runtime.InteropServices;
  34. using System.Text;
  35. using System.Diagnostics;
  36. using System.Reflection;
  37. using System.Xml;
  38. using System.IO;
  39. //using UtilityLibrary.WinControls;
  40. //namespace UtilityLibrary.Win32
  41. namespace System.Windows.Forms{
  42. //
  43. // The following methods have not been exposed by WineLib yet,
  44. // we move them here, so that errors are not displayed until
  45. // we actually use these functions.
  46. //
  47. public class Win32_WineLess {
  48. [DllImport("user32.dll", CharSet=CharSet.Ansi)]
  49. internal static extern IntPtr CopyCursor ( IntPtr pcur );
  50. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  51. internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize,
  52. IntPtr hdcSrc, ref POINT pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, UpdateLayeredWindowFlags dwFlags);
  53. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  54. static internal extern int GetScrollBarInfo(IntPtr hWnd, SystemObject id, ref SCROLLBARINFO sbi);
  55. [DllImport("comctl32.dll", EntryPoint="DllGetVersion")]
  56. internal extern static int GetCommonControlDLLVersion(ref DLLVERSIONINFO dvi);
  57. [DllImport ("comdlg32.dll",
  58. CallingConvention = CallingConvention.StdCall,
  59. CharSet = CharSet.Ansi)]
  60. internal static extern bool GetOpenFileName ( ref OPENFILENAME lpofn );
  61. [DllImport ("comdlg32.dll",
  62. CallingConvention = CallingConvention.StdCall,
  63. CharSet = CharSet.Ansi)]
  64. internal static extern bool GetSaveFileName ( ref OPENFILENAME lpofn );
  65. [DllImport ("comdlg32.dll",
  66. CallingConvention = CallingConvention.StdCall,
  67. CharSet = CharSet.Ansi)]
  68. internal static extern bool ChooseColor ( ref CHOOSECOLOR lpofn );
  69. [DllImport ("comdlg32.dll",
  70. CallingConvention = CallingConvention.StdCall,
  71. CharSet = CharSet.Ansi)]
  72. internal static extern bool PrintDlg (IntPtr pDlg);
  73. [DllImport ("comdlg32.dll",
  74. CallingConvention = CallingConvention.StdCall,
  75. CharSet = CharSet.Ansi)]
  76. internal static extern bool ChooseFont ( ref CHOOSEFONT lpcf );
  77. [DllImport ("comdlg32.dll",
  78. CallingConvention = CallingConvention.StdCall,
  79. CharSet = CharSet.Ansi)]
  80. internal static extern uint CommDlgExtendedError ( );
  81. }
  82. /// <summary>
  83. /// Windows API Functions
  84. /// </summary>
  85. public class Win32
  86. {
  87. #region Constructors
  88. // No need to construct this object
  89. #endregion
  90. #region Constans values
  91. internal const string TOOLBARCLASSNAME = "ToolbarWindow32";
  92. internal const string REBARCLASSNAME = "ReBarWindow32";
  93. internal const string PROGRESSBARCLASSNAME = "msctls_progress32";
  94. internal const string SCROLLBAR = "SCROLLBAR";
  95. internal const string TOOLTIPS_CLASS = "tooltips_class32";
  96. internal const string MDICLIENTCLASSNAME = "MDICLIENT";
  97. internal const string TABCONTROL = "SysTabControl32";
  98. internal const string DEFAULT_WINDOW_CLASS = "mono_scrollable_control";
  99. internal const string TREEVIEW_CLASS = "SysTreeView32";
  100. internal const string TOOLBAR_CLASS = "ToolbarWindow32";
  101. #endregion
  102. #region CallBacks
  103. internal delegate IntPtr FnHookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam);
  104. internal delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
  105. internal delegate int CompareFunc(IntPtr param1, IntPtr param2, IntPtr sortParam);
  106. internal delegate int WinProc(IntPtr hWnd, int message, int wParam, int lParam);
  107. internal delegate int WinProcMsg(IntPtr hWnd, Msg message, int wParam, int lParam);
  108. #endregion
  109. #region Kernel32.dll functions
  110. [DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
  111. internal static extern int GetCurrentThreadId();
  112. [DllImport("kernel32.dll")]
  113. internal static extern int GetDriveType(string rootPathName);
  114. [DllImport("kernel32.dll")]
  115. internal static extern int GetVolumeInformation(string drivePath,
  116. StringBuilder volumeNameBuffer,
  117. int driveNameBufferSize,
  118. out int serialNumber,
  119. out int maxFileNameLength,
  120. out int fileSystemFlags,
  121. StringBuilder systemNameBuffer,
  122. int systemNameBufferSize);
  123. [DllImport("kernel32.dll")]
  124. internal static extern IntPtr LoadLibraryA(string filename);
  125. [DllImport("kernel32.dll")]
  126. internal static extern bool FreeLibrary(IntPtr handle);
  127. [DllImport("kernel32.dll", EntryPoint="OutputDebugStringW")]
  128. internal static extern void OutputDebugString(string message);
  129. [DllImport ("kernel32.dll", CallingConvention = CallingConvention.StdCall,
  130. CharSet = CharSet.Auto)]
  131. internal extern static uint GetLastError ();
  132. [DllImport ("kernel32.dll", CallingConvention = CallingConvention.StdCall,
  133. CharSet = CharSet.Auto, EntryPoint = "FormatMessageW")]
  134. internal extern static uint FormatMessage (
  135. uint flags, IntPtr lpSource,uint messageId, uint languageId,
  136. StringBuilder lpBuffer, int nSize, IntPtr Arguments);
  137. internal static string FormatMessage(uint error) {
  138. StringBuilder sb = new StringBuilder(2048);
  139. Win32.FormatMessage( (uint)(FM_.FORMAT_MESSAGE_FROM_SYSTEM | FM_.FORMAT_MESSAGE_IGNORE_INSERTS),
  140. IntPtr.Zero, error, 0, sb, sb.Capacity, IntPtr.Zero);
  141. return sb.ToString();
  142. }
  143. [DllImport ("kernel32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  144. internal extern static int wine_get_unix_file_name (string dos, IntPtr unix, int len);
  145. internal static string wine_get_unix_file_name (string dos)
  146. {
  147. string result = dos;
  148. if (RunningOnUnix){
  149. // FIXME: shall we have a static buffer here ?
  150. IntPtr tempBuf = Marshal.AllocHGlobal(2048);
  151. if( Win32.wine_get_unix_file_name( dos, tempBuf, 2048) != 0){
  152. result = Marshal.PtrToStringAnsi(tempBuf);
  153. }
  154. Marshal.FreeHGlobal(tempBuf);
  155. }
  156. return result;
  157. }
  158. #endregion
  159. #region Gdi32.dll functions
  160. [DllImport("gdi32.dll")]
  161. static internal extern bool StretchBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
  162. IntPtr hDCSrc, int XOriginScr, int YOriginSrc, int WidthScr, int HeightScr, PatBltTypes Rop);
  163. [DllImport("gdi32.dll")]
  164. static internal extern IntPtr CreateCompatibleDC(IntPtr hDC);
  165. [DllImport("gdi32.dll")]
  166. static internal extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int Width, int Heigth);
  167. [DllImport("gdi32.dll")]
  168. static internal extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
  169. [DllImport("gdi32.dll")]
  170. static internal extern bool BitBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
  171. IntPtr hDCSrc, int XOriginScr, int YOriginSrc, PatBltTypes flags);
  172. [DllImport("gdi32.dll")]
  173. static internal extern IntPtr DeleteDC(IntPtr hDC);
  174. [DllImport("gdi32.dll")]
  175. static internal extern bool PatBlt(IntPtr hDC, int XLeft, int YLeft, int Width, int Height, int Rop);
  176. [DllImport("gdi32.dll")]
  177. static internal extern bool DeleteObject(IntPtr hObject);
  178. [DllImport("gdi32.dll")]
  179. static internal extern int GetPixel(IntPtr hDC, int XPos, int YPos);
  180. [DllImport("gdi32.dll")]
  181. static internal extern int SetMapMode(IntPtr hDC, int fnMapMode);
  182. [DllImport("gdi32.dll")]
  183. static internal extern int GetObjectType(IntPtr handle);
  184. [DllImport("gdi32.dll")]
  185. internal static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO_FLAT bmi,
  186. int iUsage, ref int ppvBits, IntPtr hSection, int dwOffset);
  187. [DllImport("gdi32.dll")]
  188. internal static extern int GetDIBits(IntPtr hDC, IntPtr hbm, int StartScan, int ScanLines, int lpBits, BITMAPINFOHEADER bmi, int usage);
  189. [DllImport("gdi32.dll")]
  190. internal static extern int GetDIBits(IntPtr hdc, IntPtr hbm, int StartScan, int ScanLines, int lpBits, ref BITMAPINFO_FLAT bmi, int usage);
  191. [DllImport("gdi32.dll")]
  192. internal static extern IntPtr GetPaletteEntries(IntPtr hpal, int iStartIndex, int nEntries, byte[] lppe);
  193. [DllImport("gdi32.dll")]
  194. internal static extern IntPtr GetSystemPaletteEntries(IntPtr hdc, int iStartIndex, int nEntries, byte[] lppe);
  195. [DllImport("gdi32.dll")]
  196. internal static extern int SetDCBrushColor(IntPtr hdc, int crColor);
  197. [DllImport("gdi32.dll")]
  198. internal static extern IntPtr CreateSolidBrush(int crColor);
  199. [DllImport("gdi32.dll")]
  200. internal static extern BackgroundMode SetBkMode(IntPtr hDC, BackgroundMode mode);
  201. [DllImport("gdi32.dll")]
  202. internal static extern int SetViewportOrgEx(IntPtr hdc, int x, int y, int param);
  203. [DllImport("gdi32.dll")]
  204. internal static extern int SetTextColor(IntPtr hDC, int colorRef);
  205. [DllImport("gdi32.dll")]
  206. internal static extern int SetStretchBltMode(IntPtr hDC, StrechModeFlags StrechMode);
  207. [DllImport("gdi32.dll")]
  208. internal static extern int SetPixel(IntPtr hDC, int x, int y, int color);
  209. [DllImport("gdi32.dll")]
  210. internal static extern IntPtr CreatePen(PenStyle penStyle, int width, int color);
  211. [DllImport("gdi32.dll")]
  212. internal static extern int GetClipRgn(IntPtr hDC, ref IntPtr region);
  213. [DllImport("gdi32.dll")]
  214. internal static extern IntPtr CreateRectRgn(int nLeftRect, int TopRect, int nRightRect, int nBottomRect);
  215. [DllImport("gdi32.dll")]
  216. internal static extern int GetRgnBox(IntPtr hRegion, ref RECT rc);
  217. [DllImport("gdi32.dll")]
  218. internal static extern IntPtr GetStockObject(GSO_ objectType);
  219. [DllImport("gdi32.dll",CharSet = CharSet.Ansi,EntryPoint="ExtTextOutA")]
  220. internal static extern int ExtTextOut(IntPtr hdc, int x, int y,
  221. ExtTextOutFlags options, ref RECT rc, int str, int strLen, IntPtr distances);
  222. [DllImport("gdi32.dll",CharSet = CharSet.Ansi,EntryPoint="ExtTextOutA")]
  223. internal static extern int ExtTextOut(IntPtr hdc, int x, int y,
  224. ExtTextOutFlags options, ref RECT rc, string str, int strLen, IntPtr distances);
  225. [DllImport("gdi32.dll",CharSet = CharSet.Ansi,EntryPoint="GetTextExtentPoint32A")]
  226. internal static extern bool GetTextExtentPoint32(IntPtr hDC, string lpString, int cbString, ref SIZE lpSize);
  227. [DllImport("gdi32.dll", CallingConvention = CallingConvention.StdCall )]
  228. internal static extern IntPtr CreateBitmap( int nWidth, int nHeight, uint cPlanes, uint cBitsPerPel, IntPtr lpvBits );
  229. [DllImport("gdi32.dll", CallingConvention = CallingConvention.StdCall )]
  230. internal static extern int SetDIBits( IntPtr hdc, IntPtr hbmp, uint uStartScan, uint cScanLines, IntPtr lpvBits, IntPtr lpbmi, uint fuColorUse );
  231. [DllImport ("gdi32.dll",
  232. CallingConvention = CallingConvention.StdCall,
  233. CharSet = CharSet.Auto)]
  234. internal static extern uint GetBkColor (IntPtr hdc);
  235. [DllImport ("gdi32.dll",
  236. CallingConvention = CallingConvention.StdCall,
  237. CharSet = CharSet.Auto)]
  238. internal static extern uint SetBkColor (IntPtr hdc, uint crColor);
  239. internal static int RGB(Color color)
  240. {
  241. return color.R | (color.G << 8) | (color.B << 16);
  242. }
  243. #endregion
  244. #region Uxtheme.dll functions
  245. #if USE_UXTHEME
  246. [DllImport("uxtheme.dll")]
  247. static public extern int SetWindowTheme(IntPtr hWnd, StringBuilder AppID, StringBuilder ClassID);
  248. static public void DisableWindowsXPTheme(IntPtr hWnd)
  249. {
  250. // Disable using the Window XP Theme for the Window handle
  251. // passed as a parameter
  252. StringBuilder applicationName = new StringBuilder(" ", 1);
  253. StringBuilder classIDs = new StringBuilder(" " , 1);
  254. Win32.SetWindowTheme(hWnd, applicationName, classIDs);
  255. }
  256. #endif
  257. #endregion
  258. #region user32.dll functions
  259. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  260. static internal extern IntPtr GetDesktopWindow();
  261. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  262. static internal extern bool ShowWindow(IntPtr hWnd, ShowWindowStyles State);
  263. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  264. static internal extern bool SetForegroundWindow(IntPtr hWnd);
  265. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  266. static internal extern bool OpenClipboard(IntPtr hWndNewOwner);
  267. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  268. static internal extern bool CloseClipboard();
  269. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  270. static internal extern bool EmptyClipboard();
  271. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  272. static internal extern IntPtr SetClipboardData( int Format, IntPtr hData);
  273. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  274. static internal extern bool GetMenuItemRect(IntPtr hWnd, IntPtr hMenu, int Item, ref RECT rc);
  275. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  276. internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
  277. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  278. internal static extern int SendMessage(IntPtr hWnd, Msg msg, int wParam, int lParam);
  279. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  280. internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);
  281. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  282. internal static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref RECT lParam);
  283. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  284. internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref POINT lParam);
  285. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  286. internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, string lParam);
  287. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  288. internal static extern int SendMessage(IntPtr hWnd, Msg msg, int wParam, string lParam);
  289. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  290. internal static extern void SendMessage(IntPtr hWnd, ToolBarMessages msg, int wParam, ref TBBUTTON lParam);
  291. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  292. internal static extern void SendMessage(IntPtr hWnd, ToolBarMessages msg, int wParam, ref TBBUTTONINFO lParam);
  293. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  294. internal static extern int SendMessage(IntPtr hWnd, RebarMessages msg, int wParam, ref REBARBANDINFO lParam);
  295. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  296. internal static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVITEM lParam);
  297. [DllImport("user32.dll", CharSet=CharSet.Ansi)]
  298. internal static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVINSERTSTRUCT lParam);
  299. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  300. internal static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVSORTCB lParam);
  301. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  302. internal static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVHITTESTINFO hti);
  303. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  304. internal static extern void SendMessage(IntPtr hWnd, ListViewMessages msg, int wParam, ref LVITEM lParam);
  305. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  306. internal static extern void SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, ref HDITEM lParam);
  307. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  308. internal static extern void SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, ref HD_HITTESTINFO hti);
  309. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  310. internal static extern int SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, int lParam);
  311. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="PostMessageA")]
  312. internal static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
  313. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="PostMessageA")]
  314. internal static extern IntPtr PostMessage(IntPtr hWnd, Msg msg, int wParam, int lParam);
  315. [DllImport("user32.dll", CharSet=CharSet.Auto, EntryPoint="SetWindowsHookExW")]
  316. internal static extern IntPtr SetWindowsHookEx(WindowsHookCodes hookid, HookProc pfnhook, IntPtr hinst, int threadid);
  317. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  318. internal static extern bool UnhookWindowsHookEx(IntPtr hhook);
  319. [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
  320. internal static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, IntPtr lparam);
  321. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="DrawTextA")]
  322. internal extern static int DrawText(IntPtr hdc, string lpString, int nCount, ref RECT lpRect, DrawTextFormatFlags flags);
  323. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  324. internal extern static IntPtr GetDlgItem(IntPtr hDlg, int nControlID);
  325. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  326. internal extern static int InvalidateRect(IntPtr hWnd, ref RECT rc, int bErase);
  327. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  328. internal extern static int InvalidateRect(IntPtr hWnd, IntPtr rc, int bErase);
  329. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  330. internal static extern bool WaitMessage();
  331. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  332. internal static extern int SendMessage2ref(IntPtr hWnd, int msg, ref int wParam, ref int lParam);
  333. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="PeekMessageA")]
  334. internal static extern bool PeekMessage(ref MESSAGE msg, int hWnd, int wFilterMin, int wFilterMax, PeekMessageFlags flags);
  335. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="GetMessageA")]
  336. internal static extern bool GetMessage(ref MESSAGE msg, int hWnd, int wFilterMin, int wFilterMax);
  337. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  338. internal static extern bool TranslateMessage(ref MESSAGE msg);
  339. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="DispatchMessageA")]
  340. internal static extern bool DispatchMessage(ref MESSAGE msg);
  341. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="LoadCursorA")]
  342. internal static extern IntPtr LoadCursor(IntPtr hInstance, CursorType cursor);
  343. [DllImport("user32.dll", CharSet=CharSet.Ansi)]
  344. internal static extern bool DestroyCursor ( IntPtr hCursor );
  345. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  346. internal static extern IntPtr SetCursor(IntPtr hCursor);
  347. [DllImport("user32.dll", CharSet=CharSet.Ansi)]
  348. internal static extern int ShowCursor ( bool bShow );
  349. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  350. internal static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
  351. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  352. internal static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
  353. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  354. internal static extern bool GetUpdateRect(IntPtr hwnd, ref RECT rect, bool erase);
  355. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  356. internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);
  357. internal static bool ClientToScreen(IntPtr hWnd, ref RECT rect) {
  358. POINT pt1 = new POINT();
  359. pt1.x = rect.left;
  360. pt1.y = rect.top;
  361. POINT pt2 = new POINT();
  362. pt2.x = rect.right;
  363. pt2.y = rect.bottom;
  364. bool result = Win32.ClientToScreen(hWnd, ref pt1);
  365. result &= Win32.ClientToScreen(hWnd, ref pt2);
  366. rect.left = pt1.x;
  367. rect.top = pt1.y;
  368. rect.right = pt2.x;
  369. rect.bottom = pt2.y;
  370. return result;
  371. }
  372. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  373. internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT pt);
  374. internal static bool ScreenToClient(IntPtr hWnd, ref RECT rect) {
  375. POINT pt1 = new POINT();
  376. pt1.x = rect.left;
  377. pt1.y = rect.top;
  378. POINT pt2 = new POINT();
  379. pt2.x = rect.right;
  380. pt2.y = rect.bottom;
  381. bool result = Win32.ScreenToClient(hWnd, ref pt1);
  382. result &= Win32.ScreenToClient(hWnd, ref pt2);
  383. rect.left = pt1.x;
  384. rect.top = pt1.y;
  385. rect.right = pt2.x;
  386. rect.bottom = pt2.y;
  387. return result;
  388. }
  389. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  390. internal static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT tme);
  391. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  392. internal static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
  393. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  394. internal static extern short GetKeyState(int virtKey);
  395. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  396. internal static extern short GetAsyncKeyState(int virtKey);
  397. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  398. internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
  399. [DllImport("user32.dll", CharSet=CharSet.Auto, EntryPoint="GetClassNameW")]
  400. internal static extern int GetClassName(IntPtr hWnd, StringBuilder ClassName, int nMaxCount);
  401. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="SetWindowLongA")]
  402. internal static extern int SetWindowLong(IntPtr hWnd, GetWindowLongFlag flag, int dwNewLong);
  403. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="SetWindowLongA")]
  404. internal static extern IntPtr SetWindowLong(IntPtr hWnd, GetWindowLongFlag flag, WinProc winProc);
  405. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="SetWindowLongA")]
  406. internal static extern IntPtr SetWindowLong(IntPtr hWnd, GetWindowLongFlag flag, WndProc winProc);
  407. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  408. internal static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hRegion, int flags);
  409. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  410. internal static extern IntPtr GetWindowDC(IntPtr hWnd);
  411. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  412. internal static extern int FillRect(IntPtr hDC, ref RECT rect, IntPtr hBrush);
  413. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SetWindowTextA")]
  414. internal static extern int SetWindowText(IntPtr hWnd, string text);
  415. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="GetWindowTextA")]
  416. internal static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int maxCount);
  417. [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
  418. static internal extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
  419. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  420. static internal extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
  421. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  422. static internal extern int ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
  423. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  424. static internal extern int GetSystemMetrics(SystemMetricsCodes code);
  425. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  426. static internal extern int SetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si, int fRedraw);
  427. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  428. static internal extern int ShowScrollBar(IntPtr hWnd, int bar, int show);
  429. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  430. static internal extern int EnableScrollBar(IntPtr hWnd, int flags, int arrows);
  431. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  432. static internal extern int BringWindowToTop(IntPtr hWnd);
  433. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  434. static internal extern int GetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si);
  435. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  436. static internal extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy,
  437. ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion, ref RECT rcInvalidated, int flags);
  438. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  439. static internal extern bool IsWindow(IntPtr hWnd);
  440. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  441. static internal extern bool LockWindowUpdate(IntPtr hWnd);
  442. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  443. static internal extern bool ValidateRect(IntPtr hWnd, ref RECT rcInvalidated);
  444. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  445. static internal extern bool ValidateRect(IntPtr hWnd, IntPtr rc);
  446. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="GetWindowLongA")]
  447. static internal extern IntPtr GetWindowLong(IntPtr hWnd, GetWindowLongFlag flag);
  448. [DllImport("user32.dll", CharSet=CharSet.Auto, EntryPoint="SetPropW")]
  449. static internal extern int SetProp(IntPtr hWnd, IntPtr atom, IntPtr hData);
  450. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="CallWindowProcA")]
  451. static internal extern int CallWindowProc(IntPtr hOldProc, IntPtr hWnd, int message, int wParam, int lParam);
  452. [DllImport("user32.dll", CharSet=CharSet.Auto)]
  453. static internal extern int EndMenu();
  454. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="DefWindowProcA")]
  455. static internal extern int DefWindowProc(IntPtr hWnd, int message, int wParam, int lParam);
  456. [DllImport("user32.dll", CharSet=CharSet.Ansi)]
  457. static internal extern IntPtr DefMDIChildProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
  458. [DllImport("user32.dll", CharSet=CharSet.Ansi)]
  459. static internal extern IntPtr DefFrameProc(IntPtr hWnd, IntPtr hWndMDIClient, Msg Msg, IntPtr wParam, IntPtr lParam);
  460. [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="LoadCursorA")]
  461. static internal extern IntPtr LoadCursor(IntPtr hInstance, LC_ standardCursor);
  462. [DllImport("user32.dll", CharSet=CharSet.Auto, EntryPoint="RegisterWindowMessageA")]
  463. static internal extern int RegisterWindowMessage( string message_name);
  464. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
  465. CharSet = CharSet.Auto)]
  466. internal static extern IntPtr GetMenu (IntPtr hWnd);
  467. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
  468. CharSet = CharSet.Auto)]
  469. internal static extern int SetMenu (IntPtr hWnd, IntPtr hMenu);
  470. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
  471. CharSet = CharSet.Ansi)]
  472. internal static extern int InsertMenuA(IntPtr hMenu, uint pos, uint uflags, IntPtr NewItem, string item);
  473. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
  474. CharSet = CharSet.Ansi)]
  475. internal static extern int RemoveMenu(IntPtr hMenu, uint pos, uint uflags);
  476. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall)]
  477. internal static extern int DrawMenuBar (IntPtr hWnd);
  478. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall)]
  479. internal static extern int SetMenuDefaultItem(IntPtr hMenu, int uItem, int fByPos );
  480. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  481. internal extern static int AdjustWindowRect( ref RECT rc, int dwStyle, int bMenu);
  482. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  483. internal extern static int AdjustWindowRectEx( ref RECT rc, int dwStyle, int bMenu, int dwStyleEx);
  484. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  485. internal static extern int DrawEdge(IntPtr hdc, ref RECT rc, Border3DStyle edge, Border3DSide flags);
  486. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  487. internal static extern int DrawFrameControl(IntPtr hdc, ref RECT rc, uint uType, uint uState);
  488. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  489. internal static extern int DrawFocusRect( IntPtr hdc, ref RECT rc);
  490. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  491. internal static extern IntPtr WindowFromPoint( POINT pt);
  492. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  493. internal static extern int GetSysColor( GetSysColorIndex color);
  494. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  495. internal static extern bool SetSysColors(int cElements, int[] lpaElements, uint[] lpaRgbValues);
  496. internal delegate void TimerProc(IntPtr hWnd, uint uMsg, uint idEvent, int dwTime);
  497. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  498. internal static extern uint SetTimer (IntPtr hWnd, uint nIDEvent, uint uElapse, TimerProc lpTimerFunc);
  499. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  500. internal static extern bool KillTimer (IntPtr hWnd, uint nIDEvent);
  501. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
  502. internal static extern IntPtr GetActiveWindow ( );
  503. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
  504. internal static extern IntPtr GetForegroundWindow ( );
  505. [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
  506. internal static extern bool TrackPopupMenu( IntPtr hMenu, uint uFlags, int x, int y, int nReserved,
  507. IntPtr hWnd, IntPtr prcRect );
  508. #endregion
  509. #region Shell32.dll functions
  510. #if HAVE_SHELL_SUPPORT
  511. [DllImport("shell32.dll", CharSet=CharSet.Auto)]
  512. internal static extern IntPtr SHGetFileInfo(string drivePath, int fileAttributes,
  513. out SHFILEINFO fileInfo, int countBytesFileInfo, ShellFileInfoFlags flags);
  514. [DllImport("shell32.dll", CharSet=CharSet.Auto)]
  515. internal static extern IntPtr SHGetFileInfo(IntPtr idl, int fileAttributes,
  516. out SHFILEINFO fileInfo, int countBytesFileInfo, ShellFileInfoFlags flags);
  517. [DllImport("shell32.dll", CharSet=CharSet.Auto)]
  518. internal static extern int SHGetSpecialFolderLocation(IntPtr hwndOwner, ShellSpecialFolder folder, out IntPtr idl);
  519. [DllImport("shell32.dll", CharSet=CharSet.Auto)]
  520. internal static extern int SHGetMalloc(out IMalloc alloc);
  521. [DllImport("shell32.dll", CharSet=CharSet.Auto)]
  522. internal static extern int SHGetDesktopFolder(out IShellFolder folder);
  523. [DllImport("shell32.dll", CharSet=CharSet.Auto)]
  524. internal static extern int SHGetPathFromIDList(IntPtr idl, StringBuilder path);
  525. internal static void SHFreeMalloc(IntPtr handle)
  526. {
  527. IMalloc alloc = null;
  528. try
  529. {
  530. Win32.SHGetMalloc(out alloc);
  531. Debug.Assert(alloc != null);
  532. alloc.Free(handle);
  533. // Free allocator itself
  534. IUnknown iUnknown = (IUnknown)alloc;
  535. iUnknown.Release();
  536. }
  537. catch (Exception e)
  538. {
  539. // In case the Garbage collector is trying to free
  540. // this memory from its own thread
  541. Debug.WriteLine(e.Message);
  542. }
  543. }
  544. #endif
  545. #endregion
  546. #region Common Controls functions
  547. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  548. internal static extern bool InitCommonControlsEx(INITCOMMONCONTROLSEX icc);
  549. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  550. internal static extern bool InitCommonControls();
  551. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  552. internal static extern IntPtr ImageList_Create(int width, int height, uint flags, int count, int grow);
  553. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  554. internal static extern bool ImageList_Destroy(IntPtr handle);
  555. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  556. internal static extern int ImageList_Add(IntPtr imageHandle, IntPtr hBitmap, IntPtr hMask);
  557. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  558. internal static extern bool ImageList_Remove(IntPtr imageHandle, int index);
  559. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  560. internal static extern bool ImageList_SetImageCount ( IntPtr himl, uint uNewCount );
  561. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  562. internal static extern uint ImageList_SetBkColor ( IntPtr himl, uint clrBk );
  563. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  564. internal static extern bool ImageList_SetOverlayImage( IntPtr himl, int iImage, int iOverlay );
  565. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  566. internal static extern bool ImageList_BeginDrag(IntPtr imageHandle, int imageIndex, int xHotSpot, int yHotSpot);
  567. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  568. internal static extern bool ImageList_DragEnter(IntPtr hWndLock, int x, int y);
  569. [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
  570. internal static extern bool ImageList_DragMove(int x, int y);
  571. [DllImport("comctl32.dll")]
  572. internal static extern bool ImageList_DragLeave(IntPtr hWndLock);
  573. [DllImport("comctl32.dll")]
  574. internal static extern void ImageList_EndDrag();
  575. [DllImport("comctl32.dll")]
  576. internal static extern bool ImageList_Draw(IntPtr hImageList, int imageIndex,
  577. IntPtr hDCDest, int x, int y, ImageListDrawFlags flags);
  578. [DllImport("comctl32.dll")]
  579. internal static extern int ImageList_DrawEx(
  580. IntPtr hImageList, int imageIndex, IntPtr hDCDest, int x, int y, int dx, int dy,
  581. uint backColor, uint foregColor, ImageListDrawFlags flags);
  582. [DllImport("comctl32.dll")]
  583. internal static extern int ImageList_DragShowNolock(int show);
  584. [DllImport("comctl32.dll")]
  585. internal static extern int ImageList_AddMasked(IntPtr hImageList, IntPtr hBitmap, int crMask);
  586. [DllImport("comctl32.dll")]
  587. internal static extern int ImageList_SetDragCursorImage(IntPtr himlDrag, int iDrag, int dxHotspot, int dyHotspot);
  588. internal static int ImageList_DrawEx(IntPtr hImageList, int imageIndex, IntPtr hDCDest, int x, int y, int dx, int dy,
  589. ImageListDrawColor backColor, ImageListDrawColor foreColor, ImageListDrawFlags flags)
  590. {
  591. uint bColor = (uint)ImageListDrawColors.CLR_NONE;
  592. if ( backColor == ImageListDrawColor.Default )
  593. bColor = (uint)ImageListDrawColors.CLR_DEFAULT;
  594. uint fColor = (uint)ImageListDrawColors.CLR_NONE;
  595. if ( foreColor == ImageListDrawColor.Default )
  596. fColor = (uint)ImageListDrawColors.CLR_DEFAULT;
  597. // Call actual function
  598. return ImageList_DrawEx(hImageList, imageIndex, hDCDest, x, y, dx, dy, bColor, fColor, flags);
  599. }
  600. static internal bool IsCommonCtrl6()
  601. {
  602. DLLVERSIONINFO dllVersion = new DLLVERSIONINFO();
  603. //
  604. // Windows Forms using WineLib: XP theme drawing not available
  605. //
  606. if (Environment.GetEnvironmentVariable ("SWF") != null)
  607. return false;
  608. // We are assummng here that anything greater or equal than 6
  609. // will have the new XP theme drawing enable
  610. dllVersion.cbSize = Marshal.SizeOf(typeof(DLLVERSIONINFO));
  611. Win32_WineLess.GetCommonControlDLLVersion(ref dllVersion);
  612. return (dllVersion.dwMajorVersion >= 6);
  613. }
  614. #endregion
  615. #region Win32 Macro-Like helpers
  616. internal static int X_LPARAM(int lParam)
  617. {
  618. return (lParam & 0xffff);
  619. }
  620. internal static int Y_LPARAM(int lParam)
  621. {
  622. return (lParam >> 16);
  623. }
  624. internal static Point GetPointFromLPARAM(int lParam)
  625. {
  626. return new Point(X_LPARAM(lParam), Y_LPARAM(lParam));
  627. }
  628. internal static int LOW_ORDER(int param)
  629. {
  630. return (ushort)param /*(param & 0xffff)*/;
  631. }
  632. internal static int HIGH_ORDER(int param)
  633. {
  634. return (param >> 16);
  635. }
  636. internal static int INDEXTOOVERLAYMASK(int index)
  637. {
  638. return (int)((uint)index << 8);
  639. }
  640. internal static int OVERLAYMASKTOINDEX(int index)
  641. {
  642. return (int)((uint)index >> 8);
  643. }
  644. internal static int INDEXTOSTATEIMAGEMASK(int i)
  645. {
  646. return i << 12;
  647. }
  648. internal static int STATEIMAGEMASKTOINDEX(int i)
  649. {
  650. return (int)((uint)i >> 12);
  651. }
  652. internal static short HRESULT_CODE(int hr)
  653. {
  654. return (short)(hr & 0xFFFF);
  655. }
  656. internal static bool SUCCEEDED(int status)
  657. {
  658. return (status >= 0);
  659. }
  660. internal static bool FAILED(int status)
  661. {
  662. return (status < 0);
  663. }
  664. internal static int MAKEINTRESOURCE(int res)
  665. {
  666. return 0x0000FFFF & res;
  667. }
  668. internal static int MAKELONG(int lo, int hi)
  669. {
  670. return (hi << 16) | (lo & 0x0000ffff);
  671. }
  672. #endregion
  673. #region Mono win32 Fuinctions
  674. internal delegate IntPtr WndProc (IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
  675. [DllImport ("user32.dll",
  676. CallingConvention = CallingConvention.StdCall,
  677. CharSet = CharSet.Ansi, EntryPoint = "RegisterClassA")]
  678. internal static extern uint RegisterClass(ref WNDCLASS wndClass);
  679. #region Added by Dennis hayes 10-20-2002
  680. //correct?
  681. [DllImport ("user32.dll",
  682. CallingConvention = CallingConvention.StdCall,
  683. CharSet = CharSet.Auto,EntryPoint="SendMessageA")]
  684. internal static extern uint SendMessage(
  685. IntPtr hWnd, uint Msg,
  686. IntPtr wParam, IntPtr lParam);
  687. [DllImport ("user32.dll",
  688. CallingConvention = CallingConvention.StdCall,
  689. CharSet = CharSet.Auto)]
  690. internal static extern bool GetWindowPlacement(
  691. IntPtr hWnd,
  692. ref WINDOWPLACEMENT lpwndpl // position data
  693. );
  694. #endregion
  695. [DllImport ("user32.dll",
  696. CallingConvention = CallingConvention.StdCall,
  697. CharSet = CharSet.Ansi)]
  698. internal static extern IntPtr CreateWindowEx (
  699. uint dwExStyle, string lpClassName,
  700. string lpWindowName, uint dwStyle,
  701. int x, int y, int nWidth, int nHeight,
  702. IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance,
  703. /* [ MarshalAs( UnmanagedType.AsAny )]
  704. object lpParam);*/
  705. IntPtr lpParam );
  706. [DllImport ("user32.dll",
  707. CallingConvention = CallingConvention.StdCall,
  708. CharSet = CharSet.Auto)]
  709. internal static extern IntPtr CreateMenu ();
  710. [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
  711. internal static extern IntPtr CreatePopupMenu ( );
  712. [DllImport ("user32.dll",
  713. CallingConvention = CallingConvention.StdCall,
  714. CharSet = CharSet.Ansi)]
  715. internal static extern bool AppendMenuA(IntPtr hMenu, uint uflags, IntPtr NewItem, string item);
  716. [DllImport ("user32.dll",
  717. CallingConvention = CallingConvention.StdCall)]
  718. internal static extern bool DestroyMenu (IntPtr hMenu);
  719. [DllImport ("user32.dll", CallingConvention =
  720. CallingConvention.StdCall, CharSet = CharSet.Auto)]
  721. internal extern static IntPtr DefWindowProcA (
  722. IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
  723. [DllImport ("user32.dll", CallingConvention =
  724. CallingConvention.StdCall, CharSet = CharSet.Auto)]
  725. internal extern static int DestroyWindow (IntPtr hWnd);
  726. [DllImport ("user32.dll", CallingConvention =
  727. CallingConvention.StdCall, CharSet = CharSet.Auto)]
  728. internal static extern int ShowWindow (IntPtr hWnd,
  729. uint nCmdShow);
  730. [DllImport ("user32.dll", CallingConvention =
  731. CallingConvention.StdCall,CharSet = CharSet.Auto)]
  732. internal static extern int GetMessageA (ref MSG msg, int hwnd,
  733. int msgFrom, int msgTo);
  734. [DllImport ("user32.dll", CallingConvention =
  735. CallingConvention.StdCall, CharSet = CharSet.Auto)]
  736. internal static extern int TranslateMessage (ref MSG msg);
  737. [DllImport ("user32.dll", CallingConvention =
  738. CallingConvention.StdCall, CharSet = CharSet.Auto)]
  739. internal static extern int DispatchMessageA (ref MSG msg);
  740. [DllImport ("user32.dll", CallingConvention =
  741. CallingConvention.StdCall, CharSet = CharSet.Auto)]
  742. internal static extern int PeekMessageA (
  743. ref MSG msg, IntPtr hWnd, uint wMsgFilterMin,
  744. uint wMsgFilterMax, uint wRemoveMsg);
  745. [DllImport ("user32.dll", CallingConvention =
  746. CallingConvention.StdCall,
  747. CharSet = CharSet.Auto)]
  748. internal extern static void PostQuitMessage (int nExitCode);
  749. [DllImport ("user32.dll", CallingConvention =
  750. CallingConvention.StdCall,
  751. CharSet = CharSet.Auto)]
  752. internal extern static IntPtr SetActiveWindow (IntPtr hWnd);
  753. [DllImport ("user32.dll", CallingConvention =
  754. CallingConvention.StdCall,
  755. CharSet = CharSet.Auto)]
  756. internal extern static int CloseWindow (IntPtr hWnd);
  757. [DllImport ("user32.dll", CallingConvention =
  758. CallingConvention.StdCall,
  759. CharSet = CharSet.Auto)]
  760. internal extern static int SetWindowPos (
  761. IntPtr hWnd, SetWindowPosZOrder pos,
  762. int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
  763. [DllImport ("user32.dll", CallingConvention =
  764. CallingConvention.StdCall,
  765. CharSet = CharSet.Auto)]
  766. internal extern static int SetWindowPos (
  767. IntPtr hWnd, IntPtr hWndInsertAfter,
  768. int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
  769. [DllImport ("user32.dll",
  770. CallingConvention = CallingConvention.StdCall,
  771. CharSet = CharSet.Ansi)]
  772. internal static extern int MessageBoxA (
  773. IntPtr hWnd, string pText, string pCaption, uint uType);
  774. [DllImport ("user32.dll",
  775. CallingConvention = CallingConvention.StdCall,
  776. CharSet = CharSet.Auto)]
  777. internal static extern IntPtr SetParent (
  778. IntPtr hWndChild, IntPtr hWndNewParent);
  779. [DllImport ("user32.dll",
  780. CallingConvention = CallingConvention.StdCall,
  781. CharSet = CharSet.Auto)]
  782. internal static extern IntPtr GetParent (IntPtr hWnd);
  783. [DllImport ("user32.dll",
  784. CallingConvention = CallingConvention.StdCall,
  785. CharSet = CharSet.Auto)]
  786. internal static extern IntPtr GetWindow (IntPtr hWnd, uint uCmd);
  787. [DllImport ("user32.dll",
  788. CallingConvention = CallingConvention.StdCall,
  789. CharSet = CharSet.Ansi)]
  790. internal static extern bool SetWindowTextA (
  791. IntPtr hWnd, string lpString);
  792. [DllImport ("user32.dll",
  793. CallingConvention = CallingConvention.StdCall,
  794. CharSet = CharSet.Auto)]
  795. internal static extern bool UpdateWindow (IntPtr hWnd);
  796. [DllImport ("user32.dll",
  797. CallingConvention = CallingConvention.StdCall,
  798. CharSet = CharSet.Auto)]
  799. internal static extern IntPtr GetDC (IntPtr hWnd);
  800. [DllImport ("user32.dll",
  801. CallingConvention = CallingConvention.StdCall,
  802. CharSet = CharSet.Auto)]
  803. internal static extern int ReleaseDC (IntPtr hWnd, IntPtr hDC);
  804. [DllImport ("user32.dll",
  805. CallingConvention = CallingConvention.StdCall,
  806. CharSet = CharSet.Auto)]
  807. internal static extern IntPtr GetFocus();
  808. [DllImport ("user32.dll",
  809. CallingConvention = CallingConvention.StdCall,
  810. CharSet = CharSet.Auto)]
  811. internal static extern IntPtr SetFocus (IntPtr hWnd);
  812. [DllImport ("user32.dll",
  813. CallingConvention = CallingConvention.StdCall,
  814. CharSet = CharSet.Auto)]
  815. internal static extern bool IsWindowEnabled (IntPtr hWnd);
  816. [DllImport ("user32.dll",
  817. CallingConvention = CallingConvention.StdCall,
  818. CharSet = CharSet.Auto)]
  819. internal static extern bool IsMenu (IntPtr hWnd);
  820. [DllImport ("user32.dll",
  821. CallingConvention = CallingConvention.StdCall,
  822. CharSet = CharSet.Auto)]
  823. internal static extern bool EnableWindow (
  824. IntPtr hWnd, bool bEnable);
  825. [DllImport ("user32.dll",
  826. CallingConvention = CallingConvention.StdCall,
  827. CharSet = CharSet.Ansi)]
  828. internal static extern bool IsDialogMessage (
  829. IntPtr hWnd, ref MSG mes);
  830. [DllImport ("user32.dll",
  831. CallingConvention = CallingConvention.StdCall,
  832. CharSet = CharSet.Auto)]
  833. internal static extern bool GetWindowRect (
  834. IntPtr hWnd, ref RECT lpRect);
  835. [DllImport ("user32.dll",
  836. CallingConvention = CallingConvention.StdCall,
  837. CharSet = CharSet.Auto)]
  838. internal static extern bool GetClientRect (
  839. IntPtr hWnd, ref RECT lpRect);
  840. [DllImport ("user32.dll",
  841. CallingConvention = CallingConvention.StdCall,
  842. CharSet = CharSet.Auto)]
  843. internal static extern bool InvalidateRect (
  844. IntPtr hWnd, ref RECT lpRect, bool bErase);
  845. [DllImport ("user32.dll",
  846. CallingConvention = CallingConvention.StdCall,
  847. CharSet = CharSet.Auto)]
  848. internal static extern IntPtr GetCapture ();
  849. [DllImport ("user32.dll",
  850. CallingConvention = CallingConvention.StdCall,
  851. CharSet = CharSet.Auto)]
  852. internal static extern IntPtr SetCapture (IntPtr hWnd);
  853. [DllImport ("user32.dll",
  854. CallingConvention = CallingConvention.StdCall,
  855. CharSet = CharSet.Auto)]
  856. internal static extern bool ReleaseCapture ();
  857. [DllImport ("user32.dll",
  858. CallingConvention = CallingConvention.StdCall,
  859. CharSet = CharSet.Auto)]
  860. internal static extern int GetWindowTextA (
  861. IntPtr hWnd, StringBuilder lpString, int nMaxCount);
  862. [DllImport ("user32.dll",
  863. CallingConvention = CallingConvention.StdCall,
  864. CharSet = CharSet.Auto)]
  865. internal static extern int GetWindowTextLengthA (IntPtr hWnd);
  866. [DllImport ("user32.dll",
  867. CallingConvention = CallingConvention.StdCall,
  868. CharSet = CharSet.Auto)]
  869. internal static extern bool GetCursorPos (ref POINT lpPoint);
  870. #endregion
  871. internal static void UpdateWindowStyle( IntPtr hwnd, int RemoveStyle, int AddStyle ) {
  872. UpdateWindowStyleImpl ( hwnd, RemoveStyle, AddStyle, GetWindowLongFlag.GWL_STYLE );
  873. }
  874. internal static void UpdateWindowExStyle( IntPtr hwnd, int RemoveStyle, int AddStyle ) {
  875. UpdateWindowStyleImpl ( hwnd, RemoveStyle, AddStyle, GetWindowLongFlag.GWL_EXSTYLE );
  876. }
  877. internal static void UpdateWindowStyleImpl( IntPtr hwnd, int RemoveStyle, int AddStyle, GetWindowLongFlag flag) {
  878. if( Win32.IsWindow ( hwnd ) ) {
  879. int style = Win32.GetWindowLong( hwnd, flag ).ToInt32();
  880. style &= ~RemoveStyle;
  881. style |= AddStyle;
  882. Win32.SetWindowLong(hwnd, flag, style);
  883. Win32.SetWindowPos(hwnd, 0, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE |
  884. SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOSIZE |
  885. SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED);
  886. }
  887. }
  888. internal static ButtonStyles ContentAlignment2SystemButtonStyle( ContentAlignment contentAlign) {
  889. ButtonStyles sysButtonStyle = 0;
  890. if( contentAlign == ContentAlignment.BottomCenter ||
  891. contentAlign == ContentAlignment.BottomLeft ||
  892. contentAlign == ContentAlignment.BottomRight) {
  893. sysButtonStyle |= ButtonStyles.BS_BOTTOM;
  894. }
  895. else if(contentAlign == ContentAlignment.TopCenter ||
  896. contentAlign == ContentAlignment.TopLeft ||
  897. contentAlign == ContentAlignment.TopRight) {
  898. sysButtonStyle |= ButtonStyles.BS_TOP;
  899. }
  900. else {
  901. sysButtonStyle |= ButtonStyles.BS_VCENTER;
  902. }
  903. if( contentAlign == ContentAlignment.BottomLeft ||
  904. contentAlign == ContentAlignment.MiddleLeft ||
  905. contentAlign == ContentAlignment.TopLeft) {
  906. sysButtonStyle |= ButtonStyles.BS_LEFT;
  907. }
  908. else if(contentAlign == ContentAlignment.BottomRight ||
  909. contentAlign == ContentAlignment.MiddleRight ||
  910. contentAlign == ContentAlignment.TopRight) {
  911. sysButtonStyle |= ButtonStyles.BS_RIGHT;
  912. }
  913. else {
  914. sysButtonStyle |= ButtonStyles.BS_CENTER;
  915. }
  916. return sysButtonStyle;
  917. }
  918. internal static StringFormat ContentAlignment2StringFormat( ContentAlignment contentAlign) {
  919. StringAlignment alignment = 0;
  920. StringAlignment lineAlignment = 0;
  921. if( contentAlign == ContentAlignment.BottomCenter ||
  922. contentAlign == ContentAlignment.BottomLeft ||
  923. contentAlign == ContentAlignment.BottomRight) {
  924. lineAlignment = StringAlignment.Far;
  925. }
  926. else if(contentAlign == ContentAlignment.TopCenter ||
  927. contentAlign == ContentAlignment.TopLeft ||
  928. contentAlign == ContentAlignment.TopRight) {
  929. lineAlignment = StringAlignment.Near;
  930. }
  931. else {
  932. lineAlignment = StringAlignment.Center;
  933. }
  934. if( contentAlign == ContentAlignment.BottomLeft ||
  935. contentAlign == ContentAlignment.MiddleLeft ||
  936. contentAlign == ContentAlignment.TopLeft) {
  937. alignment = StringAlignment.Near;
  938. }
  939. else if(contentAlign == ContentAlignment.BottomRight ||
  940. contentAlign == ContentAlignment.MiddleRight ||
  941. contentAlign == ContentAlignment.TopRight) {
  942. alignment = StringAlignment.Far;
  943. }
  944. else {
  945. alignment = StringAlignment.Center;
  946. }
  947. StringFormat result = new StringFormat();
  948. result.Alignment = alignment;
  949. result.LineAlignment = lineAlignment;
  950. return result;
  951. }
  952. internal static DrawTextFormatFlags ContentAlignment2DrawTextFormat( ContentAlignment contentAlign) {
  953. DrawTextFormatFlags format = 0;
  954. if( contentAlign == ContentAlignment.BottomCenter ||
  955. contentAlign == ContentAlignment.BottomLeft ||
  956. contentAlign == ContentAlignment.BottomRight) {
  957. format |= DrawTextFormatFlags.DT_BOTTOM;
  958. }
  959. else if(contentAlign == ContentAlignment.TopCenter ||
  960. contentAlign == ContentAlignment.TopLeft ||
  961. contentAlign == ContentAlignment.TopRight) {
  962. format |= DrawTextFormatFlags.DT_TOP;
  963. }
  964. else {
  965. format |= DrawTextFormatFlags.DT_VCENTER;
  966. }
  967. if( contentAlign == ContentAlignment.BottomLeft ||
  968. contentAlign == ContentAlignment.MiddleLeft ||
  969. contentAlign == ContentAlignment.TopLeft) {
  970. format |= DrawTextFormatFlags.DT_LEFT;
  971. }
  972. else if(contentAlign == ContentAlignment.BottomRight ||
  973. contentAlign == ContentAlignment.MiddleRight ||
  974. contentAlign == ContentAlignment.TopRight) {
  975. format |= DrawTextFormatFlags.DT_RIGHT;
  976. }
  977. else {
  978. format |= DrawTextFormatFlags.DT_CENTER;
  979. }
  980. return format;
  981. }
  982. internal static DrawTextFormatFlags StringFormat2DrawTextFormat( StringFormat strFormat) {
  983. DrawTextFormatFlags format = 0;
  984. if( strFormat.Alignment == StringAlignment.Far) {
  985. format |= DrawTextFormatFlags.DT_BOTTOM;
  986. }
  987. else if(strFormat.Alignment == StringAlignment.Near) {
  988. format |= DrawTextFormatFlags.DT_TOP;
  989. }
  990. else {
  991. format |= DrawTextFormatFlags.DT_VCENTER;
  992. }
  993. if( strFormat.LineAlignment == StringAlignment.Near) {
  994. format |= DrawTextFormatFlags.DT_LEFT;
  995. }
  996. else if(strFormat.LineAlignment == StringAlignment.Far) {
  997. format |= DrawTextFormatFlags.DT_RIGHT;
  998. }
  999. else {
  1000. format |= DrawTextFormatFlags.DT_CENTER;
  1001. }
  1002. return format;
  1003. }
  1004. internal static TreeViewAction uint2TreeViewAction( uint action )
  1005. {
  1006. if ( ( action & (uint)TreeViewItemExpansion.TVE_EXPAND ) != 0 )
  1007. return TreeViewAction.Expand;
  1008. if ( ( action & (uint)TreeViewItemExpansion.TVE_COLLAPSE ) != 0 )
  1009. return TreeViewAction.Collapse;
  1010. return TreeViewAction.Unknown;
  1011. }
  1012. internal static void DrawText(Graphics paintOn, string text, Font font, Color color, Rectangle rect, ContentAlignment alignment) {
  1013. RECT rc = new RECT();
  1014. rc.left = rect.Left;
  1015. rc.top = rect.Top;
  1016. rc.right = rect.Right;
  1017. rc.bottom = rect.Bottom;
  1018. IntPtr hdc = paintOn.GetHdc();
  1019. int prevColor = Win32.SetTextColor(hdc, RGB(color));
  1020. IntPtr prevFont = Win32.SelectObject(hdc, font.ToHfont());
  1021. BackgroundMode prevBkMode = Win32.SetBkMode(hdc, BackgroundMode.TRANSPARENT);
  1022. Win32.DrawText(hdc, text, text.Length, ref rc,
  1023. DrawTextFormatFlags.DT_SINGLELINE | Win32.ContentAlignment2DrawTextFormat(alignment));
  1024. Win32.SetBkMode(hdc, prevBkMode);
  1025. Win32.SelectObject(hdc, prevFont);
  1026. Win32.SetTextColor(hdc, prevColor);
  1027. paintOn.ReleaseHdc(hdc);
  1028. }
  1029. internal static SIZE GetTextExtent ( IntPtr hWnd, string text ) {
  1030. IntPtr hOldFont = new IntPtr ( 0 );
  1031. IntPtr hFont = new IntPtr ( Win32.SendMessage ( hWnd, (int)Msg.WM_GETFONT, 0, 0 ) );
  1032. IntPtr hDC = Win32.GetWindowDC ( hWnd );
  1033. if ( hFont != IntPtr.Zero )
  1034. hOldFont = Win32.SelectObject ( hDC, hFont );
  1035. SIZE size = new SIZE();
  1036. Win32.GetTextExtentPoint32 ( hDC, text, text.Length, ref size);
  1037. if ( hOldFont != IntPtr.Zero )
  1038. Win32.SelectObject ( hDC, hOldFont );
  1039. Win32.ReleaseDC ( hWnd, hDC );
  1040. return size;
  1041. }
  1042. internal static int getBorderStyle ( BorderStyle style )
  1043. {
  1044. if ( style == BorderStyle.FixedSingle )
  1045. return (int) WindowStyles.WS_BORDER;
  1046. return 0;
  1047. }
  1048. internal static int getBorderExStyle ( BorderStyle style )
  1049. {
  1050. if ( style == BorderStyle.Fixed3D )
  1051. return (int) (int)WindowExStyles.WS_EX_CLIENTEDGE;
  1052. return 0;
  1053. }
  1054. [DllImport ("libwinnt.dll.so", EntryPoint="PROCESS_InitWine")]
  1055. extern static void PROCESS_InitWine (int argc, string [] args);
  1056. [DllImport ("libwinnt.dll.so", EntryPoint="LoadLibraryA")]
  1057. extern static void NTDLL_LoadLibraryA (string s);
  1058. static string[] WinColors = {
  1059. "COLOR_SCROLLBAR",
  1060. "COLOR_BACKGROUND",
  1061. "COLOR_ACTIVECAPTION",
  1062. "COLOR_INACTIVECAPTION",
  1063. "COLOR_MENU",
  1064. "COLOR_WINDOW",
  1065. "COLOR_WINDOWFRAMET",
  1066. "COLOR_MENUTEXT",
  1067. "COLOR_WINDOWTEXT",
  1068. "COLOR_CAPTIONTEXT",
  1069. "COLOR_ACTIVEBORDER",
  1070. "COLOR_INACTIVEBORDER",
  1071. "COLOR_APPWORKSPACE",
  1072. "COLOR_HIGHLIGHT",
  1073. "COLOR_HIGHLIGHTTEXT",
  1074. "COLOR_BTNFACE",
  1075. "COLOR_BTNSHADOW",
  1076. "COLOR_GRAYTEXT",
  1077. "COLOR_BTNTEXT",
  1078. "COLOR_INACTIVECAPTIONTEXT",
  1079. "COLOR_BTNHIGHLIGHT",
  1080. "COLOR_3DDKSHADOW",
  1081. "COLOR_3DLIGHT",
  1082. "COLOR_INFOTEXT",
  1083. "COLOR_INFOBK",
  1084. "COLOR_ALTERNATEBTNFACE",
  1085. "COLOR_HOTLIGHT",
  1086. "COLOR_GRADIENTACTIVECAPTION",
  1087. "COLOR_GRADIENTINACTIVECAPTION"
  1088. };
  1089. static uint[] GetGtkSharpColors() {
  1090. string file = Path.Combine(Environment.GetEnvironmentVariable ("HOME"),Path.Combine(".gnome", "colors"));
  1091. if (File.Exists(file)) {
  1092. try {
  1093. XmlDocument doc1 = new XmlDocument();
  1094. doc1.Load(file);
  1095. XmlElement root = doc1.DocumentElement;
  1096. int i = 0;
  1097. uint[] colors = new UInt32[29];
  1098. foreach (string colorname in WinColors) {
  1099. XmlNode node = root.SelectSingleNode("/settings/colors/color[@name=\"" + colorname + "\"]");
  1100. if(node == null || node.InnerXml == "")
  1101. colors[i] = 255000000;
  1102. else
  1103. colors[i] = Convert.ToUInt32(node.InnerXml);
  1104. i++;
  1105. }
  1106. return colors;
  1107. }
  1108. catch {}
  1109. }
  1110. else {
  1111. Console.WriteLine("WARNING: Gtk+ colors were not applied. Run 'gtkswf' first.");
  1112. }
  1113. return null;
  1114. }
  1115. internal static bool RunningOnUnix = false;
  1116. //
  1117. // Used to initialize the runtime
  1118. //
  1119. static Win32 ()
  1120. {
  1121. // FIXME: this is definitely not the right way to understand that we are on Linux
  1122. RunningOnUnix = System.IO.Path.DirectorySeparatorChar == '/';
  1123. //
  1124. // Tell System.Drawing to use the Wine function drawing.
  1125. //
  1126. Thread.GetDomain ().SetData ("Mono.Running.Windows.Forms", true);
  1127. if (!RunningOnUnix)
  1128. return;
  1129. string new_mode = Environment.GetEnvironmentVariable ("SWF");
  1130. if (new_mode == null || new_mode == "1"){
  1131. Console.WriteLine ("MonoWin32: Initializing WineLib");
  1132. } else {
  1133. Console.WriteLine ("MonoWin32: Needs Wine MonoStub");
  1134. return;
  1135. }
  1136. string [] args = new string [1];
  1137. args [0] = "mono";
  1138. PROCESS_InitWine (0, args);
  1139. NTDLL_LoadLibraryA ("kernel32.dll");
  1140. NTDLL_LoadLibraryA ("user32.dll");
  1141. NTDLL_LoadLibraryA ("comctl32.dll");
  1142. string gtk_colors = Environment.GetEnvironmentVariable ("SWF_GTK_COLORS");
  1143. if (gtk_colors == "1") {
  1144. int[] elements = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28};
  1145. uint[] colors = GetGtkSharpColors();
  1146. if (colors != null)
  1147. SetSysColors(29, elements, colors);
  1148. }
  1149. }
  1150. }
  1151. }