• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Programmatically creating Windows
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Programmatically creating Windows


  • Subject: Programmatically creating Windows
  • From: HAEUPL Friedrich - RTAA <email@hidden>
  • Date: Fri, 30 Nov 2001 10:55:04 +0100

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


  • Prev by Date: How to draw a String in a Cocoa-Java-App?
  • Next by Date: NSOutlineView and cells
  • Previous by thread: How to draw a String in a Cocoa-Java-App?
  • Next by thread: NSOutlineView and cells
  • Index(es):
    • Date
    • Thread