Correct value for hWnd parameter BeginPaint?

I am trying to create a Visual C ++ 2008 program that displays some data in a window. I read from various places the correct way to do this is to override WndProc. So I made a Windows Forms application in Visual C ++ 2008 Express Edition, and I added this code to Form1.h, but it will not compile:

    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);
    }

When I try to compile this in Visual C ++ 2008 Express Edition, this error occurs: error C2664: "BeginPaint": cannot convert parameter 1 from "System :: IntPtr" to "HWND"

When I try to use this-> Handle instead of m.HWnd, the same error occurs.

m.HWnd(HWND), : C2440: " cast": "System:: IntPtr" "HWND"

, m.HWnd pin_ptr - .

+3
3

Win32, .

, , WinForms, OnPaint.

  • (, .)
  • ( , , ) . .
  • .

Paint, .


private: System::Void Form1_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) 
{
    e->Graphics->DrawRectangle(...)              
}

Win32, , . , Win32, Charles Petzold Programming Windows.

++ WinForms... , # VB.NET , .

, . .

+2

, , , ++, WinForms. OnPaint WndProc.

+2

, Win32 ( WM_PAINT) Windows Forms/.NET, draw.

Super simple drawing in .NET! You simply override the OnPaint method and then complete your entire drawing.

You can bind to the paint handler either using the toolbar in Visual Studio, or using the following code in your class;

this.Paint += new System.Windows.Forms.PaintEventHandler(this.MyForm_Paint); 

Then you implement the MyForm_Paint method, for example:

private void MyForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
  //create a graphics object from the form
  Graphics g = this.CreateGraphics();

  // create  a  pen object with which to draw
  Pen p = new Pen(Color.Red, 7);  // draw the line 

  // call a member of the graphics class
  g.DrawLine(p, 1, 1, 100, 100);
}
+1
source

Source: https://habr.com/ru/post/1704699/


All Articles