Overview Metro style Apps View Model Controller System































- Slides: 31



Overview

Metro style Apps View Model Controller System Services Core HTML / CSS XAML C C++ Desktop Apps C# VB Java. Script (Chakra) HTML C C++ C# VB Internet Explorer Win 32 . NET / SL Java. Script Win. RT APIs Communication & Data Graphics & Media Application Model Devices & Printing Windows Core OS Services




BINDINGS TO FOREIGN TYPE SYSTEMS Key Bindings Feature Summary 1. Data Types ref class Reference type value class Value type interface class Interface property Property with get/set event “Delegate property” with add/remove/raise delegate Type-safe function pointer generic Type-safe generics gcnew Garbage-collected allocation ref new Reference-counted allocation ^ Strong pointer (“hat” or “handle”) % Strong reference 2. Allocation 3. Pointer & Reference


delegate void Carousel. Init. Done. Handler IUIAnimation. Variable^ rotation void Carousel. Animation: : Initialize(double angle, Carousel. Init. Done. Handler^ callback) { // Create Animation Manager using namespace Engine: : Graphics; UIAnimation. Manager animation. Manager; // Create rotation animation variable IUIAnimation. Variable^ rotation = animation. Manager. Create. Animation. Variable(angle); // Set the event handler for the story board rotation->Get. Current. Story. Board()->Set. Story. Board. Event. Handler( ref new Carousel. Story. Board. Handler(this, Carousel. Animation: : Story. Board) ); } // Invoke the callback when done callback(rotation);

Language

Person^ p; { Person^ p 2 = ref new Person(); p 2 ->Name = “John”; p = p 2; } p = nullptr; // refcount = 1 // refcount = 2 // refcount = 1 // refcount = 0; ~Person()

public ref class Person { public: Person(String^ name, String^ email); void Greet(Person^ other); internal: ~Person(); void Set. Password(const std: : wstring& passwd); }; Person^ p = ref new Person(“John Surname”); p->Greet(ref new Person(“Jim Surename”);

public interface class IAnimal { void Play(); }; public interface class IFeline : IAnimal { void Scratch(); }; IAnimal^ animal = ref new Cat(); animal->Play(); ref class Cat : IFeline { public: virtual void Play(); virtual void Scratch(); };

public ref class Database. Connection { public: ~ Database. Connection(); }; { Database. Connection db(); db. Set. Name( “Employees”); // … lots of queries, updates, etc. … // … } // ~Database. Connection()

public: property String^ Name; public: property Person^ Sibling { Person^ get() { Init. Siblings(); return _sibling; } void set(Person^ value) { _sibling = value; Notify. Sibling(); } } private: Person^ _sibling; Person^ p = ref new Person(“John”); p->Sibling = ref new Person(p->Name);

public delegate void Property. Changed( String^ prop. Name, String^ prop. Value ); auto p = ref new Property. Changed( [](String^ pn, String^ pv) { cout << pn << ” = “ << pv; } ); auto p = ref new Property. Changed( UIProperty. Changed ); auto p = ref new Property. Changed( this, Main. Page: : On. Property. Changed ); p( “Visible”, false );

public: event Property. Changed^ On. Property. Changed; public: event Property. Changed^ On. Network. Changed { Event. Registration. Token add(Property. Changed^); void remove(Event. Registration. Token t); void raise(String^, String^); } person->On. Property. Changed += property. Changed. Delegate; auto token = person->On. Property. Changed: : add(property. Changed. Delegate); person->On. Property. Changed -= token; person->On. Property. Changed: : remove(token);

• • throw ref new Invalid. Argument. Exception(); throw ref new COMException(E_*); • try { … } catch (Out. Of. Memory. Exception^ ex) { … } ex->HResult • catch (Platform: : Exception^) HRESULT Exception E_OUTOFMEMORY Out. Of. Memory. Exception E_INVALIDARG Invalid. Argument. Exception E_NOINTERFACE Invalid. Cast. Exception E_POINTER Null. Reference. Exception E_NOTIMPL Not. Implemented. Exception E_ACCESSDENIED Access. Denied. Exception E_FAIL Failure. Exception E_BOUNDS Out. Of. Bounds. Exception E_CHANGED_STATE Changed. State. Exception REGDB_E_CLASSNOTREG Class. Not. Registered. Exception E_DISCONNECTED Disconnected. Exception E_ABORT Operation. Canceled. Exception

generic<typename T, typename U> public interface class IPair { property T First; property U Second; }; IPair<String^, Uri^>^ uri = Get. Uri(); auto first = uri->First; // type is String^ auto second = uri->Second; // type is Uri^ ref class Pair. String. Uri: IPair<String^, Uri^> { public: property String^ First; property Uri^ Second; };

template<typename T, typename U> ref class Pair: IPair<T, U> { public: property T First; property U Second; }; Pair(T first, U second) { First = first; Second = second; } IPair<String^, Uri^>^ pair = ref new Pair<String^, Uri^>( “//BUILD/”, ref new Uri(“http: //www. buildwindows. com”));

• #using <Company. Component. winmd> public

private partial ref class Main. Page: User. Control, IComponent. Connector { public: void Initialize. Component(); void Connect() { btn 1 ->Click += ref new Event. Handler(this, &Main. Page: : Button_Click); } }; ref class Main. Page { public: Main. Page() { Initialize. Component(); } void Button_Click(Object^ sender, Routed. Event. Args^ e); };


Libraries

using namespace Platform; Vector<String^>^ items = ref new Vector<String^>(); items->Append(“Hello”); • Returning a read-only view of the vector IVector. View<String^>^ Get. Items () { return items->Get. View(); } items->Vector. Changed += ref new Vector. Changed. Event. Handler<String^> (this, &My. Class: : Vector. Changed);

using namespace Platform; Map<String^, Uri^> favorites = ref new Map<String^, Uri^>(); favorites->Insert(“MSDN”, ref new Uri(“http: //msdn. com”)); if (favorites->Has. Key(“MSDN”)) favorites->Remove(“MSDN”);

Begin()/End() begin() end() IVector<int>^ v = Get. Items(); int sum = 0; std: : for_each( begin(v), end(v), [&sum](int element) { sum += element; } ); std: : vector<int> v; v. push_back(10); auto items = ref new Vector<int>(v); Vector<int>^ items = …; std: : vector<int> v = to_vector(items);

RELATED SESSIONS • 100: Improving Software Quality Using Visual Studio 11 C++ Code Analysis Rong Lu • 479: A Lap Around Visual Studio 11 Express for Metro style Apps Using C++ Vikas Bhatia, Joanna Mason • 761: A Lap Around Direct. X Game Development Tools Boris Jabes • 802: Taming GPU Compute with C++ AMP Daniel Moth • 835: Writing Modern C++ Code: How C++ has evolved over the years Herb Sutter • 845: Tips and Tricks for Developing Metro style Apps Using C++ Tarek Madkour ONLINE TALKS ON CHANNEL 9 • Bringing Existing C++ Code into Metro style Apps Ale Contenti • Under the Covers with C++ for Metro style Apps Deon Brewis • Building Metro style apps with HTML 5 and Compiled Code Raman Sharma

Q&A
