PDA

View Full Version : Carbon beginner . . .


kenyatta
2002.07.16, 07:06 PM
I'm working in Project Builder v 1.1.1 (Dec 2001 Developer Tools), it's a great help because I can find the definition to a whole bunch of functions. The following code I grabbed from a the Hello Tutorial, SillyBalls, and Chapter 1 example from K.J. Bricknell.

I wanted to take apart the code into something simpler so I would be able to understand it. I was able to use 2 function calls and I got the simple program that terminates as soon as the mouse is pressed down. The program displays a new window. That's it.

Then I tried to get fancy and add (SillyBalls code ) couldn't make it happen.
I then tried to draw 1 oval and couldn't make that happen.
Then I tried to draw a string, change the window's content color and title,
niether worked.
At least the program still was able to build successfully with a plain old window.

Anybody think they can help? And is this possible without creating a nib reference or WIND resource?


void doPreliminaries(void) {
MoreMasterPointers(32);
InitCursor();
}

void DrawWindow() {
WindowRef myWindow;
RGBColor wColor;
wColor.red = 0x0;
wColor.green = 0x0;
wColor.blue = 0x0;
SetRect(&windRect,50,50,600,600);

myWindow = NewCWindow(nil, &windRect, "\pWindow Test", true, zoomDocProc, (WindowRef) -1, true, 0);
SetPort( GetWindowPort(myWindow) );
SetWTitle( myWindow, "\p MY WINDOW TEST ");
SetWindowContentColor ( myWindow, &wColor);
}

:confused: hmm . . .

kainsin
2002.07.17, 11:05 AM
The color you are passing in for the content color is white, but the generic content color is also white. Have you tried using other colors?

I also wouldn't use NewCWindow, try looking up CreateNewWindow and using that instead.

kenyatta
2002.07.17, 06:10 PM
the CreateNewWindow function looks fairly simple, however I can't seem to get around the first 2 parameters.

WindowClass and WindowAttributes.
You got an example of how they're written.

Thanks.

OneSadCookie
2002.07.17, 08:57 PM
The definitions are near the top of MacWindows.h

Try these:

kDocumentWindowClass,
kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute,

RedWolf
2002.07.18, 12:42 AM
Originally posted by kainsin
> The color you are passing in for the content color is white, but the generic content color is also white.

Actually, it's black as he's setting the RGB values to 0, not 0xffff.

kainsin
2002.07.18, 10:47 AM
Originally posted by RedWolf
Actually, it's black as he's setting the RGB values to 0, not 0xffff.

Umm...good point. I don't know what I was thinking at the time. :)

Originally posted by kenyatta
the CreateNewWindow function looks fairly simple, however I can't seem to get around the first 2 parameters.

WindowClass and WindowAttributes.
You got an example of how they're written.

For the class and attribute constants you can check out the Carbon : Window Manager API Reference online at Apple's site or in Carbon Help in the Help menu of Project Builder.

For window class constants go here: http://developer.apple.com/techpubs/macosx/Carbon/HumanInterfaceToolbox/WindowManager/Window_Manager/Enumerations/Window_Class_Constants.html#//apple_ref/c/tag/WindowClass

For window attribtue constants go here: http://developer.apple.com/techpubs/macos8/HumanInterfaceToolbox/WindowManager/ProgWMacOS8.5WindowMgr/WindowMgr.70.html

kenyatta
2002.07.18, 04:02 PM
CreateNewWindow ( kDocumentWindowClass, kWindowNoAttributes, &windRect, myWindow);
// myWindow = NewCWindow(nil, &windRect, "\pWindow Test", true, zoomDocProc, (WindowRef) -1, true, 0);

This caused errors upon building (Project Builder):
WindowTest.app has exited due to signal 10 (SIGBUS).

-----
Does something look off?

(BTW) I got this to work with the CarbonbasedNib template. But I'll discuss some of those problems on another post

:rolleyes:

kenyatta
2002.07.18, 04:10 PM
CreateNewWindow ( kDocumentWindowClass, kWindowNoAttributes, &windRect, &myWindow);

Oops forgot to make my WindowRef a pointer, and I got a different error message,
indowTest.app has exited with status 1.

I'll be honest, I have no clue how to utilize the Debugger, I'll learn that tonight. Hopefully you can track a variable with this Debugger

kainsin
2002.07.19, 09:19 AM
The debugger's pretty easy to use. Just try clicking the debug button to run the program. If it exits with any sort of error then the debugger will bring you to the line that caused the error. This can be extremely handy in finding out what is trying to access forbiden memory.

Other types of runtime errors can be pretty tough to find, though. It's best that you learn what all of the step buttons do and how toset/remove breakpoints.