![見出し画像](https://assets.st-note.com/production/uploads/images/163480203/rectangle_large_type_2_79452d6917dcfdcdc81451ac9b145dac.png?width=1200)
ウィンドウハンドルの変換
.NET Framework の UserControl が保持しているウィンドウハンドル Handle を、レガシーコードのウィンドウハンドル(HWND型)に変換する。
// C++CLI
public ref class MyControl : System::Windows::Forms::UserControl
{
public:
MyControl()
{
InitializeComponent();
HWND hWnd = reinterpret_cast<HWND>( this->Handle.ToPointer() );
SetupOpenGL( hWnd );
}
}
UserControl の描画を GDI 関数ではなく OpenGL で行う場合には、HWND型のウィンドウハンドルが必要。OpenGLライブラリはC言語のインターフェースなので。