Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GameEngineHwndHost.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 using System;
4 using System.Runtime.InteropServices;
5 using System.Windows;
6 using System.Windows.Interop;
7 
8 using SiliconStudio.Presentation.Extensions;
9 
10 namespace SiliconStudio.Presentation.Controls
11 {
13  {
14  private readonly IntPtr childHandle;
15  private Rect previousBoundingBox;
16 
17  public GameEngineHwndHost(IntPtr childHandle)
18  {
19  this.childHandle = childHandle;
20  }
21 
22  protected override HandleRef BuildWindowCore(HandleRef hwndParent)
23  {
24  int style = NativeHelper.GetWindowLong(childHandle, NativeHelper.GWL_STYLE);
25  // Removes Caption bar and the sizing border
26  // Must be a child window to be hosted
27  style |= NativeHelper.WS_CHILD;
28 
29  NativeHelper.SetWindowLong(childHandle, NativeHelper.GWL_STYLE, style);
30  NativeHelper.ShowWindow(childHandle, NativeHelper.SW_HIDE);
31 
32  NativeHelper.SetParent(childHandle, hwndParent.Handle);
33 
34  var hwnd = new HandleRef(this, childHandle);
35  return hwnd;
36  }
37 
38  protected override void OnWindowPositionChanged(Rect rcBoundingBox)
39  {
40  if (previousBoundingBox != rcBoundingBox)
41  {
42  base.OnWindowPositionChanged(rcBoundingBox);
43  previousBoundingBox = rcBoundingBox;
44  }
45  }
46 
47  protected override void DestroyWindowCore(HandleRef hwnd)
48  {
49  NativeHelper.SetParent(childHandle, IntPtr.Zero);
50  }
51  }
52 }
override void OnWindowPositionChanged(Rect rcBoundingBox)
override HandleRef BuildWindowCore(HandleRef hwndParent)