NativeMethods.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright (c) 2007-2012 Michael Chapman
  2. // http://ipaddresscontrollib.googlecode.com
  3. // Permission is hereby granted, free of charge, to any person obtaining
  4. // a copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to
  8. // permit persons to whom the Software is furnished to do so, subject to
  9. // the following conditions:
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  15. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  16. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  17. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  18. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. using System;
  20. using System.Runtime.InteropServices;
  21. namespace IPAddressControlLib
  22. {
  23. internal class NativeMethods
  24. {
  25. private NativeMethods() {}
  26. [DllImport( "user32.dll" )]
  27. public static extern IntPtr GetWindowDC( IntPtr hWnd );
  28. [DllImport( "user32.dll" )]
  29. public static extern int ReleaseDC( IntPtr hWnd, IntPtr hDC );
  30. [DllImport( "gdi32.dll", CharSet = CharSet.Unicode )]
  31. [return: MarshalAs( UnmanagedType.Bool )]
  32. public static extern bool GetTextMetrics( IntPtr hdc, out TEXTMETRIC lptm );
  33. [DllImport( "gdi32.dll", CharSet = CharSet.Unicode )]
  34. public static extern IntPtr SelectObject( IntPtr hdc, IntPtr hgdiobj );
  35. [DllImport( "gdi32.dll", CharSet = CharSet.Unicode )]
  36. [return : MarshalAs( UnmanagedType.Bool)]
  37. public static extern bool DeleteObject( IntPtr hdc );
  38. [Serializable, StructLayout( LayoutKind.Sequential, CharSet = CharSet.Unicode )]
  39. public struct TEXTMETRIC
  40. {
  41. public int tmHeight;
  42. public int tmAscent;
  43. public int tmDescent;
  44. public int tmInternalLeading;
  45. public int tmExternalLeading;
  46. public int tmAveCharWidth;
  47. public int tmMaxCharWidth;
  48. public int tmWeight;
  49. public int tmOverhang;
  50. public int tmDigitizedAspectX;
  51. public int tmDigitizedAspectY;
  52. public char tmFirstChar;
  53. public char tmLastChar;
  54. public char tmDefaultChar;
  55. public char tmBreakChar;
  56. public byte tmItalic;
  57. public byte tmUnderlined;
  58. public byte tmStruckOut;
  59. public byte tmPitchAndFamily;
  60. public byte tmCharSet;
  61. }
  62. }
  63. }