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程序
- //
- // App.xaml.h
- // App 类的声明。
- //
- #pragma once
- #include "App.g.h"
- namespace HelloWorld_C__
- {
- /// <summary>
- /// 提供特定于应用程序的行为,以补充默认的应用程序类。
- /// </summary>
- ref class App sealed
- {
- public:
- App();
- virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs) override;
- private:
- void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
- };
- }
- //
- // App.xaml.h
- // App 类的声明。
- //
- #pragma once
- #include "App.g.h"
- namespace HelloWorld_C__
- {
- /// <summary>
- /// 提供特定于应用程序的行为,以补充默认的应用程序类。
- /// </summary>
- ref class App sealed
- {
- public:
- App();
- virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ pArgs) override;
- private:
- void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
- };
- }
- App.xaml文件<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
- }
再来看看项目的结构
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是直接放到外面的根目录下的。
运行的效果
转载于:https://blog.51cto.com/linzheng/1078338