ウィンドウにデータをプロットする Visual C++ 2008 プログラムを作成しようとしています。これを行う正しい方法は、WndProc をオーバーライドすることです。 そこで、Visual C++ 2008 Express Edition で Windows フォーム アプリケーションを作成し、このコードを Form1.h に追加しましたが、コンパイルされません。
public:
[System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
virtual void WndProc(Message %m) override
{
switch(m.Msg)
{
case WM_PAINT:
{
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint(m.HWnd, &ps);
// i'd like to insert GDI code here
EndPaint(m.Wnd, &ps);
return;
}
}
Form::WndProc(m);
}
これを Visual C++ 2008 Express Edition でコンパイルしようとすると、 エラー C2664: 'BeginPaint' : パラメーター 1 を 'System::IntPtr' から 'HWND' に変換できません。
m.HWnd の代わりに this->Handle を使用しようとすると、同じエラーが発生します。
m.HWnd を (HWND) にキャストしようとすると、次のエラーが発生します: error C2440: 'type cast' : cannot convert from 'System::IntPtr' to 'HWND'
たぶん、m.HWnd を pin_ptr などにキャストする必要があります。