The problem is that no string is drawn inside the window. Xcode's console doesn't even display the messages I have put that show that the command event handler has been activated. Can someone show me what am I doing wrong?

I write this code from a book about carbon programming. Perhaps the fault lies in that the book is from 2001?

You haven't installed the standard window event handler. If you don't install the standard event handler, you won't get the kEventWindowDrawContent event so your UpdateWindow() function will never get called.

To install the standard event handler, call the function InstallStandardEventHandler().

Also, my book doesn't mention that. Was it added in later versions? I have a book that is from 2001.

In what occasions must I use the function you told me?

Click to expand...

You must call InstallStandardEventHandler() if you want to use Apple's standard event handlers, which you normally want to do. To receive kEventWindowDrawContent events, you must install the standard window event handler.

Looking at your WindowEventHandler() function, I noticed that the code does not change the value of the variable result. Your event handler always returns eventNotHandledErr. You should change result to noErr after calling UpdateWindow().

Is your UpdateWindow() function getting called? If it is, you have a problem in your text drawing code. I have never written any code to write text in a Mac window so I cannot help you solve that problem.

If the UpdateWindow() function is not being called, you have two possible problems. The first possible problem is a problem in the event handler, either in the code itself or the code to install the handler. The second possible problem is that your program is not generating kEventWindowDrawContent events.

If you need more help with Carbon Events, read this article I wrote. Although the article covers reading the keyboard, it provides an introduction to Carbon Events that may help you solve your problem.

Looking at your WindowEventHandler() function, I noticed that the code does not change the value of the variable result. Your event handler always returns eventNotHandledErr. You should change result to noErr after calling UpdateWindow().

Click to expand...

still doesn't work

Quote

Is your UpdateWindow() function getting called? If it is, you have a problem in your text drawing code. I have never written any code to write text in a Mac window so I cannot help you solve that problem.

Click to expand...

No it's not called.

Quote

If the UpdateWindow() function is not being called, you have two possible problems. The first possible problem is a problem in the event handler, either in the code itself or the code to install the handler. The second possible problem is that your program is not generating kEventWindowDrawContent events.

Click to expand...

I wish I knew how to fix that.

Anyway, can you provide me with any reference to Carbon development? I would appreciate it if you recommended me any book too!

Anyway, can you provide me with any reference to Carbon development? I would appreciate it if you recommended me any book too!

Click to expand...

Unfortunately, there are no modern Carbon programming books. I would recommend reading Apple's Carbon documentation, especially the material on Carbon Events.

To find the source of your problem, set breakpoints at the start of your main, WindowEventHandler and UpdateWindow functions. Walk through your code line by line in the debugger. Your program is small enough that walking through your code will find the problem.

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.