Mailing Lists: Apple Mailing Lists

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

Programmatically creating Windows



I want to create a program, that displays (raw bitmap) images. I have a menuitem called open,
that open the file and puts the contents into a NSData object. From the header of the NSData
object I get the size.width and size.height of the image.
The next step is to create a window (being proportional, size-limited) containing an NSView/NSImage
to the display the data.
How do I create this window programmatically?
Is anywhere an example showing how to do this?

I have created a small test project. Two menu entries called Show Window , Hide Window. connected
to myObject, with two actions showWindow hideWindow with following code....

NSWindow *myWindow;
NSImageView *myImageView;

@implementation myObject

NSRect myRect = NSMakeRect(0, 0, 600, 350)

- (void)dealloc {
[myWindow release];
[myImageView release];
[super dealloc];
}

- (void)showWindow
{
myWindow=[[NSWindow alloc] initWithContentRect:myRect
styleMask: NSTitledWindowMask |
NSResizableWindowMask |
NSMiniaturizableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
myImageView=[[NSImageView alloc] initWithFrame:myRect];
[myImageView setFrame:[myWindow frame]];
[myWindow setContentView:myImageView];
[myWindow center];
[myWindow makeKeyAndOrderFront:self];
// like to fill with red color
[[NSColor redColor] set];
NSRectFill(myRect);

}

- (void)hideWindow
{
[myWindow close];
}

When I start the program I only have the menue, when I select show Window the window is created with a red filled
ImageView. When I select hideWindow the window goes away. But when I select show Window again I get a window,
but it is not filled. What is wrong with my code?

Thanks, fritz




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.