生活随笔
收集整理的這篇文章主要介紹了
Windows 8 Hello World
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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
總結
以上是生活随笔為你收集整理的Windows 8 Hello World的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。