Tuesday, January 31, 2012

C/C++ Exercise: sizeof() and pointer

C/C++ Exercise: sizeof() and pointer
#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: sizeof" << endl << endl;

 cout << "sizeof(int): " << sizeof(int) << endl;
 cout << "sizeof(char): " << sizeof(char) << endl;
 cout << endl;

 //Array
 char chArray[10];
 cout << "sizeof array: " << sizeof(chArray) << endl;
 cout << "sizeof a element in array: " << sizeof(chArray[0]) << endl;
 cout << "number of element in array: " << sizeof(chArray)/sizeof(chArray[0]) << endl;
 cout << endl;

 //pointer to int
 int i = 7;
 int* ptInt = &i;
 cout << "ptInt = " << ptInt << endl;
 cout << "*ptInt = " << *ptInt << endl;
 cout << "sizeof(ptInt): " << sizeof(ptInt) << endl;
 cout << "sizeof(*ptInt): " << sizeof(*ptInt) << endl;
 cout << endl;

 //pointer to char
 char* ptChar ("Hello World!");
 cout << "ptChar = " << ptChar << endl;
 cout << "*ptChar = " << *ptChar << endl;
 cout << "sizeof(ptchar): " << sizeof(ptChar) << endl;
 cout << "sizeof(*ptchar): " << sizeof(*ptChar) << endl;
 cout << endl;

 cout << endl;
 system("PAUSE");
 return 0;

}

Microsoft Xbox Live Coming To Droids And iPads

While the Xbox Live experiences and games always work best on the Windows platform, we understand that some Xbox fans may be using other types of devices. To satisfy that need, we are working to extend a few of our Xbox experiences and titles to other platforms.” ~ A Microsoft spokesman stated.

Microsoft generates a significant amount of revenue from Xbox Live, its online gaming network. Xbox Live games are currently compatible only with one platform – Windows Phone. However, Microsoft is planning to bring Xbox Live games to other platforms like Apple’s iOS and Google‘s Android.

Source: http://www.forbes.com/sites/greatspeculations/2012/01/25/microsoft-xbox-live-coming-to-droids-and-ipads/

Monday, January 30, 2012

New standard of C++ - ISO/IEC 14882:2011

ISO/IEC 14882:2011, new standard of C++ programming language, revise ISO/IEC 14882:2003 and target to publish at 2012-02-28.

ISO/IEC 14882:2011 specifies requirements for implementations of the C++ programming language. The first such requirement is that they implement the language, and so ISO/IEC 14882:2011 also defines C++. Other requirements and relaxations of the first requirement appear at various places within ISO/IEC 14882:2011.

C++ is a general purpose programming language based on the C programming language as specified in ISO/IEC 9899:1999. In addition to the facilities provided by C, C++ provides additional data types, classes, templates, exceptions, namespaces, operator overloading, function name overloading, references, free store management operators, and additional library facilities.

ISO/IEC 14882:2011

Sunday, January 29, 2012

C/C++ Exercise: cout number in dec, hex, oct format using std::

C/C++ Exercise: cout number in dec, hex, oct format using std::
#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: cout number in dec, hex, oct format using std::" << endl << endl;

 int number = 1024;
 cout << "dec: " << std::dec << number << endl;
 cout << "hex: " << std::hex << number << endl;
 cout << "oct: " << std::oct << number << endl;

 cout << endl;
 system("PAUSE");
 return 0;

}

C/C++ Exercise: Initializing pointer

C/C++ Exercise: Initializing pointer
#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: Initializing pointer" << endl << endl;

 int number = 10;
 int *p_number = &number;
 cout << "pointer to address of another variable" << endl;
 cout << "p_number: " << p_number << endl;
 cout << "*p_number: " << *p_number << endl;
 cout << endl;

 int *p_nullptr = nullptr;
 cout << "pointer to nullptr" << endl;
 cout << "p_nullptr: " << p_nullptr << endl;
 //cout << "*p_nullptr: " << *p_nullptr << endl; // <- Invalid
 /* Will cause Unhandled exception at 0x003F13AE in Win32ConsoleApplication.exe:
  *  0xC0000005: Access violation reading location 0x00000000.
  */
 cout << endl;

 //Check if pointer point to anything
 if(p_number){
  cout << "p_number point to something" << endl;
 }else{
  cout << "p_number point to nothing" << endl;
 }
 cout << endl;

 if(p_nullptr){
  cout << "p_nullptr point to something" << endl;
 }else{
  cout << "p_nullptr point to nothing" << endl;
 }
 cout << endl;


 cout << endl;
 system("PAUSE");
 return 0;

}


nullptr represents a null pointer value. Use a null pointer value to indicate that an object handle, interior pointer, or native pointer type does not point to an object.

The nullptr keyword is equivalent to Nothing in Visual Basic and null in C#.

C/C++ Exercise: Initializing two-dimension array

#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "C/C++ Exercise: Initializing two-dimension array" << endl << endl;

 const int size_i = 3;
 const int size_j = 4;
 int a[size_i][size_j] = 
 {
  {0, 1, 2, 3},
  {10}
 };

 cout << endl;
 cout << "Accessed as two dimension array" << endl;
 for(int i = 0; i < size_i; i++){
  for(int j = 0; j < size_j; j++){
   cout << a[i][j] << " ";
  }
  cout << endl;
 }

 cout << endl;

 int *p = *a;
 cout << "Accessed by pointer" << endl;
 for(int i = 0; i < size_i * size_j; i++){
  cout << i << ":" << *(p + i) << " ";
 }
 cout << endl;

 cout << endl;
 system("PAUSE");
 return 0;

}

C/C++ Exercise: Initializing two-dimension array

C/C++ Exercise: Access two-dimension array by pointer

#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "Exercise: Access two-dimension array using pointer" << endl << endl;

 const int size_i = 3;
 const int size_j = 4;
 int a[size_i][size_j];
 

 //init array
 for(int i = 0; i < size_i; i++){
  for(int j = 0; j < size_j; j++){
   a[i][j] = i * 10 + j;
  }
 }

 cout << endl;
 cout << "Accessed as two dimension array" << endl;
 for(int i = 0; i < size_i; i++){
  for(int j = 0; j < size_j; j++){
   cout << a[i][j] << " ";
  }
  cout << endl;
 }

 cout << endl;

 int *p = *a;
 cout << "Accessed by pointer" << endl;
 for(int i = 0; i < size_i * size_j; i++){
  cout << i << ":" << *(p + i) << " ";
 }
 cout << endl;

 cout << endl;
 system("PAUSE");
 return 0;

}

C/C++ Exercise: Access two-dimension array by pointer

Exercise of cin.getline()

The function getline(_Str, _Count, _Delim) Gets a line from the input stream.
where:
  • _Str: A string in which to write.
  • _Count: The number of characters to read from strbuf.
  • _Delim: The character that should terminate the read if it is encountered before _Count.


Exercise:
#include <iostream>
#include <conio.h>

using std::cin;
using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl;
 cout << "Exercise cin.getline()" << endl << endl;

 const int MAX = 10;
 char CharArray[MAX];

 int ch;
 do{
  cout << "Type something: " << endl;
  cin.getline(&CharArray[0], 5, '\n');
  cout << "CharArray: " << CharArray << endl << endl;

  cout << "Retry? <y/n>" << endl;
  ch = _getch();
  ch = toupper( ch );
 }while(ch == 'Y');

 return 0;
}


Exercise of cin.getline()

Size of String, char array

If you declare char array with pre-defined size, the size is number of char plus Termination Charcter, /0. So, in the fllowing case:

char CharArray[10];

The maxmum number of char can be stored in CharArray is 9.
Size of String, char array

Thursday, January 26, 2012

Basic usage of enum class in CLR C++

// testENUM_CLR.cpp : main project file.

#include "stdafx.h"

using namespace System;

enum class Day {SUN, MON, TUE, WED, THU, FRI, SAT};

int main(array<System::String ^> ^args)
{
    Console::WriteLine(L"http://dev-microsoft.blogspot.com/");

 Console::WriteLine("");
 Console::WriteLine(L"Day {0} have value of {1}.", Day::SUN, safe_cast<int>(Day::SUN));
 Console::WriteLine(L"Day {0} have value of {1}.", Day::MON, safe_cast<int>(Day::MON));
 Console::WriteLine(L"Day {0} have value of {1}.", Day::TUE, safe_cast<int>(Day::TUE));
 Console::WriteLine(L"Day {0} have value of {1}.", Day::WED, safe_cast<int>(Day::WED));
 Console::WriteLine(L"Day {0} have value of {1}.", Day::THU, safe_cast<int>(Day::THU));
 Console::WriteLine(L"Day {0} have value of {1}.", Day::FRI, safe_cast<int>(Day::FRI));
 Console::WriteLine(L"Day {0} have value of {1}.", Day::SAT, safe_cast<int>(Day::SAT));

 Console::ReadLine();
    return 0;
}

Basic usage of enum class in CLR C++

Compare to Basic usage of enum in C++

Basic usage of enum in C++

#include<iostream>

using std::cout;
using std::endl;

int main(){
 cout << "http://dev-microsoft.blogspot.com/" << endl << endl;

 enum Day {SUN, MON, TUE, WED, THU, FRI, SAT};

 cout << SUN << endl;
 cout << MON << endl;
 cout << TUE << endl;
 cout << WED << endl;
 cout << THU << endl;
 cout << FRI << endl;
 cout << SAT << endl;

 cout << endl;
 system("PAUSE");
}

Basic usage of enum in C++


Compare to Basic usage of enum class in CLR C++

Initializing array in C++

Initializing array in C++
#include <iostream>

using std::cout;
using std::endl;

int main(){

 int array1[10];
 array1[0] = 100;
 int array2[10] = {201, 202, 203, 204, 205, 206, 207, 208, 209, 200};
 int array3[10] = {301, 302, 303};

 cout << "http://dev-microsoft.blogspot.com/" << endl << endl;
 cout << "Array without initializing, all elements contain junk value!" << endl;
 for(int i = 0; i < 10; i++){
  cout << array1[i] << " ";
 }

 cout << endl << endl;
 cout << "Array with all element initialized." << endl;
 for(int i = 0; i < 10; i++){
  cout << array2[i] << " ";
 }

 cout << endl << endl;
 cout << "Array with partial initialized, un-initialized elemented will be set 0." << endl;
 for(int i = 0; i < 10; i++){
  cout << array3[i] << " ";
 }

 cout << endl << endl;
 system("PAUSE");
}

Wednesday, January 25, 2012

Free download MSDN Magazine 2011 December


Digital MSDN Magazine 2011 December Issue is available to download here, for FREE!

Console::ReadKey() - obtain a single from Console

  • ReadKey(): Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.
  • ReadKey(true): Obtains the next character or function key pressed by the user, NOT display the pressed key in the console window.
  • ReadKey(false): Obtains the next character or function key pressed by the user, display the pressed key in the console window.


Example:
Obtain a single from Console using Console::ReadKey()

// CLRConsole.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
 ConsoleKeyInfo keyPressed;

 do{
  Console::WriteLine(L"press and key, or Q to quit");
  keyPressed = Console::ReadKey();
  Console::WriteLine();
  Console::WriteLine(keyPressed.KeyChar);
 }while(keyPressed.KeyChar != 'Q' && keyPressed.KeyChar != 'q');

 return 0;
}

Monday, January 23, 2012

^ (Handle to Object on Managed Heap)

In last post "Get user input from Console, ReadLine()", the returned oject from Console::ReadLine() is in data type of String^. ^ indicate that it is a handle to an object.

A handle to an object on the managed heap points to the "whole" object, and not to a member of the object.

See gcnew for information on how to create an object on the managed heap.

In Visual C++ 2002 and Visual C++ 2003, __gc * was used to declare an object on the managed heap. The ^ replaces __gc * in the new syntax.

The common language runtime maintains a separate heap on which it implements a precise, asynchronous, compacting garbage collection scheme. To work correctly, it must track all storage locations that can point into this heap at runtime. ^ provides a handle through which the garbage collector can track a reference to an object on the managed heap, thereby being able to update it whenever that object is moved.

Because native C++ pointers (*) and references (&) cannot be tracked precisely, a handle-to object declarator is used.

Member selection through a handle (^) uses the pointer-to-member operator (->).


Read more: http://msdn.microsoft.com/en-us/library/yk97tc08.aspx

Get user input from Console, ReadLine()

The function Console::ReadLine() reads a complete line from user inpt from console, terminated when ENTER key pressed.

Example:
Example of using Console::ReadLine()
// CLRConsole.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{

 Console::WriteLine(L"type in something, then press ENTER:");
 String^ userInput = Console::ReadLine();

 Console::WriteLine("Thanks! you enter: " + userInput);

 Console::ReadLine();
 return 0;
}


Please note that the data returned from Console::ReadLine() is in type of String^. It's a handle that reference a String object. To know more about "^", please refer the post ^ (Handle to Object on Managed Heap).

Sunday, January 22, 2012

More output format for Console::Write()/WriteLine()

Example:
// CLRConsole.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{

 Console::WriteLine(L"More output format for Console::Write()/WriteLine()");
 Console::WriteLine(L"C/c: in Currency Format: {0:C4}", 123.456789);
 Console::WriteLine(L"D/d: output integer as decimal: {0:D4}", 123);
 Console::WriteLine(L"E/e: output floating point in scientific format: {0:E4}", 123.456789);
 Console::WriteLine(L"F/f: output floating point in fixed-point format: {0:F4}", 123.456789);
 Console::WriteLine(L"G/g: output in compact form: {0:G5}", 123.456789);
 Console::WriteLine(L"N/n: output with comma if needed: {0:N}", 12345.6789);
 Console::WriteLine(L"X/x: output integer as hexadecimal: {0:D4}", 123);

 Console::ReadLine();
    return 0;
}

output format for Console::Write()/WriteLine()

Console::Write()/WriteLine() with arguments

Modify from the exercise in Hello Visual C++ CLR Console Application using Microsoft Visual Studio 11 Developer Preview to demonstrate the use of Console::Write()/WriteLine() functions with arguments.

Console::Write()/WriteLine() with arguments

// CLRConsole.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
int number1 = 2;
float number2 = 1.23456f;

Console::WriteLine(L"Use Write()/WriteLine() without argument!");
Console::Write(L"Do you know? ");
Console::Write(number1);
Console::Write(L" + ");
Console::Write(number2);
Console::Write(L" = ");
Console::WriteLine(number1 + number2);
//The follow line have Error!
Console::WriteLine(L"Do you know? " + number1 + " + " + number2 + " = " + number1 + number2);

Console::WriteLine(L"");
Console::WriteLine(L"With arguments!");
Console::WriteLine(L"Do you know? {0} + {1} = {2}", number1, number2, number1 + number2);
Console::WriteLine(L"Do you know? {1} + {0} = {2}", number1, number2, number1 + number2);

Console::WriteLine(L"");
Console::WriteLine(L"You can also specify how much digits after decimal point:");
Console::WriteLine(L"Do you know? {0:F2} + {1:F2} = {2:F2}", number1, number2, number1 + number2);
Console::ReadLine();
return 0;
}


Related:
- More output format for Console::Write()/WriteLine()

Friday, January 20, 2012

Introducing Visual Studio Achievements


Visual Studio Achievements extension just released, here's the 60 second recap with what you need to know about how it works.

Tuesday, January 17, 2012

CES 2012 Keynote: A Look at Windows 8


Tami Reller, Chief Marketing Officer, Windows, shares a preview of Windows 8 during the Microsoft keynote at CES 2012 in Las Vegas.

How to Run cmd in Windows 8

In the new Metro style UI of Windows 8, there are no Start menu as in Windows 7, even in Desktop interface. So...how to start cmd in Windows 8?

In Metro UI, move mouse to bottom-left corner, a menu will appear, click the Search.
Move mouse to bottom-left corner, and click Search

Type "cmd" in the search box, it will be shown on the left. Click it to start.
Search cmd in Windows 8

Monday, January 16, 2012

Hello Visual C++ CLR Console Application using Microsoft Visual Studio 11 Developer Preview

- Click New project.. in the start-up page.
New Project...

- Select Visual C++ CLR Console Application, name it CLRConsole, and click OK.
Select template of Visual C++ CLR Console Application

- It's easy to notice on the auto-generated source code, CLRConsole.cpp:
: The parameters passed to main() is (array<System::String ^> ^args). To know more about "^", refer to the post ^ (Handle to Object on Managed Heap).
: The output using Console::, not cout.
: The 'L' in front of "Hello World" indicate that it's wide-character string.

Auto-generated Visual C++ CLR Console Application

- Modify to add following code before return, to make the program pause before exit.
Console::ReadLine();

// CLRConsole.cpp : main project file.

#include "stdafx.h"

using namespace System;

int main(array<System::String ^> ^args)
{
   Console::WriteLine(L"Hello World");
   Console::ReadLine();
   return 0;
}


- Save and Run.
Hello Visual C++ CLR Console Application

static variable

static variable is a variable that has been allocated statically — whose lifetime extends across the entire run of the program. If no initial value have been provided when declare it, it will be initialized for you.

Example:
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

void sub();

int _tmain(int argc, _TCHAR* argv[])
{
 cout << "First run - " << endl;
 sub();
 cout << "Second run - " << endl;
 sub();

 system("PAUSE");
 return 0;
}

void sub(){
 int i;
 static int statici;

 cout << "before assign in sub()" << endl;
 cout << "i = " << i << endl;
 cout << "statici = " << statici << endl;

 i = 1;
 statici = 2;

 cout << "after assign in sub()" << endl;
 cout << "i = " << i << endl;
 cout << "statici = " << statici << endl;
 cout << endl;
}


Example of static variable

Scope Resolution Operator (::)

#include "stdafx.h"
#include <iostream>

using namespace std;

//define Global variable
int i = 10;

int _tmain(int argc, _TCHAR* argv[])
{
 //define variable inside function main()
 int i = 5;


 cout << "i : " << i << endl;
 cout << "::i : " << ::i << endl;

 system("PAUSE");
 return 0;
}


Using of Scope Resolution Operator (::)

Sunday, January 15, 2012

FREE eBook: Programming Windows Phone 7

Programming Windows Phone 7
The eBook Programming Windows Phone 7, by Charles Petzold is free to download from Microsoft. It's available in PDF, ePub and mobi format.

Details: http://blogs.msdn.com/b/microsoft_press/archive/2010/10/28/free-ebook-programming-windows-phone-7-by-charles-petzold.aspx

TABLE OF CONTENTS

Part I The Basics

1 Hello, Windows Phone 7
Targeting Windows Phone 7
The Hardware Chassis
Sensors and Services
File | New | Project
A First Silverlight Phone Program
The Standard Silverlight Files
Color Themes
Points and Pixels
The XAP is a ZIP
An XNA Program for the Phone

2 Getting Oriented
Silverlight and Dynamic Layout
Orientation Events
XNA Orientation
Simple Clocks (Very Simple Clocks)

3 An Introduction to Touch
Low-Level Touch Handling in XNA
The XNA Gesture Interface
Low-Level Touch Events in Silverlight
The Manipulation Events
Routed Events
Some Odd Behavior?

4 Bitmaps, Also Known as Textures
XNA Texture Drawing
The Silverlight Image Element
Images Via the Web
Image and ImageSource
Loading Local Bitmaps from Code
Capturing from the Camera
The Phone’s Photo Library

5 Sensors and Services
Accelerometer
A Simple Bubble Level
Geographic Location
Using a Map Service

6 Issues in Application Architecture
Basic Navigation
Passing Data to Pages
Sharing Data Among Pages
Retaining Data across Instances
The Multitasking Ideal
Task Switching on the Phone
Page State
Isolated Storage
XNA Tombstoning and Settings
Testing and Experimentation

Part II Silverlight

7 XAML Power and Limitations
A TextBlock in Code
Property Inheritance
Property-Element Syntax
Colors and Brushes
Content and Content Properties
The Resources Collection
Sharing Brushes
x:Key and x:Name
An Introduction to Styles
Style Inheritance
Themes
Gradient Accents

8 Elements and Properties
Basic Shapes
Transforms
Animating at the Speed of Video
Handling Manipulation Events
The Border Element
TextBlock Properties and Inlines
More on Images
Playing Movies
Modes of Opacity
Non-Tiled Tile Brushes

9 The Intricacies of Layout
The Single-Cell Grid
The StackPanel Stack
Text Concatenation with StackPanel
Nested Panels
Visibility and Layout
Two ScrollViewer Applications
The Mechanism of Layout
Inside the Panel
A Single-Cell Grid Clone
A Custom Vertical StackPanel
The Retro Canvas
Canvas and ZIndex
The Canvas and Touch
The Mighty Grid

10 The App Bar and Controls
ApplicationBar Icons
Jot and Application Settings
Jot and Touch
Jot and the ApplicationBar
Elements and Controls
RangeBase and Slider
The Basic Button
The Concept of Content
Theme Styles and Precedence
The Button Hierarchy
Toggling a Stopwatch
Buttons and Styles
TextBox and Keyboard Input

11 Dependency Properties
The Problem Illustrated
The Dependency Property Difference
Deriving from UserControl
A New Type of Toggle
Panels with Properties
Attached Properties

12 Data Bindings
Source and Target
Target and Mode
Binding Converters
Relative Source
The “this” Source
Notification Mechanisms
A Simple Binding Server
Setting the DataContext
Simple Decision Making
Converters with Properties
Give and Take
TextBox Binding Updates

13 Vector Graphics
The Shapes Library
Canvas and Grid
Overlapping and ZIndex
Polylines and Custom Curves
Caps, Joins, and Dashes
Polygon and Fill
The Stretch Property
Dynamic Polygons
The Path Element
Geometries and Transforms
Grouping Geometries
The Versatile PathGeometry
The ArcSegment
Bézier Curves
The Path Markup Syntax
How This Chapter Was Created

14 Raster Graphics
The Bitmap Class Hierarchy
WriteableBitmap and UIElement
The Pixel Bits
Vector Graphics on a Bitmap
Images and Tombstoning
Saving to the Picture Library
Becoming a Photo Extras Application

15 Animations
Frame-Based vs. Time-Based
Animation Targets
Click and Spin
Some Variations
XAML-Based Animations
A Cautionary Tale
Key Frame Animations
Trigger on Loaded
Animating Attached Properties (or Not)
Splines and Key Frames
The Bouncing Ball Problem
The Easing Functions
Animating Perspective Transforms
Animations and Property Precedence

16 The Two Templates
ContentControl and DataTemplate
Examining the Visual Tree
ControlTemplate Basics
The Visual State Manager
Sharing and Reusing Styles and Templates
Custom Controls in a Library
Variations on the Slider
The Ever-Handy Thumb
Custom Controls

17 Items Controls
Items Controls and Visual Trees
Customizing Item Displays
ListBox Selection
Binding to ItemsSource
Databases and Business Objects
Fun with DataTemplates
Sorting
Changing the Panel
The DataTemplate Bar Chart
A Card File Metaphor

18 Pivot and Panorama
Compare and Contrast
Music by Composer
The XNA Connection
The XNA Music Classes: MediaLibrary
Displaying the Albums
The XNA Music Classes: MediaPlayer

Part III XNA

19 Principles of Movement
The Naïve Approach
A Brief Review of Vectors
Moving Sprites with Vectors
Working with Parametric Equations
Fiddling with the Transfer Function
Scaling the Text
Two Text Rotation Programs

20 Textures and Sprites
The Draw Variants
Another Hello Program?
Driving Around the Block
Movement Along a Polyline
The Elliptical Course
A Generalized Curve Solution

21 Dynamic Textures
The Render Target
Preserving Render Target Contents
Drawing Lines
Manipulating the Pixel Bits
The Geometry of Line Drawing
Modifying Existing Images

22 From Gestures to Transforms
Gestures and Properties
Scale and Rotate
Matrix Transforms
The Pinch Gesture
Flick and Inertia
The Mandelbrot Set
Pan and Zoom
Game Components
Affine and Non-Affine Transforms

23 Touch and Play
More Game Components
The PhingerPaint Canvas
A Little Tour Through SpinPaint
The SpinPaint Code
The Actual Drawing
PhreeCell and a Deck of Cards
The Playing Field
Play and Replay

24 Tilt and Play
3D Vectors
A Better Bubble Visualization
The Graphical Rendition
Follow the Rolling Ball
Navigating a Maze

Saturday, January 14, 2012

FREE eBook: Windows Phone 7 Guide for Symbian Qt Application Developers

Windows Phone 7 Guide for Symbian Qt Application Developers
If you have been developing Qt applications for Symbian^3, Symbian Anna, or Symbian Belle and are interested in building your applications for Windows Phone, this guide is for you.

The guide covers what you need to know to add Windows Phone development to your skill set, while leveraging what you have already learned while developing Symbian Qt applications.

Link: http://windowsphone.interoperabilitybridges.com/articles/windows-phone-7-guide-for-symbian-qt-application-developers

Chapter 1: Introducing Windows Phone Platform to Symbian^3 Qt Application Developers
Chapter 2: Windows Phone Application Design Guidelines
Chapter 3: Windows Phone Developer and Designer Tools
Chapter 4: C# programming
Chapter 5: Introducing Windows Phone Application Life Cycle
Chapter 6: Porting Applications to Windows Phone
Chapter 7: Windows Phone Example Applications
Chapter 8: Using the API Mapping Tool

Friday, January 13, 2012

FREE eBook: Windows Phone 7 Guide for iPhone Application Developers

Windows Phone 7 Guide for iPhone Application Developers
If you have been developing iPhone applications and are interested in building your applications for Windows Phone 7, this guide is for you.

The guide will cover what you need to know to add Windows Phone 7 development to your skill set, while leveraging what you have already learned building iPhone applications.

Link: http://windowsphone.interoperabilitybridges.com/articles/windows-phone-7-guide-for-iphone-application-developers

Chapter 1: Windows Phone 7 Platform introduced to iPhone application developers
- On October 11th Microsoft announced the release of Windows Phone 7 on 10 devices from a variety of manufacturers all over the world. Thousands of applications are already available on the Windows Phone 7 marketplace.

Chapter 2: User Interface Guidelines
- Microsoft's Windows Phone 7 uses a novel user interface called Metro. It sets itself apart with its clean and simple design and emphasis on color and typography.

Chapter 3: Developer and designer tools introduced to iPhone application developers
- iPhone application developers familiar with XCode will find it easy to migrate to WP7 developer tools and become productive quickly

Chapter 4: C# programming introduced to Objective-C programmers

Chapter 5: Image Format Considerations in migration of iPhone applications to Windows Phone 7
- Applications engage users visually with images rather than with use of the written word. It is important to account for resources such as images, video, and audio when you plan your Windows Phone 7 project.

Chapter 6: Application Lifecycle Differences Between Windows Phone 7 and the iPhone
- In this chapter, we are going to look at the navigation model of the Windows Phone 7. We will examine the various application states needed to support the navigation model, and what the developer needs to do to support those application states and the transitions between them. We will then look at what the developer needs to do to duplicate iPhone multitasking.

Chapter 7: iPhone to Windows Phone 7 Application Preference Migration
- Both iPhone and Windows Phone provide easy means to update application settings. They both follow a similar philosophy of ease of use and simplicity. However, they follow different ways for presenting and implementing application preferences.

Chapter 8: Introduction to Windows Phone 7 Notifications for iPhone Developers
- on Windows Phone 7, notifications play a very important and prominent role. The application notifications make the Windows Phone 7 tiles come alive. The notification mechanisms are used to display the most up-to-date status of the application that reflects the events of interest to the user. The tiles work with the notifications to bring information to the user. The user does not have to open the application to the see the updated status.

Appendix A: Migration Samples
- This section contains sample iPhone and Windows Phone applications along with documentation.

Nokia Lumia 900 official video

Introducing Nokia Lumia 900 - The Amazing Everyday

Meet the new Nokia Lumia 900 http://nokia.ly/yKZpKw Find out how fast amazing can be. And social. And beautiful. Keeping in touch with friends, and the entire Internet, has never been so easy. Experience The Amazing Everyday.

Thursday, January 12, 2012

FREE eBook: Windows Phone 7 Guide for Android Application Developers

FREE eBook: Windows Phone 7 Guide for Android Application Developers
If you have been developing Android applications and are interested in building your applications for Windows Phone 7, this guide "Windows Phone 7 Guide for Android Application Developers" is for you.

The guide will cover what you need to know to add Windows Phone 7 development to your skill set, while leveraging what you have already learned building Android applications.

Link: http://windowsphone.interoperabilitybridges.com/articles/windows-phone-7-guide-for-android-application-developers

Chapter 1: Introducing Windows Phone 7 Platform to Android Application Developers
- High level comparison of the platforms and introduction of WP7 specificities

Chapter 2: User Interface Guidelines
- Microsoft's Windows Phone 7 uses a novel user interface called Metro. It sets itself apart with its clean and simple design and emphasis on color and typography.

Chapter 3: The Developer and Designer Tools
- Microsoft brings the Visual Studio Development environment to WP7. As Android application developers you are familiar with Eclipse, and you can quickly migrate to WP7 developer tools and work with ease.

Chapter 4: C# programming
- An introduction of C# to Android Java developers.

Chapter 5: A Comparison of Application Life Cycles in Windows Phone 7 and Android
- In this chapter, we are going to look at the navigation model of the Windows Phone 7. We will examine the various application states needed to support the navigation model, and what the developer needs to do to support those application states and the transitions between them.

Chapter 6: Storing Data and Preferences
- WP7 features a very comprehensive system of managing data for your application and across all applications on the phone. This section compares the data handling features of WP7 and Android.

Chapter 7: XML Parsing in Windows Phone 7 and Android
- This chapter discusses the XML parsing methods in WP7 and compares them with the parsing methods in Android.

Appendix A: Migration Samples
- This section contains sample Android and Windows Phone applications along with documentation.

Appendix B: Migration Tips
- This section contains tips and sample Windows Phone applications along with documentation.

FREE eBook: Windows Phone 7 Quick Start Developer Guide

Windows Phone 7 Quick Start Developer Guide
If you have already developed for other mobile platforms you probably don't want to ignore Windows Phone 7. Or maybe you haven't developed for mobile devices yet but would like to start with the Windows Phone. Either way, this eBook is for you - Windows Phone 7 Quick Start Developer Guide.

Download here: http://www.internet.com/Internetcom/Door/41203/Internet.com-Sign-up-p1-v2?40890

Wednesday, January 11, 2012

2012 CES Keynote, Microsoft CEO Steve Ballmer


Microsoft CEO Steve Ballmer delivered the 2012 CES keynote on January 9, 2012 in Las Vegas. For full CES 2012 coverage, visit http://www.facebook.com/Microsoft.

Run Android App on Windows using BlueStacks App Player

With BlueStacks App Player, you can run Android App fullscreen on your PC or Windows tablet right away. You can also transfer more apps to BlueStacks from your Android device using our Cloud Connect mobile app.

Remark: BlueStacks App Player is an alpha version currently.

Web Site: http://bluestacks.com/



BlueStacks Cloud Connect at Android Market: BlueStacks Cloud Connect is a Android App Send your Android apps to the BlueStacks App Player on your PC.

Tuesday, January 10, 2012

typeid(expression)

typeid(expression) return an type_info object of expression. To read get the name of the type_info, call it's name() method.

Example:
typeid(expression)
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 cout << "typeid(): " << endl << endl;

 cout << "typeid(0.1234): " << typeid(0.1234).name() << endl;
 cout << "typeid(45): " << typeid(45).name() << endl;
 cout << "typeid(0.1234 * 45): " << typeid(0.1234 * 45).name() << endl;

 short shortArray[4];


 cout << "typeid(shortArray): " << typeid(shortArray).name() << endl;
 cout << "typeid(\"Hello\"): " << typeid("Hello").name() << endl;
 cout << "typeid(true): " << typeid(true).name() << endl;

 system("PAUSE");
 return 0;
}




CES 2012: Intel concept Windows 8 ultrabooks


At CES in Las Vegas, Intel's Mooly Eden updates the company's "ultrabook" efforts, including a concept transparent touch screen on the back side, coupled with the Windows 8 Metro user interface.

Web Application Projects versus Web Site Projects

In Visual Studio you can create Web application projects or Web site projects. Each type of project has advantages and disadvantages, and it is helpful to understand the differences between them in order to select the best project type for your needs. You must select the appropriate project type before you create a project, because it is not practical to convert from one project type to the other.

The following table summarizes the main differences:

Area

Web application projects

Web site projects

Project file structure

A Visual Studio project file (.csproj or .vbproj) stores information about the project, such as the list of files that are included in the project, and any project-to-project references.

There is no project file (.csproj or .vbproj). All the files in a folder structure are automatically included in the site.

Compilation

  • You explicitly compile the source code on the computer that is used for development or source control.

  • By default, compilation of code files (excluding .aspx and .ascx files) produces a single assembly.

  • The source code is typically compiled dynamically (automatically) by ASP.NET on the server the first time a request is received after the site has been installed or updated.

    You can precompile the site (compile in advance on a development computer or on the server).

  • By default, compilation produces multiple assemblies.

Namespaces

Explicit namespaces are added to pages, controls, and classes by default.

Explicit namespaces are not added to pages, controls, and classes by default, but you can add them manually.

Deployment

  • You copy the assembly to a server. The assembly is produced by compiling the application.

  • Visual Studio provides tools that integrate with the IIS Web deployment tool to automate many deployment tasks.

  • You copy the application source files to a computer that has IIS installed on it.

  • If you precompile the site on a development computer, you copy the assemblies produced by compilation to the IIS server.

  • Visual Studio provides tools for deployment, but they do not automate as many deployment tasks as the tools available for Web application projects.



Know more details:
- http://msdn.microsoft.com/en-us/library/dd547590.aspx

Saturday, January 7, 2012

C/C++ Casting and static_cast

Example:
C/C++ Casting and static_cast
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 cout << "casting: " << endl << endl;

 float f1 = 0.3345;
 float f2 = 12.41;

 float fa = f1 * f2;
 int i1 = f1 * f2;
 int i2 = (int)f1 * (int)f2;
 int i3 = (int)(f1 * f2);
 int i4 = static_cast<int>(f1 * f2);
 int i5 = static_cast<int>(f1) * static_cast<int>(f2);

 cout << "fa = " << fa << endl;
 cout << "i1 = " << i1 << endl;
 cout << "i2 = " << i2 << endl;
 cout << "i3 = " << i3 << endl;
 cout << "i4 = " << i4 << endl;
 cout << "i5 = " << i5 << endl;

 system("PAUSE");
 return 0;
}


Friday, January 6, 2012

Manipulator, setw()

Examples of using setw():
Manipulator, setw()
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 cout << "Usage of setw(6): " << endl;
 cout << setw(6) << 1234 << endl;
 cout << setw(6) << 1234567890 << endl;
 cout << setw(6) << 0.1 << endl;
 cout << setw(6) << "abc" << endl;
 cout << setw(6) << "abcdefghijklmn" << endl;
 cout << setw(6) << 12.3456789 << endl;
 cout << setw(6) << 123456789.0 << endl;
 cout << setw(6) << 'a' << endl ;

 system("PAUSE");
 return 0;
}


Basic input/output: cin & cout

Example:
Basic input/output: cin & cout
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 int input1;
 float input2;
 char input3;
 
 char retry;
 do{
  cout << "Hello! Enter: int, float and char" << endl;
  cin >> input1 >> input2 >> input3;
  cout << "You enter: " << endl;
  cout << input1 << endl;
  cout << input2 << endl;
  cout << input3 << endl << endl;

  cout << "Retry? <y>" << endl;
  cin >> retry;
 } while ((retry==(char)'y')||(retry==(char)'Y'));

 system("PAUSE");
 return 0;
}


Thursday, January 5, 2012

Wide character - wchar_t

According to Wikipedia:

A wide character is a computer character datatype that generally has a size greater than the traditional 8-bit character. The increased datatype size allows for the use of larger coded character sets.

in C/C++:
The standard library of the C programming language includes a lot of facilities for dealing with wide characters and strings composed of them. The wide characters are defined using datatype wchar_t, which in the original C90 standard was defined as 16-bit value due to historical compatibility reasons. C and C++ compilers that comply with the 10646-1:2000 Unicode standard generally assume 32-bit values.

However, the ISO/IEC 10646:2003 Unicode standard 4.0 says that:

"ANSI/ISO C leaves the semantics of the wide character set to the specific implementation but requires that the characters from the portable C execution set correspond to their wide character equivalents by zero extension."

and that

"The width of wchar_t is compiler-specific and can be as small as 8 bits. Consequently, programs that need to be portable across any C or C++ compiler should not use wchar_t for storing Unicode text. The wchar_t type is intended for storing compiler-defined wide characters, which may be Unicode characters in some compilers."


Example:
Wide character - wchar_t
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 
 cout << "_WCHAR_T_SIZE: " << _WCHAR_T_SIZE << endl;
 cout << "WCHAR_MIN= " << WCHAR_MIN << endl;
 cout << "WCHAR_MAX= " << WCHAR_MAX << endl << endl;

 wchar_t wideChar_heart = L'?';
 cout << wideChar_heart << endl;
 wprintf(L"wideChar_heart: %lc \n", wideChar_heart);

 system("PAUSE");
 return 0;
}



Size and range of integer; INT, SHORT, LONG and LONGLONG

Size and range of integer; INT, SHORT, LONG and LONGLONG

It's tested under Windows 8 (Developer Preview) and Visual Studio 11 Developer Preview.
Size and range of integer; INT, SHORT, LONG and LONGLONG
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

 cout << "_INT_SIZE: " << _INT_SIZE << endl;
 cout << "INT_MIN= " << INT_MIN << endl;
 cout << "INT_MAX= " << INT_MAX << endl << endl;

 cout << "_SHORT_SIZE: " << _SHORT_SIZE << endl;
 cout << "SHRT_MIN= " << SHRT_MIN << endl;
 cout << "SHRT_MAX= " << SHRT_MAX << endl;
 cout << "USHRT_MAX= " << USHRT_MAX << endl << endl;

 cout << "_LONG_SIZE: " << _LONG_SIZE << endl;
 cout << "LONG_MIN= " << LONG_MIN << endl;
 cout << "LONG_MAX= " << LONG_MAX << endl;
 cout << "ULONG_MAX" << ULONG_MAX << endl << endl;

 cout << "_LONGLONG_SIZE: " << _LONGLONG_SIZE << endl;
 cout << "LLONG_MIN= " << LLONG_MIN << endl;
 cout << "LLONG_MAX= " << LLONG_MAX << endl;
 cout << "ULLONG_MAX= " << ULLONG_MAX << endl << endl;

 system("PAUSE");
 return 0;
}


C/C++ Fundamental data type, int

C/C++ Fundamental data type, int

In C/C++, variable of int can be defined and initiated using the form:
int i1 = 10;
int i2(20);


In Windows 8(Developer Preview), it's size id 4 byte.

Example:
C/C++ Fundamental data type, int
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int i1 = 10;
int i2(20);

cout << "size of i1(int): " << sizeof(i1) << endl;
cout << "i1 = " << i1 << endl;
cout << "size of i2(int): " << sizeof(i2) << endl;
cout << "i2 = " << i2 << endl;
system("PAUSE");
return 0;
}

Wednesday, January 4, 2012

Create Win32 C++ Console application using Microsoft Vistal Studio 11 Developer Preview

- Start Microsoft Vistal Studio 11 Developer Preview

- Click New Project... in the start-up page.
New Project...

- Select template of Visuall C++ Win32 Console Application, enter Name, and optionally enter Location, and click OK.
New Project Wizard: Visuall C++ Win32 Console Application

- Review the project settings and click Next.
Project Settings

- Review and accept the default application settings, click Finish.
Application Settings

- The Wizard will generate a default project:
Auto-generated project

- Modify the code:
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
 std::cout << "Hello World!" << std::endl;
 system("PAUSE");
 return 0;
}

Add the code

- Finally, Save, Build and Run the first Visuall C++ Win32 Console Application:
Run