Drawing using CDC on a WinForm

Discussion in 'C++' started by douda123, Aug 28, 2010.

  1. douda123

    douda123 New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    I have a question concerning MFC drawing on a WinForm. I have old drawing in MFC (using CDC) and I want to use that code to draw on a C# WinForm.


    Here is the old MFC code:
    ---------------------------------------------------------------
    void CMyDrawer :: Draw(CDC& dc)
    {
    dc.Rectangle(10, 10, 50, 60);
    }
    ---------------------------------------------------------------

    And here is the code in the wrapper DLL (mixed DLL) that I used to wrap the native code and make it usable in a C# assembly:

    ---------------------------------------------------------------
    void CMyDrawerWrapper :: Draw(IntPtr handlePtr)
    {
    HDC hDC = static_cast(handlePtr.ToPointer());

    CDC dc;
    dc.Attach(hDC);

    CMyDrawer myDrawer
    myDrawer.Draw(dc);
    }
    ---------------------------------------------------------------

    And finally this is the code I have in the C# WinForm:

    ---------------------------------------------------------------
    private void Form1_Load(object sender, EventArgs e)
    {
    if (pictureBox1.Image == null)
    {
    pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
    }

    MyDrawerWrapperNamespace.CMyDrawerWrapper myDrawerWrapper = new MyDrawerWrapperNamespace.CMyDrawerWrapper();
    myDrawerWrapper.Draw(pictureBox1.Handle);

    }
    ---------------------------------------------------------------

    Unfortunately the code is not drawing anything.. Is there anything I am missing?

    Please advise.
    Thanks in advance
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice