Skip to content

Commit

Permalink
Finish modularization (barring one Visual Studio bug internal compile…
Browse files Browse the repository at this point in the history
…r error in MainWindow.cpp).
  • Loading branch information
fdwr committed Oct 5, 2017
1 parent 74efa39 commit 86f4ae5
Show file tree
Hide file tree
Showing 31 changed files with 1,124 additions and 1,069 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dlldata.c
project.lock.json
artifacts/

*.ifc
*_i.c
*_p.c
*_i.h
Expand Down
111 changes: 17 additions & 94 deletions TextLayoutSampler.cpp → Application.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -3,98 +3,39 @@
// History: 2015-06-19 Created
//----------------------------------------------------------------------------
#include "precomp.h"
#include "MainWindow.h"
#include <specstrings.h>
#include "Application.h"

import Common.String;

#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#pragma comment(lib, "DWrite.lib")
#pragma comment(lib, "D2D1.lib")
#pragma comment(lib, "GdiPlus.lib")
#pragma comment(lib, "ComCtl32.lib")
module Application;


////////////////////////////////////////
// UI related

#pragma prefast(disable:__WARNING_HARD_CODED_STRING_TO_UI_FN, "It's an internal test program.")

export class Application
{
public:
static HINSTANCE g_hModule;
static MSG g_msg;
static HWND g_mainHwnd;

static void Dispatch();
static int DisplayError(__in_z const char16_t* message, __in_z_opt const char16_t* formatString, int functionResult);
static void Fail(__in_z const char16_t* message, __in_z_opt const char16_t* formatString, int functionResult);
static void DebugLog(const char16_t* logMessage, ...);
static HRESULT ExceptionToHResult() throw();
};

HINSTANCE Application::g_hModule = nullptr;
MSG Application::g_msg;
HWND Application::g_mainHwnd;


import Common.String;

#pragma prefast(disable:__WARNING_HARD_CODED_STRING_TO_UI_FN, "It's an internal test program.")

////////////////////////////////////////


int APIENTRY wWinMain(
__in HINSTANCE hInstance,
__in_opt HINSTANCE hPrevInstance,
__in LPWSTR commandLine,
__in int nCmdShow
)
{
Application::g_hModule = hInstance;

_wsetlocale(LC_ALL, L""); // Unicode, not ANSI!

////////////////////
// Read command line parameters.

std::u16string trimmedCommandLine(ToChar16(commandLine));
TrimSpaces(IN OUT trimmedCommandLine);

if (!trimmedCommandLine.empty())
{
if (_wcsicmp(ToWChar(trimmedCommandLine.c_str()), L"/?" ) == 0
|| _wcsicmp(ToWChar(trimmedCommandLine.c_str()), L"/help" ) == 0
|| _wcsicmp(ToWChar(trimmedCommandLine.c_str()), L"-h" ) == 0
|| _wcsicmp(ToWChar(trimmedCommandLine.c_str()), L"--help") == 0
)
{
MessageBox(nullptr, L"TextLayoutSampler.exe [SomeFile.TextLayoutSamplerSettings].", APPLICATION_TITLE, MB_OK);
return (int)0;
}
else if (trimmedCommandLine[0] == '/')
{
Application::Fail(trimmedCommandLine.c_str(), u"Unknown command line option.\r\n\r\n\"%s\"", 0);
}
UnquoteString(IN OUT trimmedCommandLine);
// Else just pass the command line to the main window.
}

////////////////////
// Create user interface elements.

Application::g_mainHwnd = MainWindow::Create();
if (Application::g_mainHwnd == nullptr)
{
Application::Fail(u"Could not create main window.", u"%s = %08X", HRESULT_FROM_WIN32(GetLastError()));
}
ShowWindow(Application::g_mainHwnd, SW_SHOWNORMAL);
SendMessage(Application::g_mainHwnd, WM_CHANGEUISTATE, UIS_CLEAR | UISF_HIDEACCEL | UISF_HIDEFOCUS, (LPARAM)nullptr); // Always shows the focus rectangle.

MainWindow& mainWindow = *MainWindow::GetClass(Application::g_mainHwnd);

if (!trimmedCommandLine.empty())
{
mainWindow.LoadDrawableObjectsSettings(trimmedCommandLine.data());
}

while (GetMessage(&Application::g_msg, nullptr, 0, 0) > 0)
{
Application::Dispatch();
}

return static_cast<int>(Application::g_msg.wParam);
}


void Application::Dispatch()
{
// Fixup any messages.
Expand Down Expand Up @@ -216,21 +157,3 @@ void Application::DebugLog(const char16_t* logMessage, ...)

OutputDebugString(buffer);
}


// Maps exceptions to equivalent HRESULTs,
HRESULT Application::ExceptionToHResult() throw()
{
try
{
throw; // Rethrow previous exception.
}
catch (std::bad_alloc const&)
{
return E_OUTOFMEMORY;
}
catch (...)
{
return E_FAIL;
}
}
97 changes: 41 additions & 56 deletions TextLayoutSampler.h → Application.macros.h
Original file line number Diff line number Diff line change
@@ -1,56 +1,41 @@
//----------------------------------------------------------------------------
// Author: Dwayne Robinson
// History: 2015-06-19 Created
//----------------------------------------------------------------------------
#pragma once

#ifndef BUILD_OPTIMIZATION_STRING
#if defined(DEBUG) || defined(_DEBUG)
#define BUILD_OPTIMIZATION_STRING L"Debug"
#else
#define BUILD_OPTIMIZATION_STRING L"Release"
#endif
#endif

#if defined(_M_IX86)
#define BUILD_ARCHITECTURE_STRING L"x86 32-bit"
#elif defined(_M_X64)
#define BUILD_ARCHITECTURE_STRING L"64-bit"
#elif defined(_M_ARM_FP)
#define BUILD_ARCHITECTURE_STRING L"ARM"
#else
#define BUILD_ARCHITECTURE_STRING L"Unknown"
#endif

#ifndef NDEBUG
#define DEBUG_MESSAGE(...) Application::DebugLog(__VA_ARGS__)
#else
#define DEBUG_MESSAGE(...) (0)
#endif

#if !defined(APPLICATION_TITLE)
#define APPLICATION_TITLE L"TextLayoutSampler (displays text with various text layout/rendering API's)"
#endif

#if !defined(BUILD_TITLE_STRING)
#define BUILD_TITLE_STRING \
APPLICATION_TITLE L", "\
TEXT(__DATE__) L", "\
BUILD_ARCHITECTURE_STRING L", "\
BUILD_OPTIMIZATION_STRING
#endif


class Application
{
public:
static HINSTANCE g_hModule;
static MSG g_msg;
static HWND g_mainHwnd;

static void Dispatch();
static int DisplayError(__in_z const char16_t* message, __in_z_opt const char16_t* formatString, int functionResult);
static void Fail(__in_z const char16_t* message, __in_z_opt const char16_t* formatString, int functionResult);
static void DebugLog(const char16_t* logMessage, ...);
static HRESULT ExceptionToHResult() throw();
};
//----------------------------------------------------------------------------
// Author: Dwayne Robinson
// History: 2015-06-19 Created
//----------------------------------------------------------------------------
#pragma once

#ifndef BUILD_OPTIMIZATION_STRING
#if defined(DEBUG) || defined(_DEBUG)
#define BUILD_OPTIMIZATION_STRING L"Debug"
#else
#define BUILD_OPTIMIZATION_STRING L"Release"
#endif
#endif

#if defined(_M_IX86)
#define BUILD_ARCHITECTURE_STRING L"x86 32-bit"
#elif defined(_M_X64)
#define BUILD_ARCHITECTURE_STRING L"64-bit"
#elif defined(_M_ARM_FP)
#define BUILD_ARCHITECTURE_STRING L"ARM"
#else
#define BUILD_ARCHITECTURE_STRING L"Unknown"
#endif

#ifndef NDEBUG
#define DEBUG_MESSAGE(...) Application::DebugLog(__VA_ARGS__)
#else
#define DEBUG_MESSAGE(...) (0)
#endif

#if !defined(APPLICATION_TITLE)
#define APPLICATION_TITLE L"TextLayoutSampler (displays text with various text layout/rendering API's)"
#endif

#if !defined(BUILD_TITLE_STRING)
#define BUILD_TITLE_STRING \
APPLICATION_TITLE L", "\
TEXT(__DATE__) L", "\
BUILD_ARCHITECTURE_STRING L", "\
BUILD_OPTIMIZATION_STRING
#endif
Loading

0 comments on commit 86f4ae5

Please sign in to comment.