| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400 |
- /*
- * Copyright (C) 5/11/2002 Carlos Harvey Perez
- * Modifcations and additons, Copyright Ximian 2002/3
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject
- * to the following conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT.
- * IN NO EVENT SHALL CARLOS HARVEY PEREZ BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
- * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of Carlos Harvey Perez
- * shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written
- * authorization from Carlos Harvey Perez.
- */
- using System;
- using System.Threading;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Diagnostics;
- using System.Reflection;
- using System.Xml;
- using System.IO;
- //using UtilityLibrary.WinControls;
- //namespace UtilityLibrary.Win32
- namespace System.Windows.Forms{
- //
- // The following methods have not been exposed by WineLib yet,
- // we move them here, so that errors are not displayed until
- // we actually use these functions.
- //
- public class Win32_WineLess {
- [DllImport("user32.dll", CharSet=CharSet.Ansi)]
- internal static extern IntPtr CopyCursor ( IntPtr pcur );
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize,
- IntPtr hdcSrc, ref POINT pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, UpdateLayeredWindowFlags dwFlags);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int GetScrollBarInfo(IntPtr hWnd, SystemObject id, ref SCROLLBARINFO sbi);
- [DllImport("comctl32.dll", EntryPoint="DllGetVersion")]
- internal extern static int GetCommonControlDLLVersion(ref DLLVERSIONINFO dvi);
- [DllImport ("comdlg32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern bool GetOpenFileName ( ref OPENFILENAME lpofn );
-
- [DllImport ("comdlg32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern bool GetSaveFileName ( ref OPENFILENAME lpofn );
- [DllImport ("comdlg32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern bool ChooseColor ( ref CHOOSECOLOR lpofn );
-
-
- [DllImport ("comdlg32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern bool PrintDlg (IntPtr pDlg);
-
-
- [DllImport ("comdlg32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern bool ChooseFont ( ref CHOOSEFONT lpcf );
- [DllImport ("comdlg32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern uint CommDlgExtendedError ( );
- }
-
- /// <summary>
- /// Windows API Functions
- /// </summary>
- public class Win32
- {
- #region Constructors
- // No need to construct this object
- #endregion
-
- #region Constans values
- internal const string TOOLBARCLASSNAME = "ToolbarWindow32";
- internal const string REBARCLASSNAME = "ReBarWindow32";
- internal const string PROGRESSBARCLASSNAME = "msctls_progress32";
- internal const string SCROLLBAR = "SCROLLBAR";
- internal const string TOOLTIPS_CLASS = "tooltips_class32";
- internal const string MDICLIENTCLASSNAME = "MDICLIENT";
- internal const string TABCONTROL = "SysTabControl32";
- internal const string DEFAULT_WINDOW_CLASS = "mono_scrollable_control";
- internal const string TREEVIEW_CLASS = "SysTreeView32";
- internal const string TOOLBAR_CLASS = "ToolbarWindow32";
- #endregion
- #region CallBacks
- internal delegate IntPtr FnHookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam);
- internal delegate IntPtr HookProc(int nCode, IntPtr wParam, IntPtr lParam);
- internal delegate int CompareFunc(IntPtr param1, IntPtr param2, IntPtr sortParam);
- internal delegate int WinProc(IntPtr hWnd, int message, int wParam, int lParam);
- internal delegate int WinProcMsg(IntPtr hWnd, Msg message, int wParam, int lParam);
- #endregion
- #region Kernel32.dll functions
- [DllImport("kernel32.dll", ExactSpelling=true, CharSet=CharSet.Auto)]
- internal static extern int GetCurrentThreadId();
- [DllImport("kernel32.dll")]
- internal static extern int GetDriveType(string rootPathName);
- [DllImport("kernel32.dll")]
- internal static extern int GetVolumeInformation(string drivePath,
- StringBuilder volumeNameBuffer,
- int driveNameBufferSize,
- out int serialNumber,
- out int maxFileNameLength,
- out int fileSystemFlags,
- StringBuilder systemNameBuffer,
- int systemNameBufferSize);
- [DllImport("kernel32.dll")]
- internal static extern IntPtr LoadLibraryA(string filename);
-
- [DllImport("kernel32.dll")]
- internal static extern bool FreeLibrary(IntPtr handle);
-
- [DllImport("kernel32.dll", EntryPoint="OutputDebugStringW")]
- internal static extern void OutputDebugString(string message);
- [DllImport ("kernel32.dll", CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal extern static uint GetLastError ();
-
- [DllImport ("kernel32.dll", CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto, EntryPoint = "FormatMessageW")]
- internal extern static uint FormatMessage (
- uint flags, IntPtr lpSource,uint messageId, uint languageId,
- StringBuilder lpBuffer, int nSize, IntPtr Arguments);
-
- internal static string FormatMessage(uint error) {
- StringBuilder sb = new StringBuilder(2048);
- Win32.FormatMessage( (uint)(FM_.FORMAT_MESSAGE_FROM_SYSTEM | FM_.FORMAT_MESSAGE_IGNORE_INSERTS),
- IntPtr.Zero, error, 0, sb, sb.Capacity, IntPtr.Zero);
- return sb.ToString();
- }
-
- [DllImport ("kernel32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal extern static int wine_get_unix_file_name (string dos, IntPtr unix, int len);
-
- internal static string wine_get_unix_file_name (string dos)
- {
- string result = dos;
- if (RunningOnUnix){
- // FIXME: shall we have a static buffer here ?
- IntPtr tempBuf = Marshal.AllocHGlobal(2048);
- if( Win32.wine_get_unix_file_name( dos, tempBuf, 2048) != 0){
- result = Marshal.PtrToStringAnsi(tempBuf);
- }
- Marshal.FreeHGlobal(tempBuf);
- }
- return result;
- }
- #endregion
-
- #region Gdi32.dll functions
- [DllImport("gdi32.dll")]
- static internal extern bool StretchBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
- IntPtr hDCSrc, int XOriginScr, int YOriginSrc, int WidthScr, int HeightScr, PatBltTypes Rop);
- [DllImport("gdi32.dll")]
- static internal extern IntPtr CreateCompatibleDC(IntPtr hDC);
- [DllImport("gdi32.dll")]
- static internal extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int Width, int Heigth);
- [DllImport("gdi32.dll")]
- static internal extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
- [DllImport("gdi32.dll")]
- static internal extern bool BitBlt(IntPtr hDCDest, int XOriginDest, int YOriginDest, int WidthDest, int HeightDest,
- IntPtr hDCSrc, int XOriginScr, int YOriginSrc, PatBltTypes flags);
- [DllImport("gdi32.dll")]
- static internal extern IntPtr DeleteDC(IntPtr hDC);
- [DllImport("gdi32.dll")]
- static internal extern bool PatBlt(IntPtr hDC, int XLeft, int YLeft, int Width, int Height, int Rop);
- [DllImport("gdi32.dll")]
- static internal extern bool DeleteObject(IntPtr hObject);
- [DllImport("gdi32.dll")]
- static internal extern int GetPixel(IntPtr hDC, int XPos, int YPos);
- [DllImport("gdi32.dll")]
- static internal extern int SetMapMode(IntPtr hDC, int fnMapMode);
- [DllImport("gdi32.dll")]
- static internal extern int GetObjectType(IntPtr handle);
- [DllImport("gdi32.dll")]
- internal static extern IntPtr CreateDIBSection(IntPtr hdc, ref BITMAPINFO_FLAT bmi,
- int iUsage, ref int ppvBits, IntPtr hSection, int dwOffset);
- [DllImport("gdi32.dll")]
- internal static extern int GetDIBits(IntPtr hDC, IntPtr hbm, int StartScan, int ScanLines, int lpBits, BITMAPINFOHEADER bmi, int usage);
- [DllImport("gdi32.dll")]
- internal static extern int GetDIBits(IntPtr hdc, IntPtr hbm, int StartScan, int ScanLines, int lpBits, ref BITMAPINFO_FLAT bmi, int usage);
- [DllImport("gdi32.dll")]
- internal static extern IntPtr GetPaletteEntries(IntPtr hpal, int iStartIndex, int nEntries, byte[] lppe);
- [DllImport("gdi32.dll")]
- internal static extern IntPtr GetSystemPaletteEntries(IntPtr hdc, int iStartIndex, int nEntries, byte[] lppe);
- [DllImport("gdi32.dll")]
- internal static extern int SetDCBrushColor(IntPtr hdc, int crColor);
- [DllImport("gdi32.dll")]
- internal static extern IntPtr CreateSolidBrush(int crColor);
- [DllImport("gdi32.dll")]
- internal static extern BackgroundMode SetBkMode(IntPtr hDC, BackgroundMode mode);
- [DllImport("gdi32.dll")]
- internal static extern int SetViewportOrgEx(IntPtr hdc, int x, int y, int param);
- [DllImport("gdi32.dll")]
- internal static extern int SetTextColor(IntPtr hDC, int colorRef);
- [DllImport("gdi32.dll")]
- internal static extern int SetStretchBltMode(IntPtr hDC, StrechModeFlags StrechMode);
- [DllImport("gdi32.dll")]
- internal static extern int SetPixel(IntPtr hDC, int x, int y, int color);
- [DllImport("gdi32.dll")]
- internal static extern IntPtr CreatePen(PenStyle penStyle, int width, int color);
- [DllImport("gdi32.dll")]
- internal static extern int GetClipRgn(IntPtr hDC, ref IntPtr region);
- [DllImport("gdi32.dll")]
- internal static extern IntPtr CreateRectRgn(int nLeftRect, int TopRect, int nRightRect, int nBottomRect);
- [DllImport("gdi32.dll")]
- internal static extern int GetRgnBox(IntPtr hRegion, ref RECT rc);
- [DllImport("gdi32.dll")]
- internal static extern IntPtr GetStockObject(GSO_ objectType);
- [DllImport("gdi32.dll",CharSet = CharSet.Ansi,EntryPoint="ExtTextOutA")]
- internal static extern int ExtTextOut(IntPtr hdc, int x, int y,
- ExtTextOutFlags options, ref RECT rc, int str, int strLen, IntPtr distances);
- [DllImport("gdi32.dll",CharSet = CharSet.Ansi,EntryPoint="ExtTextOutA")]
- internal static extern int ExtTextOut(IntPtr hdc, int x, int y,
- ExtTextOutFlags options, ref RECT rc, string str, int strLen, IntPtr distances);
- [DllImport("gdi32.dll",CharSet = CharSet.Ansi,EntryPoint="GetTextExtentPoint32A")]
- internal static extern bool GetTextExtentPoint32(IntPtr hDC, string lpString, int cbString, ref SIZE lpSize);
- [DllImport("gdi32.dll", CallingConvention = CallingConvention.StdCall )]
- internal static extern IntPtr CreateBitmap( int nWidth, int nHeight, uint cPlanes, uint cBitsPerPel, IntPtr lpvBits );
- [DllImport("gdi32.dll", CallingConvention = CallingConvention.StdCall )]
- internal static extern int SetDIBits( IntPtr hdc, IntPtr hbmp, uint uStartScan, uint cScanLines, IntPtr lpvBits, IntPtr lpbmi, uint fuColorUse );
- [DllImport ("gdi32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern uint GetBkColor (IntPtr hdc);
- [DllImport ("gdi32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern uint SetBkColor (IntPtr hdc, uint crColor);
- internal static int RGB(Color color)
- {
- return color.R | (color.G << 8) | (color.B << 16);
- }
-
- #endregion
- #region Uxtheme.dll functions
- #if USE_UXTHEME
- [DllImport("uxtheme.dll")]
- static public extern int SetWindowTheme(IntPtr hWnd, StringBuilder AppID, StringBuilder ClassID);
- static public void DisableWindowsXPTheme(IntPtr hWnd)
- {
- // Disable using the Window XP Theme for the Window handle
- // passed as a parameter
- StringBuilder applicationName = new StringBuilder(" ", 1);
- StringBuilder classIDs = new StringBuilder(" " , 1);
- Win32.SetWindowTheme(hWnd, applicationName, classIDs);
- }
- #endif
- #endregion
-
- #region user32.dll functions
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern IntPtr GetDesktopWindow();
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool ShowWindow(IntPtr hWnd, ShowWindowStyles State);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool SetForegroundWindow(IntPtr hWnd);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool OpenClipboard(IntPtr hWndNewOwner);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool CloseClipboard();
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool EmptyClipboard();
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern IntPtr SetClipboardData( int Format, IntPtr hData);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool GetMenuItemRect(IntPtr hWnd, IntPtr hMenu, int Item, ref RECT rc);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage(IntPtr hWnd, Msg msg, int wParam, int lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref RECT lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref POINT lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, string lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage(IntPtr hWnd, Msg msg, int wParam, string lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern void SendMessage(IntPtr hWnd, ToolBarMessages msg, int wParam, ref TBBUTTON lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern void SendMessage(IntPtr hWnd, ToolBarMessages msg, int wParam, ref TBBUTTONINFO lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage(IntPtr hWnd, RebarMessages msg, int wParam, ref REBARBANDINFO lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVITEM lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi)]
- internal static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVINSERTSTRUCT lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern void SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVSORTCB lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage(IntPtr hWnd, TreeViewMessages msg, int wParam, ref TVHITTESTINFO hti);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern void SendMessage(IntPtr hWnd, ListViewMessages msg, int wParam, ref LVITEM lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern void SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, ref HDITEM lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern void SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, ref HD_HITTESTINFO hti);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage(IntPtr hWnd, HeaderControlMessages msg, int wParam, int lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="PostMessageA")]
- internal static extern IntPtr PostMessage(IntPtr hWnd, int msg, int wParam, int lParam);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="PostMessageA")]
- internal static extern IntPtr PostMessage(IntPtr hWnd, Msg msg, int wParam, int lParam);
- [DllImport("user32.dll", CharSet=CharSet.Auto, EntryPoint="SetWindowsHookExW")]
- internal static extern IntPtr SetWindowsHookEx(WindowsHookCodes hookid, HookProc pfnhook, IntPtr hinst, int threadid);
- [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
- internal static extern bool UnhookWindowsHookEx(IntPtr hhook);
- [DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
- internal static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wparam, IntPtr lparam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="DrawTextA")]
- internal extern static int DrawText(IntPtr hdc, string lpString, int nCount, ref RECT lpRect, DrawTextFormatFlags flags);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal extern static IntPtr GetDlgItem(IntPtr hDlg, int nControlID);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal extern static int InvalidateRect(IntPtr hWnd, ref RECT rc, int bErase);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal extern static int InvalidateRect(IntPtr hWnd, IntPtr rc, int bErase);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool WaitMessage();
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- internal static extern int SendMessage2ref(IntPtr hWnd, int msg, ref int wParam, ref int lParam);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="PeekMessageA")]
- internal static extern bool PeekMessage(ref MESSAGE msg, int hWnd, int wFilterMin, int wFilterMax, PeekMessageFlags flags);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="GetMessageA")]
- internal static extern bool GetMessage(ref MESSAGE msg, int hWnd, int wFilterMin, int wFilterMax);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool TranslateMessage(ref MESSAGE msg);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="DispatchMessageA")]
- internal static extern bool DispatchMessage(ref MESSAGE msg);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="LoadCursorA")]
- internal static extern IntPtr LoadCursor(IntPtr hInstance, CursorType cursor);
- [DllImport("user32.dll", CharSet=CharSet.Ansi)]
- internal static extern bool DestroyCursor ( IntPtr hCursor );
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern IntPtr SetCursor(IntPtr hCursor);
- [DllImport("user32.dll", CharSet=CharSet.Ansi)]
- internal static extern int ShowCursor ( bool bShow );
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool GetUpdateRect(IntPtr hwnd, ref RECT rect, bool erase);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool ClientToScreen(IntPtr hWnd, ref POINT pt);
-
- internal static bool ClientToScreen(IntPtr hWnd, ref RECT rect) {
- POINT pt1 = new POINT();
- pt1.x = rect.left;
- pt1.y = rect.top;
- POINT pt2 = new POINT();
- pt2.x = rect.right;
- pt2.y = rect.bottom;
- bool result = Win32.ClientToScreen(hWnd, ref pt1);
- result &= Win32.ClientToScreen(hWnd, ref pt2);
- rect.left = pt1.x;
- rect.top = pt1.y;
- rect.right = pt2.x;
- rect.bottom = pt2.y;
- return result;
- }
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool ScreenToClient(IntPtr hWnd, ref POINT pt);
- internal static bool ScreenToClient(IntPtr hWnd, ref RECT rect) {
- POINT pt1 = new POINT();
- pt1.x = rect.left;
- pt1.y = rect.top;
- POINT pt2 = new POINT();
- pt2.x = rect.right;
- pt2.y = rect.bottom;
- bool result = Win32.ScreenToClient(hWnd, ref pt1);
- result &= Win32.ScreenToClient(hWnd, ref pt2);
- rect.left = pt1.x;
- rect.top = pt1.y;
- rect.right = pt2.x;
- rect.bottom = pt2.y;
- return result;
- }
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool TrackMouseEvent(ref TRACKMOUSEEVENT tme);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern short GetKeyState(int virtKey);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern short GetAsyncKeyState(int virtKey);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern bool MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
- [DllImport("user32.dll", CharSet=CharSet.Auto, EntryPoint="GetClassNameW")]
- internal static extern int GetClassName(IntPtr hWnd, StringBuilder ClassName, int nMaxCount);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="SetWindowLongA")]
- internal static extern int SetWindowLong(IntPtr hWnd, GetWindowLongFlag flag, int dwNewLong);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="SetWindowLongA")]
- internal static extern IntPtr SetWindowLong(IntPtr hWnd, GetWindowLongFlag flag, WinProc winProc);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="SetWindowLongA")]
- internal static extern IntPtr SetWindowLong(IntPtr hWnd, GetWindowLongFlag flag, WndProc winProc);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hRegion, int flags);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern IntPtr GetWindowDC(IntPtr hWnd);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- internal static extern int FillRect(IntPtr hDC, ref RECT rect, IntPtr hBrush);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SetWindowTextA")]
- internal static extern int SetWindowText(IntPtr hWnd, string text);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="GetWindowTextA")]
- internal static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int maxCount);
- [DllImport("user32.dll", CharSet=CharSet.Ansi,EntryPoint="SendMessageA")]
- static internal extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int GetSystemMetrics(SystemMetricsCodes code);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int SetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si, int fRedraw);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int ShowScrollBar(IntPtr hWnd, int bar, int show);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int EnableScrollBar(IntPtr hWnd, int flags, int arrows);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int BringWindowToTop(IntPtr hWnd);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int GetScrollInfo(IntPtr hwnd, int bar, ref SCROLLINFO si);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy,
- ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion, ref RECT rcInvalidated, int flags);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool IsWindow(IntPtr hWnd);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool LockWindowUpdate(IntPtr hWnd);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool ValidateRect(IntPtr hWnd, ref RECT rcInvalidated);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern bool ValidateRect(IntPtr hWnd, IntPtr rc);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="GetWindowLongA")]
- static internal extern IntPtr GetWindowLong(IntPtr hWnd, GetWindowLongFlag flag);
- [DllImport("user32.dll", CharSet=CharSet.Auto, EntryPoint="SetPropW")]
- static internal extern int SetProp(IntPtr hWnd, IntPtr atom, IntPtr hData);
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="CallWindowProcA")]
- static internal extern int CallWindowProc(IntPtr hOldProc, IntPtr hWnd, int message, int wParam, int lParam);
- [DllImport("user32.dll", CharSet=CharSet.Auto)]
- static internal extern int EndMenu();
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="DefWindowProcA")]
- static internal extern int DefWindowProc(IntPtr hWnd, int message, int wParam, int lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi)]
- static internal extern IntPtr DefMDIChildProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
- [DllImport("user32.dll", CharSet=CharSet.Ansi)]
- static internal extern IntPtr DefFrameProc(IntPtr hWnd, IntPtr hWndMDIClient, Msg Msg, IntPtr wParam, IntPtr lParam);
-
- [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="LoadCursorA")]
- static internal extern IntPtr LoadCursor(IntPtr hInstance, LC_ standardCursor);
- [DllImport("user32.dll", CharSet=CharSet.Auto, EntryPoint="RegisterWindowMessageA")]
- static internal extern int RegisterWindowMessage( string message_name);
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr GetMenu (IntPtr hWnd);
-
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern int SetMenu (IntPtr hWnd, IntPtr hMenu);
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern int InsertMenuA(IntPtr hMenu, uint pos, uint uflags, IntPtr NewItem, string item);
-
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern int RemoveMenu(IntPtr hMenu, uint pos, uint uflags);
-
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern int DrawMenuBar (IntPtr hWnd);
-
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern int SetMenuDefaultItem(IntPtr hMenu, int uItem, int fByPos );
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal extern static int AdjustWindowRect( ref RECT rc, int dwStyle, int bMenu);
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal extern static int AdjustWindowRectEx( ref RECT rc, int dwStyle, int bMenu, int dwStyleEx);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern int DrawEdge(IntPtr hdc, ref RECT rc, Border3DStyle edge, Border3DSide flags);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern int DrawFrameControl(IntPtr hdc, ref RECT rc, uint uType, uint uState);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern int DrawFocusRect( IntPtr hdc, ref RECT rc);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern IntPtr WindowFromPoint( POINT pt);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern int GetSysColor( GetSysColorIndex color);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern bool SetSysColors(int cElements, int[] lpaElements, uint[] lpaRgbValues);
- internal delegate void TimerProc(IntPtr hWnd, uint uMsg, uint idEvent, int dwTime);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern uint SetTimer (IntPtr hWnd, uint nIDEvent, uint uElapse, TimerProc lpTimerFunc);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern bool KillTimer (IntPtr hWnd, uint nIDEvent);
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern IntPtr GetActiveWindow ( );
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern IntPtr GetForegroundWindow ( );
- [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool TrackPopupMenu( IntPtr hMenu, uint uFlags, int x, int y, int nReserved,
- IntPtr hWnd, IntPtr prcRect );
- #endregion
- #region Shell32.dll functions
- #if HAVE_SHELL_SUPPORT
- [DllImport("shell32.dll", CharSet=CharSet.Auto)]
- internal static extern IntPtr SHGetFileInfo(string drivePath, int fileAttributes,
- out SHFILEINFO fileInfo, int countBytesFileInfo, ShellFileInfoFlags flags);
- [DllImport("shell32.dll", CharSet=CharSet.Auto)]
- internal static extern IntPtr SHGetFileInfo(IntPtr idl, int fileAttributes,
- out SHFILEINFO fileInfo, int countBytesFileInfo, ShellFileInfoFlags flags);
- [DllImport("shell32.dll", CharSet=CharSet.Auto)]
- internal static extern int SHGetSpecialFolderLocation(IntPtr hwndOwner, ShellSpecialFolder folder, out IntPtr idl);
- [DllImport("shell32.dll", CharSet=CharSet.Auto)]
- internal static extern int SHGetMalloc(out IMalloc alloc);
- [DllImport("shell32.dll", CharSet=CharSet.Auto)]
- internal static extern int SHGetDesktopFolder(out IShellFolder folder);
- [DllImport("shell32.dll", CharSet=CharSet.Auto)]
- internal static extern int SHGetPathFromIDList(IntPtr idl, StringBuilder path);
- internal static void SHFreeMalloc(IntPtr handle)
- {
- IMalloc alloc = null;
- try
- {
- Win32.SHGetMalloc(out alloc);
- Debug.Assert(alloc != null);
- alloc.Free(handle);
- // Free allocator itself
- IUnknown iUnknown = (IUnknown)alloc;
- iUnknown.Release();
- }
- catch (Exception e)
- {
- // In case the Garbage collector is trying to free
- // this memory from its own thread
- Debug.WriteLine(e.Message);
- }
- }
- #endif
- #endregion
- #region Common Controls functions
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool InitCommonControlsEx(INITCOMMONCONTROLSEX icc);
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool InitCommonControls();
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern IntPtr ImageList_Create(int width, int height, uint flags, int count, int grow);
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool ImageList_Destroy(IntPtr handle);
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern int ImageList_Add(IntPtr imageHandle, IntPtr hBitmap, IntPtr hMask);
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool ImageList_Remove(IntPtr imageHandle, int index);
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool ImageList_SetImageCount ( IntPtr himl, uint uNewCount );
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern uint ImageList_SetBkColor ( IntPtr himl, uint clrBk );
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool ImageList_SetOverlayImage( IntPtr himl, int iImage, int iOverlay );
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool ImageList_BeginDrag(IntPtr imageHandle, int imageIndex, int xHotSpot, int yHotSpot);
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool ImageList_DragEnter(IntPtr hWndLock, int x, int y);
- [DllImport("comctl32.dll", CallingConvention = CallingConvention.StdCall)]
- internal static extern bool ImageList_DragMove(int x, int y);
- [DllImport("comctl32.dll")]
- internal static extern bool ImageList_DragLeave(IntPtr hWndLock);
- [DllImport("comctl32.dll")]
- internal static extern void ImageList_EndDrag();
- [DllImport("comctl32.dll")]
- internal static extern bool ImageList_Draw(IntPtr hImageList, int imageIndex,
- IntPtr hDCDest, int x, int y, ImageListDrawFlags flags);
- [DllImport("comctl32.dll")]
- internal static extern int ImageList_DrawEx(
- IntPtr hImageList, int imageIndex, IntPtr hDCDest, int x, int y, int dx, int dy,
- uint backColor, uint foregColor, ImageListDrawFlags flags);
- [DllImport("comctl32.dll")]
- internal static extern int ImageList_DragShowNolock(int show);
-
- [DllImport("comctl32.dll")]
- internal static extern int ImageList_AddMasked(IntPtr hImageList, IntPtr hBitmap, int crMask);
- [DllImport("comctl32.dll")]
- internal static extern int ImageList_SetDragCursorImage(IntPtr himlDrag, int iDrag, int dxHotspot, int dyHotspot);
- internal static int ImageList_DrawEx(IntPtr hImageList, int imageIndex, IntPtr hDCDest, int x, int y, int dx, int dy,
- ImageListDrawColor backColor, ImageListDrawColor foreColor, ImageListDrawFlags flags)
- {
- uint bColor = (uint)ImageListDrawColors.CLR_NONE;
- if ( backColor == ImageListDrawColor.Default )
- bColor = (uint)ImageListDrawColors.CLR_DEFAULT;
- uint fColor = (uint)ImageListDrawColors.CLR_NONE;
- if ( foreColor == ImageListDrawColor.Default )
- fColor = (uint)ImageListDrawColors.CLR_DEFAULT;
-
- // Call actual function
- return ImageList_DrawEx(hImageList, imageIndex, hDCDest, x, y, dx, dy, bColor, fColor, flags);
- }
-
- static internal bool IsCommonCtrl6()
- {
- DLLVERSIONINFO dllVersion = new DLLVERSIONINFO();
- //
- // Windows Forms using WineLib: XP theme drawing not available
- //
- if (Environment.GetEnvironmentVariable ("SWF") != null)
- return false;
-
- // We are assummng here that anything greater or equal than 6
- // will have the new XP theme drawing enable
- dllVersion.cbSize = Marshal.SizeOf(typeof(DLLVERSIONINFO));
- Win32_WineLess.GetCommonControlDLLVersion(ref dllVersion);
- return (dllVersion.dwMajorVersion >= 6);
- }
- #endregion
- #region Win32 Macro-Like helpers
- internal static int X_LPARAM(int lParam)
- {
- return (lParam & 0xffff);
- }
-
- internal static int Y_LPARAM(int lParam)
- {
- return (lParam >> 16);
- }
- internal static Point GetPointFromLPARAM(int lParam)
- {
- return new Point(X_LPARAM(lParam), Y_LPARAM(lParam));
- }
- internal static int LOW_ORDER(int param)
- {
- return (ushort)param /*(param & 0xffff)*/;
- }
- internal static int HIGH_ORDER(int param)
- {
- return (param >> 16);
- }
- internal static int INDEXTOOVERLAYMASK(int index)
- {
- return (int)((uint)index << 8);
- }
- internal static int OVERLAYMASKTOINDEX(int index)
- {
- return (int)((uint)index >> 8);
- }
- internal static int INDEXTOSTATEIMAGEMASK(int i)
- {
- return i << 12;
- }
- internal static int STATEIMAGEMASKTOINDEX(int i)
- {
- return (int)((uint)i >> 12);
- }
- internal static short HRESULT_CODE(int hr)
- {
- return (short)(hr & 0xFFFF);
- }
- internal static bool SUCCEEDED(int status)
- {
- return (status >= 0);
- }
- internal static bool FAILED(int status)
- {
- return (status < 0);
- }
- internal static int MAKEINTRESOURCE(int res)
- {
- return 0x0000FFFF & res;
- }
-
- internal static int MAKELONG(int lo, int hi)
- {
- return (hi << 16) | (lo & 0x0000ffff);
- }
- #endregion
- #region Mono win32 Fuinctions
- internal delegate IntPtr WndProc (IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
-
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi, EntryPoint = "RegisterClassA")]
- internal static extern uint RegisterClass(ref WNDCLASS wndClass);
-
- #region Added by Dennis hayes 10-20-2002
- //correct?
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto,EntryPoint="SendMessageA")]
- internal static extern uint SendMessage(
- IntPtr hWnd, uint Msg,
- IntPtr wParam, IntPtr lParam);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool GetWindowPlacement(
- IntPtr hWnd,
- ref WINDOWPLACEMENT lpwndpl // position data
- );
- #endregion
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern IntPtr CreateWindowEx (
- uint dwExStyle, string lpClassName,
- string lpWindowName, uint dwStyle,
- int x, int y, int nWidth, int nHeight,
- IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance,
- /* [ MarshalAs( UnmanagedType.AsAny )]
- object lpParam);*/
- IntPtr lpParam );
-
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr CreateMenu ();
- [DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern IntPtr CreatePopupMenu ( );
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern bool AppendMenuA(IntPtr hMenu, uint uflags, IntPtr NewItem, string item);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall)]
- internal static extern bool DestroyMenu (IntPtr hMenu);
-
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal extern static IntPtr DefWindowProcA (
- IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal extern static int DestroyWindow (IntPtr hWnd);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern int ShowWindow (IntPtr hWnd,
- uint nCmdShow);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall,CharSet = CharSet.Auto)]
- internal static extern int GetMessageA (ref MSG msg, int hwnd,
- int msgFrom, int msgTo);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern int TranslateMessage (ref MSG msg);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern int DispatchMessageA (ref MSG msg);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall, CharSet = CharSet.Auto)]
- internal static extern int PeekMessageA (
- ref MSG msg, IntPtr hWnd, uint wMsgFilterMin,
- uint wMsgFilterMax, uint wRemoveMsg);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal extern static void PostQuitMessage (int nExitCode);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal extern static IntPtr SetActiveWindow (IntPtr hWnd);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal extern static int CloseWindow (IntPtr hWnd);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal extern static int SetWindowPos (
- IntPtr hWnd, SetWindowPosZOrder pos,
- int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
- [DllImport ("user32.dll", CallingConvention =
- CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal extern static int SetWindowPos (
- IntPtr hWnd, IntPtr hWndInsertAfter,
- int X, int Y, int cx, int cy, SetWindowPosFlags uFlags);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern int MessageBoxA (
- IntPtr hWnd, string pText, string pCaption, uint uType);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr SetParent (
- IntPtr hWndChild, IntPtr hWndNewParent);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr GetParent (IntPtr hWnd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr GetWindow (IntPtr hWnd, uint uCmd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern bool SetWindowTextA (
- IntPtr hWnd, string lpString);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool UpdateWindow (IntPtr hWnd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr GetDC (IntPtr hWnd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern int ReleaseDC (IntPtr hWnd, IntPtr hDC);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr GetFocus();
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr SetFocus (IntPtr hWnd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool IsWindowEnabled (IntPtr hWnd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool IsMenu (IntPtr hWnd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool EnableWindow (
- IntPtr hWnd, bool bEnable);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Ansi)]
- internal static extern bool IsDialogMessage (
- IntPtr hWnd, ref MSG mes);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool GetWindowRect (
- IntPtr hWnd, ref RECT lpRect);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool GetClientRect (
- IntPtr hWnd, ref RECT lpRect);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool InvalidateRect (
- IntPtr hWnd, ref RECT lpRect, bool bErase);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr GetCapture ();
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern IntPtr SetCapture (IntPtr hWnd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool ReleaseCapture ();
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern int GetWindowTextA (
- IntPtr hWnd, StringBuilder lpString, int nMaxCount);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern int GetWindowTextLengthA (IntPtr hWnd);
- [DllImport ("user32.dll",
- CallingConvention = CallingConvention.StdCall,
- CharSet = CharSet.Auto)]
- internal static extern bool GetCursorPos (ref POINT lpPoint);
- #endregion
- internal static void UpdateWindowStyle( IntPtr hwnd, int RemoveStyle, int AddStyle ) {
- UpdateWindowStyleImpl ( hwnd, RemoveStyle, AddStyle, GetWindowLongFlag.GWL_STYLE );
- }
- internal static void UpdateWindowExStyle( IntPtr hwnd, int RemoveStyle, int AddStyle ) {
- UpdateWindowStyleImpl ( hwnd, RemoveStyle, AddStyle, GetWindowLongFlag.GWL_EXSTYLE );
- }
- internal static void UpdateWindowStyleImpl( IntPtr hwnd, int RemoveStyle, int AddStyle, GetWindowLongFlag flag) {
- if( Win32.IsWindow ( hwnd ) ) {
- int style = Win32.GetWindowLong( hwnd, flag ).ToInt32();
- style &= ~RemoveStyle;
- style |= AddStyle;
- Win32.SetWindowLong(hwnd, flag, style);
- Win32.SetWindowPos(hwnd, 0, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE |
- SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOSIZE |
- SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_FRAMECHANGED);
- }
- }
-
- internal static ButtonStyles ContentAlignment2SystemButtonStyle( ContentAlignment contentAlign) {
- ButtonStyles sysButtonStyle = 0;
-
- if( contentAlign == ContentAlignment.BottomCenter ||
- contentAlign == ContentAlignment.BottomLeft ||
- contentAlign == ContentAlignment.BottomRight) {
- sysButtonStyle |= ButtonStyles.BS_BOTTOM;
- }
- else if(contentAlign == ContentAlignment.TopCenter ||
- contentAlign == ContentAlignment.TopLeft ||
- contentAlign == ContentAlignment.TopRight) {
- sysButtonStyle |= ButtonStyles.BS_TOP;
- }
- else {
- sysButtonStyle |= ButtonStyles.BS_VCENTER;
- }
- if( contentAlign == ContentAlignment.BottomLeft ||
- contentAlign == ContentAlignment.MiddleLeft ||
- contentAlign == ContentAlignment.TopLeft) {
- sysButtonStyle |= ButtonStyles.BS_LEFT;
- }
- else if(contentAlign == ContentAlignment.BottomRight ||
- contentAlign == ContentAlignment.MiddleRight ||
- contentAlign == ContentAlignment.TopRight) {
- sysButtonStyle |= ButtonStyles.BS_RIGHT;
- }
- else {
- sysButtonStyle |= ButtonStyles.BS_CENTER;
- }
- return sysButtonStyle;
- }
- internal static StringFormat ContentAlignment2StringFormat( ContentAlignment contentAlign) {
- StringAlignment alignment = 0;
- StringAlignment lineAlignment = 0;
-
- if( contentAlign == ContentAlignment.BottomCenter ||
- contentAlign == ContentAlignment.BottomLeft ||
- contentAlign == ContentAlignment.BottomRight) {
- lineAlignment = StringAlignment.Far;
- }
- else if(contentAlign == ContentAlignment.TopCenter ||
- contentAlign == ContentAlignment.TopLeft ||
- contentAlign == ContentAlignment.TopRight) {
- lineAlignment = StringAlignment.Near;
- }
- else {
- lineAlignment = StringAlignment.Center;
- }
- if( contentAlign == ContentAlignment.BottomLeft ||
- contentAlign == ContentAlignment.MiddleLeft ||
- contentAlign == ContentAlignment.TopLeft) {
- alignment = StringAlignment.Near;
- }
- else if(contentAlign == ContentAlignment.BottomRight ||
- contentAlign == ContentAlignment.MiddleRight ||
- contentAlign == ContentAlignment.TopRight) {
- alignment = StringAlignment.Far;
- }
- else {
- alignment = StringAlignment.Center;
- }
- StringFormat result = new StringFormat();
- result.Alignment = alignment;
- result.LineAlignment = lineAlignment;
- return result;
- }
-
- internal static DrawTextFormatFlags ContentAlignment2DrawTextFormat( ContentAlignment contentAlign) {
- DrawTextFormatFlags format = 0;
-
- if( contentAlign == ContentAlignment.BottomCenter ||
- contentAlign == ContentAlignment.BottomLeft ||
- contentAlign == ContentAlignment.BottomRight) {
- format |= DrawTextFormatFlags.DT_BOTTOM;
- }
- else if(contentAlign == ContentAlignment.TopCenter ||
- contentAlign == ContentAlignment.TopLeft ||
- contentAlign == ContentAlignment.TopRight) {
- format |= DrawTextFormatFlags.DT_TOP;
- }
- else {
- format |= DrawTextFormatFlags.DT_VCENTER;
- }
- if( contentAlign == ContentAlignment.BottomLeft ||
- contentAlign == ContentAlignment.MiddleLeft ||
- contentAlign == ContentAlignment.TopLeft) {
- format |= DrawTextFormatFlags.DT_LEFT;
- }
- else if(contentAlign == ContentAlignment.BottomRight ||
- contentAlign == ContentAlignment.MiddleRight ||
- contentAlign == ContentAlignment.TopRight) {
- format |= DrawTextFormatFlags.DT_RIGHT;
- }
- else {
- format |= DrawTextFormatFlags.DT_CENTER;
- }
- return format;
- }
- internal static DrawTextFormatFlags StringFormat2DrawTextFormat( StringFormat strFormat) {
- DrawTextFormatFlags format = 0;
-
- if( strFormat.Alignment == StringAlignment.Far) {
- format |= DrawTextFormatFlags.DT_BOTTOM;
- }
- else if(strFormat.Alignment == StringAlignment.Near) {
- format |= DrawTextFormatFlags.DT_TOP;
- }
- else {
- format |= DrawTextFormatFlags.DT_VCENTER;
- }
- if( strFormat.LineAlignment == StringAlignment.Near) {
- format |= DrawTextFormatFlags.DT_LEFT;
- }
- else if(strFormat.LineAlignment == StringAlignment.Far) {
- format |= DrawTextFormatFlags.DT_RIGHT;
- }
- else {
- format |= DrawTextFormatFlags.DT_CENTER;
- }
- return format;
- }
- internal static TreeViewAction uint2TreeViewAction( uint action )
- {
- if ( ( action & (uint)TreeViewItemExpansion.TVE_EXPAND ) != 0 )
- return TreeViewAction.Expand;
- if ( ( action & (uint)TreeViewItemExpansion.TVE_COLLAPSE ) != 0 )
- return TreeViewAction.Collapse;
- return TreeViewAction.Unknown;
- }
-
- internal static void DrawText(Graphics paintOn, string text, Font font, Color color, Rectangle rect, ContentAlignment alignment) {
- RECT rc = new RECT();
- rc.left = rect.Left;
- rc.top = rect.Top;
- rc.right = rect.Right;
- rc.bottom = rect.Bottom;
-
- IntPtr hdc = paintOn.GetHdc();
- int prevColor = Win32.SetTextColor(hdc, RGB(color));
- IntPtr prevFont = Win32.SelectObject(hdc, font.ToHfont());
- BackgroundMode prevBkMode = Win32.SetBkMode(hdc, BackgroundMode.TRANSPARENT);
- Win32.DrawText(hdc, text, text.Length, ref rc,
- DrawTextFormatFlags.DT_SINGLELINE | Win32.ContentAlignment2DrawTextFormat(alignment));
- Win32.SetBkMode(hdc, prevBkMode);
- Win32.SelectObject(hdc, prevFont);
- Win32.SetTextColor(hdc, prevColor);
- paintOn.ReleaseHdc(hdc);
- }
- internal static SIZE GetTextExtent ( IntPtr hWnd, string text ) {
- IntPtr hOldFont = new IntPtr ( 0 );
- IntPtr hFont = new IntPtr ( Win32.SendMessage ( hWnd, (int)Msg.WM_GETFONT, 0, 0 ) );
- IntPtr hDC = Win32.GetWindowDC ( hWnd );
- if ( hFont != IntPtr.Zero )
- hOldFont = Win32.SelectObject ( hDC, hFont );
- SIZE size = new SIZE();
- Win32.GetTextExtentPoint32 ( hDC, text, text.Length, ref size);
- if ( hOldFont != IntPtr.Zero )
- Win32.SelectObject ( hDC, hOldFont );
- Win32.ReleaseDC ( hWnd, hDC );
- return size;
- }
- internal static int getBorderStyle ( BorderStyle style )
- {
- if ( style == BorderStyle.FixedSingle )
- return (int) WindowStyles.WS_BORDER;
- return 0;
- }
- internal static int getBorderExStyle ( BorderStyle style )
- {
- if ( style == BorderStyle.Fixed3D )
- return (int) (int)WindowExStyles.WS_EX_CLIENTEDGE;
- return 0;
- }
- [DllImport ("libwinnt.dll.so", EntryPoint="PROCESS_InitWine")]
- extern static void PROCESS_InitWine (int argc, string [] args);
- [DllImport ("libwinnt.dll.so", EntryPoint="LoadLibraryA")]
- extern static void NTDLL_LoadLibraryA (string s);
- static string[] WinColors = {
- "COLOR_SCROLLBAR",
- "COLOR_BACKGROUND",
- "COLOR_ACTIVECAPTION",
- "COLOR_INACTIVECAPTION",
- "COLOR_MENU",
- "COLOR_WINDOW",
- "COLOR_WINDOWFRAMET",
- "COLOR_MENUTEXT",
- "COLOR_WINDOWTEXT",
- "COLOR_CAPTIONTEXT",
- "COLOR_ACTIVEBORDER",
- "COLOR_INACTIVEBORDER",
- "COLOR_APPWORKSPACE",
- "COLOR_HIGHLIGHT",
- "COLOR_HIGHLIGHTTEXT",
- "COLOR_BTNFACE",
- "COLOR_BTNSHADOW",
- "COLOR_GRAYTEXT",
- "COLOR_BTNTEXT",
- "COLOR_INACTIVECAPTIONTEXT",
- "COLOR_BTNHIGHLIGHT",
- "COLOR_3DDKSHADOW",
- "COLOR_3DLIGHT",
- "COLOR_INFOTEXT",
- "COLOR_INFOBK",
- "COLOR_ALTERNATEBTNFACE",
- "COLOR_HOTLIGHT",
- "COLOR_GRADIENTACTIVECAPTION",
- "COLOR_GRADIENTINACTIVECAPTION"
- };
- static uint[] GetGtkSharpColors() {
- string file = Path.Combine(Environment.GetEnvironmentVariable ("HOME"),Path.Combine(".gnome", "colors"));
- if (File.Exists(file)) {
- try {
- XmlDocument doc1 = new XmlDocument();
- doc1.Load(file);
-
- XmlElement root = doc1.DocumentElement;
-
- int i = 0;
- uint[] colors = new UInt32[29];
-
- foreach (string colorname in WinColors) {
- XmlNode node = root.SelectSingleNode("/settings/colors/color[@name=\"" + colorname + "\"]");
- if(node == null || node.InnerXml == "")
- colors[i] = 255000000;
- else
- colors[i] = Convert.ToUInt32(node.InnerXml);
-
- i++;
- }
-
- return colors;
- }
- catch {}
- }
- else {
- Console.WriteLine("WARNING: Gtk+ colors were not applied. Run 'gtkswf' first.");
- }
-
- return null;
- }
- internal static bool RunningOnUnix = false;
- //
- // Used to initialize the runtime
- //
- static Win32 ()
- {
- // FIXME: this is definitely not the right way to understand that we are on Linux
- RunningOnUnix = System.IO.Path.DirectorySeparatorChar == '/';
- //
- // Tell System.Drawing to use the Wine function drawing.
- //
- Thread.GetDomain ().SetData ("Mono.Running.Windows.Forms", true);
- if (!RunningOnUnix)
- return;
-
- string new_mode = Environment.GetEnvironmentVariable ("SWF");
- if (new_mode == null || new_mode == "1"){
- Console.WriteLine ("MonoWin32: Initializing WineLib");
- } else {
- Console.WriteLine ("MonoWin32: Needs Wine MonoStub");
- return;
- }
-
- string [] args = new string [1];
- args [0] = "mono";
- PROCESS_InitWine (0, args);
- NTDLL_LoadLibraryA ("kernel32.dll");
- NTDLL_LoadLibraryA ("user32.dll");
- NTDLL_LoadLibraryA ("comctl32.dll");
- string gtk_colors = Environment.GetEnvironmentVariable ("SWF_GTK_COLORS");
- if (gtk_colors == "1") {
- 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};
- uint[] colors = GetGtkSharpColors();
- if (colors != null)
- SetSysColors(29, elements, colors);
- }
- }
- }
- }
|