locked
Calling a CDC* pDC function RRS feed

  • Question

  • Hi, I'm new to the whole MFC thing and have probably a basic question.

    Basically my problem is that I don't know how to call a function that I wrote.

    What I have is a function

     

    void CUserInterfaceView::MyFunc(CDC* pDC)

    { CRect tmpRect(100,100,120,120);

    pDC->Rectangle(tmpRect); }


    (Declared as 

    virtual void MyFunc(CDC* pDC);)


    and I want to call it while inside a loop in another function, but when I type it, it asks me to input a variable (the CDC* pDC something..).

    And because the other function does not recognize the pDC (pointer?), I cant write it.

     

     

    Hope this is clear enough, if not I will try to explain more. As I said, I'm really new to MFC (and C++ itself).

    Thank You.

    Saturday, March 12, 2011 11:49 PM

Answers

  •  CDC* dc=GetDC();

    MyFunc(dc); // maybe &dc

     

    and your code seems will not work, you haven't setup brush yet.

     

    CBrush pBrush(RGB(240,240,240));

    pDc.selectobject(pbursh); // maybe &pbursh;

     

    please check msdn, because you still need to release this pbrush

    • Marked as answer by MFC_Karl Sunday, March 13, 2011 11:48 AM
    Sunday, March 13, 2011 4:27 AM

All replies

  • Basically my problem is that I don't know how to call a function that I wrote.

    Bit of a dilemma there then :)

    What I have is a function
    void CUserInterfaceView::MyFunc(CDC* pDC) and I want to call it while inside a loop in another function, but when I type it, it asks me to input a variable (the CDC* pDC something..).
    And because the other function does not recognize the pDC (pointer?), I cant write it.

    Why/how have you written the function/method if you don't know how to
    call it?

    A method requiring a device context is usually going to be called as
    part of drawing/painting code. Where are you trying to call it from?

    Dave

    Sunday, March 13, 2011 12:23 AM
  •  CDC* dc=GetDC();

    MyFunc(dc); // maybe &dc

     

    and your code seems will not work, you haven't setup brush yet.

     

    CBrush pBrush(RGB(240,240,240));

    pDc.selectobject(pbursh); // maybe &pbursh;

     

    please check msdn, because you still need to release this pbrush

    • Marked as answer by MFC_Karl Sunday, March 13, 2011 11:48 AM
    Sunday, March 13, 2011 4:27 AM
  • Thank you DU SIJUN! It worked.
    Sunday, March 13, 2011 11:49 AM