FROM : Jonathan E. Jackel
DATE : Thu Nov 07 18:21:47 2002
This confused me at first, too. NSRect is a struct in Cocoa, not an object.
In fact it is a struct of structs (an origin (NSPoint) and a size (NSSize)).
Lose the * in the declaration and the java-ish setFrame argument. Also, I'm
guessing that you want the window centered on the screen (is that what you
meant by "perfect"?). Your "x" argument in setFrame should use width/2
rather than 500/2 if that is the case. Like so (not tested):
NSScreen *screen = [NSScreen mainScreen];
NSRect d = [screen frame];
NSRect newRect;
newRect.size.height = 500;
newRect.size.width = 700;
newRect.origin.x = d.size.width/2 - newRect.size.width/2;
newRect.origin.y = d.size.height/2 - newRect.size.height/2;
[[winControl window] setFrame:newRect display:NO];
You could also use the NSMakeRect() function to set up the new frame.
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/ObjC_c
lassic/Functions/FoundationFunctions.html#BCIFICGC
Jonathan
> I'm trying to use the following code to get a perfect placement
> for my window:
>
> NSRect *d;
> NSScreen *screen = [NSScreen mainScreen];
> d = [screen frame];
> [[winControl window] setFrame:[NSRect x:[[d width]/2-500/2] y:[[d
> height]/2-500/2] w:700 h:500] display:NO];
>
> But for some reason I get 2 errors trying to run it:
> following
> AppController.m:121: incompatible types in assignment
> AppController.m:122: parse error before "NSRect"
>
> Any ideas?
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
DATE : Thu Nov 07 18:21:47 2002
This confused me at first, too. NSRect is a struct in Cocoa, not an object.
In fact it is a struct of structs (an origin (NSPoint) and a size (NSSize)).
Lose the * in the declaration and the java-ish setFrame argument. Also, I'm
guessing that you want the window centered on the screen (is that what you
meant by "perfect"?). Your "x" argument in setFrame should use width/2
rather than 500/2 if that is the case. Like so (not tested):
NSScreen *screen = [NSScreen mainScreen];
NSRect d = [screen frame];
NSRect newRect;
newRect.size.height = 500;
newRect.size.width = 700;
newRect.origin.x = d.size.width/2 - newRect.size.width/2;
newRect.origin.y = d.size.height/2 - newRect.size.height/2;
[[winControl window] setFrame:newRect display:NO];
You could also use the NSMakeRect() function to set up the new frame.
http://developer.apple.com/techpubs/macosx/Cocoa/Reference/Foundation/ObjC_c
lassic/Functions/FoundationFunctions.html#BCIFICGC
Jonathan
> I'm trying to use the following code to get a perfect placement
> for my window:
>
> NSRect *d;
> NSScreen *screen = [NSScreen mainScreen];
> d = [screen frame];
> [[winControl window] setFrame:[NSRect x:[[d width]/2-500/2] y:[[d
> height]/2-500/2] w:700 h:500] display:NO];
>
> But for some reason I get 2 errors trying to run it:
> following
> AppController.m:121: incompatible types in assignment
> AppController.m:122: parse error before "NSRect"
>
> Any ideas?
> _______________________________________________
> cocoa-dev mailing list | <email_removed>
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
| Related mails | Author | Date |
|---|---|---|
| CyberRat17 | Nov 7, 12:56 | |
| Clark S. Cox III | Nov 7, 16:51 | |
| j o a r | Nov 7, 16:52 | |
| Stéphane Sudre | Nov 7, 16:57 | |
| Jonathan E. Jackel | Nov 7, 18:21 | |
| Marco Binder | Nov 7, 18:40 | |
| Marco Binder | Nov 7, 18:49 | |
| Christopher Hollan… | Nov 7, 20:18 | |
| Jonathan E. Jackel | Nov 7, 22:27 | |
| Ondra Cada | Nov 8, 01:43 | |
| John C. Randolph | Nov 11, 01:42 | |
| Kevin Callahan | Nov 11, 04:02 |






Cocoa mail archive

