Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting NSWindow windownumber ?




On 16/01/07, Tomas Zahradnicky <email@hidden> wrote:
Because I didn't want to include m files in the project and wanted to
show it is possible from C.

Well, it certainly is possible, but it's not that pretty. You'll need to link in the Cocoa framework to your project, or load it up via the CFBundle APIs. You also probably need to deal with the auto release pool using the same mechanics shown below. This is all typed in Mail, and so hopefully it compiles, but if not hopefully it at least shows you the concept behind it.


#include <objc/objc.h>
#include <objc/runtime.h>

id windowClass = objc_getClass( "NSWindow" );
id myWindow = objc_msgSend( windowClass, sel_registerName( "alloc" ), 0 );
myWindow = objc_msgSend( myWindow, sel_registerName( "initWithWindowRef:" ), myCarbonWindow );
int windowNumber = (int)objc_msgSend( myWindow, sel_registerName( "windowNumber" ), 0 );
objc_msgSend( myWindow, "release", 0 );


For even more fun times of beating multiple dead horses, you can even load these methods up dynamically and call into Objective-C from PEF applications <evil grin>. However, even with the above code, it is *infinitely* easier to simply write:

int WindowGetWindowNumber( WindowRef win )
{
	NSWindow *win = [NSWindow initWithWindowRef:win];
	int out = [win windowNumber];
	[win release];
	return out;
}

When knowing that I need to maintain code, I'd opt for the latter any day.

HTH,
Jon


-- Jonathan Johnson email@hidden REAL Software, Inc.

REAL World 2007 Conference
May 9 - 11 in Austin, Texas
<http://www.realsoftware.com/realworld>

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden
References: 
 >Getting NSWindow windownumber ? (From: Rosemary Quince <email@hidden>)
 >Re: Getting NSWindow windownumber ? (From: Tomas Zahradnicky <email@hidden>)
 >Re: Getting NSWindow windownumber ? (From: "Finlay Dobbie" <email@hidden>)
 >Re: Getting NSWindow windownumber ? (From: Tomas Zahradnicky <email@hidden>)
 >Re: Getting NSWindow windownumber ? (From: "Finlay Dobbie" <email@hidden>)
 >Re: Getting NSWindow windownumber ? (From: Tomas Zahradnicky <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.