Created
June 25, 2015 01:31
-
-
Save mntone/d53d84e1ce6ea06c6bb1 to your computer and use it in GitHub Desktop.
HwndHostを継承してHWND (native window handle)を作ってみたサンプル! 別プロセスから描画したりもできるので、自由なことができる(にやにや)。プロセス間通信は別途必須。 ちなみにほぼコピペ https://msdn.microsoft.com/ja-jp/library/ms752055.aspx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
using System.Windows.Interop; | |
namespace Testsuruo | |
{ | |
public sealed class VideoHost : HwndHost | |
{ | |
private IntPtr hwndHost; | |
internal const int | |
WS_CHILD = 0x40000000, | |
WS_VISIBLE = 0x10000000, | |
LBS_NOTIFY = 0x00000001, | |
HOST_ID = 0x00000002, | |
LISTBOX_ID = 0x00000001, | |
WS_VSCROLL = 0x00200000, | |
WS_BORDER = 0x00800000; | |
protected override HandleRef BuildWindowCore(HandleRef hwndParent) | |
{ | |
hwndHost = IntPtr.Zero; | |
hwndHost = CreateWindowEx(0, "static", "", | |
WS_CHILD | WS_VISIBLE, | |
0, 0, | |
(int)ActualWidth, (int)ActualHeight, | |
hwndParent.Handle, | |
(IntPtr)HOST_ID, | |
IntPtr.Zero, | |
0); | |
return new HandleRef(this, hwndHost); | |
} | |
protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) | |
{ | |
handled = false; | |
return IntPtr.Zero; | |
} | |
protected override void DestroyWindowCore(HandleRef hwnd) | |
{ | |
DestroyWindow(hwnd.Handle); | |
} | |
[DllImport("user32.dll", EntryPoint = "CreateWindowEx", CharSet = CharSet.Unicode)] | |
internal static extern IntPtr CreateWindowEx(int dwExStyle, | |
string lpszClassName, | |
string lpszWindowName, | |
int style, | |
int x, int y, | |
int width, int height, | |
IntPtr hwndParent, | |
IntPtr hMenu, | |
IntPtr hInst, | |
[MarshalAs(UnmanagedType.AsAny)] object pvParam); | |
[DllImport("user32.dll", EntryPoint = "DestroyWindow", CharSet = CharSet.Unicode)] | |
internal static extern bool DestroyWindow(IntPtr hwnd); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment