生活随笔
收集整理的這篇文章主要介紹了
Windows 8 Hello World
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Windows 8 的metro風(fēng)格應(yīng)用程序的開發(fā)編程和Windows phone 7是非常類似的,不過Windows 8對(duì)開發(fā)語(yǔ)言的支持是比Windows Phone 7強(qiáng)大很多,支持C++,C#和JavaScript,而Windows Phone 7只是支持C#,當(dāng)然Windows Phone 8出來(lái)之后就會(huì)支持C#和C++的開發(fā)了。下面是Windows 8的編程體系圖。
?
其實(shí)Windows 8就是在Windows 7的基礎(chǔ)上加上了metro的程序框架,通常所說(shuō)的Windows 8的開發(fā)技術(shù)就是指Windows 8的metro程序開發(fā)。
1、Windows 8 整個(gè)系統(tǒng)分成了Metro style和Desktop兩個(gè)體系,而WinRT則是全新的Metro應(yīng)用程序架構(gòu)的基礎(chǔ)所在;
2、WinRT具備了多語(yǔ)言的支持能力,支持C++,C#,VB,JavaScript;
3、WinRT和Win32、.NET是相互獨(dú)立的API體系;
4、WinRT是專門為觸屏體驗(yàn)的全新的API。
?
下面來(lái)看一下一個(gè)C++的Windows 8的hello world程序
?
// ?//?App.xaml.h ?//?App?類的聲明。 ?// ??#pragma?once ??#include?"App.g.h" ??namespace?HelloWorld_C__ ?{ ?????///?<summary>?????///?提供特定于應(yīng)用程序的行為,以補(bǔ)充默認(rèn)的應(yīng)用程序類。 ?????///?</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>?????///?提供特定于應(yīng)用程序的行為,以補(bǔ)充默認(rèn)的應(yīng)用程序類。 ?????///?</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 ?}? 再來(lái)看看項(xiàng)目的結(jié)構(gòu)
?
?
App.xaml:應(yīng)用程序?qū)ο蠛蚖p7里面的一樣,App.xaml.h, App.xaml.cpp:Application相關(guān)事件和處理。
MainPage.xaml.h, MainPage.xaml.cpp:包含默認(rèn)頁(yè)面UI的event和基本邏輯,但不包含MainPage.xaml里UI生成的代碼。
Package.appxmanifest:定義App相關(guān)的基本信息。包括App名字,描述,logo等。
pch.h, pch.cpp: 預(yù)編譯文件。
Assets文件里面存放程序的logo等相關(guān)的圖片,以前Wp7是直接放到外面的根目錄下的。
運(yùn)行的效果
?
?
?
?
轉(zhuǎn)載于:https://blog.51cto.com/linzheng/1078338
總結(jié)
以上是生活随笔為你收集整理的Windows 8 Hello World的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。