Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rahulkesharwani

macrumors newbie
Original poster
Oct 30, 2011
5
0
Hi

I have a C++ framework and I would like to pop up a progress bar with a Cancel button and update the text on the progress bar at required times. I know I should use a NSProgressIndicator but could not make it work as I am very new to Cocoa. My progress bar should look like a indeterminate progress indicator and should be placed at the centre of the window of the application that uses my framework.

Please note that mine is a C++ framework, not a Cocoa app. The links that I come across on web talks about creating NSProgressIndicator using Interface Builder etc. which I cant use. I have to do this programatically.

Thanks & Regards
Rahul
 
Hi

I have a C++ framework and I would like to pop up a progress bar with a Cancel button and update the text on the progress bar at required times. I know I should use a NSProgressIndicator but could not make it work as I am very new to Cocoa. My progress bar should look like a indeterminate progress indicator and should be placed at the centre of the window of the application that uses my framework.

Please note that mine is a C++ framework, not a Cocoa app. The links that I come across on web talks about creating NSProgressIndicator using Interface Builder etc. which I cant use. I have to do this programatically.

Thanks & Regards
Rahul

Is this a cross-platform framework or Mac OSX only?
 
Well you could utilize Objective-C++ and link to the Cocoa libraries. You can build up NSWindows programatically like you can with other GUI toolkits, it just takes a bit more effort.
 
I am trying to do this programatically. Following is some of the code I have written:

Code:
NSWindow *myWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO];
[myWindow center];
bool isWindowVisible;
isWindowVisible = [myWindow isVisible];
[myWindow setViewsNeedDisplay:YES];
NSProgressIndicator *myProgressIndicator;
myProgressIndicator = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
[[myWindow contentView] addSubview:myProgressIndicator];
[myProgressIndicator setHidden:NO];
[myProgressIndicator startAnimation:myProgressIndicator];
[myProgressIndicator stopAnimation:myProgressIndicator];

But this doesn't display anything. I also see that isVisible returns false for my created window. What else should I do to make this work?
 
Also, do you have a NSRunLoop running to handle the event dispatching? If you've called NSApplicationMain, then that will have setup up an NSRunLoop for you.
 
I have tried using orderFront and makeKeyAndOrderFront methods for the NSWindow I created. With the latter, I sometimes get a white window but not always. I am not sure what is going wrong.

Is it that I need to get the parent window of the application from within my framework and then draw my progress bar on that? If yes, how to do that.

I would be very grateful if some one can provide a code sample to do what I am trying to do. Being a beginner in Cocoa, its taking me long to figure out things and I am a bit crunched on time.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.