ADC Home > Reference Library > Technical Q&As > Carbon > Human Interface Toolbox >

CGContext parameter missing in my kEventControlDraw event


Q: I wrote a custom HIView which I embed in the root control of my window, but when I get the kEventControlDraw Carbon Event, I can't retrieve the CGContext parameter and so I can't draw anything. What's happening?

A: You are very probably trying to embed your custom HIView in a non-compositing window. That's not going to work because you won't get your CGContext parameter when you get the kEventControlDraw Carbon Event.

A window is either in compositing mode or it isn't. You obtain a compositing window by adding the kWindowCompositingAttribute attribute to the others window attributes that you pass as second parameter to CreateNewWindow.

• If your window is in compositing mode, you should add your HIViews in the content view of the window (HIViewFindByID + kHIViewWindowContentID), and you then get the CGContext in which to draw as a parameter of the kEventControlDraw Carbon Event.

• If your window is not in compositing mode, you should add your Controls in the root control of the window (GetRootControl), and you then get the QuickDraw GrafPort in which to draw as a parameter of the kEventControlDraw Carbon Event.

Other combinations (embedding in the root control of a compositing window, embedding in the content view of a non-compositing window) are not necessarily supported and may or may not work in the present or the future.

When compositing is off, the root control of a window is not the same entity as the content view of that window.
When compositing is on, they are the same entity (as a convenience for developers).


[Nov 12 2002]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.