Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Win32Native.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 //
4 // Copyright (c) 2010-2014 SharpDX - Alexandre Mutel
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP && SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
24 using System;
25 using System.Runtime.InteropServices;
26 using System.Security;
27 
28 using SharpDX;
29 using SharpDX.Win32;
30 
31 namespace SiliconStudio.Paradox.Games
32 {
33  /// <summary>
34  /// Internal class to interact with Native Message
35  /// </summary>
36  internal class Win32Native
37  {
38 
39  [DllImport("user32.dll", EntryPoint = "PeekMessage")]
40  [SuppressUnmanagedCodeSecurity]
41  public static extern int PeekMessage(
42  out NativeMessage lpMsg,
43  IntPtr hWnd,
44  int wMsgFilterMin,
45  int wMsgFilterMax,
46  int wRemoveMsg);
47 
48  [DllImport("user32.dll", EntryPoint = "GetMessage")]
49  [SuppressUnmanagedCodeSecurity]
50  public static extern int GetMessage(
51  out NativeMessage lpMsg,
52  IntPtr hWnd,
53  int wMsgFilterMin,
54  int wMsgFilterMax);
55 
56  [DllImport("user32.dll", EntryPoint = "TranslateMessage")]
57  [SuppressUnmanagedCodeSecurity]
58  public static extern int TranslateMessage(ref NativeMessage lpMsg);
59 
60  [DllImport("user32.dll", EntryPoint = "DispatchMessage")]
61  [SuppressUnmanagedCodeSecurity]
62  public static extern int DispatchMessage(ref NativeMessage lpMsg);
63 
64  public enum WindowLongType : int
65  {
66  WndProc = (-4),
67  HInstance = (-6),
68  HwndParent = (-8),
69  Style = (-16),
70  ExtendedStyle = (-20),
71  UserData = (-21),
72  Id = (-12)
73  }
74 
75  public delegate IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
76 
77  public static IntPtr GetWindowLong(HandleRef hWnd, WindowLongType index)
78  {
79  if (IntPtr.Size == 4)
80  {
81  return GetWindowLong32(hWnd, index);
82  }
83  return GetWindowLong64(hWnd, index);
84  }
85 
86  [DllImport("user32.dll", EntryPoint = "GetFocus", CharSet = CharSet.Unicode)]
87  public static extern IntPtr GetFocus();
88 
89  [DllImport("user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Unicode)]
90  private static extern IntPtr GetWindowLong32(HandleRef hwnd, WindowLongType index);
91 
92  [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Unicode)]
93  private static extern IntPtr GetWindowLong64(HandleRef hwnd, WindowLongType index);
94 
95  public static IntPtr SetWindowLong(HandleRef hwnd, WindowLongType index, IntPtr wndProcPtr)
96  {
97  if (IntPtr.Size == 4)
98  {
99  return SetWindowLong32(hwnd, index, wndProcPtr);
100  }
101  return SetWindowLongPtr64(hwnd, index, wndProcPtr);
102  }
103 
104  [DllImport("user32.dll", EntryPoint = "SetParent", CharSet = CharSet.Unicode)]
105  public static extern IntPtr SetParent(HandleRef hWnd, IntPtr hWndParent);
106 
107  [DllImport("user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Unicode)]
108  private static extern IntPtr SetWindowLong32(HandleRef hwnd, WindowLongType index, IntPtr wndProc);
109 
110 
111  public static bool ShowWindow(HandleRef hWnd, bool windowVisible)
112  {
113  return ShowWindow(hWnd, windowVisible ? 1 : 0);
114  }
115 
116  [DllImport("user32.dll", EntryPoint = "ShowWindow", CharSet = CharSet.Unicode)]
117  private static extern bool ShowWindow(HandleRef hWnd, int mCmdShow);
118 
119  [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Unicode)]
120  private static extern IntPtr SetWindowLongPtr64(HandleRef hwnd, WindowLongType index, IntPtr wndProc);
121 
122  [DllImport("user32.dll", EntryPoint = "CallWindowProc", CharSet = CharSet.Unicode)]
123  public static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam);
124 
125  [DllImport("user32.dll", EntryPoint = "GetClientRect")]
126  public static extern bool GetClientRect(IntPtr hWnd, out Rectangle lpRect);
127 
128  [DllImport("kernel32.dll", EntryPoint = "GetModuleHandle", CharSet = CharSet.Unicode)]
129  public static extern IntPtr GetModuleHandle(string lpModuleName);
130 
131  public const int WM_SIZE = 0x0005;
132 
133  public const int WM_ACTIVATEAPP = 0x001C;
134 
135  public const int WM_POWERBROADCAST = 0x0218;
136 
137  public const int WM_MENUCHAR = 0x0120;
138 
139  public const int WM_SYSCOMMAND = 0x0112;
140 
141  public const int WM_KEYDOWN = 0x100;
142 
143  public const int WM_KEYUP = 0x101;
144 
145  public const int WM_CHAR = 0x102;
146 
147  public const int WM_SYSKEYDOWN = 0x104;
148 
149  public const int WM_SYSKEYUP = 0x105;
150  }
151 }
152 #endif
System.Windows.Shapes.Rectangle Rectangle
Definition: ColorPicker.cs:16