Producer & Director: TS Huang
Architect & Chief programmer: Cloud Hsu
Programmer: Joe Huang
Arts:
FLYKING
PAPALA
SAKANA
Music & Sound: JungMusic
Translator: Charles Chung
Special Thanks
B.B.
MingJen
DGW
[[UIApplication sharedApplication] openURL: @"sms:12345678"];
HTML links:
<a href="sms:" mce_href="sms:">Launch Text Application</a>
<a href="sms:1-408-555-1212" mce_href="sms:1-408-555-1212">New SMS Message</a>
Native application URL strings:
sms:
sms:1-408-555-1212
-(IBAction) sendInAppSMS:(id) sender
{
MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Hello from Mugunth";
controller.recipients = [NSArray arrayWithObjects:@"12345678", @"87654321", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Unknown Error"
delegate:self cancelButtonTitle:@”OK” otherButtonTitles: nil];
[alert show];
[alert release];
break;
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
// SMS2ViewController.h
// SMS2
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMessageComposeViewController.h>
@interface SMS2ViewController : UIViewController <MFMessageComposeViewControllerDelegate>
{
UILabel *message;
}
@property (nonatomic, retain) UILabel *message;
-(void)displayComposerSheet;
@end
// SMS2ViewController.m
// SMS2
#import "SMS2ViewController.h"
@implementation SMS2ViewController
@synthesize message;
/*
// The designated initializer.
Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
// Custom initialization
}
return self;
}
*/
// Implement loadView to create a view hierarchy programmatically, without using a nib.
/*
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *smsButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
smsButton.frame = CGRectMake(97.0, 301.0, 125.0, 37.0);
smsButton.adjustsImageWhenDisabled = YES;
[smsButton setTitle:@" Send SMS" forState:UIControlStateNormal];
[smsButton setTitleColor:[UIColor colorWithWhite:0.000 alpha:1.000] forState:UIControlStateNormal];
[smsButton setTitleShadowColor:[UIColor colorWithWhite:0.000 alpha:1.000] forState:UIControlStateNormal];
[smsButton addTarget:self action:@selector(displayComposerSheet) forControlEvents:UIControlEventTouchUpInside];
message = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 360.0, 280.0, 29.0)];
message.frame = CGRectMake(20.0, 360.0, 280.0, 29.0);
message.adjustsFontSizeToFitWidth = YES;
message.hidden = YES;
message.text = @"";
message.userInteractionEnabled = NO;
[self.view addSubview:smsButton];
[self.view addSubview:message];
}
-(void)displayComposerSheet
{
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
icker.messageComposeDelegate = self;
picker.recipients = [NSArray arrayWithObject:@"123456789"];
// your recipient number or self for testing
picker.body = @"test from OS4";
[self presentModalViewController:picker animated:YES];
[picker release];
NSLog(@"SMS fired");
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
message.hidden = NO;\
switch (result)
{
case MessageComposeResultCancelled:
message.text = @"Result: canceled";
NSLog(@"Result: canceled");
break;
case MessageComposeResultSent:
message.text = @"Result: sent";
NSLog(@"Result: sent");
break;
case MessageComposeResultFailed:
message.text = @"Result: failed";
NSLog(@"Result: failed");
break;
default:
message.text = @"Result: not sent";
NSLog(@"Result: not sent");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload
{
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
}
@end
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface CloudReview : NSObject {
int m_appleID;
}
+(CloudReview*)sharedReview;
-(void) reviewFor:(int)appleID;
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
@end
#import "CloudReview.h"
@implementation CloudReview
static CloudReview* _sharedReview = nil;
+(CloudReview*)sharedReview
{
@synchronized([CloudReview class])
{
if (!_sharedReview)
[[self alloc] init];
return _sharedReview;
}
return nil;
}
+(id)alloc
{
@synchronized([CloudReview class])
{
NSAssert(_sharedReview == nil, @"Attempted to allocate a second instance of a singleton.");
_sharedReview = [super alloc];
return _sharedReview;
}
return nil;
}
-(void)reviewFor:(int)appleID
{
m_appleID = appleID;
BOOL neverRate = [[NSUserDefaults standardUserDefaults] boolForKey:@"neverRate"];
if(neverRate != YES) {
//Show alert here
UIAlertView *alert;
alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"rate_title",@"Rate My Appication")
message:NSLocalizedString(@"rate_main",@"Please Rate my Application")
delegate: self
cancelButtonTitle:NSLocalizedString(@"rate_cancel",@"Cancel")
otherButtonTitles: NSLocalizedString(@"rate_now",@"Rate Now"),
NSLocalizedString(@"rate_never",@"Never Rate"), nil];
[alert show];
[alert release];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Never Review Button
if (buttonIndex == 2)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"neverRate"];
}
// Review Button
else if (buttonIndex == 1)
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"neverRate"];
NSString *str = [NSString stringWithFormat:
@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",
m_appleID ];
NSLog(str);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
}
@end
char xtod(char c) {This is a conventional usage.
if (c>='0' && c<='9') return c-'0';
if (c>='A' && c<='F') return c-'A'+10;
if (c>='a' && c<='f') return c-'a'+10;
return c=0; // not Hex digit
}
#include <sstream>
#include <iostream>
int main() {
unsigned int x;
std::stringstream ss;
ss << std::hex << "FF";
ss >> x;
// output it as a signed type
std::cout << static_cast<int>(x) << std::endl;
}
#include <stdio.h>
#include <stdlib.h>
typedef void (*Walk_Fun)(struct Animal *a_This);
typedef struct Animal * (*Dtor_Fun)(struct Animal *a_This);
typedef struct _Animal_Vtable{
Walk_Fun Walk;
Dtor_Fun Dtor;
}Animal_Vtable;
typedef struct _Animal{
Animal_Vtable vtable;
char *Name;
}Animal;
typedef struct _Dog{
Animal_Vtable vtable;
char *Name; // mirror member variables for easy access
char *Type;
}Dog;
void Animal_Walk(Animal *a_This){
printf("Animal (%s) walking\n", a_This->Name);
}
struct Animal* Animal_Dtor(struct Animal *a_This){
printf("animal::dtor\n");
return a_This;
}
Animal *Animal_Alloc(){
return (Animal*)malloc(sizeof(Animal));
}
Animal *Animal_New(Animal *a_Animal){
a_Animal->vtable.Walk = Animal_Walk;
a_Animal->vtable.Dtor = Animal_Dtor;
a_Animal->Name = "Anonymous";
return a_Animal;
}
void Animal_Free(Animal *a_This){
a_This->vtable.Dtor(a_This);
free(a_This);
}
void Dog_Walk(Dog *a_This){
printf("Dog walking %s (%s)\n", a_This->Type, a_This->Name);
}
Dog* Dog_Dtor(Dog *a_This){
// explicit call to parent destructor
Animal_Dtor((Animal*)a_This);
printf("dog::dtor\n");
return a_This;
}
Dog *Dog_Alloc(){
return (Dog*)malloc(sizeof(Dog));
}
Dog *Dog_New(Dog *a_Dog){
// explict call to parent constructor
Animal_New((Animal*)a_Dog);
a_Dog->Type = "Dog type";
a_Dog->vtable.Walk = (Walk_Fun) Dog_Walk;
a_Dog->vtable.Dtor = (Dtor_Fun) Dog_Dtor;
return a_Dog;
}
int main (int argc, const char * argv[]) {
/*
base class:
Animal *a_Animal = Animal_New(Animal_Alloc());
*/
Animal *a_Animal = (Animal*)Dog_New(Dog_Alloc());
a_Animal->vtable.Walk(a_Animal);
Animal_Free(a_Animal);
return 0;
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace DrawDesktop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IntPtr hdc = GetDCEx(GetDesktopWindow(), IntPtr.Zero, 1027);
using (Graphics g = Graphics.FromHdc(hdc))
{
g.FillEllipse(Brushes.Red, 0, 0, 400, 400);
}
}
[DllImport("user32.dll")]
static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
static extern IntPtr GetDCEx(IntPtr hwnd, IntPtr hrgn, uint flags);
}
}
#include <iostream>
#include <vector>
using namespace std;
enum Suit
{
Spade = 0,
Heart,
Diamond,
Club
};
class Poker
{
private:
Suit m_suit;
int m_number;
public:
Poker(Suit suit,int number)
{
m_suit = suit;
m_number = number;
}
string GetSuit()
{
string suit = "Spade";
if(m_suit == Heart)
suit = "Heart";
if(m_suit == Diamond)
suit = "Diamond";
if(m_suit == Club)
suit = "Club";
return suit;
}
friend ostream& operator <<(ostream& os, Poker* pk)
{
string suit = pk->GetSuit();
os << "[" << suit.c_str() << ":" << pk->m_number << "]";
return os;
}
};
class Cards
{
private:
vector<Poker*> m_cards;
public:
Cards()
{
for(int i = 0 ; i < 52 ; i++)
{
m_cards.push_back(new Poker((Suit)(i / 13), (i % 13)+1));
}
}
void Output()
{
vector<Poker*>::iterator iter = m_cards.begin();
for(; iter != m_cards.end() ; iter++)
{
cout<<(Poker*)(*iter)<<endl;
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Cards *cards = new Cards();
cards->Output();
int a = 0;
a = cin.get();
return 0;
}
while(!GameEnd)
{
Update();
Render();
}
void Loader()
{
thread t1 = new thread(&Update,1000/frequency);
t1.Start();
thread t2 = new thread(&Render,1000/60);
t2.Start();
}
void Update()
{
// do update
}
void Render()
{
// do render
}
long lastTime = getTimeTick();
while(!GameEnd)
{
if( (getTimeTick() - lastTime) > (1000/frequency) )
{
Update();
lastTime = getTimeTick();
}
Render();
}
UIImage *tmp = [UIImage imageNamed:@"logo.png"]; // imageNamed will return an autorelease objectAvoid using autorelease object.
bigpicture = [[UIImageView alloc] initWithImage:tmp];
//[tmp release];
// if you release a autorelease object, you application may be crash.
// so it dose not need release
class SuccessViewIn develop of game, I used random generate NPC.
{
private:
UIImageView* m_View;
public:
SuccessView(UIView* parentView);
~SuccessView();
};
SuccessView::SuccessView(UIView* parentView)
{
m_View = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
// after alloc, m_View's retainCount = 1
[parentView addSubView:m_View];
// after addSubView, m_View's retainCount = 2
}
SuccessView::~SuccessView()
{
[m_View removeFromSuperview];
// after removeFromSuperview, m_View's retainCount = 1
[m_View release];
// after release, m_View's retainCount = 0, release success.
}
class CrashView
{
private:
UIImageView* m_View;
public:
CrashView(UIView* parentView);
~CrashView();
};
CrashView::CrashView(UIView* parentView)
{
m_View = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
// after alloc, m_View's retainCount = 1
[parentView addSubView:m_View];
// after addSubView, m_View's retainCount = 2
[m_View release];
// after release, m_View's retainCount = 1
}
CrashView::~CrashView()
{
[m_View release];
// this release may cause application crash.
}
class DemoSample
{
private:
UIView* m_MainView;
SuccessView* success;
CrashView* crash;
public:
DemoSample();
~DemoSample();
void TestRemoveSuccessView();
void TestRemoveCrashView();
};
DemoSample::DemoSample()
{
m_MainView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
success = new SuccessView(m_MainView); // draw success view on m_MainView
crash = new CrashView(m_MainView); // draw crash view on m_MainView
}
DemoSample::~DemoSample()
{
[m_MainView release];
}
void DemoSample::TestRemoveSuccessView()
{
delete success; // it will success to remove this view from m_MainView
}
void DemoSample::TestRemoveCrashView()
{
delete crash; // it will cause crash
}
template<class _Prop_t,class _ObjClass_t>
class Property
{
private:
typedef _Prop_t (_ObjClass_t::* _pmGet_t)() const;
typedef void (_ObjClass_t::* _pmSet_t)(_Prop_t);
_ObjClass_t& m_objInstance;
_pmGet_t m_pmGet;
_pmSet_t m_pmSet;
public:
Property(_ObjClass_t& objInstance, _pmGet_t pmGet, _pmSet_t pmSet)
: m_objInstance(objInstance), m_pmGet(pmGet), m_pmSet(pmSet)
{}
operator _Prop_t() { return (_Prop_t)(m_objInstance.*m_pmGet)(); }
void operator =(_Prop_t value) { (m_objInstance.*m_pmSet)(value); }
};
I will use ArrayLit/HashTable/Dictionary to compare the search algorithm's performance.
private void btnArrayList_Click(object sender, EventArgs e)
{
int t_ulStartTime = AccurateTimer.GetTimeTick();
for (int i = 1000; i < 42880; i++)
{
m_event.AddEventLogWithArrayList(i);
}
int t_ulEndTime = AccurateTimer.GetTimeTick();
double t_r8PassedTime = (double)(t_ulEndTime - t_ulStartTime) / (double)1000.0;
MessageBox.Show("ArrayList spend time:" + t_r8PassedTime);
}
private void btnHashTable_Click(object sender, EventArgs e)
{
int t_ulStartTime = AccurateTimer.GetTimeTick();
for (int i = 1000; i < 42880; i++)
{
m_event.AddEventLogWithHashtable(i);
}
int t_ulEndTime = AccurateTimer.GetTimeTick();
double t_r8PassedTime = (double)(t_ulEndTime - t_ulStartTime) / (double)1000.0;
MessageBox.Show("Hashtable spend time:" + t_r8PassedTime);
}
private void btnDictionary_Click(object sender, EventArgs e)
{
int t_ulStartTime = AccurateTimer.GetTimeTick();
for (int i = 1000; i < 42880; i++)
{
m_event.AddEventLogWithDictionary(i);
}
int t_ulEndTime = AccurateTimer.GetTimeTick();
double t_r8PassedTime = (double)(t_ulEndTime - t_ulStartTime) / (double)1000.0;
MessageBox.Show("Dictionary spend time:" + t_r8PassedTime);
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.SmoothingMode = SmoothingMode.Default;
Rectangle rect=new Rectangle(0,0,this.Width,this.Height);
PointF center=new PointF(rect.Width/2,rect.Height/2);
float offsetX=0;
float offsetY=0;
offsetX = center.X - DoorWidth / 2;
offsetY = center.Y - DoorHeight / 2;
picRect = new RectangleF(offsetX, offsetY, DoorWidth, DoorHeight);
PointF Pcenter=new PointF(picRect.X+picRect.Width/2,
picRect.Y+picRect.Height/2);
e.Graphics.TranslateTransform(Pcenter.X, Pcenter.Y);
e.Graphics.RotateTransform(-m_i4Angle);
e.Graphics.TranslateTransform(-Pcenter.X, -Pcenter.Y);
if (m_bIsOpened)
{
int t_i4doorWidth = (DoorWidth - DoorOpenWidth) / 2;
RectangleF picRect1 = new RectangleF(offsetX, offsetY, t_i4doorWidth, DoorHeight);
e.Graphics.FillRectangle(new SolidBrush(m_OpenColor), picRect1);
RectangleF picRect2 = new RectangleF(offsetX + DoorOpenWidth + t_i4doorWidth, offsetY, t_i4doorWidth, DoorHeight);
e.Graphics.FillRectangle(new SolidBrush(m_OpenColor), picRect2);
}
else
{
e.Graphics.FillRectangle(new SolidBrush(m_CloseColor), picRect);
}
e.Graphics.ResetTransform();
}
Image
First, we need to create a dll project, I named XDXD.
And create class XDXD and implement this class.