OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / FDK17プロジェクト / コード / 01.フレームワーク / Win32 / NativeMethods.cs
1 /*
2 * Copyright (c) 2007-2009 SlimDX Group
3
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22 using System;
23 using System.Drawing;
24 using System.Runtime.InteropServices;
25 using System.Security;
26
27 namespace SampleFramework
28 {
29     static class NativeMethods
30     {
31         [SuppressUnmanagedCodeSecurityAttribute]
32         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
33         [return: MarshalAs(UnmanagedType.Bool)]
34         public static extern bool PeekMessage(out NativeMessage message, IntPtr hwnd, uint messageFilterMin, uint messageFilterMax, uint flags);
35
36         [SuppressUnmanagedCodeSecurityAttribute]
37         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
38         [return: MarshalAs(UnmanagedType.Bool)]
39         static extern bool GetClientRect(IntPtr hWnd, out NativeRectangle lpRect);
40
41         [SuppressUnmanagedCodeSecurityAttribute]
42         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
43         [return: MarshalAs(UnmanagedType.Bool)]
44         static extern bool GetWindowRect(IntPtr hWnd, out NativeRectangle lpRect);
45
46         [SuppressUnmanagedCodeSecurityAttribute]
47         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
48         [return: MarshalAs(UnmanagedType.Bool)]
49         public static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
50
51         [SuppressUnmanagedCodeSecurityAttribute]
52         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
53         [return: MarshalAs(UnmanagedType.Bool)]
54         public static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
55
56         [SuppressUnmanagedCodeSecurityAttribute]
57         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
58         public static extern uint SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
59
60         [SuppressUnmanagedCodeSecurityAttribute]
61         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
62         public static extern uint GetWindowLong(IntPtr hWnd, int nIndex);
63
64         [SuppressUnmanagedCodeSecurityAttribute]
65         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
66         [return: MarshalAs(UnmanagedType.Bool)]
67         public static extern bool IsIconic(IntPtr hWnd);
68
69         [SuppressUnmanagedCodeSecurityAttribute]
70         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
71         [return: MarshalAs(UnmanagedType.Bool)]
72         public static extern bool IsZoomed(IntPtr hWnd);
73
74         [SuppressUnmanagedCodeSecurityAttribute]
75         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
76         [return: MarshalAs(UnmanagedType.Bool)]
77         public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
78
79         [SuppressUnmanagedCodeSecurityAttribute]
80         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
81         [return: MarshalAs(UnmanagedType.Bool)]
82         public static extern bool AdjustWindowRect(ref NativeRectangle lpRect, uint dwStyle, [MarshalAs(UnmanagedType.Bool)]bool bMenu);
83
84         [SuppressUnmanagedCodeSecurityAttribute]
85         [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = false)]
86         public static extern uint SetThreadExecutionState(uint esFlags);
87
88         [SuppressUnmanagedCodeSecurityAttribute]
89         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
90         [return: MarshalAs(UnmanagedType.Bool)]
91         public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
92
93         [SuppressUnmanagedCodeSecurityAttribute]
94         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
95         public static extern IntPtr MonitorFromWindow(IntPtr hwnd, uint dwFlags);
96
97         public static Rectangle GetClientRectangle(IntPtr handle)
98         {
99             NativeRectangle rect;
100             if (!GetClientRect(handle, out rect))
101                 return Rectangle.Empty;
102
103             return Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom);
104         }
105
106         public static Rectangle GetWindowRectangle(IntPtr handle)
107         {
108             NativeRectangle rect;
109             if (!GetWindowRect(handle, out rect))
110                 return Rectangle.Empty;
111
112             return Rectangle.FromLTRB(rect.left, rect.top, rect.right, rect.bottom);
113         }
114     }
115 }