Windows 8 Metro style applicationsProgramThe development programming of Windows Phone 7 is very similar to that of Windows Phone 7. However, Windows 8 has much more powerful support for development languages than Windows Phone 7, and supports C ++, C #, and JavaScript, windows Phone 7 only supports C #. Of course, Windows Phone 8 will support C # And C ++ development. The following figure shows the programming system of Windows 8.
In fact, Windows 8 adds the metro program framework on the basis of Windows 7. Generally speaking, Windows 8 development technology refers to Windows 8 Metro program development.
1. Windows 8 is divided into two systems: Metro style and desktop, while winrt is the foundation of the new Metro application architecture;
2. winrt supports multiple languages and supports C ++, C #, VB, and JavaScript;
3. winrt, Win32, And. NET are independent API systems;
4. winrt is a brand new API dedicated to touch screen experience.
Next let's look at the next C ++ Windows 8 Hello World Program.
// // App. XAML. h // The Declaration of the app class. // # Pragma Once # Include " App. G. H " Namespace Helloworld_c __{ /// <Summary> /// Provides application-specific behavior to supplement the Default Application class. /// </Summary> Ref Class AppSealed { Public : APP (); Virtual Void Onlaunched (Windows: ApplicationModel: Activation: launchactivatedeventargs ^ pargs) Override ; Private : Void Onsuspending (platform: Object ^ sender, Windows: ApplicationModel: suspendingeventargs ^ E );};}
// // App. XAML. cpp // The implementation of the app class. // # Include " Pch.h " # Include " Mainpage. XAML. h " Using Namespace Helloworld_c __; Using Namespace Platform; Using Namespace Windows: ApplicationModel; Using Namespace Windows: ApplicationModel: activation; Using Namespace Windows: Foundation; Using Namespace Windows: Foundation: collections; Using Namespace Windows: Ui: XAML; Using Namespace Windows: Ui: XAML: controls; Using Namespace Windows: Ui: XAML: Controls: primitives; Using Namespace Windows: Ui: XAML: data; Using Namespace Windows: Ui: XAML: input; Using Namespace Windows: Ui: XAML: InterOP; Using Namespace Windows: Ui: XAML: media; Using Namespace Windows: Ui: XAML: navigation; // The "blank application" template is in Http://go.microsoft.com/fwlink? Linkid = 234227 Provided on /// <Summary> /// Initialize a single instance application object. This is the creation of execution.CodeThe first line, /// The logic is equivalent to main () or winmain (). /// </Summary> APP: APP () {initializecomponent (); suspending + = Ref New Suspendingeventhandler ( This ,& APP: onsuspending );} /// <Summary> /// The application is called when the end user starts the application normally. /// When you start an application to open a specific file or display search results /// Other entry points will be used. /// </Summary> /// <Param name = "pargs"> Details about the launch request and process. </Param> Void APP: onlaunched (Windows: ApplicationModel: Activation: launchactivatedeventargs ^ Pargs ){ // Do not repeat app initialization when already running, just ensure that // The window is active If (Pargs-> previusexecutionstate = Applicationexecutionstate: Running) {window: Current -> Activate (); Return ;} If (Pargs-> previusexecutionstate = Applicationexecutionstate: terminated ){ // Todo: Load status from the previously suspended application } // Create a frame for navigation context and navigate to the first page Auto rootframe = Ref New Frame (); If (! Rootframe-> Navigate (typename (mainpage: typeid ))){ Throw Ref New Failureexception ( " Failed to create initial Page " );} // Place the frame in the current window and make sure it is active. Window: Current-> content = Rootframe; window: Current -> Activate ();} /// <Summary> /// Called when the application is to be suspended for execution. When you do not know the application /// The application state will be saved when it is terminated or restored, /// And keep the memory content unchanged. /// </Summary> /// <Param name = "sender"> The source of the pending request. </Param> /// <Param name = "E"> Details about pending requests. </Param> Void APP: onsuspending (Object ^ sender, suspendingeventargs ^ E ){( Void ) Sender; // Unused parameter ( Void ) E; // Unused parameter // Todo: Save the application status and stop any background activities. }
App. XAML File
< Application X: Class = "Helloworld_c _. app" Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation" Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml" Xmlns: Local = "Using: helloworld_c __" > < Application. Resources > < Resourcedictionary > < Resourcedictionary. mergeddictionaries > <! -- Styles that define common aspects of the Platform look and feel required by Visual Studio project and item templates --> < Resourcedictionary Source = "Common/standardstyles. XAML" /> </ Resourcedictionary. mergeddictionaries > </ Resourcedictionary > </ Application. Resources > </ Application >
Mainpage. XAML
< Page X: Class = "Helloworld_c _. mainpage" Istabstop = "False" Xmlns = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation" Xmlns: x = "Http://schemas.microsoft.com/winfx/2006/xaml" Xmlns: Local = "Using: helloworld_c __" Xmlns: d = "Http://schemas.microsoft.com/expression/blend/2008" Xmlns: MC = "Http://schemas.openxmlformats.org/markup-compatibility/2006" MC: ignorable = "D" > < Grid Background =" {Staticresource applicationpagebackgroundthemebrush} " > < Textblock X: Name = "Mytextblock" Textalignment = "Center" Fontsize = "60" /> </ Grid > </ Page >
// Mainpage. XAML. h # Pragma Once # Include " Mainpage. G. H " Namespace Helloworld_c __{ Public Ref Class Mainpage Sealed { Public : Mainpage (); Protected : Virtual Void Onnavigatedto (Windows: Ui: XAML: navigation: navigationeventargs ^ e) Override ;};}
// Mainpage. XAML. cpp # Include " Pch.h " # Include " Mainpage. XAML. h " Using Namespace Helloworld_c __; Using Namespace Platform; Using Namespace Windows: Foundation; Using Namespace Windows: Foundation: collections; Using Namespace Windows: Ui: XAML; Using Namespace Windows: Ui: XAML: controls; Using Namespace Windows: Ui: XAML: Controls: primitives; Using Namespace Windows: Ui: XAML: data; Using Namespace Windows: Ui: XAML: input; Using Namespace Windows: Ui: XAML: media; Using Namespace Windows: Ui: XAML: navigation; mainpage: mainpage () {initializecomponent (); This -> Mytextblock-> text = " Hello World " ;} Void Mainpage: onnavigatedto (navigationeventargs ^ E ){( Void ) E;// Unused parameter }
Let's take a look at the project structure.
App. XAML: The application objects are the same as those in WP7. App. XAML. H, app. XAML. cpp: Application-related events and processing.
Mainpage. XAML. H, mainpage. XAML. cpp: contains the event and basic logic of the default page UI, but does not contain the code generated by the UI in mainpage. XAML.
Package. appxmanifest: defines the basic information related to the app. Including the app name, description, and logo.
PCH. H, PCH. cpp: Pre-compiled file.
The assets File Stores Program Logos and other related images. In the past, WP7 was directly placed in the external root directory.
Running Effect