Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Adv Programmer\Cocoa Newbie (Window Help!)

Adv Programmer\Cocoa Newbie (Window Help!)
Thread Tools
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Feb 10, 2001, 03:30 PM
 
I am not too much of a newbie at the "old" programming structures, but I am fairly new to Objective-C and Cocoa.

I can do a bunch of stuff already like sending messages to actions, etc.. but I do not know how to show and hide windows in the easiest possible manner. I just want the window to open.

So far I have just been using IB to set the "visible at launch" property and use it like that, but I have a custom about screen I want to add for example, and I don't want it visible at launch.

Can someone throw some Obj-C\Cocoa oriented code my way assuming the window name is aboutwin.

I would really appreciate it. Thanks.
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Feb 10, 2001, 05:07 PM
 
First thing, I'm assuming that you mean that the name of the outlet to the window is aboutwin because the window name has almost nothing to do with referencing the window. If you don't know what an outlet is, read "Programming and The Objective C Language", by Apple. You can download it from their site.

Anyway, to make your window appear just say

[aboutwin makeKeyAndOrderFront:self];

The self is just because that method wants to know the sender. You could pass it nil and it probably wouldn't make a difference. To make the window disappear without closing it you can use:

[aboutwin orderOut:self];

There are also a whole bunch of stuff for setting the window to different levels and whatnot. Read Apple's documentation on NSWindow for more.

BTW, if you just want the same type of Lame about window that is in Project Builder, then you don't have to write any code. That is created automatically from your program icon and the stuff in InfoPlist.strings. Of course you can always not use it and make your own.

If you ever need to find out the name of your window you can use

[aboutwin title];

and it'll return the name as an NSString object. So if you wanted to find out the name of the keywindow in your program you could say

[[NSApp keyWindow] title];

Now, you could always see if that is equal to a known title, but if you have an outlet for the window just see if [NSApp keyWindow] is equal to the outlet.

One thing to note. I think that most people don't know this. When you either create your windows programmatically or when they awake from nib then you should call the method - (void)useOptimizedDrawing BOOL)flag with YES as the flag and the window as the object. Always do this unless you have overlapping subviews. The default is NO. If you have overlapping subviews then they may not draw in the correct order and you might not see them.

[This message has been edited by Dalgo (edited 02-10-2001).]
     
YupYup  (op)
Fresh-Faced Recruit
Join Date: Feb 2001
Status: Offline
Reply With Quote
Feb 10, 2001, 06:47 PM
 
Ok, this is starting to make more sense.

I tried to implement it but it is saying aboutwin is undefined.

Here is what I did.

I have the window, I also have a class called WinDisplay. In this class I created an outlet called aboutwin. I connected the window to the outlet.

Here is the code from the class. I am wondering if this is how you set it up. I learn by doing. Until I get a firm grasp on at least a bunch of the code reference is meaningless.

Two functions are there but they are unused for now. I now this "class" is setup correctly as I have been doing some other tasks with it already.


#import <AppKit/AppKit.h>
#import <Carbon/Carbon.h>
#import "WinDisplay.h"

@implementation WinDisplay

- (void)Display_About id)sender
{
[aboutwin makeKeyAndOrderFront:self];
}

- (void)Display_Registration id)sender
{

}

- (void)Display_StartupSelect id)sender
{

}


@end


Thanks

[This message has been edited by YupYup (edited 02-10-2001).]
     
Senior User
Join Date: Nov 2000
Status: Offline
Reply With Quote
Feb 10, 2001, 08:52 PM
 
I'm new to Obj-C myself so if this is incorrect let me know!

In your WinDisplay.h file you should have:

Code:
@interface WinDisplay : NSObject //I'm assuming? { id aboutwin; } - (void)Display_About: (id)sender; - (void)Display_Registration: (id)sender; - (void)Display_StartupSelect: (id)sender; @end

You would control+drag from the WinDisplay object in IB to the NSPanel(or NSWindow) that you're using for the About Window. Then select aboutwin in the Inspector and click Connect.

Also, you can control+drag from the "About" menuitem straight to your NSPanel(or Window) and connect the action to makeKeyAndOrderFront.

Hope it helps! Good luck.

[Enclosed the code in code tags! ]
[Another attempt to get rid of the sad faces.]

[This message has been edited by IamBob (edited 02-10-2001).]
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Feb 11, 2001, 09:37 AM
 
Yea, if you are making the interface before the implementation then it's really handy to use the "Create Files" option in the classes menu in Interface Builder. Select the class whose files you'd like to create, and choose "Create Files" from the menu, add it to your project and then you have a sort of skeleton around which you can write you code. It's handy because you don't have to declare all of your Actions and Outlets in the header; it does it for you automatically. Less typing is good.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:20 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2