help with carbon events please

help with carbon events please

Post by patric » Thu, 20 Jun 2002 02:18:33



Hello

after reading apple's web site several times, I still don't understand how
to use carbon events. ( i guess i'm missing something essential because i
can't find the mecanism that is translating message)

I'm looking for a minimal example , something like ( pseudo code here )  :

void main( void )
{

 myWin = CreateWindow( blabla )
SetEventHandler( myWin, myProc )

 while( true ) { }

Quote:}

bool myProc( event )
{
    if event == quit then
       alertbox( "The user wants to quit" ) ;
     quit program
   end if
     return defaultWindowProc;

Quote:}

thank you
 
 
 

help with carbon events please

Post by Bryan Horlin » Thu, 20 Jun 2002 09:51:29


Here's some window-level event code, perhaps it will help. You'll also
need a main event loop where you first call
InstallApplicationEventHandler and then RunApplicationEventLoop.

void createWindow() {
        WindowAttributes        windowAttrs;
        OSStatus                        err;

        windowAttrs = kWindowCloseBoxAttribute |
                                  kWindowCollapseBoxAttribute |
                      kWindowStandardHandlerAttribute;
        err = CreateNewWindow (kDocumentWindowClass, windowAttrs, &border, &window);
        assert(err == noErr, "Error creating window");

        // Event handling
        InstallStandardEventHandler(GetWindowEventTarget(window));

        EventHandlerUPP         handlerUPP;
        EventTypeSpec           eventTypes[] = {
                { kEventClassWindow,
kEventWindowDrawContent },
                { kEventClassWindow,
kEventWindowUpdate },
                { kEventClassWindow,
kEventWindowShown },
                { kEventClassWindow,
kEventWindowClose}
        };

        handlerUPP = NewEventHandlerUPP(windowHandleEventGlue);
        InstallWindowEventHandler(window, handlerUPP, sizeof(eventTypes) /
sizeof(EventTypeSpec), eventTypes, (void *)this, null);

Quote:}

pascal OSStatus windowHandleEventGlue(EventHandlerCallRef nextHandler,
EventRef theEvent, void *userData) {

        OSStatus        status = eventNotHandledErr;    

        UInt32  eventClass = GetEventClass(theEvent);
        UInt32  eventKind  = GetEventKind(theEvent);

        switch (eventClass) {
        case kEventClassWindow:
                switch (eventKind) {
                case kEventWindowClose:
                case kEventWindowDrawContent:
                case kEventWindowUpdate:
                case kEventWindowShown:
                        // Do something here
                        status = noErr;
                        break;
                }
                break;

        default:
                break;
        }

        return status;

Quote:}


 
 
 

help with carbon events please

Post by patric » Thu, 20 Jun 2002 11:33:00


Thanks a lot !!!

I didn't know about the existence of RunApplicationEventLoop, it does not
appear anywhere on the pages i visited !

thank you !

 
 
 

help with carbon events please

Post by Miro Jurisi » Thu, 20 Jun 2002 14:19:54




> I didn't know about the existence of RunApplicationEventLoop, it does not
> appear anywhere on the pages i visited !

I am pretty sure that the Sample Code page
(developer.apple.com/samplecode) has adequate Carbon Events samples, but
I am behind a slow link now, so I can't check for you

hth

meeroh

 
 
 

1. Mouse down events being lost under Carbon

I am porting a Pascal game to Carbon and the following trick used to work to
make sure that all mouse down events came to my game, even when the game was
being played in a Document window that did not cover the whole screen:

SetRect(theRect, 30000, 30000, 30100, 30100);
theDialog := NewColorDialog (NIL, theRect, '', FALSE,
                kWindowModalDialogProc, Pointer(-1), False, 0, itemLstHdl);
ShowWindow (GetDialogWindow(theDialog));
HiliteWindow (GetDialogWindow(myGameWindow), TRUE);

'myGameWindow' is also set up with:
myGameWindow:= NewColorDialog (NIL, windowRect, 'Game Name', FALSE,
                kWindowDocumentProc, cowWindow, True, 0, itemLstHdl);

When the game is paused the 'theDialog' dialog is closed, and the Document
window 'myGameWindow' acts like any other and allows clicks on the
background.

This simply sets up a hidden modal dialog as the front window.

Under OS 9 this worked. However, under Carbon I do not get mouse down events
that occur within the bounds of 'myGameWindow' being reported to the game.
Instead I get 'beep' that (I guess) occurs when you click outside of a modal
dialog. All other mouse down events get reported to my game correctly.

I am current using CodeWarrior Pro 6 (with the full set of patches), which
is fine for developing Carbon applications from within an OS 9 environment.

Any suggestions would be greatly appeciated.

Thanks,
Alasdair Klyne.

2. RRecommend OS/2 screensaver for WARP?!

3. Please HELP- HP ORBPlus and X event loop

4. Linux and win2k

5. Please Help With Definitions Events/Traps

6. A4000 IDE

7. PLEASE HELP !!! PLEASE HELP !!!

8. A600

9. MSN Messenger 4.5 problem (Toshiba Laptop) PLEASE HELP PLEASE HELP

10. Help: Carbon and Command Line Executable??

11. Please post Mechassult? Please please please

12. HELP HELP HELP PLEASE

13. HELP-HELP-HELP ME - PLEASE want to include internet pages to msword documents !