I have made a simple window in my nib file. And I want it to display a string and update the window every time it needs to.
here is my code:
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?
here is my code:
Code:
#include <iostream>
#include <Carbon/Carbon.h>
using namespace std;
pascal OSStatus WindowEventHandler(EventHandlerCallRef handlerRef,
EventRef event, void *userData);
void UpdateWindow(WindowRef window);
//**********************************
int main(int argc, char* argv[]){
IBNibRef nibRef;
WindowRef window;
OSStatus err;
EventTargetRef target;
EventHandlerUPP handlerUPP;
EventTypeSpec windowEvent;
windowEvent.eventClass = kEventClassWindow;;
windowEvent.eventKind = kEventWindowDrawContent;
err = CreateNibReference(CFSTR("main"), &nibRef);
err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
err = CreateWindowFromNib(nibRef,CFSTR("MainWindow"), &window);
DisposeNibReference(nibRef);
target = GetWindowEventTarget(window);
handlerUPP = NewEventHandlerUPP(WindowEventHandler);
InstallEventHandler(target, handlerUPP, 1, &windowEvent, (void *) window,NULL);
ShowWindow(window);
RunApplicationEventLoop();
return 0;
}
//**********************************************
pascal OSStatus WindowEventHandler(EventHandlerCallRef handlerRef,
EventRef event, void *userData)
{
cout << "entered the function\n";
OSStatus result = eventNotHandledErr;
UInt32 eventKind;
WindowRef window;
window = (WindowRef)userData;
eventKind = GetEventKind(event);
if(eventKind == kEventWindowDrawContent)
{
UpdateWindow(window);
}
return result;
}
void UpdateWindow(WindowRef window)
{
cout << "updatewindow\n";
FMFontFamily fontFamily;
SetPortWindowPort(window);
fontFamily = FMGetFontFamilyFromName("\pTimes");
TextFont(fontFamily);
TextFace(bold + italic);
TextSize(24);
MoveTo(30,60);
DrawString("\pThis is drawn from code!");
}
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?