Feb
05
2009

FYP Technology: WinAPI and UIKit Junk

I spent a lot of time today not getting a lot of work done, but spending a lot of time mucking about in what I wouldn’t describe as enjoyable APIs. The first is the win32 API, which no-one likes anyway. A few hours of work involved looking through a few .rc files from other projects and finding where I was going wrong with mine, and then the following few of lines of code:

HWND hwnd = 0;
HINSTANCE hInst = GetModuleHandle(NULL);
mWindow->getCustomAttribute( "WINDOW", &hwnd ); // mWindow is an Ogre window
 
// IDI_APPICON is defined in Resource.h, generated from Yakumo.rc
SendMessage( hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_APPICON)) );
SendMessage( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_APPICON)) );

This changed my application’s icon in Alt+Tab and in the corner of the window. A small result for the amount of time it took.

The latter half of the day was spent with UIKit, and especially struggling with Interface Builder. That involved a whole lot of guessing and looking at Apple’s sample projects until I found one that was organised a bit like my own, and figured out where I was going wrong. Turns out I needed to have my custom UIView’s UIViewController (MainViewController) added to the main UIWindow’s XIB file, not in with the UIView’s XIB. Also, instead of loading the MainViewController from its own XIB file when it’s displayed at runtime, I set up an outlet from the UIViewController which displays MainViewController (that is, BrowserController), connecting to MainViewController. That way it instantiates it itself automagically and I can just use the reference at runtime without worrying about loading it from its XIB.

This allowed me get a workaround sorted out for the trouble I’ve been having with shouldAutorotateToInterfaceOrientation:. Right now I’m struggling with this piece of code:

- (void) didLoseConnection
{	
	[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
	UIAlertView *mbox = [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Game connection lost." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
	[mbox show];
	[self dismissModalViewControllerAnimated:YES];
}

It should display an alert box and then make the MainViewController disappear… but the screen dims like it’s about to show an alert box but just freezes… (update: solution is here)

Here’s how I’m displaying MainViewController using the outlet:

[self presentModalViewController:mainViewController animated:YES];
Written by ダニエル氏 in: University |

No Comments »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com