我正在尝试制作一个在窗口中绘制一些数据的 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' : cannot convert parameter 1 from 'System::IntPtr' to 'HWND'
当我尝试使用 this->Handle 而不是 m.HWnd 时,会发生相同的错误。
当我尝试将 m.HWnd 转换为 (HWND) 时,会出现此错误: 错误 C2440: 'type cast' : cannot convert from 'System::IntPtr' to 'HWND'
也许我需要将 m.HWnd 转换为 pin_ptr 或其他东西。