GetDC 
Author Message
 GetDC

Hey

How can I get the DC, when I call the function from another file:

CClassView *ptr = ((CClassView *)AfxGetMainWnd());
ptr->MyFunc();

void CClassView::MyFunc()
{
 CDC *pDC;
 pDC = ptr->GetDC();

Quote:
}

I get an access violation error, when I try this. How shall I call the
function, so that the DC can be accessed???

Thanks Denker(DK)



Sun, 26 Oct 2003 21:34:30 GMT  
 GetDC
It is called from a static thread, how to get access to DC?

Denker(DK)


Quote:
> Hey

> How can I get the DC, when I call the function from another file:

> CClassView *ptr = ((CClassView *)AfxGetMainWnd());
> ptr->MyFunc();

> void CClassView::MyFunc()
> {
>  CDC *pDC;
>  pDC = ptr->GetDC();
> }

> I get an access violation error, when I try this. How shall I call the
> function, so that the DC can be accessed???

> Thanks Denker(DK)



Sun, 26 Oct 2003 21:58:18 GMT  
 GetDC

Quote:
> I get an access violation error, when I try this. How shall I call the
> function, so that the DC can be accessed???

This sounds more as if the DC does not exist (i.e. if your class wasn't
initialized before with new MyClass () and MyClass->Create (). Access
violation means, that there seems to be no read/write pointer, what makes me
think the above problem occured. Be sure, that you check if (MyClass !=
NULL) before you try to access the CDC * of your class...

regards,

Sascha

P.S. Why do you want to do this outside of your class ? I think drawing
should be done inside the class to be drawn, while the dependency with other
classes can cause very hard to recover errors in your program.



Sun, 26 Oct 2003 21:58:50 GMT  
 GetDC
Are you sure that AfxGetMainWnd() returns a pointer to the view? I think you
need to be sure of that, and probably it does not. You should do more to
validate the value returned by AfxGetMainWnd().

I agree that it would be best to limit all use of a DC to functions in the
class for the window that the DC is for. Whatever you need the DC for, it is
probably possible to do processing in a member function for the window and
then return the results or process a parameter passed to the function.


Quote:
> Hey

> How can I get the DC, when I call the function from another file:

> CClassView *ptr = ((CClassView *)AfxGetMainWnd());
> ptr->MyFunc();

> void CClassView::MyFunc()
> {
>  CDC *pDC;
>  pDC = ptr->GetDC();
> }

> I get an access violation error, when I try this. How shall I call the
> function, so that the DC can be accessed???

> Thanks Denker(DK)



Mon, 27 Oct 2003 02:09:43 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How to do GetDC(0) and not CDC* GetDC(..) in MFC ?

2. IOleInPlaceSite::GetDC fails

3. GetDC?

4. GetDC causes remote debugging to crash ?

5. GetDC() example please.

6. Difference between BeginPaint and GetDC????

7. GetDC returning Null!

8. hwnd/GetDC drawing

9. ::GetDC and ::ReleaseDC

10. Memory leak calling GetDC()???

11. GetDC() example please.

12. pDC not equal to GetDC() call ?

 

 
Powered by phpBB® Forum Software