// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
// Modify the following definitions if you need to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER // Allow use of features specific to Windows 7 or later.
#define WINVER 0x0700 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows 7 or later.
#define _WIN32_WINNT 0x0700 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef UNICODE
#define UNICODE
#endif
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used items from Windows headers
// Windows Header Files:
#include <windows.h>
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <wchar.h>
#include <math.h>
#include <d2d1.h>
#include <d2d1helper.h>
#include <dwrite.h>
#include <wincodec.h>
/******************************************************************
* *
* Macros *
* *
******************************************************************/
template<class Interface>
inline void
SafeRelease(
Interface **ppInterfaceToRelease
)
{
if (*ppInterfaceToRelease != NULL)
{
(*ppInterfaceToRelease)->Release();
(*ppInterfaceToRelease) = NULL;
}
}
#ifndef Assert
#if defined( DEBUG ) || defined( _DEBUG )
#define Assert(b) if (!(b)) {OutputDebugStringA("Assert: " #b "\n");}
#else
#define Assert(b)
#endif //DEBUG || _DEBUG
#endif
#ifndef HINST_THISCOMPONENT
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
#endif
/******************************************************************
* *
* DemoApp *
* *
******************************************************************/
class DemoApp
{
public:
DemoApp();
~DemoApp();
// Register the window class and call methods for instantiating drawing resources
HRESULT Initialize();
// Process and dispatch messages
void RunMessageLoop();
private:
// Initialize device-independent resources
HRESULT CreateDeviceIndependentResources();
// Initialize device-dependent resources
HRESULT CreateDeviceResources();
HRESULT CreateGridPatternBrush(
ID2D1RenderTarget *pRenderTarget,
ID2D1BitmapBrush **ppBitmapBrush
);
// Release device-dependent resource
void DiscardDeviceResources();
// Draw content
HRESULT OnRender();
// Resize the render target
void OnResize(
UINT width,
UINT height
);
// The windows procedure
static LRESULT CALLBACK WndProc(
HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam
);
private:
HWND m_hwnd;
ID2D1Factory *m_pD2DFactory;
ID2D1HwndRenderTarget *m_pRenderTarget;
ID2D1SolidColorBrush *m_pBlackBrush;
ID2D1SolidColorBrush *m_pCornflowerBlueBrush;
ID2D1BitmapBrush *m_pGridPatternBitmapBrush;
ID2D1StrokeStyle *m_pStrokeStyleSolidMiter;
ID2D1StrokeStyle *m_pStrokeStyleSolidBevel;
ID2D1StrokeStyle *m_pStrokeStyleSolidRoundwRoundCap;
ID2D1StrokeStyle *m_pStrokeStyleSolidRoundwFlatCap;
ID2D1StrokeStyle *m_pStrokeStyleSolidRoundwSquareCap;
ID2D1StrokeStyle *m_pStrokeStyleSolidRoundwTriangleCap;
ID2D1StrokeStyle *m_pStrokeStyleSolidMiterOrBevel;
ID2D1StrokeStyle *m_pStrokeStyleDash;
ID2D1StrokeStyle *m_pStrokeStyleDot;
ID2D1StrokeStyle *m_pStrokeStyleDashDot;
ID2D1StrokeStyle *m_pStrokeStyleDashDotDot;
ID2D1StrokeStyle *m_pStrokeStyleCustomOffsetZero;
ID2D1StrokeStyle *m_pStrokeStyleCustomOffsetNegOne;
ID2D1StrokeStyle *m_pStrokeStyleCustomOffsetNegTwo;
ID2D1StrokeStyle *m_pStrokeStyleCustomOffsetPosOne;
ID2D1StrokeStyle *m_pStrokeStyleCustomOffsetPosTwo;
ID2D1PathGeometry *m_pPathGeometry;
//DirectWrite
IDWriteFactory *m_pDWriteFactory;
IDWriteTextFormat *m_pTextFormat;
};