Development of Windows 8 Direct2D-Metro application example based on visualstudio11 (1) Hello World

Source: Internet
Author: User

 

Direct2d is used by Microsoft to replace DirectDraw and new technologies such as GDI and GDI + [1]. It mainly provides 2D animation hardware acceleration. Currently, it only supports Windows Vista SP2 and Windows 7 and later [2].
 
The direct2d technical architecture is built on the direct3d 10.1 API. It can build 2D images through hardware acceleration and fully supports transparent and Alpha mixing. Direct2d also supports software Rasterizer (software Rasterizer), that is, when the video card does not support hardware acceleration, direct2d can still be depicted using software, and the effect is still better than that of GDI.
 
Direct2d can use dxgi (DirectX graphics infrastructure) and interactive operations. direct2d also supports directwrite.
 
Direct2d Supports high-quality rendering and has the following features:
Supports cleartype text rendering (provided by directwrite)
Remove the original image (per primitive antialiasing)
Draw and fill in geometric shapes (straight lines, curves) and bitmap.
Solid color and linearity.
Depicts the middle layer.
Multiple geometric operations (such as unions, intersections, widening, and outlining)

The direct template is provided in Microsoft vs11.

 

After creating an application,

Insert the following code

See Code Analysis

# Include "PCH. H "# include" dwritehelloworld. H "using namespace Microsoft: WRL; using namespace windows: ApplicationModel: core; using namespace windows: ApplicationModel: activation; using namespace windows:: Ui: core; using namespace windows: system; using namespace windows: Foundation; using namespace windows: graphics: display; dwritehelloworld: dwritehelloworld () {} Void dwritehelloworld: createdeviceindependentresources () {directxbase: createdeviceindependentresources (); DX, 64.0f, l "En-us", // locale & m_textformat); // center the text horizontally and vertically. m_textformat-> settextalignment (dwrite_t Response); m_textformat-> setparagraphalignment (response);} void dwritehelloworld: createdeviceresources () {directxbase: createdeviceresources (); m_sampleoverlay = ref new sampleoverlay (); m_sampleoverlay-> initialize (m_d2ddevice.get (), m_d2dcontext.get (), m_wicfactory.get (), Digest (), "D2d Hello World sample by Microsoft MVP yincheng"); DX: throwif Failed (m_d2dcontext-> createsolidcolorbrush (d2d1: colgrading (d2d1: colgrading: Black), & m_blackbrush);} void dwritehelloworld: createwindowsizedependentresources () {directxbase :: createwindowsizedependentresources (); platform: String ^ text = "Hello world by Microsoft MVP-yincheng! "; D2dinclusize_f size = m_d2dcontext-> getsize (); // create a text output device DX: throwiffailed (m_dwritefactory-> createtextlayout (text-> data (), text-> length (), m_textformat.get (), size. width, size. height, & m_textlayout); dwrite_text_range textrange = {21, 12}; // set the text size m_textlayout-> setfontsize (100366f, textrange); // create a graphic text display device DX:: Transform (m_dwritefactory-> createtypography (& m_texttypography); then fontfeature = {character, 1}; m_texttypography-> addfontfeature (fontfeature); // The length of the mobile text textrange. length = text-> length (); textrange. startposition = 0; // display text DX: throwiffailed (m_textlayout-> settypography (m_texttypography.get (), textrange); // set the text length and start position textrange. length = 12; textrange. startposition = 21; // set the horizontal line m_textlayout-> setunderline (true, textrange); m_textlayout-> setfontweight (dwrite_font_weight_bold, textrange);} void dwritehelloworld: render () {m_d2dcontext-> begindraw (); m_d2dcontext-> clear (d2d1: colgrading (d2d1: collf: cornflowerblue); m_d2dcontext-> settransform (d2d1: matrix3x2f :: identity (); m_d2dcontext-> drawtextlayout (d2d1: point2f (0.0f, 0.0f), m_textlayout.get (), m_blackbrush.get (); hresult hR = m_d2dcontext-> enddraw (); if (hR = d2derr_recreate_target) {m_d2dcontext-> settarget (nullptr); m_d2dtargetbitmap = nullptr; createwindowsizedependentresources ();} else {DX: throwiffailed (HR );} m_sampleoverlay-> render ();} void dwritehelloworld: Initialize (_ in _ coreapplicationview ^ applicationview) {applicationview-> activated + = ref new typedeventhandler <coreapplicationview ^, activities ^> (this, & dwritehelloworld: onactivated); coreapplication: suspending + = ref new eventhandler <suspendingeventargs ^> (this, & dwritehelloworld: onsuspending); coreapplication :: resuming + = ref new eventhandler <platform: Object ^> (this, & dwritehelloworld: onresuming);} void dwritehelloworld: setwindow (_ in _ corewindow ^ window) {window-> pointercursor = ref new corecursor (corecursortype: Arrow, 0); window-> sizechanged + = ref new typedeventhandler <corewindow ^, windowsizechangedeventargs ^> (this, & dwritehelloworld:: onwindowsizechanged); displayproperties: blank + = ref new partition (this, & dwritehelloworld: blank); directxbase: Initialize (window, displayproperties: logicaldpi);} void dwritehelloworld:: load (platform: String ^ entrypoint) {} void dwritehelloworld: Run () {render (); present (); m_window-> Dispatcher-> processevents (coreprocesseventsoption :: processuntilquit);} void dwritehelloworld: uninitialize () {} void dwritehelloworld: onwindowsizechanged (_ in _ corewindow ^ sender, _ in _ blank ^ ARGs) {updateforwindowsizechange (); m_sampleoverlay-> updateforwindowsizechange (); render (); present ();} void dwritehelloworld: onlogicaldpichanged (_ in _ platform: Object ^ sender) {setdpi (displayproperties :: logicaldpi); render (); present ();} void dwritehelloworld: onactivated (_ in _ coreapplicationview ^ applicationview, _ in _ iactivatedeventargs ^ ARGs) {m_window-> activate ();} void dwritehelloworld: onsuspending (_ in _ platform: Object ^ sender, _ in _ suspendingeventargs ^ ARGs) {} void dwritehelloworld :: onresuming (_ in _ platform: Object ^ sender, _ in _ platform: Object ^ ARGs) {} iframeworkview ^ directxappsource: createview () {return ref new dwritehelloworld ();} [Platform: mtathread] int main (platform: array <platform: String ^> ^) {auto directxappsource = ref new directxappsource (); coreapplication: Run (directxappsource); Return 0 ;}

 

 

Download vs11 now

Http://www.microsoft.com/click/services/Redirect2.ashx? Cr_cc = 200098144

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.