Windows 8 的metro风格应用程序的开发编程和Windows phone 7是非常类似的,不过Windows 8对开发语言的支持是比Windows Phone 7强大很多,支持C++,C#和JavaScript,而Windows Phone 7只是支持C#,当然Windows Phone 8出来之后就会支持C#和C++的开发了。下面是Windows 8的编程体系图。

 

其实Windows 8就是在Windows 7的基础上加上了metro的程序框架,通常所说的Windows 8的开发技术就是指Windows 8的metro程序开发。

1、Windows 8 整个系统分成了Metro style和Desktop两个体系,而WinRT则是全新的Metro应用程序架构的基础所在;
2、WinRT具备了多语言的支持能力,支持C++,C#,VB,JavaScript;
3、WinRT和Win32、.NET是相互独立的API体系;

4、WinRT是专门为触屏体验的全新的API。

 

下面来看一下一个C++的Windows 8的hello world程序

 

 
  
  1. //  
  2. // App.xaml.h  
  3. // App 类的声明。  
  4. //  
  5.  
  6. #pragma once  
  7.  
  8. #include "App.g.h"  
  9.  
  10. namespace HelloWorld_C__  
  11. {  
  12.     /// <summary> 
  13.     /// 提供特定于应用程序的行为,以补充默认的应用程序类。  
  14.     /// </summary> 
  15.     ref class App sealed  
  16.     {  
  17.     public:  
  18.         App();  
  19.         virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs) override;  
  20.  
  21.     private:  
  22.         void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);  
  23.     };  

 

 
  
  1. //  
  2. // App.xaml.h  
  3. // App 类的声明。  
  4. //  
  5.  
  6. #pragma once  
  7.  
  8. #include "App.g.h"  
  9.  
  10. namespace HelloWorld_C__  
  11. {  
  12.     /// <summary> 
  13.     /// 提供特定于应用程序的行为,以补充默认的应用程序类。  
  14.     /// </summary> 
  15.     ref class App sealed  
  16.     {  
  17.     public:  
  18.         App();  
  19.         virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs) override;  
  20.  
  21.     private:  
  22.         void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);  
  23.     };  

 

 
  
  1. App.xaml文件<Application 
  2.     x:Class="HelloWorld_C__.App" 
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  5.     xmlns:local="using:HelloWorld_C__"> 
  6.  
  7.     <Application.Resources> 
  8.         <ResourceDictionary> 
  9.             <ResourceDictionary.MergedDictionaries> 
  10.  
  11.                 <!--   
  12.                     Styles that define common aspects of the platform look and feel  
  13.                     Required by Visual Studio project and item templates  
  14.                  --> 
  15.                 <ResourceDictionary Source="Common/StandardStyles.xaml"/> 
  16.             </ResourceDictionary.MergedDictionaries> 
  17.  
  18.         </ResourceDictionary> 
  19.     </Application.Resources> 
  20. </Application> 

MainPage.xaml

 

 
  
  1. <Page   
  2.     x:Class="HelloWorld_C__.MainPage" 
  3.     IsTabStop="false" 
  4.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  5.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  6.     xmlns:local="using:HelloWorld_C__" 
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  9.     mc:Ignorable="d"> 
  10.  
  11.     <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> 
  12. <TextBlock  x:Name="myTextBlock"  TextAlignment="Center" FontSize="60" /> 
  13.     </Grid> 
  14. </Page> 

 

 
  
  1. //MainPage.xaml.h  
  2. #pragma once  
  3.  
  4. #include "MainPage.g.h"  
  5.  
  6. namespace HelloWorld_C__  
  7. {  
  8.     public ref class MainPage sealed  
  9.     {  
  10.     public:  
  11.         MainPage();  
  12.  
  13.     protected:  
  14.         virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;  
  15.     };  

 

 
  
  1. //MainPage.xaml.cpp  
  2. #include "pch.h"  
  3. #include "MainPage.xaml.h"  
  4.  
  5. using namespace HelloWorld_C__;  
  6.  
  7. using namespace Platform;  
  8. using namespace Windows::Foundation;  
  9. using namespace Windows::Foundation::Collections;  
  10. using namespace Windows::UI::Xaml;  
  11. using namespace Windows::UI::Xaml::Controls;  
  12. using namespace Windows::UI::Xaml::Controls::Primitives;  
  13. using namespace Windows::UI::Xaml::Data;  
  14. using namespace Windows::UI::Xaml::Input;  
  15. using namespace Windows::UI::Xaml::Media;  
  16. using namespace Windows::UI::Xaml::Navigation;  
  17.  
  18.  
  19. MainPage::MainPage()  
  20. {  
  21.     InitializeComponent();  
  22.     this->myTextBlock->Text="Hello World";  
  23. }  
  24.  
  25. void MainPage::OnNavigatedTo(NavigationEventArgs^ e)  
  26. {  
  27.     (void) e;    // Unused parameter  

再来看看项目的结构

 

 

App.xaml:应用程序对象和Wp7里面的一样,App.xaml.h, App.xaml.cpp:Application相关事件和处理。

MainPage.xaml.h, MainPage.xaml.cpp:包含默认页面UI的event和基本逻辑,但不包含MainPage.xaml里UI生成的代码。

Package.appxmanifest:定义App相关的基本信息。包括App名字,描述,logo等。

pch.h, pch.cpp: 预编译文件。

Assets文件里面存放程序的logo等相关的图片,以前Wp7是直接放到外面的根目录下的。

运行的效果