Added back some old files I deleted a long time ago, just so we can do

some platform-specific testing easily.
This commit is contained in:
casey langen 2017-01-06 12:37:08 -08:00
parent 40fe1512de
commit 3ba692d20a
97 changed files with 17376 additions and 8 deletions

View File

@ -43,68 +43,123 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nomaddecoder", "src\contrib
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "directsoundout", "src\contrib\directsoundout\directsoundout.vcxproj", "{51C18730-DC48-411A-829D-F2B3B7AC4C97}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "musikwin", "src\musikwin\musikwin.vcxproj", "{C0039E74-6E03-4FEE-8701-74CA6B90B380}"
ProjectSection(ProjectDependencies) = postProject
{68AA481E-3CCE-440F-8CCE-69F1B371C89D} = {68AA481E-3CCE-440F-8CCE-69F1B371C89D}
{B2165720-B4B2-4F4B-8888-8C390C3CB4DB} = {B2165720-B4B2-4F4B-8888-8C390C3CB4DB}
{B2165720-B4B2-4F4B-9634-8C390C3CB4DB} = {B2165720-B4B2-4F4B-9634-8C390C3CB4DB}
{51C18730-DC48-411A-829D-F2B3B7AC4C97} = {51C18730-DC48-411A-829D-F2B3B7AC4C97}
{3E30064E-B9C4-4690-8AC2-2C694176A319} = {3E30064E-B9C4-4690-8AC2-2C694176A319}
{EBD2E652-AA1B-4B8B-8D03-CCECB9BF3304} = {EBD2E652-AA1B-4B8B-8D03-CCECB9BF3304}
{54764854-5A73-4329-9BAD-9AF22C72D9E2} = {54764854-5A73-4329-9BAD-9AF22C72D9E2}
{465EF178-91C1-4068-BE1D-F9616ECCB6DE} = {465EF178-91C1-4068-BE1D-F9616ECCB6DE}
{4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8} = {4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8}
{4993E68D-E97A-4CD2-AC8E-168AE315BAC5} = {4993E68D-E97A-4CD2-AC8E-168AE315BAC5}
{CA56A398-7F9A-493A-A7FC-C6B4D550B674} = {CA56A398-7F9A-493A-A7FC-C6B4D550B674}
{292974B0-C8B7-41EF-B603-554A2B25CB90} = {292974B0-C8B7-41EF-B603-554A2B25CB90}
{7CD00EC4-D090-48BE-9388-FA4857AC332C} = {7CD00EC4-D090-48BE-9388-FA4857AC332C}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}.Debug|Win32.ActiveCfg = Debug|Win32
{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}.Debug|Win32.Build.0 = Debug|Win32
{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}.Debug|x64.ActiveCfg = Debug|Win32
{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}.Release|Win32.ActiveCfg = Release|Win32
{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}.Release|Win32.Build.0 = Release|Win32
{C7102EB1-7311-4B36-A7FF-89DD7F077FF9}.Release|x64.ActiveCfg = Release|Win32
{292974B0-C8B7-41EF-B603-554A2B25CB90}.Debug|Win32.ActiveCfg = Debug|Win32
{292974B0-C8B7-41EF-B603-554A2B25CB90}.Debug|Win32.Build.0 = Debug|Win32
{292974B0-C8B7-41EF-B603-554A2B25CB90}.Debug|x64.ActiveCfg = Debug|Win32
{292974B0-C8B7-41EF-B603-554A2B25CB90}.Release|Win32.ActiveCfg = Release|Win32
{292974B0-C8B7-41EF-B603-554A2B25CB90}.Release|Win32.Build.0 = Release|Win32
{292974B0-C8B7-41EF-B603-554A2B25CB90}.Release|x64.ActiveCfg = Release|Win32
{54764854-5A73-4329-9BAD-9AF22C72D9E2}.Debug|Win32.ActiveCfg = Debug|Win32
{54764854-5A73-4329-9BAD-9AF22C72D9E2}.Debug|Win32.Build.0 = Debug|Win32
{54764854-5A73-4329-9BAD-9AF22C72D9E2}.Debug|x64.ActiveCfg = Debug|Win32
{54764854-5A73-4329-9BAD-9AF22C72D9E2}.Release|Win32.ActiveCfg = Release|Win32
{54764854-5A73-4329-9BAD-9AF22C72D9E2}.Release|Win32.Build.0 = Release|Win32
{54764854-5A73-4329-9BAD-9AF22C72D9E2}.Release|x64.ActiveCfg = Release|Win32
{B2165720-B4B2-4F4B-8888-8C390C3CB4DB}.Debug|Win32.ActiveCfg = Debug|Win32
{B2165720-B4B2-4F4B-8888-8C390C3CB4DB}.Debug|Win32.Build.0 = Debug|Win32
{B2165720-B4B2-4F4B-8888-8C390C3CB4DB}.Debug|x64.ActiveCfg = Debug|Win32
{B2165720-B4B2-4F4B-8888-8C390C3CB4DB}.Release|Win32.ActiveCfg = Release|Win32
{B2165720-B4B2-4F4B-8888-8C390C3CB4DB}.Release|Win32.Build.0 = Release|Win32
{B2165720-B4B2-4F4B-8888-8C390C3CB4DB}.Release|x64.ActiveCfg = Release|Win32
{B2165720-B4B2-4F4B-9634-8C390C3CB4DB}.Debug|Win32.ActiveCfg = Debug|Win32
{B2165720-B4B2-4F4B-9634-8C390C3CB4DB}.Debug|Win32.Build.0 = Debug|Win32
{B2165720-B4B2-4F4B-9634-8C390C3CB4DB}.Debug|x64.ActiveCfg = Debug|Win32
{B2165720-B4B2-4F4B-9634-8C390C3CB4DB}.Release|Win32.ActiveCfg = Release|Win32
{B2165720-B4B2-4F4B-9634-8C390C3CB4DB}.Release|Win32.Build.0 = Release|Win32
{B2165720-B4B2-4F4B-9634-8C390C3CB4DB}.Release|x64.ActiveCfg = Release|Win32
{7CD00EC4-D090-48BE-9388-FA4857AC332C}.Debug|Win32.ActiveCfg = Debug|Win32
{7CD00EC4-D090-48BE-9388-FA4857AC332C}.Debug|Win32.Build.0 = Debug|Win32
{7CD00EC4-D090-48BE-9388-FA4857AC332C}.Debug|x64.ActiveCfg = Debug|Win32
{7CD00EC4-D090-48BE-9388-FA4857AC332C}.Release|Win32.ActiveCfg = Release|Win32
{7CD00EC4-D090-48BE-9388-FA4857AC332C}.Release|Win32.Build.0 = Release|Win32
{7CD00EC4-D090-48BE-9388-FA4857AC332C}.Release|x64.ActiveCfg = Release|Win32
{4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8}.Debug|Win32.ActiveCfg = Debug|Win32
{4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8}.Debug|Win32.Build.0 = Debug|Win32
{4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8}.Debug|x64.ActiveCfg = Debug|Win32
{4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8}.Release|Win32.ActiveCfg = Release|Win32
{4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8}.Release|Win32.Build.0 = Release|Win32
{4F10C17A-8AF7-4FAC-A4E2-087AE6E8F9D8}.Release|x64.ActiveCfg = Release|Win32
{465EF178-91C1-4068-BE1D-F9616ECCB6DE}.Debug|Win32.ActiveCfg = Debug|Win32
{465EF178-91C1-4068-BE1D-F9616ECCB6DE}.Debug|Win32.Build.0 = Debug|Win32
{465EF178-91C1-4068-BE1D-F9616ECCB6DE}.Debug|x64.ActiveCfg = Debug|Win32
{465EF178-91C1-4068-BE1D-F9616ECCB6DE}.Release|Win32.ActiveCfg = Release|Win32
{465EF178-91C1-4068-BE1D-F9616ECCB6DE}.Release|Win32.Build.0 = Release|Win32
{465EF178-91C1-4068-BE1D-F9616ECCB6DE}.Release|x64.ActiveCfg = Release|Win32
{4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Debug|Win32.ActiveCfg = Debug|Win32
{4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Debug|Win32.Build.0 = Debug|Win32
{4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Debug|x64.ActiveCfg = Debug|Win32
{4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Release|Win32.ActiveCfg = Release|Win32
{4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Release|Win32.Build.0 = Release|Win32
{4993E68D-E97A-4CD2-AC8E-168AE315BAC5}.Release|x64.ActiveCfg = Release|Win32
{3E30064E-B9C4-4690-8AC2-2C694176A319}.Debug|Win32.ActiveCfg = Debug|Win32
{3E30064E-B9C4-4690-8AC2-2C694176A319}.Debug|Win32.Build.0 = Debug|Win32
{3E30064E-B9C4-4690-8AC2-2C694176A319}.Debug|x64.ActiveCfg = Debug|Win32
{3E30064E-B9C4-4690-8AC2-2C694176A319}.Release|Win32.ActiveCfg = Release|Win32
{3E30064E-B9C4-4690-8AC2-2C694176A319}.Release|Win32.Build.0 = Release|Win32
{3E30064E-B9C4-4690-8AC2-2C694176A319}.Release|x64.ActiveCfg = Release|Win32
{68AA481E-3CCE-440F-8CCE-69F1B371C89D}.Debug|Win32.ActiveCfg = Debug|Win32
{68AA481E-3CCE-440F-8CCE-69F1B371C89D}.Debug|Win32.Build.0 = Debug|Win32
{68AA481E-3CCE-440F-8CCE-69F1B371C89D}.Debug|x64.ActiveCfg = Debug|Win32
{68AA481E-3CCE-440F-8CCE-69F1B371C89D}.Release|Win32.ActiveCfg = Release|Win32
{68AA481E-3CCE-440F-8CCE-69F1B371C89D}.Release|Win32.Build.0 = Release|Win32
{68AA481E-3CCE-440F-8CCE-69F1B371C89D}.Release|x64.ActiveCfg = Release|Win32
{EBD2E652-AA1B-4B8B-8D03-CCECB9BF3304}.Debug|Win32.ActiveCfg = Debug|Win32
{EBD2E652-AA1B-4B8B-8D03-CCECB9BF3304}.Debug|Win32.Build.0 = Debug|Win32
{EBD2E652-AA1B-4B8B-8D03-CCECB9BF3304}.Debug|x64.ActiveCfg = Debug|Win32
{EBD2E652-AA1B-4B8B-8D03-CCECB9BF3304}.Release|Win32.ActiveCfg = Release|Win32
{EBD2E652-AA1B-4B8B-8D03-CCECB9BF3304}.Release|Win32.Build.0 = Release|Win32
{EBD2E652-AA1B-4B8B-8D03-CCECB9BF3304}.Release|x64.ActiveCfg = Release|Win32
{CA56A398-7F9A-493A-A7FC-C6B4D550B674}.Debug|Win32.ActiveCfg = Debug|Win32
{CA56A398-7F9A-493A-A7FC-C6B4D550B674}.Debug|Win32.Build.0 = Debug|Win32
{CA56A398-7F9A-493A-A7FC-C6B4D550B674}.Debug|x64.ActiveCfg = Debug|Win32
{CA56A398-7F9A-493A-A7FC-C6B4D550B674}.Release|Win32.ActiveCfg = Release|Win32
{CA56A398-7F9A-493A-A7FC-C6B4D550B674}.Release|Win32.Build.0 = Release|Win32
{CA56A398-7F9A-493A-A7FC-C6B4D550B674}.Release|x64.ActiveCfg = Release|Win32
{51C18730-DC48-411A-829D-F2B3B7AC4C97}.Debug|Win32.ActiveCfg = Debug|Win32
{51C18730-DC48-411A-829D-F2B3B7AC4C97}.Debug|Win32.Build.0 = Debug|Win32
{51C18730-DC48-411A-829D-F2B3B7AC4C97}.Debug|x64.ActiveCfg = Debug|Win32
{51C18730-DC48-411A-829D-F2B3B7AC4C97}.Release|Win32.ActiveCfg = Release|Win32
{51C18730-DC48-411A-829D-F2B3B7AC4C97}.Release|Win32.Build.0 = Release|Win32
{51C18730-DC48-411A-829D-F2B3B7AC4C97}.Release|x64.ActiveCfg = Release|Win32
{C0039E74-6E03-4FEE-8701-74CA6B90B380}.Debug|Win32.ActiveCfg = Debug|Win32
{C0039E74-6E03-4FEE-8701-74CA6B90B380}.Debug|Win32.Build.0 = Debug|Win32
{C0039E74-6E03-4FEE-8701-74CA6B90B380}.Debug|x64.ActiveCfg = Debug|x64
{C0039E74-6E03-4FEE-8701-74CA6B90B380}.Debug|x64.Build.0 = Debug|x64
{C0039E74-6E03-4FEE-8701-74CA6B90B380}.Release|Win32.ActiveCfg = Release|Win32
{C0039E74-6E03-4FEE-8701-74CA6B90B380}.Release|Win32.Build.0 = Release|Win32
{C0039E74-6E03-4FEE-8701-74CA6B90B380}.Release|x64.ActiveCfg = Release|x64
{C0039E74-6E03-4FEE-8701-74CA6B90B380}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -39,9 +39,9 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">bin/$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)\bin\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">obj/$(Configuration)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">bin/$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\bin\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">obj/$(Configuration)\</IntDir>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />

View File

@ -39,9 +39,9 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.40219.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)/bin/$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)\bin\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">obj/$(Configuration)\</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">bin/$(Configuration)\</OutDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)\bin\$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">obj/$(Configuration)\</IntDir>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />

View File

@ -70,6 +70,7 @@ static inline bool isVisible() {
if (hwnd) {
return !IsIconic(hwnd);
}
return true;
#else
return true;
#endif
@ -196,10 +197,7 @@ void App::Run(ILayoutPtr layout) {
ch = wgetch(stdscr);
}
if (ch == ERR) {
std::this_thread::yield();
}
else {
if (ch != ERR) {
std::string kn = key::Read((int) ch);
if (ch == '\t') { /* tab */

31
src/musikwin/Main.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <pch.h>
#include <win32cpp/Application.hpp>
#include <win32cpp/TopLevelWindow.hpp>
#include <core/library/LibraryFactory.h>
#include <core/audio/GaplessTransport.h>
using namespace musik::core;
using namespace musik::core::audio;
using namespace win32cpp;
int APIENTRY _tWinMain(HINSTANCE instance, HINSTANCE previousInstance, LPTSTR commandLine, int showCommand) {
LibraryPtr library = LibraryFactory::Libraries().at(0);
GaplessTransport transport;
transport.Start("c:\\test.ogg");
Application::Initialize(instance, previousInstance, commandLine, showCommand);
Application& app = Application::Instance();
TopLevelWindow mainWindow(_TT("musikwin").c_str());
mainWindow.Resize(800, 600);
mainWindow.MoveTo(10, 10);
app.Run(mainWindow);
LibraryFactory::Instance().Shutdown();
return 0;
}

View File

@ -0,0 +1,252 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{C0039E74-6E03-4FEE-8701-74CA6B90B380}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>musikwin</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)\bin\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>./;../;../3rdparty/include;../3rdparty/win32_include;../../../boost_1_60_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>../../../boost_1_60_0/lib32-msvc-14.0;$(SolutionDir)bin\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>3rdparty.lib;core.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalIncludeDirectories>./;../;../3rdparty/include;../3rdparty/win32_include;../../../boost_1_60_0;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>../../../boost_1_60_0/lib32-msvc-14.0;$(SolutionDir)bin\$(Configuration)\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>3rdparty.lib;core.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
<ClInclude Include="win32cpp\Application.hpp" />
<ClInclude Include="win32cpp\ApplicationThread.hpp" />
<ClInclude Include="win32cpp\Button.hpp" />
<ClInclude Include="win32cpp\CheckBox.hpp" />
<ClInclude Include="win32cpp\Color.hpp" />
<ClInclude Include="win32cpp\ComboBox.hpp" />
<ClInclude Include="win32cpp\Config.hpp" />
<ClInclude Include="win32cpp\Container.hpp" />
<ClInclude Include="win32cpp\DeviceContext.hpp" />
<ClInclude Include="win32cpp\EditView.hpp" />
<ClInclude Include="win32cpp\Exception.hpp" />
<ClInclude Include="win32cpp\FolderBrowseDialog.hpp" />
<ClInclude Include="win32cpp\Font.hpp" />
<ClInclude Include="win32cpp\Frame.hpp" />
<ClInclude Include="win32cpp\GroupBox.hpp" />
<ClInclude Include="win32cpp\ILayout.hpp" />
<ClInclude Include="win32cpp\ImageList.hpp" />
<ClInclude Include="win32cpp\Label.hpp" />
<ClInclude Include="win32cpp\LinearLayout.hpp" />
<ClInclude Include="win32cpp\ListView.hpp" />
<ClInclude Include="win32cpp\Locale.hpp" />
<ClInclude Include="win32cpp\MemoryDC.hpp" />
<ClInclude Include="win32cpp\Menu.hpp" />
<ClInclude Include="win32cpp\Panel.hpp" />
<ClInclude Include="win32cpp\ProgressBar.hpp" />
<ClInclude Include="win32cpp\RadioButton.hpp" />
<ClInclude Include="win32cpp\RedrawLock.hpp" />
<ClInclude Include="win32cpp\Splitter.hpp" />
<ClInclude Include="win32cpp\TabView.hpp" />
<ClInclude Include="win32cpp\Timer.hpp" />
<ClInclude Include="win32cpp\TopLevelWindow.hpp" />
<ClInclude Include="win32cpp\Trackbar.hpp" />
<ClInclude Include="win32cpp\TrayIconManager.hpp" />
<ClInclude Include="win32cpp\Types.hpp" />
<ClInclude Include="win32cpp\Utility.hpp" />
<ClInclude Include="win32cpp\VirtualWindow.hpp" />
<ClInclude Include="win32cpp\Win32Config.hpp" />
<ClInclude Include="win32cpp\win32cpp.hpp" />
<ClInclude Include="win32cpp\Win32Exception.hpp" />
<ClInclude Include="win32cpp\Window.hpp" />
<ClInclude Include="win32cpp\WindowGeometry.hpp" />
<ClInclude Include="win32cpp\WindowPadding.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Main.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="win32cpp\Application.cpp" />
<ClCompile Include="win32cpp\ApplicationThread.cpp" />
<ClCompile Include="win32cpp\Button.cpp" />
<ClCompile Include="win32cpp\CheckBox.cpp" />
<ClCompile Include="win32cpp\Color.cpp" />
<ClCompile Include="win32cpp\ComboBox.cpp" />
<ClCompile Include="win32cpp\Config.cpp" />
<ClCompile Include="win32cpp\Container.cpp" />
<ClCompile Include="win32cpp\DeviceContext.cpp" />
<ClCompile Include="win32cpp\EditView.cpp" />
<ClCompile Include="win32cpp\Exception.cpp" />
<ClCompile Include="win32cpp\FolderBrowseDialog.cpp" />
<ClCompile Include="win32cpp\Font.cpp" />
<ClCompile Include="win32cpp\Frame.cpp" />
<ClCompile Include="win32cpp\GroupBox.cpp" />
<ClCompile Include="win32cpp\ImageList.cpp" />
<ClCompile Include="win32cpp\Label.cpp" />
<ClCompile Include="win32cpp\LinearLayout.cpp" />
<ClCompile Include="win32cpp\ListView.cpp" />
<ClCompile Include="win32cpp\Locale.cpp" />
<ClCompile Include="win32cpp\MemoryDC.cpp" />
<ClCompile Include="win32cpp\Menu.cpp" />
<ClCompile Include="win32cpp\Panel.cpp" />
<ClCompile Include="win32cpp\ProgressBar.cpp" />
<ClCompile Include="win32cpp\RadioButton.cpp" />
<ClCompile Include="win32cpp\RedrawLock.cpp" />
<ClCompile Include="win32cpp\Splitter.cpp" />
<ClCompile Include="win32cpp\TabView.cpp" />
<ClCompile Include="win32cpp\Timer.cpp" />
<ClCompile Include="win32cpp\TopLevelWindow.cpp" />
<ClCompile Include="win32cpp\Trackbar.cpp" />
<ClCompile Include="win32cpp\TrayIconManager.cpp" />
<ClCompile Include="win32cpp\Utility.cpp" />
<ClCompile Include="win32cpp\VirtualWindow.cpp" />
<ClCompile Include="win32cpp\Window.cpp" />
<ClCompile Include="win32cpp\WindowGeometry.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="win32cpp\win32cpp.sln" />
<None Include="win32cpp\win32cpp.vcproj" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,263 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="win32cpp">
<UniqueIdentifier>{01f8691c-a7bb-4dd7-822e-0747f9f1631c}</UniqueIdentifier>
</Filter>
<Filter Include="musikwin">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="win32cpp\Button.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\CheckBox.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Color.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\ComboBox.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Config.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Container.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\DeviceContext.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\EditView.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Exception.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\FolderBrowseDialog.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Font.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Frame.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\GroupBox.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\ILayout.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\ImageList.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Label.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\LinearLayout.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\ListView.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Locale.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\MemoryDC.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Menu.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Panel.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\ProgressBar.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\RadioButton.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\RedrawLock.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Splitter.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\TabView.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Timer.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\TopLevelWindow.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Trackbar.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\TrayIconManager.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Types.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Utility.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\VirtualWindow.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Win32Config.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\win32cpp.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Win32Exception.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Window.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\WindowGeometry.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\WindowPadding.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\Application.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="win32cpp\ApplicationThread.hpp">
<Filter>win32cpp</Filter>
</ClInclude>
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="win32cpp\CheckBox.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Color.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\ComboBox.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Config.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Container.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\DeviceContext.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\EditView.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Exception.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\FolderBrowseDialog.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Font.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Frame.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\GroupBox.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\ImageList.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Label.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\LinearLayout.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\ListView.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Locale.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\MemoryDC.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Menu.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Panel.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\ProgressBar.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\RadioButton.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\RedrawLock.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Splitter.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\TabView.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Timer.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\TopLevelWindow.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Trackbar.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\TrayIconManager.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Utility.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\VirtualWindow.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Window.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\WindowGeometry.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Application.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\ApplicationThread.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="win32cpp\Button.cpp">
<Filter>win32cpp</Filter>
</ClCompile>
<ClCompile Include="pch.cpp" />
<ClCompile Include="Main.cpp">
<Filter>musikwin</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="win32cpp\win32cpp.sln">
<Filter>win32cpp</Filter>
</None>
<None Include="win32cpp\win32cpp.vcproj">
<Filter>win32cpp</Filter>
</None>
</ItemGroup>
</Project>

1
src/musikwin/pch.cpp Normal file
View File

@ -0,0 +1 @@
#include "pch.h"

20
src/musikwin/pch.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include <memory>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Application.hpp>
#include <win32cpp/TrayIconManager.hpp>
#include <win32cpp/TopLevelWindow.hpp>
#include <win32cpp/Container.hpp>
#include <win32cpp/Menu.hpp>
#include <win32cpp/Window.hpp>
#include <win32cpp/Font.hpp>
#include <win32cpp/Exception.hpp>
#include <win32cpp/Types.hpp>
#include <win32cpp/WindowGeometry.hpp>
#include <win32cpp/win32cpp.hpp>

View File

@ -0,0 +1,281 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Application.hpp>
#include <win32cpp/ApplicationThread.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
// Application
//////////////////////////////////////////////////////////////////////////////
Application Application::sMainApplication;
/*ctor*/ Application::Application()
: instance(NULL)
, previousInstance(NULL)
, commandLine(_T(""))
, showCommand(NULL)
, mainWindow(NULL)
, appThread(NULL)
, trayIconManager(NULL)
{
this->appThread = new ApplicationThread();
}
///\brief
///Initialize the Application instance.
///
///This method is best called from WinMain.
///
///\param instance
///The HINSTANCE supplied to WinMain.
///
///\param previousInstance
///The "previous" HINSTANCE supplied to WinMain.
///
///\param commandLine
///The command line supplied to WinMain
///
///\param showCommand
///The show command supplied to WinMain.
///
///\throws AlreadyInitializedException
///This exception is thrown if Initialize() has already been called
///
///\see
///Application::Run
void Application::Initialize(HINSTANCE instance, HINSTANCE previousInstance, LPTSTR commandLine, int showCommand)
{
if (sMainApplication.instance)
{
throw ApplicationAlreadyInitializedException();
}
INITCOMMONCONTROLSEX initCtrls;
initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
initCtrls.dwICC = ICC_WIN95_CLASSES;
::InitCommonControlsEx(&initCtrls);
sMainApplication.instance = instance;
sMainApplication.previousInstance = previousInstance;
sMainApplication.commandLine = commandLine;
sMainApplication.showCommand = showCommand;
sMainApplication.mainWindow = NULL;
}
///\brief
///Show the specified TopLevelWindow and runs the message pump.
///
///\param mainWindow
///The Application's main Window.
///
///\throws AlreadyRunningException
///AlreadyRunningException will be thrown if the Application instance is
///already runnning.
void Application::Run(TopLevelWindow& mainWindow)
{
if (this->mainWindow)
{
throw ApplicationAlreadyRunningException();
}
this->mainWindow = &mainWindow;
if ( ! mainWindow) // shortcut for IsInitialized()
{
mainWindow.Initialize();
}
this->appThread->Initialize();
this->trayIconManager = new TrayIconManager;
mainWindow.Destroyed.connect(this, &Application::OnMainWindowDestroyed);
//
mainWindow.Show(this->ShowCommand());
// start main message loop
MSG msg;
while (::GetMessage(&msg, NULL, 0, 0) > 0)
{
if (msg.message == WM_QUIT)
{
::PostQuitMessage(0);
break;
}
/*if (::IsDialogMessage(this->windowHandle, &msg))
{
switch (msg.message)
{
case WM_PAINT: // 15
OutputDebugStringA("WM_PAINT\n");
break;
case WM_KEYUP: // 257 (0x101)
case WM_KEYFIRST: // 256 (0x100)
this->OnRequestFocusNext();
this->SendMessage(WM_NEXTDLGCTL, (WPARAM) Window::LastFocus(), TRUE);
OutputDebugStringA((boost::format("focus: %1%\n") % Window::LastFocus()).str().c_str());
OutputDebugStringA("WM_KEYUP\n");
break;
case WM_MOUSEFIRST: // 500 (0x200)
OutputDebugStringA("WM_MOUSEFIRST\n");
break;
case WM_MOUSELEAVE: // 675 (0x2a3)
OutputDebugStringA("WM_MOUSELEAVE\n");
break;
case WM_NCMOUSEMOVE: // 160 (0xa0)
OutputDebugStringA("WM_NCMOUSEMOVE\n");
break;
case WM_TIMER: // 275 (0x113)
OutputDebugStringA("WM_TIMER\n");
break;
case WM_NCMOUSELEAVE: // 274 (0x2a2)
OutputDebugStringA("WM_NCMOUSELEAVE\n");
break;
case WM_LBUTTONDOWN: // 513 (0x201)
OutputDebugStringA("WM_LBUTTONDOWN\n");
break;
case WM_LBUTTONUP: // 514 (0x202)
OutputDebugStringA("WM_LBUTTONUP\n");
break;
//case WM_KEYFIRST: // 256 (0x100)
// this->OnRequestFocusNext();
// OutputDebugStringA("WM_KEYFIRST\n");
// break;
default:
OutputDebugStringA((boost::format("%1%\n") % msg.message).str().c_str());
break;
}
continue;
}*/
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
// end main message loop
delete this->trayIconManager;
this->trayIconManager = NULL;
delete this->appThread;
this->appThread = NULL;
this->mainWindow = NULL;
}
void Application::OnMainWindowDestroyed(Window* window)
{
::PostQuitMessage(0);
}
///\brief
///Returns the Application instance.
///
///\returns
///The Application instance.
Application& Application::Instance()
{
return Application::sMainApplication;
}
///\brief
///Returns a pointer to the main Window.
///
///If this value is NULL the application is not currently running.
TopLevelWindow* Application::MainWindow()
{
return this->mainWindow;
}
///\brief
///Returns the "previous" HINSTANCE specified in WinMain.
HINSTANCE Application::PreviousInstance() const
{
return this->previousInstance;
}
///\brief
///Returns the command line specified in WinMain.
const uistring& Application::CommandLine() const
{
return this->commandLine;
}
///\brief
///Returns the "show command" specified in WinMain.
int Application::ShowCommand() const
{
return this->showCommand;
}
///\brief
///Terminates the application if it is running.
void Application::Terminate() const
{
if (this->mainWindow)
{
::PostQuitMessage(0);
}
}
///\brief
///Returns the Application instance's HINSTANCE.
Application::operator HINSTANCE() const
{
return this->instance;
}
///\brief
///Returns the ApplicationThread associated with this application instance.
ApplicationThread* Application::Thread()
{
return this->appThread;
}
///\brief Returns the TrayIconManager
TrayIconManager* Application::SysTrayManager() const
{
return this->trayIconManager;
}

View File

@ -0,0 +1,113 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Types.hpp>
#include <win32cpp/TopLevelWindow.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// forward declaration
class ApplicationThread;
///\brief
///Application is a singleton that provides basic information about the
///current process.
///
///Application::Initialize should be called from the WinMain method, followed
///by Application::Run to show the main Window and start the message loop.
///
///Access Application's sole instance by using the Application::Instance method.
///
///\see
///TopLevelWindow
class Application : public EventHandler
{
public: // types
///\brief Thrown if Application::Initialize() is called more than once
class ApplicationAlreadyInitializedException: public Exception { };
///\brief Thrown if Application::Run() is called while the application
///is already running.
class ApplicationAlreadyRunningException: public Exception { };
public:
/*ctor*/ Application();
public: // methods
static void Initialize(HINSTANCE instance, HINSTANCE previousInstance, LPTSTR commandLine, int showCommand);
static Application& Instance();
void Run(TopLevelWindow& mainWindow);
TopLevelWindow* MainWindow();
HINSTANCE PreviousInstance() const;
const uistring& CommandLine() const;
int ShowCommand() const;
void Terminate() const;
TrayIconManager* SysTrayManager() const;
ApplicationThread* Thread();
public: // operator overloads
operator HINSTANCE() const;
private: // methods
void OnMainWindowDestroyed(Window* window);
private: // instance data
HINSTANCE instance;
HINSTANCE previousInstance;
uistring commandLine;
int showCommand;
TopLevelWindow* mainWindow;
ApplicationThread* appThread;
TrayIconManager* trayIconManager;
private: // class data
static Application sMainApplication;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,213 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Daniel Önnerby
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "pch.hpp"
#include "ApplicationThread.hpp"
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////
///\brief
///Constructor
//////////////////////////////////////////
ApplicationThread::ApplicationThread()
: helperWindow(NULL)
{
this->applicationThreadId = GetCurrentThreadId();
}
//////////////////////////////////////////
///\brief
///Destructor
///
///\remarks
///Will also delete the HelperWindow
//////////////////////////////////////////
ApplicationThread::~ApplicationThread()
{
delete this->helperWindow;
}
//////////////////////////////////////////
///\brief
///Ask if the current caller is executed in the main thread
//////////////////////////////////////////
bool ApplicationThread::InMainThread()
{
ApplicationThread *thread = Application::Instance().Thread();
if(thread)
{
DWORD theThread = GetCurrentThreadId();
return (thread->applicationThreadId == theThread);
}
return false;
}
//////////////////////////////////////////
///\brief
///Adds a call to the calls queue of calls.
//////////////////////////////////////////
void ApplicationThread::AddCall(CallClassBase *callClass)
{
{
std::unique_lock<std::mutex> lock(this->mutex);
this->calls.push_back(CallClassPtr(callClass));
}
this->NotifyMainThread();
}
//////////////////////////////////////////
///\brief
///Method called by the HelperWindow to execute the calls
//////////////////////////////////////////
void ApplicationThread::MainThreadCallback()
{
std::unique_lock<std::mutex> lock(this->mutex);
while( ! this->calls.empty())
{
CallClassPtr currentCall = this->calls.front();
currentCall->Call();
this->calls.pop_front();
}
}
//////////////////////////////////////////
///\brief
///Sends a message to the HelperWindow to notify that there are new calls
//////////////////////////////////////////
void ApplicationThread::NotifyMainThread()
{
if(this->helperWindow)
{
::PostMessage(this->helperWindow->Handle(), WM_W32CPP_APPLICATIONTHREAD_CALL_WAITING, NULL, NULL);
}
}
//////////////////////////////////////////
///\brief
///Initialize the HelperWindow
//////////////////////////////////////////
void ApplicationThread::Initialize()
{
// Create helper window
this->helperWindow = new ApplicationThread::HelperWindow();
this->helperWindow->Initialize();
this->NotifyMainThread();
}
//////////////////////////////////////////
///\brief
///Constructor for HelperWindow
//////////////////////////////////////////
ApplicationThread::HelperWindow::HelperWindow()
{
}
//////////////////////////////////////////
///\brief
///Create HelperWindow
///
/// The parent window is not needed since message windows
/// does not require this.
//////////////////////////////////////////
HWND ApplicationThread::HelperWindow::Create(Window* parent){
HINSTANCE hInstance = Application::Instance();
// create the window
DWORD style = WS_CHILD;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
_T("Message"), // Class name
_T("ThreadHelperWindow"), // Window name
style, // Style
0, // X
0, // Y
0, // Width
0, // Height
HWND_MESSAGE, // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
//////////////////////////////////////////
///\brief
///HelperWindow message handler.
//////////////////////////////////////////
LRESULT ApplicationThread::HelperWindow::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_W32CPP_APPLICATIONTHREAD_CALL_WAITING:
// This is a ApplicationTread message
ApplicationThread *thread = Application::Instance().Thread();
if(thread)
{
thread->MainThreadCallback();
}
return 0; // 0 = processed
}
return this->DefaultWindowProc(message, wParam, lParam);
}
//////////////////////////////////////////
///\brief
///This method is called when message window has been created
///
///If calls has been added to the calls queue
///before this, they have not been called.
///This method will make a call to the MainThreadCallback
//////////////////////////////////////////
void ApplicationThread::HelperWindow::OnCreated()
{
ApplicationThread *thread = Application::Instance().Thread();
if(thread)
{
thread->MainThreadCallback();
}
}

View File

@ -0,0 +1,241 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Daniel Önnerby
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Application.hpp>
#include <win32cpp/Window.hpp>
#include <sigslot/sigslot.h>
#include <list>
#include <mutex>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
///\brief
///ApplicationThread is a class handling intercommunication to main thread.
///
///To make a call to the main thread you do like this:
///\code
///win32cpp::ApplicationThread::Call1(this /*pointer to object*/,&MyClass::MyMethod,argument1);
///\endcode
///
///The calls are using the sigslot library and are threadsafe. If the object
///is deleted before mainthread have the time to call it, the call will not be made.
///
///\remarks
///ApplicationThread has only one instance in the Application class (singleton)
///
///\see
///Application
//////////////////////////////////////////
class ApplicationThread
{
friend class Application;
private: // types
class CallClassBase;
class HelperWindow;
typedef std::shared_ptr<CallClassBase> CallClassPtr;
typedef std::list<CallClassPtr> CallVector;
public: // ctor, dtor
ApplicationThread();
~ApplicationThread();
public: // methods
static bool InMainThread();
private: // methods
void MainThreadCallback();
void NotifyMainThread();
void Initialize();
void AddCall(CallClassBase *callClass);
private: // instance data
///\brief
///The applications thread id
DWORD applicationThreadId;
///\brief
///mutex for protecting the calls
std::mutex mutex;
///\brief
///A list of all the calls to be made
CallVector calls;
///\brief
///instance of the HelperWindow. Created when the Initialize is called.
HelperWindow *helperWindow;
private: // "Call" classes
///\brief
///The HelperWindow is a message only Window (invisible) to help sending messages to main thread.
class HelperWindow : public win32cpp::Window
{
public:
HelperWindow();
virtual HWND Create(Window* parent);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void OnCreated();
};
///\brief
///A virtual base class for all CallClasses
class CallClassBase
{
public:
virtual ~CallClassBase() { };
virtual void Call() = 0;
};
template<class DestinationType>
class CallClass0 : public CallClassBase
{
public:
sigslot::signal0<> signal;
CallClass0(
DestinationType* destinationObject,
void (DestinationType::*memberMethod)())
{
this->signal.connect(destinationObject, memberMethod);
};
void Call()
{
this->signal();
};
};
template<class DestinationType, class Arg1Type>
class CallClass1 : public CallClassBase
{
public:
sigslot::signal1<Arg1Type> signal;
Arg1Type arg1mem;
CallClass1(
DestinationType* destinationObject,
void (DestinationType::*memberMethod)(Arg1Type),
Arg1Type &arg1)
: arg1mem(arg1)
{
this->signal.connect(destinationObject,memberMethod);
};
void Call()
{
this->signal(this->arg1mem);
};
};
template<class DestinationType, class Arg1Type, class Arg2Type>
class CallClass2 : public CallClassBase
{
public:
sigslot::signal2<Arg1Type, Arg2Type> signal;
Arg1Type arg1mem;
Arg2Type arg2mem;
CallClass2(
DestinationType* destinationObject,
void (DestinationType::*memberMethod)(Arg1Type, Arg2Type),
Arg1Type &arg1,
Arg2Type &arg2)
: arg1mem(arg1)
, arg2mem(arg2)
{
this->signal.connect(destinationObject,memberMethod);
};
void Call()
{
this->signal(this->arg1mem,this->arg2mem);
};
};
public: // "Call" invocation
template<class DestinationType>
static void Call0(
DestinationType* destinationObject,
void (DestinationType::*memberMethod)())
{
win32cpp::Application::Instance().Thread()->AddCall(
new CallClass0<DestinationType>(
destinationObject,
memberMethod));
};
template<class DestinationType,class Arg1Type>
static void Call1(
DestinationType* destinationObject,
void (DestinationType::*memberMethod)(Arg1Type),
Arg1Type &arg1)
{
win32cpp::Application::Instance().Thread()->AddCall(
new CallClass1<DestinationType, Arg1Type>(
destinationObject,
memberMethod,
arg1));
};
template<class DestinationType, class Arg1Type, class Arg2Type>
static void Call2(
DestinationType* destinationObject,
void (DestinationType::*memberMethod)(Arg1Type, Arg2Type),
Arg1Type &arg1,
Arg2Type &arg2)
{
win32cpp::Application::Instance().Thread()->AddCall(
new CallClass2<DestinationType, Arg1Type, Arg2Type>(
destinationObject,
memberMethod,
arg1,
arg2));
};
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp
//////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,115 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Button.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Constructor.
///
///\param caption
///The caption that will be drawn on the button.
/*ctor*/ Button::Button(const uichar* caption, LayoutFlags layoutFlags)
: base(layoutFlags)
, caption(caption)
{
}
HWND Button::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_NOTIFY | BS_TEXT;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
_T("BUTTON"), // Class name
this->caption.c_str(), // Window name
style, // Style
0, // X
0, // Y
64, // Width
32, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
LRESULT Button::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
switch (HIWORD(wParam))
{
case BN_CLICKED:
this->OnPressed();
return 0;
}
}
return this->DefaultWindowProc(message, wParam, lParam);
}
void Button::OnPressed()
{
this->Pressed(this);
}
void Button::PaintToHDC(HDC hdc, const Rect& rect)
{
this->WindowProc(WM_PAINT, (WPARAM) (HDC) hdc, PRF_CLIENT);
if (::GetFocus() == this->Handle())
{
RECT focusRect = rect;
::InflateRect(&focusRect, -4, -4);
::DrawFocusRect(hdc, &focusRect);
}
}

View File

@ -0,0 +1,85 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class Button; // forward decl
///\brief
///The type of event used when a Button is pressed..
///\see
///Button.
typedef sigslot::signal1<Button*> ButtonPressedEvent;
///\brief
///A standard push-button. The Button::Pressed event is emitted when
///the user activates the button.
class Button: public Window
{
private: // types
typedef Window base;
public: // events
///\brief This event is emitted when the user presses the Button
ButtonPressedEvent Pressed;
public: // constructors
/*ctor*/ Button(const uichar* caption = _T(""), LayoutFlags = LayoutWrapWrap);
protected: // methods
virtual HWND Create(Window* parent);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void OnPressed();
virtual void PaintToHDC(HDC hdc, const Rect& rect);
protected: // instance data
uistring caption;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,152 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Casey Langen, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/CheckBox.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Constructor.
///
///\param caption
///The caption that beside the checkbox
/*ctor*/ CheckBox::CheckBox(const uichar* caption, LayoutFlags layoutFlags, int style)
: base(layoutFlags)
, caption(caption)
, style(style)
{
}
HWND CheckBox::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | this->style | BS_NOTIFY;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
_T("BUTTON"), // Class name
this->caption.c_str(), // Window name
style, // Style
0, // X
0, // Y
64, // Width
28, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
LRESULT CheckBox::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
switch (HIWORD(wParam))
{
case BN_CLICKED:
this->state = (int)SendMessage(BM_GETCHECK, 0, 0);
this->OnPressed(this->state);
return 0;
}
}
return this->DefaultWindowProc(message, wParam, lParam);
}
void CheckBox::OnPressed(int state)
{
this->Pressed(this, state);
}
void CheckBox::PaintToHDC(HDC hdc, const Rect& rect)
{
this->WindowProc(WM_PAINT, (WPARAM) (HDC) hdc, PRF_CLIENT);
if (::GetFocus() == this->Handle())
{
RECT focusRect = rect;
::InflateRect(&focusRect, -4, -4);
::DrawFocusRect(hdc, &focusRect);
}
}
bool CheckBox::IsChecked(void) const
{
return (this->state == BST_CHECKED);
}
bool CheckBox::IsUnchecked(void) const
{
return (this->state == BST_UNCHECKED);
}
bool CheckBox::IsIndeterminate(void) const
{
return (this->state == BST_INDETERMINATE);
}
void CheckBox::Check(void)
{
SendMessage(BM_SETCHECK, BST_CHECKED, 0);
this->state = BST_CHECKED;
}
void CheckBox::Uncheck(void)
{
SendMessage(BM_SETCHECK, BST_UNCHECKED, 0);
this->state = BST_UNCHECKED;
}
void CheckBox::SetIndeterminate(void)
{
SendMessage(BM_SETCHECK, BST_INDETERMINATE, 0);
this->state = BST_INDETERMINATE;
}

View File

@ -0,0 +1,97 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Casey Langen, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class CheckBox;
///\brief
///The type of event used when the CheckBox is pressed..
///\see
///CheckBox.
typedef sigslot::signal2<CheckBox*, int> CheckboxPressedEvent;
///\brief
///A standard CheckBox.
class CheckBox : public Window
{
private: // types
typedef Window base;
public: // events
///\brief This event is emitted when the user presses the CheckBox
CheckboxPressedEvent Pressed;
public: // constructors
/*ctor*/ CheckBox(
const uichar* caption = _T(""),
LayoutFlags layoutFlags = LayoutWrapWrap,
int style = BS_AUTOCHECKBOX);
protected: // methods
virtual HWND Create(Window* parent);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void OnPressed(int state);
virtual void PaintToHDC(HDC hdc, const Rect& rect);
public:
virtual bool IsChecked(void) const;
virtual bool IsUnchecked(void) const;
virtual bool IsIndeterminate(void) const;
virtual void Check(void);
virtual void Uncheck(void);
virtual void SetIndeterminate(void);
protected: // instance data
int state;
int style;
uistring caption;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,171 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Color.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///Constructor.
///
///\param red
///The red component of the color.
///
///\param green
///The green component of the color.
///
///\param blue
///The blue component of the color.
///
///\param alpha
///The alpha component of the color.
/*ctor*/ Color::Color(byte red, byte green, byte blue, byte alpha)
: red(red)
, green(green)
, blue(blue)
, alpha(alpha)
{
}
///\brief
///Constructor.
///
///\param color
///A COLORREF used to create this color
/*ctor*/ Color::Color(COLORREF color)
: red(GetRValue(color))
, green(GetGValue(color))
, blue(GetBValue(color))
, alpha(0)
{
}
byte Color::ClampByte(int value)
{
if (value > 255) return 255;
if (value < 0) return 0;
return value;
}
///\brief
///Returns a Color based on a system color identifier.
///
///For example:
///\code
///Color myColor = Color::SystemColor(COLOR_BTNFACE);
///\endcode
///
///\param systemColorID
///A system color identifier.
///
///\returns
///A Color based on the specified system color identifier.
Color Color::SystemColor(DWORD systemColorID)
{
COLORREF sysColor = ::GetSysColor(systemColorID);
return Color(
GetRValue(sysColor),
GetGValue(sysColor),
GetBValue(sysColor));
}
///\brief
///Lightens a Color by the specified amount.
///
///\param color
///The color to lighten.
///
///\param amount
///The amount to lighten.
///
///\returns
///A new Color, "amount" lighter than the input color.
///
///\see
///Color::Darken
Color Color::Lighten(const Color& color, byte amount)
{
return Color(
ClampByte(color.red + amount),
ClampByte(color.green + amount),
ClampByte(color.blue + amount),
color.alpha);
}
///\brief
///Darkens a Color by the specified amount.
///
///\param color
///The color to darken.
///
///\param amount
///The amount to darken.
///
///\returns
///A new Color, "amount" darker than the input color.
///
///\see
///Color::Lighten
Color Color::Darken(const Color& color, byte amount)
{
return Color(
ClampByte(color.red - amount),
ClampByte(color.green - amount),
ClampByte(color.blue - amount),
color.alpha);
}
///\brief
///Returns a Win32 COLORREF based on the Color.
Color::operator COLORREF()
{
return RGB(this->red, this->green, this->blue);
}
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,86 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Types.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///An RGBA color. This class can be implicitly casted to and from
///Win32 COLORREF objects.
///
///\code
///COLORREF baseColor = RGB(255, 0, 0);
///Color myColor = baseColor;
///Color::Lighten(myColor, 15);
///COLORREF newColor = myColor;
///\endcode
struct Color
{
public: // constructors
/*ctor*/ Color(byte red = 255, byte green = 255, byte blue = 255, byte alpha = 0);
/*ctor*/ Color(COLORREF color);
public: // fields
byte red;
byte green;
byte blue;
byte alpha;
public: // methods
static byte ClampByte(int value);
static Color SystemColor(DWORD systemColorID);
static Color Lighten(const Color& color, byte amount);
static Color Darken(const Color& color, byte amount);
public: // operators
virtual operator COLORREF();
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,194 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Casey Langen, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/ComboBox.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
const LPCWSTR ComboBox::BoxType_Standard = WC_COMBOBOX;
const LPCWSTR ComboBox::BoxType_Extended = WC_COMBOBOXEX;
ComboBox::ModelRef ComboBox::sNullModel(new ComboBox::NullModel());
ComboBox::ComboBox(DisplayType displayType, LPCWSTR boxType) :
model(ComboBox::sNullModel),
displayType(displayType),
boxType(boxType)
{
}
ComboBox::~ComboBox()
{
}
HWND ComboBox::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_USEREX_CLASSES;
// We need the extended combobox from the common controls
InitCommonControlsEx(&icex);
/**
* TODO: For CBS_DROPDOWN-support (editable entries) pszText of COMBOBOXEXITEM in OnDataChanged
* must be adapted to a send/retrieve behaviour or we must implement a
* callback behaviour with CBEN_GETDISPINFO. (as it is in the ListView)
*/
DWORD style = WS_CHILD | WS_VISIBLE | WS_BORDER | displayType;
// Create the ComboBox
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
boxType, // Class name
_T(""), // Window name
style, // Style
0, // X
0, // Y
0, // Width
100, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
bool ComboBox::Info(PCOMBOBOXINFO pcbi)
{
return !!(::GetComboBoxInfo(this->windowHandle, pcbi));
}
void ComboBox::SetModel(ModelRef model)
{
// Unbind event handlers, assign new model and rebind event handler
this->model->DataChanged.disconnect(this);
this->model = model;
this->model->DataChanged.connect(this, &ComboBox::OnDataChanged);
// On change of model ask combobox to reload the items from the model
this->OnDataChanged();
}
int ComboBox::Selected()
{
return (int)this->SendMessage(
CB_GETCURSEL,
0,
0
);
}
void ComboBox::Select(int index)
{
// If index is -1 the selection is cleared
this->SendMessage(
CB_SETCURSEL,
(WPARAM)index,
0
);
}
void ComboBox::OnDataChanged()
{
// Delete old items in combobox
int last, item = 0;
do {
last = (int)this->SendMessage(
CBEM_DELETEITEM,
(WPARAM)(DWORD)item,
0
);
item++;
} while(last != 0 && last != CB_ERR);
// Set image list (given by model)
ImageList* imagelist = this->model->ImageList();
if(imagelist) {
this->SendMessage(
CBEM_SETIMAGELIST,
0,
(LPARAM)imagelist->Handle()
);
}
// Iterate through available items
for(int i=0; i<this->model->ItemCount(); i++) {
// Get item string
uistring val = this->model->ItemToString(i);
// Get extended data for item
LPARAM data = this->model->ItemToExtendedData(i);
// Get indentation for item (1 space = 10 pixels)
int indent = this->model->ItemToIndent(i);
// Get image for item (only valid if image list is set)
int ilindex = this->model->ItemToImageListIndex(i);
// Initialize combobox item
COMBOBOXEXITEM item;
::ZeroMemory(&item, sizeof(COMBOBOXEXITEM));
item.mask = CBEIF_TEXT | CBEIF_LPARAM | CBEIF_INDENT;
item.iItem = i;
item.pszText = (wchar_t*)val.c_str();
item.cchTextMax = (int)val.length();
item.lParam = data;
item.iIndent = indent;
if(imagelist) {
// If given, add image from image list to item
item.mask |= CBEIF_IMAGE | CBEIF_SELECTEDIMAGE;
item.iImage = ilindex;
item.iSelectedImage = ilindex;
}
// Insert item
this->SendMessage(
CBEM_INSERTITEM,
0,
(LPARAM)(PCOMBOBOXEXITEM)&item
);
}
}

View File

@ -0,0 +1,173 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Casey Langen, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
#include <win32cpp/Win32Exception.hpp>
#include <win32cpp/Color.hpp>
#include <win32cpp/ImageList.hpp>
#include <boost/format.hpp>
#include <vector>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// ComboBox
//////////////////////////////////////////////////////////////////////////////
class ComboBox : public Window
{
public:
enum DisplayType {
DisplayType_Simple = CBS_SIMPLE,
DisplayType_DropDownList = CBS_DROPDOWNLIST
};
static const LPCWSTR BoxType_Standard;
static const LPCWSTR BoxType_Extended;
class Model;
typedef std::shared_ptr<Model> ModelRef;
typedef sigslot::signal1<ComboBox*> SelectionChangedEvent;
ComboBox(
DisplayType displayType = DisplayType_DropDownList,
LPCWSTR boxType = BoxType_Extended
);
~ComboBox();
void SetModel(ModelRef model);
int Selected();
void Select(int index);
bool Info(PCOMBOBOXINFO pcbi);
protected:
ModelRef model;
static ModelRef sNullModel;
virtual HWND Create(Window* parent);
virtual void OnDataChanged();
private:
typedef Window base;
class NullModel;
DisplayType displayType;
LPCWSTR boxType;
};
//////////////////////////////////////////////////////////////////////////////
// ComboBox::Model
//////////////////////////////////////////////////////////////////////////////
class ComboBox::Model
{
private:
int itemCount;
public:
typedef sigslot::signal0<> DataChangedEvent;
DataChangedEvent DataChanged;
Model(int itemCount = 0) :
itemCount(itemCount)
{
}
virtual int ItemCount()
{
return this->itemCount;
}
virtual ImageList* ImageList()
{
return NULL;
}
virtual int ItemToImageListIndex(int index)
{
return -1;
}
virtual uistring ItemToString(int index) = 0;
virtual int ItemToIndent(int index) = 0;
virtual LPARAM ItemToExtendedData(int index) = 0;
};
//////////////////////////////////////////////////////////////////////////////
// ComboBox::NullModel
//////////////////////////////////////////////////////////////////////////////
class ComboBox::NullModel : public ComboBox::Model
{
public:
virtual int ItemCount()
{
return 0;
}
virtual uistring ItemToString(int index)
{
return uistring();
}
virtual int ItemToImageListIndex(int index)
{
return -1;
}
virtual int ItemToIndent(int index)
{
return 0;
}
virtual LPARAM ItemToExtendedData(int index)
{
return 0;
}
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,197 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Config.hpp>
#include <win32cpp/Win32Exception.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
Config::Config()
{
;
}
Config::Config(const uistring &fileName) : iniFileName(fileName)
{
;
}
Config::~Config()
{
;
}
void Config::SetSection(const uistring &newSection)
{
this->currentSection = newSection;
}
void Config::SetFileName(const uistring& fileName)
{
this->iniFileName = fileName;
}
BOOL Config::SectionExists(const uistring& section)
{
DWORD bufferLen = 255, retLen;
std::unique_ptr<TCHAR> buffer(new TCHAR[bufferLen]);
// get section keys
retLen = ::GetPrivateProfileSection(
section.c_str(),
buffer.get(),
bufferLen,
this->iniFileName.c_str());
return (retLen > 0);
}
uistring Config::Value(const uistring &key)
{
uistring value;
DWORD bufferLen = 255, retLen;
std::unique_ptr<TCHAR> buffer(new TCHAR[bufferLen]);
// get value
retLen = ::GetPrivateProfileString(
this->currentSection.c_str(),
key.c_str(),
NULL,
buffer.get(),
bufferLen,
this->iniFileName.c_str());
// if size exceeds the limit, realloc and read again
while(retLen == bufferLen-1)
{
bufferLen += bufferLen;
buffer.reset(new TCHAR[bufferLen]);
retLen = ::GetPrivateProfileString(
this->currentSection.c_str(),
key.c_str(),
NULL,
buffer.get(),
bufferLen,
this->iniFileName.c_str());
}
if (retLen)
{
value = uistring(buffer.get());
}
return value;
}
BOOL Config::SetValue(const uistring &key, const uistring &value)
{
// check if section name is empty
if(this->currentSection.empty())
throw Exception("Please provide a section!");
// write value to ini file
BOOL ret = ::WritePrivateProfileString(
this->currentSection.c_str(),
key.c_str(),
value.c_str(),
this->iniFileName.c_str());
// throw an exception if call was invalid
if(!ret)
throw Win32Exception();
return ret;
}
ConfigSectionList Config::Sections()
{
ConfigSectionList list;
DWORD bufferLen = 255, retLen;
std::unique_ptr<TCHAR> buffer(new TCHAR[bufferLen]);
// get string with section names
retLen = ::GetPrivateProfileSectionNames(
buffer.get(),
bufferLen,
this->iniFileName.c_str());
// if string length exceeds the limit, realloc with bigger size and read again
while(retLen == bufferLen-1)
{
bufferLen += bufferLen;
buffer.reset(new TCHAR[bufferLen]);
retLen = ::GetPrivateProfileSectionNames(
buffer.get(),
bufferLen,
this->iniFileName.c_str());
}
if (retLen)
{
std::unique_ptr<TCHAR> buffer2(new TCHAR[retLen]);
// split up string with section names
for(DWORD lastIndex = 0, i = 0; i < retLen; i++)
{
if(buffer.get()[i] == 0) {
// copy section name to separate buffer
::_tcsncpy_s(
buffer2.get(),
i + 1,
&buffer.get()[lastIndex],
_TRUNCATE);
// push section name into list
list.push_back(buffer2.get());
// save last index to get next element
lastIndex = i + 1;
// the end of the list is terminated with \0\0
if(buffer.get()[i+1] == 0) break;
}
}
}
return list;
}

View File

@ -0,0 +1,74 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Types.hpp>
#include <vector>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// Config
//////////////////////////////////////////////////////////////////////////////
typedef std::vector<uistring> ConfigSectionList;
class Config {
private:
uistring currentSection;
uistring iniFileName;
public:
/*ctor*/ Config();
/*ctor*/ Config(const uistring& fileName);
/*dtor*/ ~Config();
void SetSection(const uistring& newSection);
void SetFileName(const uistring& fileName);
uistring Value(const uistring& key);
BOOL SetValue(const uistring& key, const uistring& value);
BOOL SectionExists(const uistring& section);
ConfigSectionList Sections();
};
//////////////////////////////////////////////////////////////////////////////
}

View File

@ -0,0 +1,277 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Container.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
/*ctor*/ Container::Container()
: base()
, focusedWindow(NULL)
{
}
/*ctor*/ Container::Container(LayoutFlags layoutFlags)
: base(layoutFlags)
, focusedWindow(NULL)
{
}
/*dtor*/ Container::~Container()
{
this->DestroyChildren();
}
void Container::DestroyChildren()
{
try
{
// destroy all of our managed child windows
WindowList& allChildren = Window::sAllChildWindows;
WindowList::iterator end = this->childWindows.end();
WindowList::iterator it = this->childWindows.begin();
//
while (it != end)
{
allChildren.erase(
std::find(allChildren.begin(), allChildren.end(), *it));
try
{
(*it)->Destroy();
delete (*it);
}
catch(...)
{
// FIXME: log window couldn't be destroyed
}
++it;
}
//
this->childWindows.clear();
this->Destroy();
}
catch(...)
{
// FIXME: log dtor threw unexpectedly
}
}
bool Container::AddChildWindow(Window* window)
{
if ( ! this->Handle())
{
this->Initialize(Application::Instance().MainWindow());
}
if ( ! window->Handle())
{
window->Initialize(this);
}
this->childWindows.push_back(window);
window->RequestFocusNext.connect(
this, &Container::OnChildWindowRequestFocusNext);
window->RequestFocusPrev.connect(
this, &Container::OnChildWindowRequestFocusPrev);
return true;
}
bool Container::RemoveChildWindow(Window* window)
{
WindowList::iterator it = this->FindChild(window);
//
if (it == this->childWindows.end())
{
return false;
}
window->RequestFocusNext.disconnect(this);
window->RequestFocusPrev.disconnect(this);
this->childWindows.erase(it);
if (this->focusedWindow == window)
{
this->focusedWindow = NULL;
}
return true;
}
Window::WindowList::iterator Container::FindChild(const Window* child)
{
return std::find(
this->childWindows.begin(), this->childWindows.end(), child);
}
Window::WindowList::reverse_iterator Container::ReverseFindChild(const Window* child)
{
return std::find(
this->childWindows.rbegin(), this->childWindows.rend(), child);
}
template <typename List, typename Iterator>
Window* FocusNextValidChild(List& collection, Iterator it, Iterator end)
{
if (collection.size())
{
while ((it != end) && ( ! (*it)->TabStop()))
{
it++;
}
if ((it != end) && ((*it)->SetFocus()))
{
return (*it);
}
}
return NULL;
}
bool Container::FocusFirstChild()
{
this->focusedWindow = FocusNextValidChild(
this->childWindows,
this->childWindows.begin(),
this->childWindows.end());
return (this->focusedWindow != NULL);
}
bool Container::FocusLastChild()
{
this->focusedWindow = FocusNextValidChild(
this->childWindows,
this->childWindows.rbegin(),
this->childWindows.rend());
return (this->focusedWindow != NULL);
}
bool Container::FocusNextChild()
{
WindowList::iterator it = this->FindChild(this->focusedWindow);
it++;
this->focusedWindow = FocusNextValidChild(
this->childWindows,
it,
this->childWindows.end());
return (this->focusedWindow != NULL);
}
bool Container::FocusPrevChild()
{
WindowList::reverse_iterator it = this->ReverseFindChild(this->focusedWindow);
it++;
this->focusedWindow = FocusNextValidChild(
this->childWindows,
it,
this->childWindows.rend());
return (this->focusedWindow != NULL);
}
void Container::OnGainedFocus()
{
bool success;
Window::sFocusDirection == Window::FocusForward
? success = this->FocusFirstChild()
: success = this->FocusLastChild();
if ( ! success)
{
Window::sFocusDirection == Window::FocusForward
? this->OnRequestFocusNext()
: this->OnRequestFocusPrev();
}
}
void Container::OnChildWindowRequestFocusNext(Window* window)
{
this->focusedWindow = window;
this->OnRequestFocusNext();
}
void Container::OnChildWindowRequestFocusPrev(Window* window)
{
this->focusedWindow = window;
this->OnRequestFocusPrev();
}
void Container::OnRequestFocusNext()
{
bool focusChildSuccess = (this->focusedWindow == NULL)
? this->FocusFirstChild()
: this->FocusNextChild();
// we weren't able to focus the next child, so notify the parent.
if (focusChildSuccess == NULL)
{
base::OnRequestFocusNext();
}
}
void Container::OnRequestFocusPrev()
{
bool focusChildSuccess = (this->focusedWindow == NULL)
? this->FocusLastChild()
: this->FocusPrevChild();
// we weren't able to focus the previous child, so notify the parent.
if ( ! focusChildSuccess)
{
base::OnRequestFocusPrev();
}
}

View File

@ -0,0 +1,244 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///Container is a specialization of Window that can house one or more child controls.
///
///Use Container::AddChild and Container::RemoveChild to manage
///children. Once a Window is added to a Container, the Container
///takes ownership of it. <b>Do not, under any circumstances, call
///delete on a Window that is a child of a Container!</b> If the caller
///removes a child via Container::RemoveChild he is then responsible for
///deleting it.
///
///A Window may only have one parent, and a WindowAlreadyHasParentException
///will be thrown if this contract is violated.
///
///Some types of Containers can only hold a specific number of children,
///and will throw a TooManyChildWindowsException if that number is
///exceeded. Frame, for example, only allows one child Window. Splitter
///allows two. Be sure to read the documentation of classes derived
///from Container for more information.
/*abstract*/ class Container: public Window
{
public: // types
class TooManyChildWindowsException { };
class WindowAlreadyHasParentException: public Exception { };
class WindowHasNoParentException: public Exception { };
class InvalidChildWindowException: public Exception { };
private: //types
typedef Window base;
public: // constructors, methods
/*ctor*/ Container();
/*ctor*/ Container(LayoutFlags layoutFlags);
/*dtor*/ virtual ~Container();
template <typename WindowType>
WindowType* AddChild(WindowType* window);
template <typename WindowType>
WindowType* RemoveChild(WindowType* window);
protected: // methods
virtual HWND Create(Window* parent) = 0;
virtual bool AddChildWindow(Window* window);
virtual bool RemoveChildWindow(Window* window);
virtual void OnChildAdded(Window* newChild) { /*for derived use*/ }
virtual void OnChildRemoved(Window* oldChild) { /*for derived use*/ }
virtual void OnRequestFocusNext();
virtual void OnRequestFocusPrev();
virtual void OnChildWindowRequestFocusNext(Window* child);
virtual void OnChildWindowRequestFocusPrev(Window* child);
virtual void OnGainedFocus();
virtual bool FocusLastChild();
virtual bool FocusFirstChild();
virtual bool FocusPrevChild();
virtual bool FocusNextChild();
private: // methods
void DestroyChildren();
WindowList::iterator FindChild(const Window* child);
WindowList::reverse_iterator ReverseFindChild(const Window* child);
protected: // instance data
WindowList childWindows;
Window* focusedWindow;
};
//////////////////////////////////////////////////////////////////////////////
// Container template methods
//////////////////////////////////////////////////////////////////////////////
///\brief
///Add the specified Window as a child of the Container.
///
///This method is a templated to make adding children as painless as possible.
///The return value is a pointer to the child that was just added. The user
///can use this method as follows:
///
///\code
///Label* myLabel = myContainer->AddChild(new Label(_T("Value: ")));
///\endcode
///
///\param window
///The Window to add.
///
///\returns
///Returns the Window that was added.
///
///\throws WindowIsNullException
///if window is NULL
///
///\throws WindowAlreadyHasParentException
///if the Window already has a parent
///
///\throws WindowAlreadyHasParentException
///if a class derived from Container doesn't like the child
///
///\see
///Container::RemoveChild
template <typename WindowType>
WindowType* Container::AddChild(WindowType* window)
{
if ( ! window)
{
throw WindowIsNullException();
return window;
}
if (Window::WindowHasParent(window))
{
throw WindowAlreadyHasParentException();
return window;
}
if ( ! this->AddChildWindow(static_cast<Window*>(window)))
{
throw InvalidChildWindowException();
return window;
}
// keep track of all windows that have parents
Window::sAllChildWindows.push_back(window);
// set us as the window's new parent
Window::SetParent(window, this);
this->OnChildAdded(window);
return window;
}
///\brief
///Removes the specified Window from the Container.
///
///Whoever calls this method is responsible for deleting the Window
///returned. This method is templated to make this as painless
///as possible. The return value is a pointer to the window removed.
///
///\code
///delete myContainer->RemoveChild(myLabel);
///\endcode
///
///\param window
///The Window to remove.
///
///\returns
///Returns the Window that was removed.
///
///\throws WindowIsNullException
///if window is NULL
///
///\throws WindowHasNoParentException
///if the Window doesn't have a parent
///
///\throws InvalidChildWindowException
///if a class derived from Container doesn't like the child
///
///\see
///Container::AddChild
template <typename WindowType>
WindowType* Container::RemoveChild(WindowType* window)
{
if ( ! window)
{
throw WindowIsNullException();
return window;
}
if ( ! Window::WindowHasParent(window))
{
throw WindowHasNoParentException();
return window;
}
if ( ! this->RemoveChildWindow(static_cast<Window*>(window)))
{
throw InvalidChildWindowException();
return window;
}
// window is no longer a child window, remove it from the mapping.
WindowList& allChildren = Window::sAllChildWindows;
//
allChildren.erase(
std::find(allChildren.begin(), allChildren.end(), window));
this->OnChildRemoved(window);
return window;
}
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,300 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/DateTime.hpp>
#include <win32cpp/Win32Exception.hpp>
#include <win32cpp/Utility.hpp>
#include <boost/regex.hpp>
#include <sstream>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
DateTime::DateTime() : locale(NULL)
{
// use current local time
this->SetLocaltime();
}
DateTime::DateTime(Locale* useLocale) : locale(useLocale)
{
// use current local time
::GetLocalTime(&this->curDateTime);
}
DateTime::DateTime(Locale* useLocale, const SYSTEMTIME& dateTime) :
locale(useLocale),
curDateTime(dateTime)
{
// use given time
;
}
DateTime::~DateTime()
{
}
void DateTime::SetSystemtime(void)
{
::GetSystemTime(&this->curDateTime);
}
void DateTime::FromSystemtime(const SYSTEMTIME& dateTime)
{
this->curDateTime = dateTime;
}
void DateTime::SetLocaltime(void)
{
::GetLocalTime(&this->curDateTime);
}
bool DateTime::FromSQLDateTime(const uistring& sqlDate)
{
// match YYYY-MM-DD HH:MM:SS
// HH:MM:SS is optional
boost::wcmatch matches;
boost::wregex e(_T("(\\d{4})-(\\d{2})-(\\d{2})(?: (\\d{2}):(\\d{2}):(\\d{2}))?"));
if(boost::regex_match(sqlDate.c_str(), matches, e))
{
for(unsigned int i = 1; i <= 6; i++)
{
int c;
if(matches[i].matched)
{
std::string match(matches[i].first, matches[i].second);
std::stringstream mstream(match);
mstream >> c;
}
else
{
c = 0;
}
switch(i)
{
case 1: this->curDateTime.wYear = c; break;
case 2: this->curDateTime.wMonth = c; break;
case 3: this->curDateTime.wDay = c; break;
case 4: this->curDateTime.wHour = c; break;
case 5: this->curDateTime.wMinute = c; break;
case 6: this->curDateTime.wSecond = c; break;
}
}
this->curDateTime.wMilliseconds = 0;
return true;
}
return false;
}
void DateTime::Set(int year = -1, int month = -1, int dow = -1, int day = -1, int hour = -1, int minute = -1, int second = -1, int millisecond = -1)
{
// use negative numbers if you don't want to set an element
if(year >= 0) this->curDateTime.wYear = year;
if(month >= 0) this->curDateTime.wMonth = month;
if(dow >= 0) this->curDateTime.wDayOfWeek = dow;
if(day >= 0) this->curDateTime.wDay = day;
if(hour >= 0) this->curDateTime.wHour = hour;
if(minute >= 0) this->curDateTime.wMinute = minute;
if(second >= 0) this->curDateTime.wSecond = second;
if(millisecond >= 0) this->curDateTime.wMilliseconds = millisecond;
}
uistring DateTime::FormatDate(const uistring& format, DWORD flags = 0)
{
TCHAR formatted[64];
LPCTSTR fstr = NULL;
WORD langid = (this->locale != NULL)
? (this->locale->LangID())
: LOCALE_USER_DEFAULT;
if(!format.empty()) fstr = format.c_str();
int ret = ::GetDateFormat(
MAKELCID(langid, SORT_DEFAULT),
flags,
&this->curDateTime,
fstr,
formatted,
64
);
if(!ret) {
throw Win32Exception();
}
return uistring(formatted);
}
uistring DateTime::FormatTime(const uistring& format, DWORD flags = 0)
{
TCHAR formatted[64];
LPCTSTR fstr = NULL;
WORD langid = (this->locale != NULL)
? (this->locale->LangID())
: LOCALE_USER_DEFAULT;
if(!format.empty()) fstr = format.c_str();
int ret = ::GetTimeFormat(
MAKELCID(langid, SORT_DEFAULT),
flags,
&this->curDateTime,
fstr,
formatted,
64
);
if(!ret) {
throw Win32Exception();
}
return uistring(formatted);
}
uistring DateTime::Date()
{
// is a locale set?
if(this->locale)
{
// get format string for dates
uistring fmtDate = this->locale->DateFormat();
if(fmtDate.empty())
{
// if the date format is empty, use the locale-specific
return this->FormatDate(_T(""), DATE_SHORTDATE);
}
else
{
// if the date format is given, use it
return this->FormatDate(fmtDate);
}
}
else
{
// if no locale is set, use the user/system-specific
// (which is ALWAYS installed and supported)
return this->FormatDate(_T(""), DATE_SHORTDATE);
}
}
uistring DateTime::Time()
{
// is a locale set?
if(this->locale)
{
// get format string for times
uistring fmtTime = this->locale->TimeFormat();
if(fmtTime.empty())
{
// if the time format is empty, use the locale-specific
return this->FormatTime(_T(""));
}
else
{
// if the time format is given, use it
return this->FormatTime(fmtTime);
}
}
else
{
// if no locale is set, use the user/system-specific
// (which is ALWAYS installed and supported)
return this->FormatTime(_T(""));
}
}
uistring DateTime::MonthString()
{
// if a locale is given and installed, return specified by locale
if(this->locale && this->locale->SystemSupport())
{
return this->FormatDate(_T("MMMM"));
}
// otherwise, use the standard names, passing them through the translation map of the locale
// if a locale is not installed in the NLS-subsystem of windows
switch(this->curDateTime.wMonth)
{
case 1: return _(_T("January"));
case 2: return _(_T("February"));
case 3: return _(_T("March"));
case 4: return _(_T("April"));
case 5: return _(_T("May"));
case 6: return _(_T("June"));
case 7: return _(_T("July"));
case 8: return _(_T("August"));
case 9: return _(_T("September"));
case 10: return _(_T("October"));
case 11: return _(_T("November"));
case 12: return _(_T("December"));
}
return _T("(null)");
}
uistring DateTime::DayOfWeekString()
{
// if a locale is given and installed, return specified by locale
if(this->locale && this->locale->SystemSupport())
{
return this->FormatDate(_T("dddd"));
}
// otherwise, use the standard names, passing them through the translation map of the locale
// if a locale is not installed in the NLS-subsystem of windows
switch(this->curDateTime.wDayOfWeek)
{
case 0: return _(_T("Sunday"));
case 1: return _(_T("Monday"));
case 2: return _(_T("Tuesday"));
case 3: return _(_T("Wednesday"));
case 4: return _(_T("Thursday"));
case 5: return _(_T("Friday"));
case 6: return _(_T("Saturday"));
}
return _T("(null)");
}

View File

@ -0,0 +1,95 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Locale.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// DateTime
//////////////////////////////////////////////////////////////////////////////
class DateTime {
private:
SYSTEMTIME curDateTime;
Locale* locale;
public:
int Year() const { return this->curDateTime.wYear; }
int Month() const { return this->curDateTime.wMonth; }
int DayOfWeek() const { return this->curDateTime.wDayOfWeek; }
int Day() const { return this->curDateTime.wDay; }
int Hour() const { return this->curDateTime.wHour; }
int Minute() const { return this->curDateTime.wMinute; }
int Second() const { return this->curDateTime.wSecond; }
int Millisecond() const { return this->curDateTime.wMilliseconds; }
uistring MonthString();
uistring DayOfWeekString();
uistring Date();
uistring Time();
ULONG Timestamp() const;
uistring FormatDate(const uistring& format, DWORD flags);
uistring FormatTime(const uistring& format, DWORD flags);
const PSYSTEMTIME
Win32Systemtime();
void Set(int year, int month, int dow, int day, int hour, int minute, int second, int millisecond);
void SetSystemtime(void);
void SetLocaltime(void);
void FromSystemtime(const SYSTEMTIME& dateTime);
bool FromSQLDateTime(const uistring& sqlDate);
/* ctor */ DateTime();
/* ctor */ DateTime(Locale* useLocale);
/* ctor */ DateTime(Locale* useLocale, const SYSTEMTIME& dateTime);
/* dtor */ ~DateTime();
};
//////////////////////////////////////////////////////////////////////////////
}

View File

@ -0,0 +1,57 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/DeviceContext.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
/*ctor*/ DeviceContext::DeviceContext(HWND hwnd)
: hwnd(hwnd)
, hdc(::GetDC(hwnd))
{
}
/*dtor*/ DeviceContext::~DeviceContext()
{
::ReleaseDC(this->hwnd, this->hdc);
}

View File

@ -0,0 +1,64 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class DeviceContext
{
public: // constructors, methods
/*ctor*/ DeviceContext(HWND hwnd);
/*dtor*/ ~DeviceContext();
operator HDC() { return this->hdc; }
private: // instance data
HDC hdc;
HWND hwnd;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,231 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/EditView.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Constructor.
///
///\param width
///The width of the edit box
///\param height
///The height of the edit box
/*ctor*/ EditView::EditView(int width, int height)
: base(LayoutWrapWrap)
{
this->InitializeInstance();
}
///\brief
///Constructor.
///
///\param layoutFlags
///The layout hints to use when laying a control out in a parent.
/*ctor*/ EditView::EditView(LayoutFlags layoutFlags)
: base(layoutFlags)
{
this->InitializeInstance();
}
/*ctor*/ EditView::EditView(const uistring& caption, LayoutFlags layoutFlags)
: base(layoutFlags)
{
this->InitializeInstance();
}
EditView::~EditView()
{
}
void EditView::InitializeInstance()
{
this->width = 200;
this->height = 22;
this->caption = caption;
}
HWND EditView::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL;
DWORD styleEx = WS_EX_CLIENTEDGE;
//
HWND hwnd = CreateWindowEx(
styleEx, // ExStyle
_T("EDIT"), // Class name
NULL, // Window name
style, // Style
0, // X
0, // Y
this->width, // Width
this->height, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
if (hwnd)
{
::SetWindowText(hwnd, this->caption.c_str());
}
return hwnd;
}
LRESULT EditView::PreWindowProc(UINT message, WPARAM wParam, LPARAM lParam, bool &discardMessage)
{
switch (message)
{
case WM_CHAR:
{
// avoid a *ding* that chimes if we don't say we want tab.
if ((wParam == VK_TAB) && (this->TabStop()))
{
this->SelectAll();
discardMessage = true;
}
}
break;
}
return 0;
}
LRESULT EditView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
WORD notifyHeader = HIWORD(wParam);
switch (notifyHeader)
{
case EN_CHANGE:
this->OnChanged();
return 0; // 0 = processed
}
}
break;
}
return this->DefaultWindowProc(message, wParam, lParam);
}
void EditView::OnChanged()
{
this->Changed(this);
}
///\brief SetReadOnly
///Sets the edit control to be read only.
///\param setting
///True or False (Read only and Read/Write respectively)
void EditView::SetReadOnly(bool setting)
{
Edit_SetReadOnly(this->Handle(), setting);
}
///\brief ShowCaret
///Moves the caret to a visible position.
///
void EditView::ShowCaret()
{
Edit_ScrollCaret(this->Handle());
return;
}
///\brief SetTooltip
///Sets the tooltip text for the edit control.
///\param text
///The tooltip text to set
void EditView::SetTooltip(uistring text)
{
Edit_SetCueBannerText(this->Handle(), text.c_str());
//Edit_SetCueBannerTextFocused(this->headerHandle, text.c_str(), true);
//The second one is vista only
}
///\brief LimitText
///Sets the limit for the amount of text that can be entered
///\param chars
///The number of characters allowed
void EditView::LimitText(int chars)
{
Edit_LimitText(this->Handle(), chars);
}
///\brief SetSelection
///Sets the positions of the first and last character of selected text in the edit box
///\param first
///The position of the first char to select
///\param second
///The position of the end char to select up to
void EditView::SetSelection(int first, int second)
{
Edit_SetSel(this->Handle(), first, second);
}
///\brief SelectAll
///Selects all the characters in the view
void EditView::SelectAll()
{
Edit_SetSel(this->Handle(), 0, -1);
}
///\brief Undo
///Undoes the last edit
///
void EditView::Undo()
{
if(Edit_CanUndo(this->Handle()))
{
Edit_Undo(this->Handle());
}
return;
}

View File

@ -0,0 +1,102 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class EditView; // forward decl
///\brief
///The type of event used when a the edit control is changed
///\see
///Button.
typedef sigslot::signal1<EditView*> EditViewChangedEvent;
///\brief
///A standard edit control.
class EditView: public Window
{
private: // typedefs
typedef Window base;
public: // events
EditViewChangedEvent Changed;
public: // constructors, methods
/*ctor*/ EditView(int width, int height);
/*ctor*/ EditView(LayoutFlags layoutFlags);
/*ctor*/ EditView(const uistring& caption = _T(""), LayoutFlags layoutFlags = LayoutWrapWrap);
/*dtor*/ ~EditView();
void SetReadOnly(bool setting);
void ShowCaret();
void SetTooltip(uistring text);
void LimitText(int chars);
void SetSelection(int first, int second);
void SelectAll();
void Undo();
protected: // methods
virtual HWND Create(Window* parent);
virtual LRESULT PreWindowProc(UINT message, WPARAM wParam, LPARAM lParam, bool &discardMessage);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void OnChanged();
private:
void InitializeInstance();
protected: // instance data
uistring caption;
int width;
int height;
uistring editText;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,70 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Exception.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Default constructor.
/*ctor*/ Exception::Exception()
{
}
///\brief
///Constructor.
/*ctor*/ Exception::Exception(const char* message)
: message(message)
{
}
/*dtor*/ Exception::~Exception()
{
}
///\brief
///Returns a string representation of the exception, usually a description.
const char* Exception::Message()
{
return this->message.c_str();
}

View File

@ -0,0 +1,73 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <string>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///The base class for all exceptions thrown by win32cpp.
class Exception
{
public: // constructors
/*ctor*/ Exception();
/*ctor*/ Exception(const char* message);
/*dtor*/ virtual ~Exception();
public: // methods
virtual const char* Message();
private: // instance data
std::string message;
};
//////////////////////////////////////////////////////////////////////////////
///\brief
///Thrown when a method is not yet implemented.
class NotImplementedException: public Exception { };
//////////////////////////////////////////////////////////////////////////////
} // namespace win32cpp

View File

@ -0,0 +1,119 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/FolderBrowseDialog.hpp>
#include <shlobj.h>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
typedef FolderBrowseDialog::Result Result;
//////////////////////////////////////////////////////////////////////////////
static int CALLBACK FolderBrowseSetInitialDirectory(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
if ((uMsg == BFFM_INITIALIZED) && (lpData))
{
::SendMessage(hWnd, BFFM_SETSELECTION, TRUE, lpData);
}
return 0;
}
//////////////////////////////////////////////////////////////////////////////
/*ctor*/ FolderBrowseDialog::FolderBrowseDialog()
{
}
Result FolderBrowseDialog::Show(Window* owner, const uichar* initialPath)
{
TCHAR path[_MAX_PATH];
BROWSEINFO browseInfo;
::SecureZeroMemory(&browseInfo, sizeof(browseInfo));
//
browseInfo.lpszTitle = _T("Select a directory to continue.");
browseInfo.hwndOwner = owner ? owner->Handle() : NULL;
browseInfo.ulFlags |= BIF_NEWDIALOGSTYLE;
browseInfo.pidlRoot = NULL;
if (initialPath != NULL)
{
browseInfo.lpfn = FolderBrowseSetInitialDirectory;
browseInfo.lParam = (LPARAM)(LPTSTR)initialPath;
}
LPITEMIDLIST pidl = SHBrowseForFolder(&browseInfo);
if (pidl != NULL)
{
SHGetPathFromIDList(pidl, path);
IMalloc* imalloc = NULL;
//
if (SUCCEEDED(SHGetMalloc(&imalloc)))
{
imalloc->Free(pidl);
imalloc->Release();
}
this->directory = path;
if (this->directory.size() > 0)
{
if (this->directory[directory.size() - 1] != '\\')
{
this->directory += '\\';
}
}
return ResultOK;
}
return ResultCanceled;
}
uistring FolderBrowseDialog::Directory()
{
return this->directory;
}

View File

@ -0,0 +1,72 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class FolderBrowseDialog
{
public: // types
enum Result
{
ResultOK = 0,
ResultCanceled
};
public: // ctor
FolderBrowseDialog();
public: // methods
Result Show(Window* owner = NULL, const uichar* initialPath = NULL);
uistring Directory();
private: // instance data
uistring directory;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,393 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Font.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
// Font
//////////////////////////////////////////////////////////////////////////////
#define INVALIDATE_FONT_ATTRIBUTE(varName) \
this->varName = varName; \
this->Invalidate(); \
///\brief
///Default constructor.
/*ctor*/ Font::Font()
: invalid(true)
, font(NULL)
, faceName(_T(""))
, pointSize(-1)
, weight(FW_REGULAR)
, italic(false)
, underline(false)
{
}
///\brief
///Constructor.
///
///\param fontFace
///the name of the fontface to use.
///
///\param pointSize
///the pointsize of the font.
///
///\param bold
///if true the font will be bold
///
///\param italic
///if true the font will be italic
///
///\param underline
///if true the font will be underlined
/*ctor*/ Font::Font(const uistring& fontFace, unsigned pointSize, bool bold, bool italic, bool underline)
: invalid(true)
, font(NULL)
, faceName(fontFace)
, pointSize(pointSize)
, weight(bold ? FW_BOLD : FW_REGULAR)
, italic(italic)
, underline(underline)
{
}
///\brief
///Constructor.
///
///\param logFont
///the font parameters to use when creating this font.
///
///\param hdc
///The device context to use when creating the HFONT. If this parameter
///is NULL the Desktop's HDC will be used.
/*ctor*/ Font::Font(const LOGFONT& logFont, HDC hdc)
: invalid(true)
{
this->InitializeFont(logFont, hdc);
}
/*dtor*/ Font::~Font()
{
::DeleteObject(this->font);
}
///\brief
///Renders text to the specified device context.
///
///\param hdc
///the device context to render the text to.
///
///\param rect
///the bounding rectangle.
///
///\param caption
///the text to render.
///
///\param alignment
///the text alignment to use
void Font::DrawToHDC(HDC hdc, const Rect& rect, const uistring& caption, TextAlignment alignment)
{
if (this->invalid)
{
this->InitializeFont(hdc);
this->invalid = false;
}
HGDIOBJ oldObject = ::SelectObject(hdc, this->font);
// draw
DRAWTEXTPARAMS drawTextParams;
::SecureZeroMemory(&drawTextParams, sizeof(DRAWTEXTPARAMS));
drawTextParams.cbSize = sizeof(DRAWTEXTPARAMS);
//
int bufferSize = (int) caption.size() + 5; // DrawTextEx may add up to 4 additional characters
std::unique_ptr<uichar> buffer(new uichar[bufferSize]);
::wcsncpy_s(buffer.get(), bufferSize, caption.c_str(), caption.size());
//
RECT drawRect = rect;
//
::DrawTextEx(
hdc,
buffer.get(),
-1, // buffer is NULL terminated
&drawRect,
DT_END_ELLIPSIS | DT_VCENTER | DT_SINGLELINE | alignment,
&drawTextParams);
::SelectObject(hdc, oldObject);
}
///\brief
///Return the HFONT representation of the Font object. Do NOT call
///::DeleteObject() on the HFONT returned.
///
///\returns
///a HFONT representation of the Font.
HFONT Font::GetHFONT()
{
if (this->invalid)
{
this->InitializeFont(NULL);
this->invalid = false;
}
return this->font;
}
///\returns
///the Font's faceName.
uistring Font::FaceName() const
{
return this->faceName;
}
///\brief
///Sets the Font's facename.
///
///\param faceName
///the font's facename.
void Font::SetFaceName(const uistring& faceName)
{
INVALIDATE_FONT_ATTRIBUTE(faceName)
}
///\brief
///Returns the point size of the font.
unsigned Font::PointSize() const
{
return this->pointSize;
}
///\brief
///Sets the Font's point size.
void Font::SetPointSize(unsigned pointSize)
{
INVALIDATE_FONT_ATTRIBUTE(pointSize)
}
///\returns
///true if the Font is bold.
bool Font::Bold() const
{
return this->weight > 400;
}
///\brief
///Sets the Font's bold property.
void Font::SetBold(bool bold)
{
if ((bold) && (this->weight != FW_BOLD))
{
this->weight = FW_BOLD;
this->Invalidate();
}
else if (( ! bold) && (this->weight != FW_REGULAR))
{
this->weight = FW_REGULAR;
this->Invalidate();
}
}
///\returns
///Returns the Font's weight.
///
///See: http://msdn2.microsoft.com/en-us/library/ms534214.aspx
int Font::Weight() const
{
return this->weight;
}
///\brief
///Sets the Font's weight.
///
///See: http://msdn2.microsoft.com/en-us/library/ms534214.aspx
void Font::SetWeight(int weight)
{
if((weight > 1000) && (weight < 0))
{
throw InvalidFontWeightException();
}
if (weight != this->weight)
{
this->weight = weight;
this->Invalidate();
}
}
///\brief
///Returns the Font's italic property.
bool Font::Italic() const
{
return this->italic;
}
///\brief
///Sets the Font's weight.
///
///See: http://msdn2.microsoft.com/en-us/library/ms534214.aspx
void Font::SetItalic(bool italic)
{
INVALIDATE_FONT_ATTRIBUTE(italic)
}
///\brief
///Returns the Font's underline property
bool Font::Underline() const
{
return this->underline;
}
///\brief
///Sets the Font's underline property
void Font::SetUnderline(bool underline)
{
INVALIDATE_FONT_ATTRIBUTE(underline)
}
bool Font::InitializeFont(HDC hdc)
{
HFONT newFont = Font::CreateHFONT(*this, hdc);
if (newFont)
{
::DeleteObject(this->font);
this->font = newFont;
}
return (newFont != NULL);
}
bool Font::InitializeFont(const LOGFONT& logFont, HDC hdc)
{
bool releaseDC = ( ! hdc);
//
if ( ! hdc)
{
// if no HDC is supplied then use the desktop's
hdc = ::GetDC(NULL);
}
this->pointSize = -MulDiv(logFont.lfHeight, 72, ::GetDeviceCaps(hdc, LOGPIXELSY));
this->faceName.assign(logFont.lfFaceName);
this->weight = logFont.lfWeight;
this->italic = (logFont.lfItalic != 0);
this->underline = (logFont.lfUnderline != 0);
bool result = this->InitializeFont(hdc);
if (releaseDC)
{
::ReleaseDC(NULL, hdc);
}
return result;
}
///\brief
///Create a HFONT from a Font object. The caller is responsible for calling
///::DeleteObject() on the HFONT when finished with it.
///
///\param font
///the Font to use when creating the HFONT
///
///\param hdc
///the device context to use when creating the font. If this parameter is
///NULL the desktop DC will be used.
///
///\returns
///a new HFONT. Caller is responsible for calling ::DeleteObject()
HFONT Font::CreateHFONT(const Font& font, HDC hdc)
{
bool releaseDC = (hdc == NULL);
if (hdc == NULL)
{
hdc = ::GetDC(NULL);
}
NONCLIENTMETRICS nonClientMetrics;
nonClientMetrics.cbSize = sizeof(NONCLIENTMETRICS);
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nonClientMetrics, NULL);
uistring faceName = font.FaceName();
// if no face is specified use the system defaults.
if ( ! faceName.size())
{
faceName.assign(nonClientMetrics.lfMessageFont.lfFaceName);
}
// if the size is -1, use default system size
int height;
//
if (font.pointSize == -1)
{
height = nonClientMetrics.lfMessageFont.lfHeight;
}
else
{
height = -MulDiv(font.pointSize, ::GetDeviceCaps(hdc, LOGPIXELSY), 72); // from MSDN CreateFont()
}
HFONT newFont = ::CreateFont(
height,
0, // width. 0 = default
0, // angle of escapement vector
0, // orientation. angle between each character and hdc's x-axis
font.weight, // font weight
font.italic,
font.underline,
false, // strke through
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, // default precision
CLIP_DEFAULT_PRECIS, // default clip precision
CLEARTYPE_QUALITY, // quality
DEFAULT_PITCH, // pitch
faceName.c_str()); // face name
if (releaseDC)
{
::ReleaseDC(NULL, hdc);
}
return newFont;
}

View File

@ -0,0 +1,151 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Types.hpp>
#include <win32cpp/Exception.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// Font
//////////////////////////////////////////////////////////////////////////////
struct Font;
///
///\brief A shared pointer to a Font object
///
typedef std::shared_ptr<Font> FontRef;
///\brief
///TextAlignment specifies how text should be aligned when rendered.
///
///\see
///Font::DrawToHDC
enum TextAlignment
{
TextAlignLeft = DT_LEFT, /*!< */
TextAlignCenter = DT_CENTER, /*!< */
TextAlignRight = DT_RIGHT /*!< */
};
///\brief
///Font provides a light-weight wrapper around a Win32 HFONT object.
///
///Font exposes many useful utility functions for manipulating the underlying
///font attributes, including: face, size, weight, italic, and underline.
///
///\see
///FontRef
struct Font
{
public: // types
class InvalidFontWeightException: public Exception { };
private: // constructors
/*ctor*/ Font();
/*ctor*/ Font(const uistring& face, unsigned pointSize = -1,
bool bold = false, bool italic = false, bool underline = false);
/*ctor*/ Font(const LOGFONT& logFont, HDC hdc = NULL);
public: // creation methods
static FontRef Create()
{
return FontRef(new Font());
}
static FontRef Create(const uistring& face, int pointSize = -1,
bool bold = false, bool italic = false, bool underline = false)
{
return FontRef(new Font(face, pointSize, bold, italic, underline));
}
static FontRef Create(const LOGFONT& logFont, HDC hdc = NULL)
{
return FontRef(new Font(logFont, hdc));
}
public: // destructor
/*dtor*/ ~Font();
public: // methods
void DrawToHDC(HDC hdc, const Rect& rect, const uistring& caption, TextAlignment = TextAlignLeft);
uistring FaceName() const;
void SetFaceName(const uistring& faceName);
unsigned PointSize() const;
void SetPointSize(unsigned pointSize);
bool Bold() const;
void SetBold(bool bold = true);
int Weight() const;
void SetWeight(int weight);
bool Italic() const;
void SetItalic(bool italic = true);
bool Underline() const;
void SetUnderline(bool underline = true);
HFONT GetHFONT();
static HFONT CreateHFONT(const Font& font, HDC hdc);
protected: // methods
void Invalidate() { this->invalid = true; }
bool InitializeFont(HDC hdc);
bool InitializeFont(const LOGFONT& font, HDC hdc);
private: // instance data
uistring faceName;
unsigned pointSize;
bool italic, underline;
int weight;
bool invalid;
HFONT font;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,225 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Frame.hpp>
#include <win32cpp/Color.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
#define CLASS_NAME _T("Frame")
///\brief Constructor
///
///\remarks
///If child is not specified (NULL) it can be added later by using the
///Container::AddChild method.
///
///\param child
///The Window to be housed within the frame.
///
///\param padding
///The amount of padding, in pixels, for all edges.
/*ctor*/ Frame::Frame(Window* child, int padding)
: base()
, padding(padding, padding, padding, padding)
, child(child)
, isResizingHACK(false)
{
}
///\brief Constructor
///
///\remarks
///If child is not specified (NULL) it can be added later by using the
///Container::AddChild method.
///
///\param child
///The Window to be housed within the frame.
///
///\param padding
///The padding parameters to use.
/*ctor*/ Frame::Frame(Window* child, const WindowPadding& padding)
: base()
, padding(padding)
, child(child)
, isResizingHACK(false)
{
}
///\brief Set the Child's padding.
///
///\param padding
///The new padding parameters to use.
void Frame::SetPadding(const WindowPadding& padding)
{
this->padding = padding;
this->OnResized(this->WindowSize());
}
///\brief Set the Child's padding.
///
///\param padding
///The amount of padding, in pixels, for all edges.
void Frame::SetPadding(int padding)
{
this->SetPadding(WindowPadding(padding, padding, padding, padding));
}
void Frame::OnCreated()
{
if (this->child)
{
this->AddChild(child);
}
}
bool Frame::AddChildWindow(Window* window)
{
if (this->childWindows.size())
{
throw TooManyChildWindowsException();
}
return base::AddChildWindow(window);
}
Size Frame::ClientSize() const
{
Size clientSize = this->WindowSize();
clientSize.width -= (this->padding.left + this->padding.right);
clientSize.height -= (this->padding.top + this->padding.bottom);
return clientSize;
}
void Frame::OnChildAdded(Window* newChild)
{
this->child = newChild;
this->ResizeFromChild();
this->child->Resized.connect(this, &Frame::OnChildResized);
newChild->MoveTo(this->padding.left, this->padding.top);
}
void Frame::OnResized(const Size& newSize)
{
if (this->child && (! isResizingHACK))
{
this->child->Resize(this->ClientSize());
this->child->MoveTo(this->padding.left, this->padding.top);
}
}
void Frame::OnChildResized(Window* window, Size newSize)
{
// If we were resized then we had to change our child's size. Doing
// so will cause a Resize event to fire, resulting in and endless
// recursive loop. Don't field this event if WE did the resizing!
if ( ! this->isResizingHACK)
{
this->ResizeFromChild();
}
}
void Frame::ResizeFromChild()
{
Size size = this->child->WindowSize();
size.width += (this->padding.left + this->padding.right);
size.height += (this->padding.top + this->padding.bottom);
//
this->isResizingHACK = true;
this->Resize(size);
this->isResizingHACK = false;
this->child->MoveTo(this->padding.left, this->padding.top);
}
HWND Frame::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
if ( ! Frame::RegisterWindowClass())
{
return NULL;
}
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
CLASS_NAME, // Class name
_T(""), // Window name
style, // Style
0, // X
0, // Y
120, // Width
36, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
bool Frame::RegisterWindowClass()
{
static bool registered = false;
if ( ! registered)
{
WNDCLASSEX wc = { 0 };
// use STATIC window class as our base
::GetClassInfoEx(NULL, _T("STATIC"), &wc);
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpszClassName = CLASS_NAME;
registered = (::RegisterClassEx(&wc) != 0);
}
return registered;
}

View File

@ -0,0 +1,99 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Panel.hpp>
#include <win32cpp/WindowPadding.hpp>
#include <win32cpp/Application.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///Frame is a Container that adds a padding (border) to a single child Window.
///
///If the child is resized, Frame will automatically resize itself
///to accomidate the child and respect the the specified WindowPadding.
///If the Frame is resized, it will automatically resize the child window
///to fit its new ClientSize.
///
///Attempting to add more than 1 child Window to a Frame will result
///in a TooManyChildWindowsException.
///
///\see
///Container, Panel
class Frame: public Panel
{
private: //types
typedef Panel base;
public: // constructors
/*ctor*/ Frame(Window* child = NULL, int padding = 0);
/*ctor*/ Frame(Window* child, const WindowPadding& padding);
public: // methods
void SetPadding(const WindowPadding& padding);
void SetPadding(int padding);
virtual Size ClientSize() const;
protected: // methods
void ResizeFromChild();
void OnChildResized(Window* window, Size newSize);
virtual bool AddChildWindow(Window* window);
virtual void OnChildAdded(Window* newChild);
virtual void OnCreated();
virtual void OnResized(const Size& newSize);
virtual HWND Create(Window* parent);
static bool RegisterWindowClass();
private: // instance data
WindowPadding padding;
Window* child;
bool isResizingHACK;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,116 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/GroupBox.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Default constructor.
/*ctor*/ GroupBox::GroupBox(const uichar* caption)
: base()
, caption(caption)
{
}
HWND GroupBox::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
// create the window
// (use WS_CLIPSIBLINGS to avoid unnecessary repainting of controls inside)
DWORD style = WS_CHILD | WS_VISIBLE | BS_GROUPBOX | WS_CLIPSIBLINGS;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
_T("BUTTON"), // Class name
this->caption.c_str(), // Window name
style, // Style
0, // X
0, // Y
100, // Width
100, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
void GroupBox::OnChildAdded(Window* newChild)
{
SIZE idealSize;
idealSize.cx = 0;
idealSize.cy = 0;
// all child elements should be resized to their ideal size
if(newChild->SendMessageW(BCM_GETIDEALSIZE, 0, (LPARAM)(SIZE*)&idealSize)) {
newChild->Resize(idealSize.cx, idealSize.cy);
}
// all child elements should be WITHIN the groupbox frame,
// so we need to try to position them perfectly
RECT childRect = newChild->ClientRect();
newChild->MoveTo(
childRect.left + GetSystemMetrics(SM_CXDLGFRAME) + GetSystemMetrics(SM_CXBORDER),
childRect.top + GetSystemMetrics(SM_CYDLGFRAME) + GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYCAPTION)
);
}
void GroupBox::OnEraseBackground(HDC hdc)
{
HBRUSH bgbrush;
RECT bgrect;
// repaint background (since its white due to its parent controls)
bgbrush = ::CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
::SelectObject(hdc, bgbrush);
::GetClientRect(this->windowHandle, &bgrect);
::FillRect(hdc, &bgrect, bgbrush);
::DeleteObject(bgbrush);
}

View File

@ -0,0 +1,69 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Casey Langen, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Container.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class GroupBox: public Container
{
public: // types
typedef Container base;
public: // constructors
/*ctor*/ GroupBox(const uichar* caption = _T(""));
protected: // methods
virtual HWND Create(Window* parent);
virtual void OnEraseBackground(HDC hdc);
virtual void OnChildAdded(Window* newChild);
protected: // instance data
uistring caption;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,55 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class ILayout
{
public: // methods
virtual void Layout() = 0;
};
/////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,121 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Image.hpp>
#include <boost/filesystem.hpp>
#include <boost/gil/gil_all.hpp>
#include <boost/gil/extension/io/dynamic_io.hpp>
#include <boost/gil/extension/io/png_dynamic_io.hpp>
#include <utf8/utf8.h>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
///\brief
///Constructor.
///
///\param filename
///A filename of an image to load
/*ctor*/ Image::Image()
{
}
/*dtor*/ Image::~Image()
{
}
///\brief
///Creates a new Image
///
///\param filename
///Path to image to be loaded
///
///\returns
///The image at filename, NULL if the image couldn't be loaded.
ImageRef Image::Create(const uistring& filename)
{
ImageRef result = ImageRef(new Image());
try
{
// convert the UTF16 path to a UTF8 path
std::string utf8filename;
utf8::utf16to8(filename.begin(), filename.end(), std::back_inserter(utf8filename));
//
if (utf8filename.size())
{
// make sure the file exists
boost::filesystem::path path(utf8filename.c_str());
if (boost::filesystem::exists(path))
{
std::string extension = boost::filesystem::extension(path);
std::transform(extension.begin(), extension.end(), extension.begin(), tolower);
// figure out what type of image to read based on the extension
if (extension == ".png")
{
boost::gil::png_read_image(utf8filename.c_str(), result->image);
}
}
}
}
catch (std::ios_base::failure)
{
// TODO: log
return ImageRef();
}
return result;
}
///\brief
///Draws this bitmap to the specified device context.
///
///\param hdc
///The destination device context
///\param point
///Where to draw the image on the HDC
void Image::DrawToHDC(HDC hdc, const Point& point)
{
}

View File

@ -0,0 +1,102 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Types.hpp>
#include <win32cpp/Exception.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/gil/extension/dynamic_image/dynamic_image_all.hpp>
#include <boost/gil/gil_all.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
class Image;
///
///\brief A shared pointer to a Font object
///
typedef boost::shared_ptr<Image> ImageRef;
///\brief
///Image provides a light-weight wrapper around an image. It is backed
///by boost::gil.
///
///\see
///ImageRef
class Image
{
public: // types
class InvalidFontWeightException: public Exception { };
private: // types
typedef boost::mpl::vector<
boost::gil::gray8_image_t,
boost::gil::gray16_image_t,
boost::gil::rgb8_image_t,
boost::gil::rgb16_image_t> SupportedFormats;
typedef boost::gil::any_image<
SupportedFormats> ImageType;
private: // constructors
/*ctor*/ Image();
public: // creation methods
static ImageRef Create(const uistring& filename);
public: // destructor
/*dtor*/ ~Image();
public: // methods
void DrawToHDC(HDC hdc, const Point& point);
private: // instance data
ImageType image;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,128 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Casey Langen, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/ImageList.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
ImageList::ImageList(int width, int height, ImageList::ColorDepth depth) :
imageWidth(width),
imageHeight(height),
imageDepth(depth),
imagelistHandle(NULL)
{
::InitCommonControls();
this->imagelistHandle = ::ImageList_Create(imageWidth, imageHeight, depth, 1, 128);
if(!this->imagelistHandle) {
throw Exception("Cannot create image list!");
}
}
ImageList::~ImageList()
{
for(int i = 0; i < this->Count(); i++) {
IMAGEINFO info;
this->Info(i, &info);
DeleteObject(info.hbmImage);
if(info.hbmMask) DeleteObject(info.hbmMask);
this->Remove(i);
}
::ImageList_Destroy(this->imagelistHandle);
}
HIMAGELIST ImageList::Handle() const
{
return this->imagelistHandle;
}
int ImageList::Count() const
{
return ::ImageList_GetImageCount(this->imagelistHandle);
}
int ImageList::Add(HBITMAP image)
{
return ::ImageList_Add(this->imagelistHandle, image, NULL);
}
int ImageList::Add(const uistring& filename, bool transparence)
{
UINT fuLoad = LR_LOADFROMFILE;
if(transparence) {
fuLoad |= LR_LOADTRANSPARENT;
}
HANDLE image = ::LoadImage(
NULL,
filename.c_str(),
IMAGE_BITMAP,
this->imageWidth,
this->imageHeight,
fuLoad
);
if(image) {
return this->Add((HBITMAP)image);
}
return -1;
}
bool ImageList::Remove(int index)
{
return !!(::ImageList_Remove(this->imagelistHandle, index));
}
bool ImageList::Clear()
{
return !!(::ImageList_Remove(this->imagelistHandle, -1));
}
bool ImageList::Info(int index, IMAGEINFO *info)
{
return !!(::ImageList_GetImageInfo(this->imagelistHandle, index, info));
}

View File

@ -0,0 +1,89 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Types.hpp>
#include <win32cpp/Exception.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// ImageList
//////////////////////////////////////////////////////////////////////////////
class ImageList {
private:
HIMAGELIST imagelistHandle;
int imageWidth, imageHeight;
int imageDepth;
ImageList()
{
;
}
protected:
public:
enum ColorDepth {
Color4 = ILC_COLOR4,
Color8 = ILC_COLOR8,
Color16 = ILC_COLOR16,
Color32 = ILC_COLOR32
};
ImageList(int width, int height, ImageList::ColorDepth depth);
~ImageList();
HIMAGELIST Handle() const;
int Count() const;
int Add(HBITMAP image);
int Add(const uistring& filename, bool transparence = false);
bool Remove(int index);
bool Clear();
bool Info(int index, IMAGEINFO *info);
};
//////////////////////////////////////////////////////////////////////////////
}

View File

@ -0,0 +1,163 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Label.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief Constructor.
///\param caption The caption to draw.
/*ctor*/ Label::Label(const uichar* caption)
: base()
, caption(caption)
, autoResize(true)
{
}
HWND Label::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance().Instance();
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | SS_NOTIFY | SS_ENDELLIPSIS;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
_T("STATIC"), // Class name
this->caption.c_str(), // Window name
style, // Style
0, // X
0, // Y
120, // Width
36, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
if (hwnd)
{
this->tabStop = false;
this->windowHandle = hwnd;
this->ResizeFromCaption();
}
return hwnd;
}
LRESULT Label::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SETTEXT:
{
LRESULT result = base::WindowProc(message, wParam, lParam);
if (result)
{
this->ResizeFromCaption();
}
return result;
}
break;
}
return base::WindowProc(message, wParam, lParam);
}
void Label::OnFontChanged()
{
this->ResizeFromCaption();
}
void Label::OnCaptionChanged()
{
if (this->autoResize)
{
this->ResizeFromCaption();
}
}
///\brief Resizes the Label to the size of the caption.
///
///ResizeFromCaption will generate a Resized event.
void Label::ResizeFromCaption()
{
static uichar buffer[4096];
if (::GetWindowText(this->Handle(), buffer, 4096))
{
HFONT font = this->Font()->GetHFONT();
if (font)
{
HDC hdc = ::GetDC(this->Handle());
HGDIOBJ oldObj = ::SelectObject(hdc, font);
SIZE textExtent;
int length = (int) wcslen(buffer);
if (::GetTextExtentPoint32(hdc, buffer, length, &textExtent))
{
this->Resize(Size(textExtent));
}
::SelectObject(hdc, oldObj);
::ReleaseDC(this->Handle(), hdc);
}
}
}
///\brief If enabled the Label will automatically resize itself
///when the caption is changed.
void Label::EnableAutoResizeFromCaption(bool enable)
{
this->autoResize = enable;
if (this->autoResize)
{
this->ResizeFromCaption();
}
}
///\brief Returns whether or not the label will be automatically resized
///when the caption is changed.
bool Label::AutoResizeFromCaptionEnabled() const
{
return this->autoResize;
}

View File

@ -0,0 +1,78 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///A simple Window that draws only a caption.
class Label: public Window
{
private: // types
typedef Window base;
public: // constructors
/*ctor*/ Label(const uichar* caption = _T(""));
public: // methods
void ResizeFromCaption();
void EnableAutoResizeFromCaption(bool enable = true);
bool AutoResizeFromCaptionEnabled() const;
protected: // methods
virtual HWND Create(Window* parent);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void OnFontChanged();
virtual void OnCaptionChanged();
protected: // instance data
uistring caption;
bool autoResize;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,426 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/LinearLayout.hpp>
#include <win32cpp/RedrawLock.hpp>
#include <algorithm>
#include <limits>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
#define CLASS_NAME _T("LinearLayout")
///\brief
///Constructor.
///
///\param orientation
///The LinearLayout's orientation (LayoutHorizontal or LayoutVertical)
///
///\param layoutFlags
///The size flags to be used when positioning this control within a parent
/*ctor*/ LinearLayout::LinearLayout(LayoutOrientation orientation, LayoutFlags layoutFlags)
: base(layoutFlags)
, orientation(orientation)
, spacing(4)
, childIsResizing(false)
, isResizing(false)
{
}
///\brief
///Sets the amount spacing between children, in pixels.
///
///\param spacing
///The amount of spacing, in pixels.
void LinearLayout::SetSpacing(int spacing)
{
if (this->spacing == spacing)
{
return;
}
this->spacing = spacing;
this->Layout();
}
///\brief
///Returns the amount of spacing between children (in pixels)
int LinearLayout::Spacing() const
{
return this->spacing;
}
void LinearLayout::OnChildAdded(Window* newChild)
{
newChild->Resized.connect(this, &LinearLayout::OnChildResized);
newChild->LayoutParametersChanged.connect(this, &LinearLayout::OnChildLayoutParametersChanged);
this->childSizeMap[newChild] = newChild->WindowSize();
this->ResizeWrapContent();
this->Layout();
}
void LinearLayout::OnChildRemoved(Window* oldChild)
{
oldChild->Resized.disconnect(this);
oldChild->LayoutParametersChanged.disconnect(this);
oldChild->Resize(childSizeMap[oldChild]);
this->childSizeMap.erase(oldChild);
this->ResizeWrapContent();
this->Layout();
}
void LinearLayout::OnChildLayoutParametersChanged(Window* window)
{
this->ResizeWrapContent();
this->Layout();
}
void LinearLayout::OnChildResized(Window* window, Size newSize)
{
if ( ! this->childIsResizing)
{
this->childSizeMap[window] = newSize;
this->ResizeWrapContent();
this->Layout();
}
}
inline void LinearLayout::ThrowIfNotChild(Window* child)
{
WindowList::iterator it =
std::find(this->childWindows.begin(), this->childWindows.end(), child);
if (it == this->childWindows.end())
{
throw InvalidChildWindowException();
}
}
void LinearLayout::OnResized(const Size& newSize)
{
if ( ! this->isResizing)
{
this->Layout();
}
}
void LinearLayout::ResizeWrapContent()
{
bool wrapWidth = this->LayoutWidth() == LayoutWrapContent;
bool wrapHeight = this->LayoutHeight() == LayoutWrapContent;
if (( ! wrapWidth) && ( ! wrapHeight))
{
return;
}
bool isVertical = (this->orientation == VerticalLayout);
Size size = this->ClientSize();
int wrappedWidth = 0, wrappedHeight = 0;
WindowList::iterator it = this->childWindows.begin();
for ( ; it != this->childWindows.end(); it++)
{
Window* child = (*it);
Size size = child->WindowSize();
if (wrapWidth)
{
isVertical
? wrappedWidth = std::max(wrappedWidth, size.width)
: wrappedWidth += size.width;
}
if (wrapHeight)
{
isVertical
? wrappedHeight += size.height
: wrappedHeight = std::max(wrappedHeight, size.height);
}
}
int spacing = this->spacing * ((int) this->childWindows.size() - 1);
// adjust for spacing
if ((wrapWidth) && ( ! isVertical))
{
wrappedWidth += spacing;
}
//
if ((wrapHeight) && (isVertical))
{
wrappedHeight += spacing;
}
// keep current size in given orientation if not wrapping
if ( ! wrapWidth) wrappedWidth = size.width;
if ( ! wrapHeight) wrappedHeight = size.height;
this->isResizing = true;
this->Resize(wrappedWidth, wrappedHeight);
this->isResizing = false;
}
Point LinearLayout::AlignChildInRect(LayoutAlignFlag alignment, Size childSize, Rect alignmentRect)
{
bool isVertical = (this->orientation == VerticalLayout);
Point result = alignmentRect.location;
int childLayoutSize = isVertical
? childSize.width
: childSize.height;
int rectLayoutSize = isVertical
? alignmentRect.size.width
: alignmentRect.size.height;
int& location = isVertical
? result.x
: result.y;
switch (alignment)
{
case LayoutAlignCenter: // && LayoutAlignMiddle
location += (rectLayoutSize - childLayoutSize) / 2;
break;
case LayoutAlignRight: // && LayoutAlignBottom
location += (rectLayoutSize - childLayoutSize);
break;
case LayoutAlignLeft: // && LayoutAlignTop
default:
// don't need to do anything
break;
}
return result;
}
HWND LinearLayout::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
if ( ! LinearLayout::RegisterWindowClass())
{
return NULL;
}
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
CLASS_NAME, // Class name
_T(""), // Window name
style, // Style
0, // X
0, // Y
120, // Width
36, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
bool LinearLayout::RegisterWindowClass()
{
static bool registered = false;
if ( ! registered)
{
WNDCLASSEX wc = { 0 };
// use STATIC window class as our base
::GetClassInfoEx(NULL, _T("STATIC"), &wc);
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpszClassName = CLASS_NAME;
registered = (::RegisterClassEx(&wc) != 0);
}
return registered;
}
void LinearLayout::Layout()
{
if ( ! this->childWindows.size())
{
return;
}
RedrawLock stopRedraw(this);
bool isVertical = (this->orientation == VerticalLayout);
bool isHorizontal = ( ! isVertical);
WindowList wrappedChildren;
WindowList filledChildren;
ChildSizeMap finalSizes;
int wrappedSize = 0;
float totalWeight = 0.0f;
WindowList::iterator it, end;
Size layoutSize = this->ClientSize();
// PASS 1: figure out which windows are wrapped in direction of the
// orientation, and which are filled. Also, calculate the correct
// size of the child opposite to its orientation.
it = this->childWindows.begin();
end = this->childWindows.end();
for ( ; it != end; it++)
{
Window* child = (*it);
Size childSize = child->WindowSize();
// map the child to its fill type
if (((isVertical) && (child->LayoutHeight() == LayoutFillParent))
|| ((isHorizontal) && (child->LayoutWidth() == LayoutFillParent)))
{
filledChildren.push_back(child);
totalWeight += child->LayoutWeight();
}
else
{
wrappedChildren.push_back(child);
// figure out the space all of the wrapped children will occupy.
wrappedSize += (isVertical ? childSize.height : childSize.width);
}
// fill direction opposite the orientation
if ((isVertical) && (child->LayoutWidth() == LayoutFillParent))
{
childSize.width = layoutSize.width;
}
else if ((isHorizontal) && (child->LayoutHeight() == LayoutFillParent))
{
childSize.height = layoutSize.height;
}
//
finalSizes[child] = childSize;
}
//
wrappedSize += (this->spacing * ((int) this->childWindows.size() - 1));
// PASS 2: determine final child size for the filled children based on
// their specified LayoutWeight()'s.
if (filledChildren.size())
{
int remainingSize = (isVertical)
? layoutSize.height - wrappedSize
: layoutSize.width - wrappedSize;
//
int weightedSize = 0;
//
it = filledChildren.begin();
end = filledChildren.end();
for ( ; it != end; it++)
{
Window* child = (*it);
Size childSize = finalSizes[child];
float remainingRatio = (child->LayoutWeight() / totalWeight);
int newSize = (int) ((float) remainingSize * remainingRatio);
// using floating calculations may cause small rounding errors. give
// give the last filled child whatever space may be left over
weightedSize += newSize;
if ((it + 1) == end)
{
newSize += (remainingSize - weightedSize);
}
isVertical
? childSize.height = newSize
: childSize.width = newSize;
finalSizes[child] = childSize;
}
}
// PASS 3: layout everything out!
it = this->childWindows.begin();
end = this->childWindows.end();
int x = 0, y = 0;
for ( ; it != end; it++)
{
Window* child = (*it);
Size size = finalSizes[child];
Size alignSize(
(isVertical) ? layoutSize.width : size.width,
(isVertical) ? size.height : layoutSize.height);
Point location = this->AlignChildInRect(
child->LayoutAlignment(),
size,
Rect(Point(x, y), alignSize));
this->childIsResizing = true;
{
if (child->WindowSize() != size)
{
child->Resize(size);
}
if (child->Location() != location)
{
child->MoveTo(location);
}
}
this->childIsResizing = false;
isVertical
? y += (size.height + this->spacing)
: x += (size.width + this->spacing);
}
}

View File

@ -0,0 +1,124 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Panel.hpp>
#include <win32cpp/ILayout.hpp>
#include <win32cpp/Application.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief Specifies the orientation of a LinearLayout
enum LayoutOrientation
{
VerticalLayout, /*!< */
HorizontalLayout /*!< */
};
///\brief A Container that is used to stack controls horizontally or
///vertically.
///
///Children are added to and removed from a LinearLayout using
///Container::AddChild and Container::RemoveChild, respectively. The order
///in which the children are arranged is determined by the order in
///which they are added to the Container. First in, first out.
///
///The orientation (VerticalLayout or HorizontalLayout) is determined at
///construction time by specifying a win32cpp::LinearLayoutOrientation.
///
///If a child is resized, LinearLayout will adjust itself accordingly.
///
///\code
/// // create a new Horizontal LinearLayout with 4 buttons.
/// LinearLayout* layout = new LinearLayout(LinearColumnLayout);
/// layout->AddChild(new Button(_T("Prev")));
/// layout->AddChild(new Button(_T("Play")));
/// layout->AddChild(new Button(_T("Stop")));
/// layout->AddChild(new Button(_T("Next")));
///\endcode
///
///Children are positioned and sized according to their LayoutWidth(),
///LayoutHeight(), LayoutAlignment(), and LayoutWeight() properties.
///\endcode
class LinearLayout: public Panel, public ILayout
{
private: // types
typedef Panel base;
typedef std::map<Window*, Size> ChildSizeMap;
public: // constructors
/*ctor*/ LinearLayout(
LayoutOrientation orientation,
LayoutFlags layoutFlags = LayoutWrapWrap);
public: // methods
void SetSpacing(int spacing);
int Spacing() const;
public: // ILayout
virtual void Layout();
protected: // methods
static bool RegisterWindowClass();
virtual HWND Create(Window* parent);
virtual void OnResized(const Size& newSize);
void OnChildAdded(Window* newChild);
void OnChildLayoutParametersChanged(Window* newChild);
void OnChildRemoved(Window* oldChild);
void OnChildResized(Window* window, Size newSize);
void ThrowIfNotChild(Window* child);
void ResizeWrapContent();
Point AlignChildInRect(LayoutAlignFlag alignment, Size childSize, Rect alignmentRect);
private: // instance data
LayoutOrientation orientation;
int spacing;
ChildSizeMap childSizeMap;
bool childIsResizing, isResizing;
};
/////////////////////////////////////////////////////////////////////////////
} // win32cpp

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,596 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
#include <win32cpp/Win32Exception.hpp>
#include <win32cpp/Color.hpp>
#include <boost/format.hpp>
#include <vector>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// ListView
//////////////////////////////////////////////////////////////////////////////
///\brief
///ScrollBar is an enumeration that describles the orientation of a scrollbar.
enum ScrollBar
{
HorizontalScrollBar = SB_HORZ, /*!< */
VerticalScrollBar = SB_VERT, /*!< */
BothScrollBars = SB_BOTH /*!< */
};
///\brief
///Defines the a ListView's default row height.
///
///\see
///ListView::RowHeight, ListView::SetRowHeight
const int DefaultRowHeight = -1;
///\brief
///A ListView is used for displaying data in row/column format.
///
///The ListView class wraps a Win32 WC_LISTVIEW with LVS_OWNERDATA; all data is
///virtualized. In other words, data isn't stuffed into the view. Rather,
///the ListView asks a ListView::Model to supply it with data as needed.
///This makes displaying large amounts of data extremely efficient.
///
///ListView also supports custom drawing via CellRenderer and RowRenderer
///objects. The model can optionally supply custom renderers to easily
///change the appearance of the view.
///
///\see
///Window
class ListView: public Window
{
public: // types
/*! */ class InvalidColumnException: public Exception { };
/*! */ class InvalidSelectionTypeException: public Exception { };
class Column;
class RowRenderer;
/*abstract*/ class CellRenderer;
/*abstract*/ class Model;
template <typename T> class TextCellRenderer;
/*! */ typedef std::vector<int> RowIndexList;
///\brief A shared pointer to a ListView::Column
typedef std::shared_ptr<Column> ColumnRef;
///\brief A shared pointer to a ListView::CellRenderer
typedef std::shared_ptr<CellRenderer> CellRendererRef;
///\brief A shared pointer to a ListView::RowRenderer
typedef std::shared_ptr<RowRenderer> RowRendererRef;
///\brief A shared pointer to a ListView::Model
typedef std::shared_ptr<Model> ModelRef;
/*! */ typedef sigslot::signal2<ListView* /*sender*/, int /*row*/> HotRowChangedEvent;
/*! */ typedef sigslot::signal2<ListView* /*sender*/, int /*row*/> RowActivatedEvent;
/*! */ typedef sigslot::signal3<ListView* /*sender*/, int /*row*/, ColumnRef> HotCellChangedEvent;
/*! */ typedef sigslot::signal1<ListView* /*sender*/> SelectionChangedEvent;
/*! */ typedef sigslot::signal2<ListView*, ColumnRef> ColumnClickedEvent;
/*! */ typedef sigslot::signal2<ListView*, MenuRef> PrepareContextMenuEvent;
struct RenderParams
{
int rowIndex;
ColumnRef column;
Color backColor;
Color foreColor;
Rect rect;
HDC hdc;
};
private: // types
typedef Window base;
typedef std::map<ColumnRef, int> ColumnToIndexMap;
class NullModel;
public: // events
///\brief Emitted when the the mouse cursor has entered a new row
HotRowChangedEvent HotRowChanged;
///\brief Emitted when the the mousebutton doubleclicks on a row
RowActivatedEvent RowActivated;
///\brief Emitted when the the mouse cursor has entered a new cell
HotCellChangedEvent HotCellChanged;
///\brief Emitted when the selection has changed
SelectionChangedEvent SelectionChanged;
///\brief Emitted when a Column is clicked
ColumnClickedEvent ColumnClicked;
///\brief Emitted immediately prior to showing the Context menu. listeners
///can use this event ot add/remove/update menu items
PrepareContextMenuEvent PrepareContextMenu;
public: // constructors
/*ctor*/ ListView(LayoutFlags layoutFlags = LayoutWrapWrap);
public: // methods
void AddColumn(ColumnRef column);
void RemoveColumn(ColumnRef column);
int ColumnWidth(ColumnRef column) const;
bool SetColumnWidth(ColumnRef column, int width);
void EnableColumnResizing(bool enable);
bool ResizableColumnsEnabled() const;
void EnableStripedBackground(bool enable);
bool StripedBackgroundEnabled() const;
void EnableMultipleSelection(bool enable);
bool MultipleSelectionEnabled() const;
void SetScrollBarVisibility(ScrollBar scrollBar, bool isVisible);
void SetRowHeight(int height = DefaultRowHeight);
int RowHeight() const;
void SetModel(ModelRef model);
void SetColumnsVisible(bool visible);
bool ColumnsVisible() const;
void ScrollToRow(int rowIndex);
int RowAtPoint(const Point& location) const;
bool CellAtPoint(const Point& location, int& rowIndex, ColumnRef& column) const;
void RedrawRow(int rowIndex) const;
void RedrawCell(int rowIndex, ColumnRef column) const;
int HotRow() const;
ColumnRef HotColumn() const;
RowIndexList SelectedRows();
int SelectedRow();
void SelectRows(const std::vector<int>& indices);
void SelectRow(int index);
void DeselectRows(const std::vector<int>& indices);
void DeselectRow(int index);
void SetContextMenu(MenuRef contextMenu);
protected: // methods
virtual HWND Create(Window* parent);
virtual LRESULT PreWindowProc(UINT message, WPARAM wParam, LPARAM lParam, bool& discardMessage);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void DrawRow(DRAWITEMSTRUCT* drawInfo);
ColumnRef ColumnIndexToColumnRef(int index) const;
int ColumnRefToColumnIndex(ColumnRef column) const;
Rect CellRect(int rowIndex, int columnIndex) const;
Rect CellRect(int rowIndex, ColumnRef column) const;
Rect RowRect(int rowIndex) const;
void SetHotCell(int rowIndex, ColumnRef column);
void IndexSelectedRows();
virtual void OnSelectionChanged();
// Window overrides
virtual void OnEraseBackground(HDC hdc);
virtual void OnPaint();
virtual void OnRowCountChanged();
virtual void OnDataChanged(int rowIndex);
virtual void OnMeasureItem(MEASUREITEMSTRUCT* measureItemStruct);
virtual void OnMouseMoved(MouseEventFlags flags, const Point& location);
virtual void OnRowActivated(int rowIndex);
virtual LRESULT OnCustomDraw(NMLVCUSTOMDRAW* customDraw);
void OnMouseExit();
protected: // instance data
ColumnToIndexMap columnToIndexMap;
bool stripedBackground, multipleSelection;
bool horizScrollBarVisible, vertScrollBarVisible;
bool columnsResizable, columnsVisible;
ModelRef model;
HWND headerHandle;
mutable int rowHeight, originalRowHeight;
int hotRowIndex;
ColumnRef hotColumn;
RowIndexList selectedRows;
int selectedRowIndex;
bool selectedRowsDirty;
MenuRef contextMenu;
protected: // class data
static ModelRef sNullModel;
};
//////////////////////////////////////////////////////////////////////////////
// ListView::Column
//////////////////////////////////////////////////////////////////////////////
///\brief
///Represents a Column of data in a ListView.
///
///Columns are typically passed around in the form of a ColumnRef, a
///shared pointer to a Column. It is best to create them as follows:
///
///\code
///ColumnRef myColumn(new Column(_T("My Column")));
///\endcode
///
///\see
///ListView::ColumnRef
class ListView::Column
{
protected: // constructors
///\brief Constructor
///
///\param name Name of the column.
///\param defaultWidth The default width of the column, in pixels
///\param alignment The Column's text alignment
/*ctor*/ Column(const uichar* name, int defaultWidth = 100, TextAlignment alignment = TextAlignLeft)
: name(name)
, defaultWidth(defaultWidth)
, alignment(alignment)
{
}
public: // create methods
static ColumnRef Create(const uichar* name, int defaultWidth = 100, TextAlignment alignment = TextAlignLeft)
{
return ColumnRef(new Column(name, defaultWidth, alignment));
}
public: // methods
///\brief Returns the display name of the column
virtual const uichar* Name() { return this->name.c_str(); }
///\brief Returns default display width of the column
virtual int DefaultWidth() { return this->defaultWidth; }
///\brief Returns requested text alignment of the column
virtual TextAlignment Alignment() { return this->alignment; }
protected: // instance data
int defaultWidth;
uistring name;
TextAlignment alignment;
};
//////////////////////////////////////////////////////////////////////////////
// ListView::RowRenderer
//////////////////////////////////////////////////////////////////////////////
///\brief
///Used for rendering rows in the ListView.
///
///RowRenderers typically prepare the background for CellRenderers, e.g.
///by drawing alternating background color. CellRenderers are used to
///draw the contents of a specific (rowIndex, Column) pair.
///
///The default RowRenderer just fills the the background with
///renderParams.backColor.
///
///RowRenderers are usually passed by shared pointer (RowRendererRef), e.g.
///\code
///RowRendererRef rowRenderRef(new MyRowRenderer());
///\endcode
///
///\see
///ListView::CellRenderer
class ListView::RowRenderer
{
public: // methods
///\brief
///Render the background of listView to with the parameters of renderParams.
///
///\param listView
///The parent ListView.
///
///\param renderParams
///The suggested draw parameters.
virtual void Render(const ListView& listView, RenderParams& renderParams);
};
//////////////////////////////////////////////////////////////////////////////
// ListView::CellRenderer
//////////////////////////////////////////////////////////////////////////////
///\brief
///Used for rendering a (rowIndex, Column) pair.
///
///The default CellRenderer, TextCellRenderer, renders any class that
///supports the output stream operator <<
///
///CellRenderers are usually passed by shared pointer (CellRendererRef), e.g.
///\code
///CellRendererRef cellRenderer(new MyCellRenderer());
///\endcode
///
///\see
///ListView::RowRenderer
class ListView::CellRenderer
{
public: // methods
///\brief
///Render the cell with the parameters of renderParams.
///
///\param listView
///The parent ListView.
///
///\param renderParams
///The suggested draw parameters.
virtual void Render(const ListView& listView, RenderParams& renderParams) = 0;
};
//////////////////////////////////////////////////////////////////////////////
// ListView::TextCellRenderer
//////////////////////////////////////////////////////////////////////////////
///\brief
///The default CellRenderer.
///
///Renders any class that supports the output stream operator <<
///
///\see
///ListView::CellRenderer
template <typename T>
class ListView::TextCellRenderer : public ListView::CellRenderer
{
public: // constructors
///\brief
///Constructor.
///
///\param value The value to render
///\param alignment The alignment to use
/*ctor*/ TextCellRenderer(const T& value, TextAlignment alignment = TextAlignLeft);
public: // methods
void Render(const ListView& listView, RenderParams& renderParams);
protected: // instance data
uistring textValue;
TextAlignment alignment;
};
template <typename T>
/*ctor*/ ListView::TextCellRenderer<T>::TextCellRenderer(const T& value, TextAlignment alignment)
: alignment(alignment)
{
typedef boost::basic_format<uichar> format;
this->textValue = (format(_T("%1%")) % value).str();
}
template <typename T>
void ListView::TextCellRenderer<T>::Render(const ListView& listView, RenderParams& renderParams)
{
::SetTextColor(renderParams.hdc, renderParams.foreColor);
::SetBkMode(renderParams.hdc, TRANSPARENT);
DRAWTEXTPARAMS drawTextParams;
::SecureZeroMemory(&drawTextParams, sizeof(DRAWTEXTPARAMS));
drawTextParams.cbSize = sizeof(DRAWTEXTPARAMS);
drawTextParams.iLeftMargin = 6;
//
int bufferSize = (int) this->textValue.size() + 4; // DrawTextEx may add up to 4 additional characters
std::unique_ptr<uichar> buffer(new uichar[bufferSize]);
::wcsncpy_s(buffer.get(), bufferSize, this->textValue.c_str(), this->textValue.size());
//
RECT drawRect = renderParams.rect;
//
::DrawTextEx(
renderParams.hdc,
buffer.get(),
-1, // buffer is NULL terminated
&drawRect,
this->alignment | DT_END_ELLIPSIS | DT_VCENTER | DT_SINGLELINE,
&drawTextParams);
}
//////////////////////////////////////////////////////////////////////////////
// ListView::Model
//////////////////////////////////////////////////////////////////////////////
///\brief
///Supplies one or more ListView instances with data to display.
///
///The user must subclass Model and override Model::CellValueToString
///to get data into the ListView.
///
///\code
///class MyModel: public ListView::Model
///{
///public:
/// virtual uistring CellValueToString(int rowIndex, ColumnRef column)
/// {
/// // a real implementation would do something more useful!
/// return _T("value at rowIndex, column");
/// }
///};
///
///class MyController
///{
///private:
/// //...
/// void OnViewCreated();
/// ListView::ModelRef model;
/// ListView& listView;
///};
///
///void MyController::OnViewCreated()
///{
/// //...
/// // Create an instance of MyModel and give it to the view.
/// this->model.reset(new MyModel());
/// this->listView.SetModel(this->model);
///
/// // SetRowCount will emit a RowCountChanged event, which the
/// // ListView listens for. Once the row count is set, the ListView
/// // will call Model::CellValueToString to display the data.
/// this->model->SetRowCount(60);
/// //...
///};
///\endcode
///
///
///Model instances are usually passed by shared pointer, so it's best to
///create and use them as follows:
///
///\code
///ModelRef myModel(new MyModel());
///\endcode
///
///A single ListView::ModelRef can be shared amongst multiple ListView instances.
///
///A Model can also be used to (optionally) provide the ListView
///with custom RowRenderer and CellRenderer instances to drastically
///change the appearance of the view.
///
///\see
///ListView, ListView::RowRenderer, ListView::CellRenderer
/*abstract*/ class ListView::Model
{
public: // types
/*! */ typedef sigslot::signal0<> RowCountChangedEvent;
/*! */ typedef sigslot::signal1<int> DataChangedEvent;
public: // events
/*!\brief Emitted when the number of rows has changed. */
RowCountChangedEvent RowCountChanged;
/*!\brief Emitted when data in the model has been updated. */
DataChangedEvent DataChanged;
public: // constructors
///\brief Constructor
///\param rowCount The number of rows to initialize the Model with.
/*ctor*/ Model(int rowCount = 0)
: rowCount(rowCount)
{
}
public: // methods
///\brief Returns the number of rows in the Model.
int RowCount()
{
return this->rowCount;
}
///\brief Returns a CellRenderer for the specified (rowIndex, Column)
///
///If no CellRenderer is returned the ListView will use a TextCellRenderer
///with the value obtained by Model::CellValueToString
///
///\param rowIndex
///The row index of interest.
///
///\param column
///The Column of the row.
///
///\returns
///A CellRenderer for the specified (rowIndex, Column)
///
///\see
///Model::RowRenderer, Model::CellValueToString.
virtual CellRendererRef CellRenderer(int rowIndex, ColumnRef column)
{
return CellRendererRef();
}
///\brief Returns a RowRenderer for the specified row index
///
///If no RowRenderer is returned the ListView will fill the row with
///the default background color.
///
///\param rowIndex
///The row index of interest.
///
///\returns
///A RowRenderer for the specified row index
///
///\see
///Model::CellRenderer, Model::CellValueToString.
virtual RowRendererRef RowRenderer(int rowIndex)
{
return RowRendererRef(new ListView::RowRenderer());
}
///\brief Returns a string representation of the value at (rowIndex, Column)
///
///This is the only pure virtual method of the class, and must be overriden.
///
///\param rowIndex
///The rowIndex.
///
///\param column
///The Column.
///
///\returns
///A string representation of the value at (rowIndex, Column)
virtual uistring CellValueToString(int rowIndex, ColumnRef column) = 0;
protected: // methods
///\brief Sets the number of rows in the Model.
///
///This method will cause RowCountChanged to be emitted.
///
///\param rowCount The new number of rows.
void SetRowCount(int rowCount)
{
if (rowCount != this->rowCount)
{
this->rowCount = rowCount;
this->RowCountChanged();
}
}
void InvalidateData(int forRow = -1)
{
this->DataChanged(forRow);
}
private: // instance data
int rowCount;
};
//////////////////////////////////////////////////////////////////////////////
// ListView::NullModel
//////////////////////////////////////////////////////////////////////////////
class ListView::NullModel : public ListView::Model
{
public: // methods
virtual int RowCount()
{
return 0;
}
virtual uistring
CellValueToString(int rowIndex, ListView::ColumnRef column)
{
return uistring();
}
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,217 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Locale.hpp>
#include <win32cpp/Win32Exception.hpp>
#include <win32cpp/Utility.hpp>
#include <boost/filesystem/operations.hpp>
#include <iostream>
namespace fs = boost::filesystem;
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
Locale::Locale()
{
// set default language identifier
// 0x0409 = English (United States) / en-US / Codepage 1252
this->localeID = 0x0409;
}
Locale::Locale(const uistring& dirName, const uistring& locale)
{
Locale();
this->SetLocaleDirectory(dirName);
if(!this->LoadConfig(locale))
{
throw Exception("Cannot load locale config!");
}
}
Locale::~Locale()
{
;
}
uistring Locale::Translate(const uistring& original)
{
if(this->translationMap.find(original) != this->translationMap.end())
{
return this->translationMap[original];
}
return original;
}
uistring Locale::Translate(const uichar* original)
{
uistring str(original);
if (this->translationMap.find(str) != this->translationMap.end())
{
return this->translationMap[str];
}
return original;
}
bool Locale::LoadConfig(const uistring& localeName)
{
uistring path = this->localeDirectory + _T("\\" + localeName + L".ini");
if(!fs::exists(path))
{
return false;
}
this->config.SetFileName(path);
// read locale configuration
this->config.SetSection(_T("config"));
// read name (for combo box displaying the languages)
this->localeName = this->config.Value(_T("name"));
if(this->localeName.empty())
{
return false;
}
// read locale identifier, necessary for e.g. DateTime
// (http://msdn.microsoft.com/en-us/library/ms776260(VS.85).aspx)
// example: 0x0407 for german
uistring temp = this->config.Value(_T("locale_identifier"));
int id = HexToInt(temp.c_str());
if(id != 0)
{
this->localeID = static_cast<WORD>(id);
}
// read format strings for date/time formatting
this->dateFormat = this->config.Value(_T("locale_date"));
this->timeFormat = this->config.Value(_T("locale_time"));
// generate translation map
for(int i = 1; ; i++)
{
// convert int to tchar
TCHAR section[8];
_stprintf_s(section, _T("%d"), i);
if(this->config.SectionExists(uistring(section)))
{
this->config.SetSection(section);
// put translation into map
uistring
original = config.Value(_T("original")),
translated = config.Value(_T("translated"));
this->translationMap[original] = translated;
}
else
{
// break if next section has not been found
break;
}
}
return true;
}
void Locale::SetLocaleDirectory(const uistring &dirName)
{
TCHAR localeDir[MAX_PATH];
// get absolute path
if(!::GetFullPathName(dirName.c_str(), MAX_PATH, localeDir, NULL))
{
throw Win32Exception();
}
// check if path exists
if(!fs::exists(localeDir))
{
throw Exception("Cannot find directory with locales!");
}
this->localeDirectory = uistring(localeDir);
}
LocaleList Locale::EnumLocales(void)
{
uistring path = this->localeDirectory;
// check if path is valid
if(!fs::exists(path) && fs::is_directory(path))
{
throw new Exception("Could not enumerate. Directory with locales is invalid.");
}
// iterate through locale directory and collect available locales
LocaleList localeList;
// convert directory to boost path
fs::wpath localePath(path, fs::native);
// now iterate...
fs::directory_iterator iEnd;
for(fs::directory_iterator iDir(localePath); iDir != iEnd; ++iDir)
{
uistring dirEntry = iDir->path().leaf().c_str();
// read name of config
Config entryConfig(path + _T("\\") + dirEntry);
if(entryConfig.SectionExists(_T("config")))
{
entryConfig.SetSection(_T("config"));
localeList[dirEntry] = entryConfig.Value(_T("name"));
}
}
return localeList;
}
BOOL Locale::SystemSupport() const
{
return ::IsValidLocale(this->localeID, LCID_INSTALLED);
}

View File

@ -0,0 +1,108 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Config.hpp>
#include <map>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// Locale
//////////////////////////////////////////////////////////////////////////////
typedef std::map<uistring, uistring> LocaleList;
typedef std::map<uistring, uistring> LocaleTranslationMap;
class Locale {
private:
Config config;
uistring localeDirectory;
uistring localeName;
WORD localeID;
uistring dateFormat;
uistring timeFormat;
LocaleTranslationMap
translationMap;
public:
bool LoadConfig(const uistring& localeName);
void SetLocaleDirectory(const uistring& dirName);
LocaleList EnumLocales(void);
uistring Translate(const uistring& original);
uistring Translate(const uichar* original);
uistring LocaleName(void) const { return this->localeName; }
WORD LangID(void) const { return this->localeID; }
uistring DateFormat(void) const { return this->dateFormat; }
uistring TimeFormat(void) const { return this->timeFormat; }
BOOL SystemSupport(void) const;
static Locale* Instance()
{
// singleton implementation (scott meyers variant)
// due to the static initialization the compiler is creating code
// with an atexit()-registration of a function which is responsible
// for a guaranteed destruction of the singleton object when
// the program exists (resource leaks can be avoided by this method)
static Locale singletonInstance;
// we return the pointer so we can pass the Locale instance
// around without the need to forbid instance-based
// (copy-)construction
return &singletonInstance;
}
/*ctor*/ Locale();
/*ctor*/ Locale(const uistring& dirName, const uistring& locale);
/*dtor*/ ~Locale();
};
#define _(ORIGINALTEXT) (win32cpp::Locale::Instance()->Translate(ORIGINALTEXT).c_str())
#define _TT(ORIGINALTEXT) (win32cpp::Locale::Instance()->Translate(_T(ORIGINALTEXT)))
#define _TTP(ORIGINALTEXT) (win32cpp::Locale::Instance()->Translate(_T(ORIGINALTEXT)).c_str())
//////////////////////////////////////////////////////////////////////////////
}

View File

@ -0,0 +1,104 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/MemoryDC.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
// MemoryDC
//////////////////////////////////////////////////////////////////////////////
///\brief
///Constructor.
///
///\param hdc
///The destination HDC. The final contents of the memory buffer will
///be copied here upon destruction.
///
///\param rect
///The Rectangle that represents the drawable area of the HDC.
/*ctor*/ MemoryDC::MemoryDC(HDC hdc, const RECT& rect)
: rectIsValid(false)
, screenDC(hdc)
, memoryBitmap(NULL)
, memoryDC(NULL)
, clientRect(rect)
{
int width = rect.right - rect.left;
int height = rect.bottom - rect.top;
this->memoryDC = ::CreateCompatibleDC(this->screenDC);
//
this->memoryBitmap = ::CreateCompatibleBitmap(this->screenDC, width, height);
this->oldObject = ::SelectObject(this->memoryDC, this->memoryBitmap);
this->rectIsValid = ((width > 0) && (height > 0));
}
/*dtor*/ MemoryDC::~MemoryDC()
{
if (this->rectIsValid)
{
::BitBlt(
this->screenDC,
this->clientRect.left,
this->clientRect.top,
this->clientRect.right - this->clientRect.left,
this->clientRect.bottom - this->clientRect.top,
this->memoryDC,
0,
0,
SRCCOPY);
}
::SelectObject(this->memoryDC, this->oldObject);
::DeleteObject(this->memoryBitmap);
::DeleteObject(this->memoryDC);
}
///\brief
///Returns a handle to the offscreen device context.
MemoryDC::operator HDC()
{
return this->memoryDC;
}

View File

@ -0,0 +1,102 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///A memory device context. MemoryDC is used internally by various classes,
///including Window, for flicker free drawing.
///
///When performing graphics operations on a Window's DC, changes are drawn
///directly to screen; this leads to flickering. MemoryDC creates an offscreen
///buffer that "accumulates" changes, which are copied to a desination DC
///when all drawing has finished.
///
///MemoryDC is constructed with an HDC and a Rect as parameters, and provides
///an implicit HDC cast operator that returns a handle to the offscreen buffer.
///This means that regular Win32 drawing routines, such as DrawLine, FillRect,
///etc, can transparently use a MemoryDC as if it were a regular HDC.
///
///When a MemoryDC's destructor is called the contents of the offscren buffer
///are automatically copied to to the HDC it was constructed with, resulting
///in flicker-free drawing.
///
///\code
///PAINTSTRUCT paintStruct;
///HDC hdc = ::BeginPaint(this->Handle(), &paintStruct);
///{
/// MemoryDC memDC(hdc, paintStruct.rcPaint);
///
/// //...
/// //draw to memDC as if you were drawing to hdc
/// //...
///
///} // when the MemoryDC destructor is called, the contents will be copied to hdc
///::EndPaint(this->Handle(), &paintStruct);
///\endcode
///
///\see
///RedrawLock
class MemoryDC
{
public: // constructors, destructor
/*ctor*/ MemoryDC(HDC hdc, const RECT& rect);
/*dtor*/ ~MemoryDC();
public: // operators
operator HDC();
private: // instance data
HBITMAP memoryBitmap;
HDC memoryDC, screenDC;
HANDLE oldObject;
RECT clientRect;
bool rectIsValid;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,398 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Menu.hpp>
#include <win32cpp/Win32Exception.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
// Menu
//////////////////////////////////////////////////////////////////////////////
Menu::IDToMenuItemMap Menu::sIDToMenuItemRef;
/*ctor*/ Menu::Menu()
: menuHandle(NULL)
{
}
/*dtor*/ Menu::~Menu()
{
::DestroyMenu(this->menuHandle);
}
MenuRef Menu::Create()
{
MenuRef menu(new Menu());
menu->Initialize(::CreateMenu());
return menu;
}
MenuRef Menu::CreatePopup()
{
MenuRef menu(new Menu());
menu->Initialize(::CreatePopupMenu());
return menu;
}
void Menu::Initialize(HMENU menuHandle)
{
this->items.reset(new MenuItemCollection(*this));
this->menuHandle = menuHandle;
if ( ! this->menuHandle)
{
throw Win32Exception();
}
this->items->ItemAdded.connect(this, &Menu::OnItemAdded);
this->items->ItemRemoved.connect(this, &Menu::OnItemRemoved);
}
void Menu::OnItemAdded(MenuItemRef newMenuItem, unsigned index)
{
newMenuItem->Changed.connect(this, &Menu::OnItemChanged);
// used by MenuItemActivated()
Menu::sIDToMenuItemRef[newMenuItem->id] = newMenuItem;
if (this->menuHandle)
{
MENUITEMINFO menuItem;
newMenuItem->FillMenuItemInfo(menuItem);
if ( ! ::InsertMenuItem(this->menuHandle, index, TRUE, &menuItem))
{
throw Win32Exception();
}
}
}
void Menu::OnItemRemoved(MenuItemRef oldMenuItem)
{
// used by MenuItemActivated()
Menu::sIDToMenuItemRef.erase(oldMenuItem->id);
if (this->menuHandle)
{
if ( ! ::RemoveMenu(this->menuHandle, oldMenuItem->id, MF_BYCOMMAND))
{
throw Win32Exception();
}
}
oldMenuItem->Changed.disconnect(this);
}
void Menu::OnItemChanged(MenuItemRef menuItem)
{
if (this->menuHandle)
{
MENUITEMINFO menuItemInfo;
menuItem->FillMenuItemInfo(menuItemInfo);
if ( ! ::SetMenuItemInfo(
this->menuHandle,
menuItem->id,
FALSE,
&menuItemInfo))
{
throw Win32Exception();
}
}
}
void Menu::ItemActivated(UINT menuItemID)
{
IDToMenuItemMap::iterator it = Menu::sIDToMenuItemRef.find(menuItemID);
if (it != Menu::sIDToMenuItemRef.end())
{
it->second->Activated(it->second);
}
}
//////////////////////////////////////////////////////////////////////////////
// MenuItem
//////////////////////////////////////////////////////////////////////////////
/*ctor*/ MenuItem::MenuItem(const uistring& caption, MenuRef subMenu)
: caption(caption)
, subMenu(subMenu)
, checked(false)
, id(MenuItem::NextID())
{
}
MenuItemRef MenuItem::Create(const uistring& caption, MenuRef subMenu)
{
MenuItemRef result = MenuItemRef(new MenuItem(caption, subMenu));
result->weakThis = std::weak_ptr<MenuItem>(result);
return result;
}
void MenuItem::SetCaption(const uistring& caption)
{
if (this->caption != caption)
{
this->caption = caption;
this->OnChanged();
}
}
void MenuItem::SetChecked(bool checked)
{
if (this->checked != checked)
{
this->checked = checked;
this->OnChanged();
}
}
uistring MenuItem::Caption() const
{
return this->caption;
}
void MenuItem::SetSubMenu(MenuRef subMenu)
{
if (this->subMenu != subMenu)
{
this->subMenu = subMenu;
this->OnChanged();
}
}
MenuRef MenuItem::SubMenu() const
{
return this->subMenu;
}
UINT MenuItem::NextID()
{
static UINT sNextID = 0;
return sNextID++;
}
void MenuItem::FillMenuItemInfo(MENUITEMINFO& target)
{
static uichar caption[4096];
const size_t captionSize = std::min(4096, (int) this->caption.size() + 1);
::wcsncpy_s(caption, captionSize, this->caption.c_str(), captionSize);
caption[captionSize - 1] = 0;
::SecureZeroMemory(&target, sizeof(MENUITEMINFO));
target.cbSize = sizeof(MENUITEMINFO);
target.wID = this->id;
target.cch = (UINT) (this->caption.size() + 1);
target.dwTypeData = caption;
target.hSubMenu = (this->subMenu ? this->subMenu->Handle() : NULL);
target.fMask = MIIM_STRING | MIIM_ID | MIIM_SUBMENU | MIIM_STATE;
target.fState = (this->checked ? MFS_CHECKED : MFS_UNCHECKED);
}
void MenuItem::OnChanged()
{
this->Changed(MenuItemRef(this->weakThis));
}
//////////////////////////////////////////////////////////////////////////////
// SeparatorMenuItem
//////////////////////////////////////////////////////////////////////////////
MenuItemRef SeparatorMenuItem::Create()
{
typedef std::shared_ptr<SeparatorMenuItem> SeparatorMenuItemRef;
SeparatorMenuItemRef result = SeparatorMenuItemRef(new SeparatorMenuItem());
result->weakThis = std::weak_ptr<MenuItem>(result);
return result;
}
/*ctor*/ SeparatorMenuItem::SeparatorMenuItem()
: base(_T(""))
{
}
void SeparatorMenuItem::FillMenuItemInfo(MENUITEMINFO& target)
{
::SecureZeroMemory(&target, sizeof(MENUITEMINFO));
target.cbSize = sizeof(MENUITEMINFO);
target.wID = this->id;
target.fMask = MIIM_TYPE;
target.fType = MFT_SEPARATOR;
}
//////////////////////////////////////////////////////////////////////////////
// MenuItemCollection
//////////////////////////////////////////////////////////////////////////////
#if defined(_DEBUG)
#define THROW_IF_MENUITEM_ALREADY_EXISTS(list, menuItem) \
if (std::find(list.begin(), list.end(), menuItem) != list.end()) \
{ \
throw MenuItemAlreadyExistsException(); \
}
#endif
/*ctor*/ MenuItemCollection::MenuItemCollection(Menu& owner)
: owner(owner)
{
}
MenuItemRef MenuItemCollection::Append(MenuItemRef newMenuItem)
{
#if defined(_DEBUG)
THROW_IF_MENUITEM_ALREADY_EXISTS(this->menuItemList, newMenuItem);
#endif
this->menuItemList.push_back(newMenuItem);
unsigned index = (unsigned) (this->menuItemList.size() - 1);
this->OnItemAdded(newMenuItem, index);
return newMenuItem;
}
MenuItemRef MenuItemCollection::FindByCaption(const uistring& name, unsigned offset /* = 0 */)
{
if (offset > this->menuItemList.size())
{
throw IndexOutOfRangeException();
}
for (unsigned i = offset; i < this->menuItemList.size(); i++)
{
MenuItemRef current = this->menuItemList[i];
if (current->Caption() == name)
{
return current;
}
}
return MenuItemRef();
}
MenuItemRef MenuItemCollection::InsertWithOffset(MenuItemRef newMenuItem, MenuItemRef insertPoint, unsigned offset)
{
for (size_t i = 0; i < this->menuItemList.size(); i++)
{
if (insertPoint == this->menuItemList[i])
{
MenuItemList::iterator it = this->menuItemList.begin() + i + offset;
this->menuItemList.insert(it, newMenuItem);
this->OnItemAdded(newMenuItem, (unsigned) (i + offset));
return newMenuItem;
}
}
throw InvalidMenuItemException();
}
MenuItemRef MenuItemCollection::InsertAfter(MenuItemRef newMenuItem, MenuItemRef after)
{
#if defined(_DEBUG)
THROW_IF_MENUITEM_ALREADY_EXISTS(this->menuItemList, newMenuItem);
#endif
return this->InsertWithOffset(newMenuItem, after, 1);
}
MenuItemRef MenuItemCollection::InsertBefore(MenuItemRef newMenuItem, MenuItemRef before)
{
#if defined(_DEBUG)
THROW_IF_MENUITEM_ALREADY_EXISTS(this->menuItemList, newMenuItem);
#endif
return this->InsertWithOffset(newMenuItem, before, 0);
}
void MenuItemCollection::OnItemAdded(MenuItemRef newMenuItem, unsigned index)
{
this->ItemAdded(newMenuItem, index);
}
void MenuItemCollection::OnItemRemoved(MenuItemRef oldMenuItem)
{
this->ItemRemoved(oldMenuItem);
}
void MenuItemCollection::Remove(MenuItemRef toRemove)
{
MenuItemList::iterator it =
std::find(this->menuItemList.begin(), this->menuItemList.end(), toRemove);
if (it == this->menuItemList.end())
{
throw InvalidMenuItemException();
}
this->menuItemList.erase(it);
this->OnItemRemoved(toRemove);
}
unsigned MenuItemCollection::Count()
{
return (unsigned) this->menuItemList.size();
}
MenuItemRef MenuItemCollection::ItemAt(unsigned index)
{
if (index >= this->menuItemList.size())
{
throw IndexOutOfRangeException();
}
return this->menuItemList.at(index);
}
MenuItemRef MenuItemCollection::operator[](unsigned index)
{
return this->ItemAt(index);
}

View File

@ -0,0 +1,214 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Exception.hpp>
#include <win32cpp/Types.hpp>
#include <vector>
#include <map>
#include <boost/utility.hpp> // noncopyable
#include <sigslot/sigslot.h>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// Menu related types
//////////////////////////////////////////////////////////////////////////////
class Menu;
typedef std::shared_ptr<Menu> MenuRef;
class MenuItem;
typedef std::shared_ptr<MenuItem> MenuItemRef;
typedef sigslot::signal1<MenuItemRef> MenuItemActivatedEvent;
typedef sigslot::signal2<MenuItemRef /*new*/, unsigned /*index*/> MenuItemAddedEvent;
typedef sigslot::signal1<MenuItemRef> MenuItemRemovedEvent;
class InvalidMenuItemException: public Exception { };
class MenuItemAlreadyExistsException: public Exception { };
class NullMenuItemException: public Exception { };
class IndexOutOfRangeException: public Exception { };
//////////////////////////////////////////////////////////////////////////////
// MenuItem
//////////////////////////////////////////////////////////////////////////////
// unimplemented
class MenuItem: public boost::noncopyable
{
friend class Menu; // uses Changed and FillMenuItemInfo:
protected: // constructors
/*ctor*/ MenuItem(const uistring& caption, MenuRef subMenu = MenuRef());
public: // events
MenuItemActivatedEvent Activated;
protected: // events
sigslot::signal1<MenuItemRef> Changed;
public: // methods
static MenuItemRef Create(const uistring& caption, MenuRef subMenu = MenuRef());
void SetCaption(const uistring& caption);
uistring Caption() const;
void SetSubMenu(MenuRef subMenu);
MenuRef SubMenu() const;
bool Checked() const { return this->checked; }
void SetChecked(bool checked);
protected: // methods
virtual void FillMenuItemInfo(MENUITEMINFO& target);
virtual void OnChanged();
UINT static NextID();
protected: // instance data
UINT id;
std::weak_ptr<MenuItem> weakThis;
private: // instance data
MenuRef subMenu;
uistring caption;
bool checked;
};
//////////////////////////////////////////////////////////////////////////////
// SeparatorMenuItem
//////////////////////////////////////////////////////////////////////////////
class SeparatorMenuItem: public MenuItem
{
private: //types
typedef MenuItem base;
private: // constructors
/*ctor*/ SeparatorMenuItem();
public: // methods
static MenuItemRef Create();
protected: // methods
virtual void FillMenuItemInfo(MENUITEMINFO& target);
};
//////////////////////////////////////////////////////////////////////////////
// MenuItemCollection
//////////////////////////////////////////////////////////////////////////////
// implemented, untested
class MenuItemCollection: public boost::noncopyable
{
friend class Menu;
public: // events
MenuItemAddedEvent ItemAdded;
MenuItemRemovedEvent ItemRemoved;
private: // types
typedef std::vector<MenuItemRef> MenuItemList;
private: // constructors
/*ctor*/ MenuItemCollection(Menu& owner);
public: // methods
MenuItemRef Append(MenuItemRef newMenuItem);
MenuItemRef InsertAfter(MenuItemRef newMenuItem, MenuItemRef after);
MenuItemRef InsertBefore(MenuItemRef newMenuItem, MenuItemRef before);
void Remove(MenuItemRef toRemove);
unsigned Count();
MenuItemRef ItemAt(unsigned index);
MenuItemRef FindByCaption(const uistring& name, unsigned offset = 0);
MenuItemRef operator[](unsigned index);
protected: // methods
virtual void OnItemAdded(MenuItemRef newMenuItem, unsigned index);
virtual void OnItemRemoved(MenuItemRef oldMenuItem);
MenuItemRef InsertWithOffset(MenuItemRef newMenuItem, MenuItemRef insertPoint, unsigned offset);
private: // instance data
MenuItemList menuItemList;
Menu& owner;
};
//////////////////////////////////////////////////////////////////////////////
// Menu
//////////////////////////////////////////////////////////////////////////////
// Only menu related class that holds any WIN32 handle or state.
class Menu: public boost::noncopyable, public EventHandler
{
friend class Window;
private: // types
typedef std::map<UINT, MenuItemRef> IDToMenuItemMap;
public: // constructors, destructors
/*dtor*/ ~Menu();
private: // constructors
/*ctor*/ Menu();
public: // methods
static MenuRef Create();
static MenuRef CreatePopup();
MenuItemCollection& Items() { return (*this->items); }
HMENU Handle() { return this->menuHandle; }
static void ItemActivated(UINT menuID); // used by Window
protected: // methods
void Initialize(HMENU menu);
void OnItemAdded(MenuItemRef newMenuItem, unsigned index);
void OnItemRemoved(MenuItemRef oldMenuItem);
void OnItemChanged(MenuItemRef menuItem);
private: // instance data
std::unique_ptr<MenuItemCollection> items;
HMENU menuHandle;
static IDToMenuItemMap sIDToMenuItemRef;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,96 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Panel.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Default constructor.
/*ctor*/ Panel::Panel()
: base()
{
}
///\brief
///constructor.
///\param layoutFlags
///The size flags to be used when positioning this control within a parent
/*ctor*/ Panel::Panel(LayoutFlags layoutFlags)
: base(layoutFlags)
{
}
HWND Panel::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
_T("STATIC"), // Class name
_T(""), // Window name
style, // Style
0, // X
0, // Y
120, // Width
36, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
void Panel::OnEraseBackground(HDC hdc)
{
// Do nothing! calling ::InvalidateRect() here can cause redraw problems
// when another window is dragged on top of us. the problems go away
// as soon as we gain focus, but still annoying.
//
// This is somehow related to the WS_CLIPCHILDREN flag
}

View File

@ -0,0 +1,76 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Container.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///Panel is the most basic concrete implementation of Container.
///
///Panel does not offer any special layout functionality, and has no
///limitations as to the number of child controls that can be added.
///Panel is the base class for most more advanced Container
///implementations, including Splitter and BoxLayout.
///
///\see
///BoxLayout, Splitter
class Panel: public Container
{
public: // types
typedef Container base;
public: // constructors
/*ctor*/ Panel();
/*ctor*/ Panel(LayoutFlags layoutFlags);
protected: // methods
virtual HWND Create(Window* parent);
virtual void OnEraseBackground(HDC hdc);
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,181 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/ProgressBar.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Constructor.
///
///\param width
///The width of the edit box
///\param height
///The height of the edit box
/*ctor*/ ProgressBar::ProgressBar(int width, int height)
: base()
, width(width)
, height(height)
//, caption(caption)
{
this->caption = _T("Progress Bar");
}
/*dtor*/ ProgressBar::~ProgressBar()
{
}
HWND ProgressBar::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
// create the window
DWORD style = WS_CHILD | WS_VISIBLE;
DWORD styleEx = this->styleEx;
//
HWND hwnd = CreateWindowEx(
0, // ExStyle
PROGRESS_CLASS, // Class name
this->caption.c_str(), // Window name
style, // Style
0, // X
0, // Y
this->width, // Width
this->height, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
DWORD error = GetLastError();
if (hwnd)
{
::SetWindowText(hwnd, this->caption.c_str());
}
return hwnd;
}
LRESULT ProgressBar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
return this->DefaultWindowProc(message, wParam, lParam);
}
///\brief
///Sets the progress bar to have a smooth bar
void ProgressBar::SetMarqueeStyle()
{
SetWindowLongPtr(this->Handle(), GWL_STYLE, GetWindowLongPtr(this->Handle(), GWL_STYLE) | PBS_MARQUEE);
SetWindowPos(this->Handle(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
return;
}
///\brief
///Sets the progress bar to have a smooth bar
void ProgressBar::SetSmoothStyle()
{
SetWindowLongPtr(this->Handle(), GWL_STYLE, GetWindowLongPtr(this->Handle(), GWL_STYLE) | PBS_SMOOTH);
SetWindowPos(this->Handle(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
return;
}
///\brief
///Sets the progress bar to have a smooth bar
void ProgressBar::SetVerticalStyle()
{
SetWindowLongPtr(this->Handle(), GWL_STYLE, GetWindowLongPtr(this->Handle(), GWL_STYLE) | PBS_VERTICAL);
SetWindowPos(this->Handle(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);
return;
}
///\brief
///Sets the progress bar to have a marquee style (Windows XP or above)
///\param set
///Boolean to say whether to marquee or not
///\param delay
///Time in milliseconds between animation updates
void ProgressBar::StartMarquee(bool set, unsigned int delay)
{
this->SendMessage(PBM_SETMARQUEE, (WPARAM)set, (LPARAM)delay);
return;
}
///\brief
///Sets the min and max values of the progress bar
///\param min
///The minimum value (unsigned)
///\param max
///The maximum value (unsigned)
void ProgressBar::SetRange(unsigned int min, unsigned int max)
{
this->SendMessage(PBM_SETRANGE, 0, MAKELPARAM(min,max));
}
///\brief
///Sets the current position of the progress bar
///\param pos
///The new position of the progress bar
void ProgressBar::SetPos(int pos)
{
this->SendMessage(PBM_SETPOS, pos, 0 /*must be 0. Not used*/);
return;
}
///\brief
///Sets the current position of the progress bar
///\param pos
///The new step increment
void ProgressBar::SetStepIncrement(int inc)
{
this->SendMessage(PBM_SETSTEP, inc, 0 /*must be 0. Not used*/);
return;
}
///\brief
///Steps the progress bar forward once. Default step is 10
void ProgressBar::Step()
{
this->SendMessage(PBM_STEPIT, 0, 0);
return;
}

View File

@ -0,0 +1,83 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class ProgressBar; // forward decl
///\brief
///A progress bar.
class ProgressBar: public Window
{
private: // types
typedef Window base;
public: // constructors, methods
/*ctor*/ ProgressBar(int width, int height);
/*dtor*/ ~ProgressBar();
void SetMarqueeStyle();
void SetSmoothStyle();
void SetVerticalStyle();
void StartMarquee(bool set, unsigned int delay);
void SetRange(unsigned int min, unsigned int max);
void SetPos(int pos);
void SetStepIncrement(int inc);
void Step();
protected: // methods
virtual HWND Create(Window* parent);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
protected: // instance data
uistring caption;
int width;
int height;
DWORD styleEx;
};
} //win32cpp

View File

@ -0,0 +1,193 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Casey Langen, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/RadioButton.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Constructor.
///
///\param caption
///The caption beside the radio button
/*ctor*/ RadioButton::RadioButton(const uichar* caption, RadioButton* prev, LayoutFlags layoutFlags)
: base(layoutFlags)
, caption(caption)
, prev(prev)
, next(NULL)
{
}
///\brief
///Constructor.
///
///\param caption
///The caption beside the radio button
/*ctor*/ RadioButton::RadioButton(const uichar* caption, LayoutFlags layoutFlags)
: base(layoutFlags)
, caption(caption)
, prev(NULL)
, next(NULL)
{
}
/*dtor*/ RadioButton::~RadioButton()
{
// fix linked list after deletion of an item
if(this->prev) {
if(this->next) {
this->prev->next = this->next;
} else {
this->prev->next = NULL;
}
}
if(this->next) {
if(this->prev) {
this->next->prev = this->prev;
} else {
this->next->prev = NULL;
}
}
}
HWND RadioButton::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | BS_NOTIFY | BS_AUTORADIOBUTTON;
if(this->prev == NULL) {
style |= WS_GROUP;
} else {
this->prev->next = this;
}
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
_T("BUTTON"), // Class name
this->caption.c_str(), // Window name
style, // Style
0, // X
0, // Y
64, // Width
28, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
LRESULT RadioButton::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
switch (HIWORD(wParam))
{
case BN_CLICKED:
this->OnPressed();
return 0;
}
}
return this->DefaultWindowProc(message, wParam, lParam);
}
void RadioButton::OnPressed()
{
this->Pressed(this);
}
void RadioButton::PaintToHDC(HDC hdc, const Rect& rect)
{
this->WindowProc(WM_PAINT, (WPARAM) (HDC) hdc, PRF_CLIENT);
if (::GetFocus() == this->Handle())
{
RECT focusRect = rect;
::InflateRect(&focusRect, -4, -4);
::DrawFocusRect(hdc, &focusRect);
}
}
RadioButton* RadioButton::GetCheckedInGroup(void)
{
RadioButton* traverser = const_cast<RadioButton*>(this);
// check this item first
if(traverser->IsChecked()) {
return traverser;
}
// traverse to first item on list
while(traverser->prev != NULL) {
traverser = traverser->prev;
}
// traverse through whole list to find active icon
while(traverser != NULL) {
if(traverser->SendMessage(BM_GETCHECK, 0, 0) == BST_CHECKED) {
return traverser;
}
traverser = traverser->next;
}
return NULL;
}
bool RadioButton::IsChecked(void)
{
return (this->SendMessage(BM_GETCHECK, 0, 0) == BST_CHECKED);
}
void RadioButton::Check(void)
{
// we need to emulate a click. otherwise the other radio buttons don't get unchecked :-)
SendMessage(BM_CLICK, 0, 0);
}

View File

@ -0,0 +1,105 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, Casey Langen, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class RadioButton;
///\brief
///The type of event used when the RadioButton is pressed.
///\see
///RadioButton.
typedef sigslot::signal1<RadioButton*> RadioButtonPressedEvent;
///\brief
///A standard RadioButton.
///They are organised as linked list to enforce the grouping behaviour
class RadioButton : public Window
{
private: // types
typedef Window base;
public: // events
///\brief This event is emitted when the user presses the RadioButton
RadioButtonPressedEvent Pressed;
public: // constructors
/*ctor*/ RadioButton(
const uichar* caption = _T(""),
RadioButton* attach = NULL,
LayoutFlags layoutFlags = LayoutWrapWrap);
/*ctor*/ RadioButton(
const uichar* caption,
LayoutFlags layoutFlags = LayoutWrapWrap);
/*dtor*/ ~RadioButton();
protected: // methods
virtual HWND Create(Window* parent);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void OnPressed();
virtual void PaintToHDC(HDC hdc, const Rect& rect);
public:
void Check(void);
bool IsChecked(void);
RadioButton* GetCheckedInGroup(void);
// for testing
uistring Caption(void) const { return caption; }
protected: // instance data
RadioButton* prev; // previous item, NULL if group begin
RadioButton* next; // next item, NULL if group ends
uistring caption;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,88 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/RedrawLock.hpp>
#include <win32cpp/Window.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
RedrawLock::LockList RedrawLock::sLockList;
///\brief
///Constructor
///
///\param window
///The Window whose redraw will be locked
/*ctor*/ RedrawLock::RedrawLock(Window* window)
: hwnd(window ? window->Handle() : NULL)
{
Iterator it = RedrawLock::sLockList.find(this->hwnd);
if (it == RedrawLock::sLockList.end())
{
RedrawLock::sLockList[this->hwnd] = 1;
::SendMessage(this->hwnd, WM_SETREDRAW, 0, 0);
}
else
{
RedrawLock::sLockList[this->hwnd]++;
}
}
/*dtor*/ RedrawLock::~RedrawLock()
{
Iterator it = RedrawLock::sLockList.find(this->hwnd);
if (it == RedrawLock::sLockList.end())
{
// TODO: log error
}
RedrawLock::sLockList[this->hwnd]--;
//
if ( ! RedrawLock::sLockList[this->hwnd])
{
::SendMessage(this->hwnd, WM_SETREDRAW, 1, 0);
::RedrawWindow(this->hwnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
RedrawLock::sLockList.erase(this->hwnd);
}
}

View File

@ -0,0 +1,100 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
// Forward declare
namespace win32cpp {
class Window;
}
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <map>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///Use RedrawLock to stop the specified Window from being redrawn.
///Redrawing is automatically enabled on the Window when the RedrawLock's
///destructor is called.
///
///RedrawLock uses the the WM_SETREDRAW message, see. For more information
///see http://msdn2.microsoft.com/en-us/library/ms534853.aspx
///
///\code
///Splitter* mySplitter = ...;
///{
/// RedrawLock redrawLock(mySplitter)
///
/// //...
/// //perform operations to mySplitter
/// //...
///
///} // mySplitter will be redrawn when redrawLock's destructor is called
///
///\endcode
///
///RedrawLock is safe against locking the same Window multiple times, recursively.
///The Window will not be redrawn until all locks have been destructed.
struct RedrawLock
{
private: // types
typedef std::map<HWND, unsigned> LockList;
typedef LockList::iterator Iterator;
public: // constructors, destructors
/*ctor*/ RedrawLock(Window* window);
/*dtor*/ ~RedrawLock();
private: // instance data
HWND hwnd;
private: // class data
static LockList sLockList;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,468 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Splitter.hpp>
#include <win32cpp/Frame.hpp>
#include <win32cpp/RedrawLock.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
HCURSOR Splitter::sHSizeCursor = ::LoadCursor(0, MAKEINTRESOURCE(IDC_SIZEWE));
HCURSOR Splitter::sVSizeCursor = ::LoadCursor(0, MAKEINTRESOURCE(IDC_SIZENS));
HCURSOR Splitter::sArrowCursor = ::LoadCursor(0, MAKEINTRESOURCE(IDC_ARROW));
///\brief
///Constructor.
///
///\param direction
///The split direction, SplitColumn or SplitRow
///
///\param child1
///The left (horizontal) or top (vertical) child.
///
///\param child2
///The right (horizontal) or bottom (vertical) child.
///
///\param layoutFlags
///The size flags to be used when positioning this control within a parent
/*ctor*/ Splitter::Splitter(SplitDirection direction, Window* child1, Window* child2, LayoutFlags layoutFlags)
: base(layoutFlags)
{
this->InitializeInstance(direction, child1, child2);
}
///\brief
///Constructor.
///
///\param direction
///The split direction, SplitColumn or SplitRow
///
///\param layoutFlags
///The size flags to be used when positioning this control within a parent
/*ctor*/ Splitter::Splitter(SplitDirection direction, LayoutFlags layoutFlags)
: base(layoutFlags)
{
this->InitializeInstance(direction, NULL, NULL);
}
void Splitter::InitializeInstance(SplitDirection direction, Window* child1, Window* child2)
{
this->child1 = child1;
this->child2 = child2;
this->child1Frame = new Frame(child1, 0);
this->child2Frame = new Frame(child2, 0);
this->gripperSize = 4;
this->anchorSize = -1;
this->direction = direction;
this->isDragging = false;
this->isSizable = true;
this->anchor = (direction == SplitColumn ? AnchorLeft : AnchorTop);
this->minAnchorSize = -1;
this->maxAnchorSize = -1;
this->sizeFromMouse = -1;
}
LRESULT Splitter::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
return this->DefaultWindowProc(message, wParam, lParam);
}
///\brief
///Returns true if the Splitter can be resized with the mouse, false otherwise.
bool Splitter::IsSizable()
{
return this->isSizable;
}
///\brief
///Sets whether or not the Splitter can be resized with the mouse via
///click and drag
void Splitter::SetSizable(bool sizable)
{
this->isSizable = sizable;
}
void Splitter::SetSizeCursor()
{
if ( ! this->isSizable)
{
return;
}
::SetCursor(this->direction == SplitColumn
? Splitter::sHSizeCursor
: Splitter::sVSizeCursor);
}
bool Splitter::AddChildWindow(Window* window)
{
if (this->childWindows.size() >= 2)
{
throw TooManyChildWindowsException();
}
return base::AddChildWindow(window);
}
///\brief
///Set the left (if SplitColumn) or top (if SplitRow) child.
///
///The Splitter will assume ownership of the specified Window and
///will delete it when destroyed.
///
///\param window
///The Window to use as a child.
///
///\returns
///The previous child Window. The caller is responsible for freeing
///the Window.
Window* Splitter::SetChild1(Window* window)
{
Window* oldChild = this->child1;
if (oldChild)
{
this->child1Frame->RemoveChild(oldChild);
}
this->child1Frame->AddChild(window);
this->child1 = window;
this->Layout();
return oldChild;
}
///\brief
///Returns the first (left, or top) child.
const Window* Splitter::Child1()
{
return this->child1;
}
///\brief
///Set the right (SplitColumn) or bottom (SplitRow) child.
///
///The Splitter will assume ownership of the specified Window and
///will delete it when destroyed.
///
///\param window
///The Window to use as a child.
///
///\returns
///The previous child Window. The caller is responsible for freeing
///the Window.
Window* Splitter::SetChild2(Window* window)
{
Window* oldChild = this->child2;
if (oldChild)
{
this->child2Frame->RemoveChild(oldChild);
}
this->child2Frame->AddChild(window);
this->child2 = window;
this->Layout();
return oldChild;
}
///\brief
///Returns the second (right, or bottom) child.
const Window* Splitter::Child2()
{
return this->child2;
}
void Splitter::LayoutFromMouse()
{
Rect clientRect = this->ClientRect();
int clientSize = (this->direction == SplitRow
? clientRect.size.height
: clientRect.size.width);
bool child1IsAnchor = (this->anchor == AnchorLeft || this->anchor == AnchorTop);
int control1Size = this->sizeFromMouse;
int control2Size = clientSize - control1Size - this->gripperSize;
control2Size = std::max(control2Size, 0);
this->anchorSize = (child1IsAnchor ? control1Size : control2Size);
// done! set this back for the next call to Layout()
this->sizeFromMouse = -1;
this->Layout();
}
void Splitter::Layout()
{
if (this->sizeFromMouse != -1)
{
this->LayoutFromMouse();
return;
}
Rect clientRect = this->ClientRect();
//
int clientSize = (this->direction == SplitRow
? clientRect.size.height
: clientRect.size.width);
int splitterPos = this->anchorSize;
//
if (splitterPos <= -1)
{
splitterPos = (clientSize / 2);
}
else
{
// don't allow the split to go beyond the window boundries
splitterPos = std::min(splitterPos, clientSize - this->gripperSize);
}
// size the windows in their split direction
bool child1IsAnchor = (this->anchor == AnchorLeft || this->anchor == AnchorTop);
if (this->minAnchorSize >= 0) splitterPos = std::max(this->minAnchorSize, splitterPos);
if (this->maxAnchorSize >= 0) splitterPos = std::min(this->maxAnchorSize, splitterPos);
int nonAnchorSize = clientSize - (splitterPos + this->gripperSize);
//
int control1Size = child1IsAnchor ? splitterPos : nonAnchorSize;
int control2Size = child1IsAnchor ? nonAnchorSize : splitterPos;
if (this->direction == SplitColumn)
{
child1Frame->Resize(control1Size, clientRect.size.height);
child2Frame->Resize(control2Size, clientRect.size.height);
child2Frame->MoveTo(control1Size + this->gripperSize, clientRect.location.y);
}
else // vertical
{
child1Frame->Resize(clientRect.size.width, control1Size);
child2Frame->Resize(clientRect.size.width, control2Size);
child2Frame->MoveTo(clientRect.location.x, control1Size + this->gripperSize);
}
// remember our splitter rect
if (this->direction == SplitColumn)
{
this->splitRect = Rect(
Point(control1Size, 0),
Size(this->gripperSize, clientRect.size.height));
}
else
{
this->splitRect = Rect(
Point(0, control1Size),
Size(clientRect.size.width, this->gripperSize));
}
}
///\brief Returns the AnchorDirection of the splitter.
///\see Splitter
AnchorDirection Splitter::Anchor()
{
return this->anchor;
}
///\brief Sets the AnchorDirection of the splitter.
///\param newAnchor The new AnchorDirection
///\see Splitter
void Splitter::SetAnchor(AnchorDirection newAnchor)
{
this->anchor = newAnchor;
}
///\brief Sets the new AnchorDirection of the splitter.
///
///The size will be the width if SplitColumn, the height if
///SplitRow.
///
///\param anchorSize the new size of the anchor control, in pixels.
//
///\see Splitter
void Splitter::SetAnchorSize(int anchorSize)
{
this->anchorSize = anchorSize;
this->Layout();
}
///\brief Sets the size of the resize gripper, in pixels.
void Splitter::SetGripperSize(int gripperSize)
{
this->gripperSize = gripperSize;
this->Layout();
}
void Splitter::OnResized(const Size& newSize)
{
this->Layout();
}
void Splitter::OnCreated()
{
this->AddChild(this->child1Frame);
this->AddChild(this->child2Frame);
}
void Splitter::OnMouseMoved(MouseEventFlags flags, const Point& location)
{
this->SetSizeCursor();
if (this->isDragging)
{
Rect clientRect = this->ClientRect();
int position = this->direction == SplitColumn ? location.x : location.y;
//
if (this->direction == SplitColumn)
{
int minX = clientRect.location.x;
int maxX = clientRect.location.x + clientRect.size.width;
//
if (position < minX) position = minX;
if (position > maxX) position = maxX;
}
else
{
int minY = clientRect.location.y;
int maxY = clientRect.location.y + clientRect.size.height;
//
if (position < minY) position = minY;
if (position > maxY) position = maxY;
}
// don't allow the main window to be redrawn until resizing has finished. we
// do this because we may be redrawing complex child controls (including other
// splitters) unnecessarily.
RedrawLock redrawLock(Application::Instance().MainWindow());
this->sizeFromMouse = position;
this->Layout();
}
else if ( ! ::PointInRect(this->CursorPosition(), this->splitRect))
{
this->EndMouseCapture();
}
else
{
if (Window::Capture() != this)
{
this->BeginMouseCapture();
}
}
}
void Splitter::OnMouseButtonDown(MouseEventFlags flags, const Point& location)
{
if ( ! isSizable)
{
return;
}
if (::PointInRect(this->CursorPosition(), this->splitRect))
{
this->isDragging = true;
}
}
void Splitter::OnMouseExit()
{
this->EndMouseCapture();
}
void Splitter::OnMouseEnter()
{
this->BeginMouseCapture();
}
void Splitter::OnMouseButtonUp(MouseEventFlags flags, const Point& location)
{
this->isDragging = false;
this->EndMouseCapture();
}
void Splitter::BeginMouseCapture()
{
if (this->isSizable)
{
Window::BeginCapture(this);
this->SetSizeCursor();
}
}
void Splitter::EndMouseCapture()
{
if (this->isSizable)
{
Window::EndCapture(this);
::SetCursor(Splitter::sArrowCursor);
}
}
///\brief Returns the minimum and maximum allowed sizes of the anchored child.
///\param minSize the minimum size of the anchored child
///\param maxSize the maximum size of the anchored child
void Splitter::AnchorConstraints(int& minSize, int& maxSize)
{
if (&minSize) minSize = this->minAnchorSize;
if (&maxSize) maxSize = this->maxAnchorSize;
}
///\brief Sets the minimum and maximum allowed sizes of the anchored child.
///
///Clients may pass win32cpp::DisableConstraint to disable contraints.
///
///\param minSize the minimum size of the anchored child
///\param maxSize the maximum size of the anchored child
void Splitter::SetAnchorConstraints(int minSize, int maxSize)
{
this->minAnchorSize = minSize;
this->maxAnchorSize = maxSize;
this->Layout();
}

View File

@ -0,0 +1,164 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
// Forward declare
namespace win32cpp {
class Frame;
}
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Panel.hpp>
#include <win32cpp/ILayout.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
/*! */
enum SplitDirection
{
/*! */ SplitRow,
/*! */ SplitColumn
};
/*! */
enum AnchorDirection
{
/*! */ AnchorTop,
/*! */ AnchorBottom,
/*! */ AnchorLeft,
/*! */ AnchorRight
};
///\brief Used to disable anchor constraints in Splitter
///\see Splitter::SetAnchorConstraints
const int DisableConstraint = -1;
///\brief A Container with two children that can be resized with the mouse.
///
///Splitter works with any two Window derived instances. Adding more
///than two children will result in a TooManyChildWindowsException.
///
///Splitter will automatically expand its children
///
///\code
///Button* button1 = new Button(_T("button1"));
///Button* button2 = new Button(_T("button2"));
///Splitter* splitter = new Splitter(SplitColumn, button1, button2);
///Application::Instance().MainWindow()->AddChild(splitter);
///splitter->Resize(400, 300);
///\endcode
///
///Typically when a Splitter is resized it's preferable to keep one of the
///children stationary or "anchored," while allowing the other to be resized
///to fill the new space. The anchor can be set via Splitter::SetAnchor by
///specifying a win32cpp::AnchorDirection.
class Splitter: public Panel, public ILayout
{
private: // types
typedef Panel base;
public: // constructors
/*ctor*/ Splitter(
SplitDirection direction,
Window* child1 = NULL,
Window* child2 = NULL,
LayoutFlags layoutFlags = LayoutWrapWrap);
/*ctor*/ Splitter(
SplitDirection direction,
LayoutFlags layoutFlags = LayoutWrapWrap);
public: // methods
bool IsSizable();
void SetSizable(bool sizable);
Window* SetChild1(Window* window);
const Window* Child1();
Window* SetChild2(Window* window);
const Window* Child2();
AnchorDirection Anchor();
void SetAnchor(AnchorDirection newAnchor);
void AnchorConstraints(int& minSize, int& maxSize);
void SetAnchorConstraints(int minSize = DisableConstraint, int maxSize = DisableConstraint);
void SetAnchorSize(int anchorSize);
void SetGripperSize(int pixels);
protected: // methods
void SetSizeCursor();
int AnchorSizeFromMouse(int splitPosition, const Size& newSize);
void BeginMouseCapture();
void EndMouseCapture();
// overrides
virtual bool AddChildWindow(Window* window);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void Layout();
virtual void LayoutFromMouse();
virtual void OnResized(const Size& newSize);
virtual void OnMouseMoved(MouseEventFlags flags, const Point& location);
virtual void OnMouseButtonDown(MouseEventFlags flags, const Point& location);
virtual void OnMouseButtonUp(MouseEventFlags flags, const Point& location);
virtual void OnMouseExit();
virtual void OnMouseEnter();
virtual void OnCreated();
private:
void InitializeInstance(SplitDirection direction, Window* child1, Window* child2);
private: // instance data
Window *child1, *child2;
Frame *child1Frame, *child2Frame;
int gripperSize, anchorSize;
int minAnchorSize, maxAnchorSize;
int sizeFromMouse;
bool isDragging, isSizable;
SplitDirection direction;
AnchorDirection anchor;
Rect splitRect;
private: // class data
static HCURSOR sHSizeCursor, sVSizeCursor, sArrowCursor;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,274 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/TabView.hpp>
#include <win32cpp/MemoryDC.hpp>
#include <win32cpp/Application.hpp>
#include <win32cpp/Color.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
///\brief
///Default constructor.
/*ctor*/ TabView::TabView(LayoutFlags layoutFlags)
: base(layoutFlags)
, visibleChild(NULL)
, padding(4)
{
}
HWND TabView::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
DWORD styleEx = NULL;
//
HWND hwnd = CreateWindowEx(
styleEx, // ExStyle
WC_TABCONTROL, // Class name
_T(""), // Window name
style , // Style
0, // X
0, // Y
120, // Width
100, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
this->tabStop = true;
return hwnd;
}
void TabView::OnPaint()
{
PAINTSTRUCT paintStruct;
RECT clientRect = this->ClientRect(); // using paintStruct.rcPaint gives redraw artifacts!
HDC hdc = ::BeginPaint(this->Handle(), &paintStruct);
//
{
MemoryDC memDC(hdc, clientRect);
HBRUSH backBrush = ::CreateSolidBrush(this->BackgroundColor());
::FillRect(memDC, &(RECT) clientRect, backBrush);
DeleteObject(backBrush);
this->DefaultWindowProc(WM_PAINT, (WPARAM) (HDC) memDC, NULL);
}
//
::EndPaint(this->Handle(), &paintStruct);
}
void TabView::OnEraseBackground(HDC hdc)
{
// do nothing!
}
LRESULT TabView::DrawItem(DRAWITEMSTRUCT& item)
{
return 0;
}
LRESULT TabView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_NOTIFY:
{
NMHDR* notifyHeader = reinterpret_cast<NMHDR*>(lParam);
switch (notifyHeader->code)
{
case TCN_SELCHANGE:
this->OnTabSelected();
return 0;
}
}
return 0; // stack overflow if we don't return that we handled this! WHY?!
}
return this->DefaultWindowProc(message, wParam, lParam);
}
void TabView::SetActiveTab(Window* window)
{
int current = 0;
WindowList::iterator it = this->childWindows.begin();
while (it != childWindows.end())
{
if ((*it) == window)
{
this->SetActiveTab(current);
return;
}
++current;
it++;
}
}
void TabView::SetActiveTab(unsigned index)
{
TabCtrl_SetCurFocus(this->Handle(), index);
}
void TabView::OnTabSelected()
{
int tabIndex = TabCtrl_GetCurSel(this->Handle());
Window* window = this->WindowForTabIndex(tabIndex);
if (window)
{
if (this->visibleChild)
{
this->visibleChild->SetVisible(false);
}
window->SetVisible(true);
this->visibleChild = window;
}
this->Layout();
}
void TabView::OnResized(const Size& newSize)
{
this->Layout();
}
Size TabView::ClientSize() const
{
RECT windowRect = this->WindowRect();
TabCtrl_AdjustRect(this->Handle(), FALSE, &windowRect);
return Rect(windowRect).size;
}
int TabView::Padding() const
{
return this->padding;
}
void TabView::SetPadding(int padding)
{
if (this->padding != padding)
{
this->padding = padding;
this->Layout();
}
}
void TabView::Layout()
{
if ( ! this->visibleChild)
{
return;
}
// calculate the display rect
RECT windowRect = this->WindowRect();
windowRect.left += this->padding;
windowRect.right -= this->padding;
windowRect.top += this->padding;
windowRect.bottom -= this->padding;
TabCtrl_AdjustRect(this->Handle(), FALSE, &windowRect);
//
POINT topLeft;
topLeft.x = windowRect.left;
topLeft.y = windowRect.top;
//
::ScreenToClient(this->Handle(), &topLeft);
//
Rect normalizedWindowRect(windowRect);
normalizedWindowRect.location.x = topLeft.x;
normalizedWindowRect.location.y = topLeft.y;
this->visibleChild->SetRectangle(normalizedWindowRect);
}
void TabView::OnChildAdded(Window* child)
{
WindowToTabIndexMap::iterator it = this->windowToTabMap.find(child);
if (it == this->windowToTabMap.end())
{
// child wasn't added via AddTab, throw.
throw AddTabNotUsedException();
}
// if we already have a child displayed, hide this one!
if (this->visibleChild)
{
child->SetVisible(false);
}
}
void TabView::SelectFirstChild()
{
TabCtrl_SetCurSel(this->Handle(), 0);
this->OnTabSelected(); // grumble. we really have to do this manually?
}
Window* TabView::WindowForTabIndex(int tabIndex)
{
// boost::bimap would be nice...
WindowToTabIndexMap::iterator it = this->windowToTabMap.begin();
WindowToTabIndexMap::iterator end = this->windowToTabMap.end();
for ( ; it != end; it++)
{
if (it->second == tabIndex)
{
return it->first;
}
}
return NULL;
}
Window* TabView::ActiveWindow()
{
return this->WindowForTabIndex(TabCtrl_GetCurSel(this->Handle()));
}

View File

@ -0,0 +1,138 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Container.hpp>
#include <win32cpp/ILayout.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///TabView
///
///\see
///BoxLayout, Splitter
class TabView: public Container, public ILayout
{
public: // types
typedef Container base;
class TabCreationFailedException: public Exception { };
class AddTabNotUsedException: public Exception { };
private: // types
typedef std::map<Window*, int> WindowToTabIndexMap;
public: // constructors
/*ctor*/ TabView(LayoutFlags layoutFlags = LayoutWrapWrap);
public: // methods
template <typename WindowType>
WindowType* AddTab(const uistring& tabTitle, WindowType* window);
template <typename WindowType>
WindowType* RemoveTab(WindowType* window);
Window* ActiveWindow();
virtual Size ClientSize() const;
int Padding() const;
void SetPadding(int padding);
void SetActiveTab(Window* window);
void SetActiveTab(unsigned index);
protected: // methods
virtual HWND Create(Window* parent);
virtual void OnPaint();
virtual void OnEraseBackground(HDC hdc);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void OnTabSelected();
virtual void Layout();
virtual void OnResized(const Size& newSize);
virtual void OnChildAdded(Window* child);
virtual LRESULT DrawItem(DRAWITEMSTRUCT& item);
Window* WindowForTabIndex(int tabIndex);
void SelectFirstChild();
protected: // instance data
WindowToTabIndexMap windowToTabMap;
Window* visibleChild;
int padding;
};
//////////////////////////////////////////////////////////////////////////////
template <typename WindowType>
WindowType* TabView::AddTab(const uistring& tabTitle, WindowType* window)
{
this->windowToTabMap[window] = (int) this->windowToTabMap.size(); // placeholder
this->AddChild(window);
TCITEM tabItem;
::SecureZeroMemory(&tabItem, sizeof(tabItem));
tabItem.iImage = -1;
tabItem.mask = TCIF_TEXT | TCIF_IMAGE;
tabItem.pszText = const_cast<wchar_t*>(tabTitle.c_str());
int result = TabCtrl_InsertItem(this->Handle(), this->windowToTabMap.size(), &tabItem);
if (result == -1)
{
this->windowToTabMap.erase(window);
throw TabCreationFailedException();
}
else
{
// make sure this is still correct...
this->windowToTabMap[window] = result;
}
if (this->windowToTabMap.size() == 1)
{
this->SelectFirstChild();
}
return window;
}
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,106 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "pch.hpp"
#include <win32cpp/Theme.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
ThemeRef Theme::Create(HWND handle, const std::wstring& className)
{
ThemeRef theme(new Theme(handle, className));
return (theme->dll ? theme : ThemeRef());
}
/*ctor*/ Theme::Theme(HWND handle, const std::wstring& className)
: dll(NULL)
, theme(NULL)
{
if ( ! handle)
{
return;
}
this->dll = ::LoadLibrary(L"UXTHEME.DLL");
if (this->dll != NULL)
{
this->OpenThemeDataProc = (PFNOPENTHEMEDATA)GetProcAddress(this->dll, "OpenThemeData");
this->DrawThemeBackgroundProc = (PFNDRAWTHEMEBACKGROUND)GetProcAddress(this->dll, "DrawThemeBackground");
this->CloseThemeDataProc = (PFNCLOSETHEMEDATA)GetProcAddress(this->dll, "CloseThemeData");
this->DrawThemeTextProc = (PFNDRAWTHEMETEXT)GetProcAddress(this->dll, "DrawThemeText");
if (( ! this->OpenThemeDataProc) || ( ! this->DrawThemeBackgroundProc)
|| ( ! this->CloseThemeDataProc) || ( ! this->DrawThemeTextProc))
{
::FreeLibrary(this->dll);
this->dll = NULL;
}
else
{
this->theme = this->OpenThemeDataProc(handle, className.c_str());
}
}
}
/*dtor*/ Theme::~Theme()
{
if (this->dll)
{
::FreeLibrary(this->dll);
this->dll = NULL;
}
if ((this->theme) && (this->CloseThemeDataProc))
{
this->CloseThemeDataProc(this->theme);
this->theme = NULL;
}
}
HRESULT Theme::DrawThemeBackground(HDC hdc, int iPartId, int iStateId, const RECT* pRect, const RECT* pClipRect)
{
return this->DrawThemeBackgroundProc(this->theme, hdc, iPartId, iStateId, pRect, pClipRect);
}

View File

@ -0,0 +1,89 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <boost/shared_ptr.hpp>
#include <uxtheme.h>
#include <tmschema.h>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class Theme;
typedef boost::shared_ptr<Theme> ThemeRef;
///\brief
///A class that wraps Theme (UXTHEME.DLL) handling for XP+ systems
class Theme : public boost::noncopyable
{
public: // types
private: // types
typedef HRESULT (__stdcall *PFNCLOSETHEMEDATA)(HTHEME hTheme);
typedef HRESULT (__stdcall *PFNDRAWTHEMEBACKGROUND)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect);
typedef HTHEME (__stdcall *PFNOPENTHEMEDATA)(HWND hwnd, LPCWSTR pszClassList);
typedef HRESULT (__stdcall *PFNDRAWTHEMETEXT)(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT *pRect);
public:
static ThemeRef Create(HWND handle, const std::wstring& className);
public: // destructor
/*dtor*/ ~Theme();
private: // constructors
/*ctor*/ Theme(HWND handle, const std::wstring& className);
public: // methods
HRESULT DrawThemeBackground(HDC hdc, int iPartId, int iStateId, const RECT* pRect, const RECT* pClipRect);
private: // instance data
HMODULE dll;
HTHEME theme;
PFNOPENTHEMEDATA OpenThemeDataProc;
PFNCLOSETHEMEDATA CloseThemeDataProc;
PFNDRAWTHEMEBACKGROUND DrawThemeBackgroundProc;
PFNDRAWTHEMETEXT DrawThemeTextProc;
};
//////////////////////////////////////////////////////////////////////////////
} // namespace win32cpp

View File

@ -0,0 +1,94 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Daniel Önnerby
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "pch.hpp"
#include <win32cpp/Timer.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
Timer::Timer(unsigned int timeout)
: timeout(timeout)
, wnd(NULL)
{
static unsigned int staticTimerCounter(0);
++staticTimerCounter;
this->timerId = staticTimerCounter;
}
Timer::~Timer(void)
{
}
void Timer::ConnectToWindow(win32cpp::Window *window)
{
this->wnd = window->Handle();
window->TimerTimeout.connect(this, &Timer::OnTimerTimeout);
}
bool Timer::Start()
{
if (::SetTimer(this->wnd, this->timerId, this->timeout, NULL) == NULL)
{
return false;
}
return true;
}
bool Timer::Stop()
{
if (::KillTimer(this->wnd, this->timerId) == NULL)
{
return false;
}
return true;
}
void Timer::OnTimerTimeout(unsigned int timeoutId)
{
if (this->timerId == timeoutId)
{
this->OnTimeout();
}
}

View File

@ -0,0 +1,80 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Daniel Önnerby
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
#include <sigslot/sigslot.h>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class Timer : public EventHandler
{
public: // types
typedef sigslot::signal0<> TimeoutEvent;
public: // events
TimeoutEvent OnTimeout;
public: // ctor, dtor
Timer(unsigned timeout);
~Timer();
public: // methods
void ConnectToWindow(Window *window);
bool Start();
bool Stop();
private: // methods
void OnTimerTimeout(unsigned int timeoutId);
private: // instance data
unsigned timerId;
unsigned timeout;
HWND wnd;
};
//////////////////////////////////////////////////////////////////////////////
} // namespace
//////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,371 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/TopLevelWindow.hpp>
#include <win32cpp/Types.hpp>
#include <win32cpp/MemoryDC.hpp>
#include <win32cpp/Application.hpp>
#include <win32cpp/Color.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
#define CLASS_NAME _T("win32cpp TopLevelWindow")
///\brief Constructor.
///
///\param windowTitle
///The title that will be displayed in the title bar..
/*ctor*/ TopLevelWindow::TopLevelWindow(const uichar* windowTitle)
: base()
, windowTitle(windowTitle)
, minSize(0, 0)
, closed(false)
, modalChild(NULL)
, parentWindow(NULL)
{
}
/*dtor*/ TopLevelWindow::~TopLevelWindow()
{
}
bool TopLevelWindow::RegisterWindowClass()
{
static bool registered = false;
if ( ! registered)
{
WNDCLASSEX wc = { 0 };
// register the window class
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = Window::StaticWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = Application::Instance();
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = CLASS_NAME;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
registered = (::RegisterClassEx(&wc) != 0);
}
return registered;
}
HWND TopLevelWindow::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
HWND parentHWND = (parent ? parent->Handle() : NULL);
if ( ! TopLevelWindow::RegisterWindowClass())
{
return NULL;
}
// create the window
DWORD style = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
DWORD styleEx = NULL;
//
HWND hwnd = ::CreateWindowEx(
styleEx, // ExStyle
CLASS_NAME, // Class name
this->windowTitle.c_str(), // Window name
style, // Style
CW_USEDEFAULT, // X
CW_USEDEFAULT, // Y
(this->minSize.width) ? this->minSize.width : 240, // Width
(this->minSize.height) ? this->minSize.height: 120, // Height
parentHWND, // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
///\brief Sets the minimum size of the window.
///\param size The minimium size.
void TopLevelWindow::SetMinimumSize(const Size& size)
{
this->minSize = size;
Size currentSize = this->WindowSize();
if (currentSize.width < size.width) currentSize.width = size.width;
if (currentSize.height < size.height) currentSize.height = size.height;
this->Resize(currentSize);
}
///\brief Returns the minimum size of the window.
Size TopLevelWindow::MinimumSize() const
{
return this->minSize;
}
///\brief Closes the TopLevelWindow
void TopLevelWindow::Close()
{
this->SendMessage(WM_CLOSE, NULL, NULL);
}
LRESULT TopLevelWindow::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(this == Application::Instance().MainWindow()) {
Application::Instance().SysTrayManager()->WindowProc(this->Handle(), message, wParam, lParam);
}
switch (message)
{
case WM_SIZE:
{
Size size(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
this->OnResizedBase(size);
}
return 0;
case WM_CLOSE:
{
// Close handler is used together with ShowModal
// According to http://msdn.microsoft.com/en-us/library/ms646291.aspx
// we need to do:
// "A window must be enabled before it can be activated. For example,
// if an application is displaying a modeless dialog box and has disabled
// its main window, the application must enable the main window before
// destroying the dialog box. Otherwise, another window will receive the
// keyboard focus and be activated."
if(this->parentWindow) {
this->parentWindow->Enable(true);
SetForegroundWindow(this->parentWindow->Handle());
BringWindowToTop(this->parentWindow->Handle());
this->parentWindow = NULL;
}
this->closed = true;
}
break;
case WM_PRINTCLIENT:
{
HDC hdc = (HDC) wParam;
RECT rcClient = this->ClientRect();
HBRUSH bgBrush = ::CreateSolidBrush(this->BackgroundColor());
::FillRect(hdc, &rcClient, bgBrush);
::DeleteObject(bgBrush);
}
return 0;
case WM_GETMINMAXINFO:
{
MINMAXINFO* minMaxInfo = reinterpret_cast<MINMAXINFO*>(lParam);
minMaxInfo->ptMinTrackSize.x = this->minSize.width;
minMaxInfo->ptMinTrackSize.y = this->minSize.height;
}
return 0;
}
return base::WindowProc(message, wParam, lParam);
}
void TopLevelWindow::OnRequestFocusNext()
{
bool focusChildSuccess = false;
// if we're on the last focused item, loop back around to the first.
if ((this->focusedWindow != NULL)
&& (this->focusedWindow == this->childWindows.back()))
{
focusChildSuccess = this->FocusFirstChild();
}
// we weren't able to focus the next child, so notify the parent.
if ( ! focusChildSuccess)
{
base::OnRequestFocusNext();
}
}
void TopLevelWindow::OnRequestFocusPrev()
{
bool focusChildSuccess = false;
// if we're on the first focused item, jump to the last.
if ((this->focusedWindow != NULL)
&& (this->focusedWindow == this->childWindows.front()))
{
focusChildSuccess = this->FocusLastChild();
}
// we weren't able to focus the next child, so notify the parent.
if ( ! focusChildSuccess)
{
base::OnRequestFocusPrev();
}
}
void TopLevelWindow::OnEraseBackground(HDC hdc)
{
// do nothing.
}
void TopLevelWindow::OnPaint()
{
PAINTSTRUCT paintStruct;
RECT clientRect = this->ClientRect();
HDC hdc = ::BeginPaint(this->Handle(), &paintStruct);
//
{
MemoryDC memDC(hdc, clientRect);
HBRUSH backBrush = ::CreateSolidBrush(this->BackgroundColor());
::FillRect(memDC, &clientRect, backBrush);
DeleteObject(backBrush);
this->DefaultWindowProc(WM_PAINT, (WPARAM) (HDC) memDC, NULL);
}
//
::EndPaint(this->Handle(), &paintStruct);
}
void TopLevelWindow::ShowModal(TopLevelWindow* parent)
{
if (this->closed)
{
throw WindowAlreadyClosedException();
}
if ( ! this->Handle())
{
this->Initialize(parent);
}
if (parent)
{
parent->modalChild = this;
// Disable keyboard/mouse input on the parent window,
// this also means it gets deactivated (NOT in foreground)
parent->Enable(false);
// Remember the parent window
this->parentWindow = parent;
}
try
{
// center the child dialog over the parent
if (parent)
{
Point location(0, 0);
RECT parentRect;
::GetWindowRect(parent->windowHandle, &parentRect);
Size thisSize = this->WindowSize();
location.x = (parentRect.left + parentRect.right) / 2 - thisSize.width / 2;
location.y = (parentRect.top + parentRect.bottom) / 2 - thisSize.height / 2;
this->MoveTo(location);
}
// removes the dialog from the titlebar
::SetWindowLong(this->Handle(), GWL_STYLE, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME);
this->Show(SW_SHOW);
bool shouldQuit = false;
MSG msg;
while (( ! shouldQuit) && (::GetMessage(&msg, NULL, 0, 0) > 0))
{
if (msg.message == WM_QUIT)
{
shouldQuit = true;
::PostQuitMessage(0);
break;
}
::TranslateMessage(&msg);
::DispatchMessage(&msg);
shouldQuit |= this->closed;
}
}
catch (Exception e)
{
// TODO: log me
}
if (parent)
{
parent->modalChild = NULL;
}
if (this->parentWindow)
{
this->parentWindow = NULL;
}
}
void TopLevelWindow::OnGainedFocus()
{
if (this->modalChild)
{
this->modalChild->SetFocus();
}
}
TopLevelWindow* TopLevelWindow::FindFromAncestor(Window* window)
{
Window* topLevelWindow = window->Parent(), *scratch = NULL;
while ((topLevelWindow) && (scratch = topLevelWindow->Parent()))
{
topLevelWindow = scratch;
}
return dynamic_cast<TopLevelWindow*>(topLevelWindow);
}

View File

@ -0,0 +1,98 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Container.hpp>
#include <win32cpp/TrayIconManager.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///A TopLevelWindow is a Window with a title bar, menu, and minimize, maximize,
///close boxes,
///
///TopLevelWindows can house an arbitrary number of child windows.
///
///\see
///Window, Container.
class TopLevelWindow: public Container
{
private: // types
typedef Container base;
class WindowAlreadyClosedException : public Exception { };
public: // ctor, dtor
/*ctor*/ TopLevelWindow(const uichar* windowTitle);
/*dtor*/ virtual ~TopLevelWindow();
public: // methods
void SetMinimumSize(const Size& minSize);
Size MinimumSize() const;
void ShowModal(TopLevelWindow* parent);
void Close();
static TopLevelWindow* FindFromAncestor(Window* window);
protected: // methods
virtual HWND Create(Window* parent);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual void OnRequestFocusNext();
virtual void OnRequestFocusPrev();
virtual void OnEraseBackground(HDC hdc);
virtual void OnPaint();
virtual void OnGainedFocus();
static bool RegisterWindowClass();
private: // instance data
uistring windowTitle;
bool closed;
Size minSize;
TopLevelWindow* modalChild;
Window* parentWindow;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,245 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Trackbar.hpp>
#include <win32cpp/Application.hpp>
#include <win32cpp/Color.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
/*ctor*/ Trackbar::Trackbar(short minValue, short maxValue, TrackbarOrientation orientation)
: base()
, minValue(minValue)
, maxValue(maxValue)
, orientation(orientation)
, trackHeight(2)
, thumbHeight(16)
, tickFrequency(0)
, position(0)
{
}
HWND Trackbar::Create(Window* parent)
{
DWORD style = WS_CHILD | WS_VISIBLE | TBS_NOTICKS | TBS_BOTH | TBS_FIXEDLENGTH | this->orientation;
//
return CreateWindowEx(
NULL, // ExStyle
TRACKBAR_CLASS, // Class name
_T(""), // Window name
style, // Style
0, // X
0, // Y
120, // Width
24, // Height
parent->Handle(), // Parent
NULL, // Menu
Application::Instance(), // Instance
NULL); // lParam
}
LRESULT Trackbar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_NOTIFY:
{
if ( ! lParam)
{
break;
}
NMHDR* notifyHeader = reinterpret_cast<NMHDR*>(lParam);
switch (notifyHeader->code)
{
case NM_CUSTOMDRAW:
{
// The header ctrl also emits NM_CUSTOMDRAW messages
if (notifyHeader->hwndFrom == this->Handle())
{
NMCUSTOMDRAW* customDraw = reinterpret_cast<NMCUSTOMDRAW*>(notifyHeader);
return this->OnCustomDraw(*customDraw);
}
}
break;
case NM_RELEASEDCAPTURE:
{
if (notifyHeader->hwndFrom == this->Handle())
{
this->OnRepositioned();
}
}
break;
}
}
break;
}
return base::WindowProc(message, wParam, lParam);
}
void Trackbar::SetRange(short minValue, short maxValue)
{
this->minValue = minValue;
this->maxValue = maxValue;
LONG range = MAKELONG(this->minValue, this->maxValue);
::SendMessage(this->Handle(), TBM_SETRANGE, FALSE, range);
}
void Trackbar::OnCreated()
{
this->SetRange(this->minValue, this->maxValue);
this->SetThumbHeight(this->thumbHeight);
}
LRESULT Trackbar::OnCustomDraw(NMCUSTOMDRAW& customDraw)
{
switch (customDraw.dwDrawStage)
{
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTERASE;
}
switch (customDraw.dwItemSpec)
{
case TBCD_CHANNEL: // seems to be the most reliable place to draw the background
{
Rect clientRect = this->ClientRect();
if (::GetBkMode(customDraw.hdc) != TRANSPARENT)
{
HBRUSH brush = ::CreateSolidBrush(Color::SystemColor(COLOR_BTNFACE));
::FillRect(customDraw.hdc, &(RECT)clientRect, brush);
::DeleteObject(brush);
}
// windows doesn't automatically center the track vertically if no ticks
// are visible on the trackbar.
if (this->tickFrequency == 0)
{
Rect channelRect = customDraw.rc;
//
channelRect.location.y = (clientRect.Height() - channelRect.Height()) / 2;
customDraw.rc = channelRect;
}
short topOffset = this->trackHeight / 2;
customDraw.rc.top -= (topOffset);
customDraw.rc.bottom += (this->trackHeight - topOffset);
}
break;
case TBCD_THUMB:
{
// center the thumb vertically if no ticks are visible
if (this->tickFrequency == 0)
{
Rect clientRect = this->ClientRect();
Rect channelRect = customDraw.rc;
channelRect.location.y = (clientRect.Height() - channelRect.Height()) / 2;
customDraw.rc = channelRect;
}
}
break;
case TBCD_TICS:
break;
}
return CDRF_DODEFAULT;
}
void Trackbar::OnEraseBackground(HDC hdc)
{
}
void Trackbar::OnPaint()
{
::InvalidateRect(this->Handle(), NULL, FALSE);
base::OnPaint();
}
void Trackbar::SetTickFrequency(short tickFrequency)
{
DWORD style = ::GetWindowLong(this->Handle(), GWL_STYLE);
//
if ( ! tickFrequency)
{
style |= TBS_NOTICKS;
style &= ~TBS_AUTOTICKS;
}
else
{
style &= ~TBS_NOTICKS;
style |= TBS_AUTOTICKS;
}
//
::SetWindowLong(this->Handle(), GWL_STYLE, style);
this->tickFrequency = tickFrequency;
this->SendMessage(TBM_SETTICFREQ, (WPARAM) this->tickFrequency, NULL);
}
void Trackbar::OnRepositioned()
{
this->position = (short) this->SendMessage(TBM_GETPOS, 0, 0);
this->Repositioned(this);
}
void Trackbar::SetThumbHeight(short thumbHeight)
{
this->thumbHeight = thumbHeight;
::SendMessage(this->Handle(), TBM_SETTHUMBLENGTH, this->thumbHeight, 0);
}
void Trackbar::SetTrackHeight(short trackHeight)
{
this->trackHeight = trackHeight;
this->Redraw();
}
void Trackbar::SetPosition(short position)
{
this->position = position;
this->SendMessage(TBM_SETPOS, (WPARAM) true, (LPARAM) this->position);
}

View File

@ -0,0 +1,112 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Window.hpp>
#include <win32cpp/Types.hpp> // uichar, uistring
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class Trackbar; // forward declr
/*! */
enum TrackbarOrientation
{
/*! */ VerticalTrack = TBS_VERT,
/*! */ HorizontalTrack = TBS_HORZ
};
///\brief
///Event used when position on trackbar is changed
///\see
///Trackbar
typedef sigslot::signal1<Trackbar*> TrackbarRepositionedEvent;
///\brief Trackbar allows the user to select a value from a range.
class Trackbar: public Window
{
private: // typedefs
typedef Window base;
public: // events
///\brief This event is emitted when the position of the slider is changed
TrackbarRepositionedEvent Repositioned;
public: // constructors
public: /*ctor*/ Trackbar(
short minValue = 0, short maxValue = 100,
TrackbarOrientation orientation = HorizontalTrack);
public: // methods
void SetRange(short minValue, short maxValue);
short Range() { return this->maxValue - this->minValue; }
int MinValue() const { return this->minValue; }
int MaxValue() const { return this->maxValue; }
void SetTickFrequency(short tickFrequency = 0);
short TickFrequency() const { return this->tickFrequency; }
void SetTrackHeight(short trackHeight);
short TrackHeight() { return this->trackHeight; }
void SetThumbHeight(short thumbHeight);
short ThumbHeight() { return this->thumbHeight; }
void SetPosition(short position);
short Position() const { return this->position; }
protected: // methods
virtual HWND Create(Window* parent);
virtual void OnEraseBackground(HDC hdc);
virtual void OnPaint();
virtual void OnCreated();
virtual void OnRepositioned();
virtual LRESULT OnCustomDraw(NMCUSTOMDRAW& customDraw);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
protected: // instance data
short minValue, maxValue, tickFrequency, position;
short trackHeight, thumbHeight;
TrackbarOrientation orientation;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,338 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: mC2, win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/TrayIconManager.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
///\brief Contains the list of notify icons
IconList TrayIconManager::iconList;
///\brief Contains a list of menus for each icon
MenuList TrayIconManager::menuList;
///\brief Contains a list of options for each icon
OptionsList TrayIconManager::optionsList;
///\brief Each notify icon has its own UID. This counter increments
///when an icon is created.
int TrayIconManager::uidCounter = 100;
TrayIconManager::TrayIconManager()
{
::InitCommonControls();
}
TrayIconManager::~TrayIconManager()
{
// iterate through list and delete icons
for(IconList::iterator i = TrayIconManager::iconList.begin(); i != TrayIconManager::iconList.end(); ++i) {
::Shell_NotifyIcon(NIM_DELETE, &i->second);
}
}
///\brief
///Deletes an icon from the tray and all internal structures
///
///\param uid
///The Icon ID
///
///\return bool
bool TrayIconManager::DeleteIcon(UINT uid)
{
if(TrayIconManager::iconList.find(uid) != TrayIconManager::iconList.end()) {
if(::Shell_NotifyIcon(NIM_DELETE, &TrayIconManager::iconList[uid]) != 0) {
TrayIconManager::iconList.erase(uid);
TrayIconManager::menuList.erase(uid);
TrayIconManager::optionsList.erase(uid);
return true;
}
}
return false;
}
///\brief
///Shows a balloon tip over the tray icon
///
///\note
///Windows XP is required for this feature!
///
///\param uid
///The Icon ID
///
///\param title
///Balloon title
///
///\param text
///Balloon inner text
///
///\param timeout
///Time to show the balloon in seconds. There are special restrictions defined
///by the Windows-API. Look here:
///http://msdn.microsoft.com/en-us/library/bb773352(VS.85).aspx
///
///\param text
///Icon to show. Select from NIIF_NONE, NIIF_INFO, NIIF_WARNING, NIIF_ERROR
///
///\return bool
bool TrayIconManager::ShowBalloon(UINT uid, const uistring& title, const uistring& text, UINT timeout, UINT icon)
{
if(TrayIconManager::iconList.find(uid) != TrayIconManager::iconList.end()) {
TrayIconManager::iconList[uid].uFlags |= NIF_INFO;
TrayIconManager::iconList[uid].uTimeout = timeout * 1000;
TrayIconManager::iconList[uid].dwInfoFlags = icon;
::wcsncpy_s(TrayIconManager::iconList[uid].szInfoTitle, 64, title.c_str(), 64);
::wcsncpy_s(TrayIconManager::iconList[uid].szInfo, 256, text.c_str(), 256);
return (::Shell_NotifyIcon(NIM_MODIFY, &TrayIconManager::iconList[uid]) != 0);
}
return false;
}
///\brief
///Sets a new icon for the specified tray icon.
///
///\param uid
///The Icon ID
///
///\param icon
///New Icon
///
///\return bool
bool TrayIconManager::SetIcon(UINT uid, HICON icon)
{
if(TrayIconManager::iconList.find(uid) != TrayIconManager::iconList.end()) {
TrayIconManager::iconList[uid].hIcon = icon;
return (::Shell_NotifyIcon(NIM_MODIFY, &TrayIconManager::iconList[uid]) != 0);
}
return false;
}
///\brief
///Sets the tooltip for the specified tray icon.
///
///\param uid
///The Icon ID
///
///\param tooltip
///Tooltip to show
///
///\return bool
bool TrayIconManager::SetTooltip(UINT uid, const uistring& tooltip)
{
if(TrayIconManager::iconList.find(uid) != TrayIconManager::iconList.end()) {
TrayIconManager::iconList[uid].uFlags |= NIF_TIP;
::wcsncpy_s(TrayIconManager::iconList[uid].szTip, 128, tooltip.c_str(), 128);
return (::Shell_NotifyIcon(NIM_MODIFY, &TrayIconManager::iconList[uid]) != 0);
}
return false;
}
///\brief
///Sets the popup menu for the specified tray icon.
///
///\param uid
///The Icon ID
///
///\param menu
///Reference to the menu which should be displayed
///
///\return bool
bool TrayIconManager::SetPopupMenu(UINT uid, MenuRef menu)
{
if(menu) {
TrayIconManager::menuList[uid] = menu;
return true;
}
return false;
}
///\brief
///Window procedure for all TrayIconManager handling. Here WM_RBUTTONDOWN (for popup menu),
///WM_LBUTTONDOWN (for restoring the window after it has been minimized to tray) &
///WM_SIZE for the Minimize to tray feature are handled.
///
///\param window
///Affected window handle
///
///\param message
///Message-ID
///
///\param wParam
///\param lParam
///\return LRESULT
///In this case always 0
LRESULT TrayIconManager::WindowProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
{
if(TrayIconManager::menuList.find(message - WM_W32CPP_SYSTRAY) != TrayIconManager::menuList.end()) {
UINT uid = message - WM_W32CPP_SYSTRAY;
switch(LOWORD(lParam)) {
case WM_RBUTTONDOWN:
{
if(TrayIconManager::menuList.find(uid) != TrayIconManager::menuList.end()) {
POINT mousePos = { 0 };
::GetCursorPos(&mousePos);
TrackPopupMenu(
TrayIconManager::menuList[uid]->Handle(),
TPM_LEFTBUTTON,
mousePos.x,
mousePos.y,
NULL,
TrayIconManager::iconList[uid].hWnd,
NULL);
}
}
return 0;
case WM_LBUTTONDOWN:
{
if(TrayIconManager::optionsList[uid] & TrayIconManager::MINIMIZE_TO_TRAY) {
// get window object
Window* wnd = Window::SubclassedWindowFromHWND(TrayIconManager::iconList[uid].hWnd);
// restore window
wnd->Show(SW_SHOW);
wnd->Show(SW_RESTORE);
}
}
return 0;
}
}
// handle minimize to tray
if(message == WM_SIZE && wParam == SIZE_MINIMIZED) {
// iterate through list with icon options and look, if the assigned icon/window pair wants that
for(IconList::iterator i = TrayIconManager::iconList.begin(); i != TrayIconManager::iconList.end(); ++i) {
// look if there is a corresponding window
if(i->second.hWnd == window) {
if(TrayIconManager::optionsList[i->second.uID] & TrayIconManager::MINIMIZE_TO_TRAY) {
// get window object
Window* wnd = Window::SubclassedWindowFromHWND(window);
// and finally minimize it to tray
wnd->Show(SW_SHOWMINIMIZED);
wnd->Show(SW_HIDE);
}
}
}
}
return 0;
}
///\brief
///Activates minimize to tray for the icon specified by uid.
///
///\param uid
///The Icon ID
void TrayIconManager::EnableMinimizeToTray(UINT uid)
{
TrayIconManager::optionsList[uid] |= TrayIconManager::MINIMIZE_TO_TRAY;
}
///\brief
///Creates and add a notify icon
///
///\param window
///The window to associate the icon with
///
///\param icon
///The Icon to show as HICON
///
///\param tooltip
///The tooltip to show. Leave it empty to show no tooltip
///
///\return int
///Returns the new Icon ID or -1 on failure
int TrayIconManager::AddIcon(Window* window, HICON icon, const uistring& tooltip)
{
UINT uid = TrayIconManager::uidCounter++;
NOTIFYICONDATA nid;
// setup notifyicondata structure
::ZeroMemory(&nid, sizeof(nid));
nid.cbSize = sizeof(NOTIFYICONDATA);
nid.hWnd = window->Handle();
nid.uID = uid;
nid.uFlags = NIF_MESSAGE | NIF_ICON;
if(tooltip != _T("")) {
nid.uFlags |= NIF_TIP;
::wcsncpy_s(nid.szTip, 64, tooltip.c_str(), 64);
}
nid.hIcon = icon;
nid.uCallbackMessage = WM_W32CPP_SYSTRAY + uid;
// create icon
if(!::Shell_NotifyIcon(NIM_ADD, &nid)) {
return -1;
}
nid.uVersion = NOTIFYICON_VERSION;
if(!::Shell_NotifyIcon(NIM_SETVERSION, &nid)) {
return -1;
}
// add to icon list
TrayIconManager::iconList[uid] = nid;
// add to options list
TrayIconManager::optionsList[uid] = 0;
return uid;
}

View File

@ -0,0 +1,130 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2008, André Wösten
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <map>
#include <win32cpp/Menu.hpp>
#include <win32cpp/Window.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// TrayIconManager
//////////////////////////////////////////////////////////////////////////////
typedef std::map<UINT, NOTIFYICONDATA> IconList;
typedef std::map<UINT, MenuRef> MenuList;
typedef std::map<UINT, UINT> OptionsList;
///\brief
///The TrayIconManager class is used for managing icons in the Taskbar. It must be
///seen as pure manager for the icons in the TrayIconManager bar. Thus there are no
///special classes for TrayIcons.
///
///Since TrayIconManager communicates using the handle of its associated window, it is
///necessary, that icons are associated to a window handle.
///
///That's why the TrayIconManager component should NOT be used directly, but from the
///Application Singleton. Use Application::Instance().SysTrayManager() to
///get the TrayIconManager object!
///
///Internally each icon has three lists associated:
///
/// - IconList iconList - with NOTIFYICONDATA structures
/// - MenuList menuList - with references to win32cpp's MenuRef
/// - OptionsList optionsList - option bits are set here
///
///Each notify icon is represted by its unique ID, which is assigned by
///AddIcon(). Using this ID you can access all other methods.
///
///Code example:
///\Example
///\code
///
/// // Create Menu
/// MenuRef myMenu = Menu::CreatePopup();
/// myMenu->Items().Append(MenuItem::Create(_T("Test 1")));
/// myMenu->Items().Append(MenuItem::Create(_T("Test 2")));
/// MenuItemRef trayExit = myMenu->Items().Append(MenuItem::Create(_T("E&xit")));
///
/// // Bind Exit to a handler
/// trayExit->Activated.connect(this, &MainWindowController::OnFileExit);
///
/// // Init tray icon
/// UINT uidTrayIcon = Application::Instance().SysTrayManager()->AddIcon(Application::Instance().MainWindow(), icon16);
/// Application::Instance().SysTrayManager()->SetTooltip(uidTrayIcon, _T("Test");
/// Application::Instance().SysTrayManager()->SetPopupMenu(uidTrayIcon, myMenu);
/// Application::Instance().SysTrayManager()->ShowBalloon(uidTrayIcon, _T("Test"), _T("Welcome to this application!"), 2);
/// Application::Instance().SysTrayManager()->EnableMinimizeToTray(uidTrayIcon);
///\endcode
///\see
///Application
///TopLevelWindow
///MenuRef
class TrayIconManager {
private: // types
///\brief List with per-icon options - need to be power of 2!
enum Options {
MINIMIZE_TO_TRAY = 1
};
static IconList iconList;
static MenuList menuList;
static OptionsList optionsList;
static int uidCounter;
public:
LRESULT WindowProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam);
bool DeleteIcon(UINT uid);
int AddIcon(Window* window, HICON icon, const uistring& tooltip = _T(""));
bool SetIcon(UINT uid, HICON icon);
bool SetTooltip(UINT uid, const uistring& tooltip);
bool SetPopupMenu(UINT uid, MenuRef menu);
bool ShowBalloon(UINT uid, const uistring& title, const uistring& text, UINT timeout, UINT icon = NIIF_INFO);
void EnableMinimizeToTray(UINT uid);
/* ctor */ TrayIconManager();
/* dtor */ ~TrayIconManager();
};
//////////////////////////////////////////////////////////////////////////////
}

View File

@ -0,0 +1,96 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/WindowGeometry.hpp>
#include <string>
#include <sigslot/sigslot.h>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// uichar, uistring
//////////////////////////////////////////////////////////////////////////////
#include <TCHAR.H>
///\brief A single character, as used in the UI (a TCHAR).
typedef TCHAR uichar;
///\brief A std::basic_string<TCHAR>
typedef std::basic_string<uichar> uistring;
//////////////////////////////////////////////////////////////////////////////
// byte
//////////////////////////////////////////////////////////////////////////////
///\brief An unsigned byte.
typedef unsigned char byte;
//////////////////////////////////////////////////////////////////////////////
// GET_X_LPARAM, GET_Y_LPARAM
//////////////////////////////////////////////////////////////////////////////
#define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
//////////////////////////////////////////////////////////////////////////////
///\brief
///Classes wishing to handle <b>sigslot</b> signals must inherit from this class.
typedef sigslot::has_slots<> EventHandler;
//////////////////////////////////////////////////////////////////////////////
///\brief
///User-defined application-wide messages
#define WM_W32CPP (WM_USER + 1000)
#define WM_W32CPP_SYSTRAY (WM_W32CPP + 1)
#define WM_W32CPP_APPLICATIONTHREAD_CALL_WAITING (WM_W32CPP + 2)
//////////////////////////////////////////////////////////////////////////////
} // namespace win32cpp

View File

@ -0,0 +1,140 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/Utility.hpp>
#include <boost/algorithm/string.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
uistring win32cpp::Escape(uistring string){
boost::algorithm::replace_all(string,_T("&"),_T("&&"));
return string;
}
uistring win32cpp::WidenString(const char* sourceBuffer)
{
int length = (int) strlen(sourceBuffer) + 1;
size_t convertedChars = 0;
std::shared_ptr<uichar> targetBuffer(
new uichar[length],
[](uichar* p) { delete[] p; });
mbstowcs_s(
&convertedChars,
targetBuffer.get(),
length,
sourceBuffer,
length);
return uistring(targetBuffer.get());
}
std::string win32cpp::ShrinkString(const uistring& sourceString)
{
int length = (int) sourceString.length() + 1;
std::unique_ptr<char> targetBuffer(new char[length]);
size_t convertedChars = 0;
wcstombs_s(
&convertedChars,
targetBuffer.get(),
length,
sourceString.c_str(),
length);
return std::string(targetBuffer.get());
}
int win32cpp::HexToInt(const uichar* value)
{
struct CHexMap
{
TCHAR chr;
int value;
};
const int HexMapL = 16;
CHexMap HexMap[HexMapL] =
{
{'0', 0}, {'1', 1},
{'2', 2}, {'3', 3},
{'4', 4}, {'5', 5},
{'6', 6}, {'7', 7},
{'8', 8}, {'9', 9},
{'A', 10}, {'B', 11},
{'C', 12}, {'D', 13},
{'E', 14}, {'F', 15}
};
size_t length = _tcslen(value) + 1;
TCHAR *mstr = _tcsdup(value);
_tcsupr_s(mstr, length);
TCHAR *s = mstr;
int result = 0;
if (*s == '0' && *(s + 1) == 'X') s += 2;
bool firsttime = true;
while (*s != '\0')
{
bool found = false;
for (int i = 0; i < HexMapL; i++)
{
if (*s == HexMap[i].chr)
{
if (!firsttime) result <<= 4;
result |= HexMap[i].value;
found = true;
break;
}
}
if (!found) break;
s++;
firsttime = false;
}
free(mstr);
return result;
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,56 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Types.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
uistring Escape(uistring string);
int HexToInt(const uichar* value);
uistring WidenString(const char* str);
std::string ShrinkString(const uistring& str);
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,197 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/VirtualWindow.hpp>
#include <win32cpp/Color.hpp>
//////////////////////////////////////////////////////////////////////////////
using namespace win32cpp;
//////////////////////////////////////////////////////////////////////////////
#define CLASS_NAME _T("VirtualWindow")
/*ctor*/ VirtualWindow::VirtualWindow(HWND handle, int padding, LayoutFlags flags)
: base()
, padding(padding, padding, padding, padding)
, realHWND(handle)
{
this->SetLayoutFlags(flags);
this->SetBackgroundColor(Color(255, 0, 255));
}
///\brief Set the Child's padding.
///
///\param padding
///The new padding parameters to use.
void VirtualWindow::SetPadding(const WindowPadding& padding)
{
this->padding = padding;
this->OnResized(this->WindowSize());
}
///\brief Set the Child's padding.
///
///\param padding
///The amount of padding, in pixels, for all edges.
void VirtualWindow::SetPadding(int padding)
{
this->SetPadding(WindowPadding(padding, padding, padding, padding));
}
void VirtualWindow::OnCreated()
{
if (this->realHWND)
{
::SetParent(this->realHWND, this->Handle());
}
}
bool VirtualWindow::AddChildWindow(Window* window)
{
throw TooManyChildWindowsException();
}
void VirtualWindow::OnResized(const Size& newSize)
{
if (realHWND)
{
Size clientSize = this->ClientSize();
::SetWindowPos(
this->realHWND,
HWND_TOP,
0, 0,
clientSize.width, clientSize.height,
NULL);
}
}
LRESULT VirtualWindow::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_NCCALCSIZE:
{
if (wParam && lParam)
{
NCCALCSIZE_PARAMS* params =
reinterpret_cast<NCCALCSIZE_PARAMS*>(lParam);
(*params->rgrc).left += this->padding.left;
(*params->rgrc).right -= this->padding.right;
(*params->rgrc).top += this->padding.top;
(*params->rgrc).bottom -= this->padding.bottom;
}
}
return 0;
case WM_NCPAINT:
{
HDC hdc = ::GetWindowDC(this->Handle());
RECT windowRect = Rect(Point(0, 0), this->WindowSize());
Point clientLoc(this->padding.left, this->padding.top);
RECT clientRect = Rect(clientLoc, this->ClientSize());
::ExcludeClipRect(
hdc,
clientRect.left, clientRect.top,
clientRect.right, clientRect.bottom);
HBRUSH backBrush = ::CreateSolidBrush(Color::SystemColor(COLOR_BTNFACE));
::FillRect(hdc, &windowRect, backBrush);
::DeleteObject(backBrush);
ReleaseDC(this->Handle(), hdc);
}
return 0;
}
return base::WindowProc(message, wParam, lParam);
}
HWND VirtualWindow::Create(Window* parent)
{
HINSTANCE hInstance = Application::Instance();
if ( ! VirtualWindow::RegisterWindowClass())
{
return NULL;
}
// create the window
DWORD style = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
//
HWND hwnd = CreateWindowEx(
NULL, // ExStyle
CLASS_NAME, // Class name
_T(""), // Window name
style, // Style
0, // X
0, // Y
120, // Width
36, // Height
parent->Handle(), // Parent
NULL, // Menu
hInstance, // Instance
NULL); // lParam
return hwnd;
}
bool VirtualWindow::RegisterWindowClass()
{
static bool registered = false;
if ( ! registered)
{
WNDCLASSEX wc = { 0 };
// use STATIC window class as our base
::GetClassInfoEx(NULL, _T("STATIC"), &wc);
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpszClassName = CLASS_NAME;
registered = (::RegisterClassEx(&wc) != 0);
}
return registered;
}

View File

@ -0,0 +1,80 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Application.hpp>
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Panel.hpp>
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class VirtualWindow: public Panel
{
private: //types
typedef Panel base;
public: // constructors
/*ctor*/ VirtualWindow(HWND handle, int padding = 0, LayoutFlags flags = LayoutWrapWrap);
public: // methods
void SetPadding(const WindowPadding& padding);
void SetPadding(int padding);
protected: // methods
virtual bool AddChildWindow(Window* window);
virtual void OnCreated();
virtual void OnResized(const Size& newSize);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual HWND Create(Window* parent);
static bool RegisterWindowClass();
private: // instance data
WindowPadding padding;
HWND realHWND;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,52 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#define _WIN32_WINNT 0x0501
#define _WIN32_IE 0x0500
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <shellapi.h>

View File

@ -0,0 +1,99 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Exception.hpp>
#include <win32cpp/Application.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief An Exception that represents an Win32 error.
class Win32Exception : public Exception
{
public: // ctors
//\brief Default constructor. Calls ::GetLastError()
/*ctor*/ Win32Exception()
{
this->errorCode = ::GetLastError();
}
//\brief Constructor.
/*ctor*/ Win32Exception(DWORD errorCode)
{
this->errorCode = errorCode;
}
public: // methods
//\brief Uses FormatMessage() to return a human readable exception string.
virtual const char* Message()
{
static char resultPtr[4096];
resultPtr[0] = 0;
//
::FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM,
Application::Instance(),
this->errorCode,
NULL,
resultPtr,
4096,
NULL);
//
return resultPtr;
}
DWORD ErrorCode()
{
return this->errorCode;
}
private: // instance data
DWORD errorCode;
};
//////////////////////////////////////////////////////////////////////////////
} // namespace win32cpp
//////////////////////////////////////////////////////////////////////////////

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,383 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
// Forward declare
namespace win32cpp {
struct Color;
}
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
#include <win32cpp/Types.hpp>
#include <win32cpp/Exception.hpp>
#include <win32cpp/Font.hpp>
#include <win32cpp/Menu.hpp>
#include <win32cpp/WindowPadding.hpp>
#include <vector>
#include <map>
#include <set>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
class Window;
///\brief Flags used for control layout
enum LayoutFlags
{
LayoutFillParent = -1, /*!< */
LayoutWrapContent = -2, /*!< */
LayoutWrapWrap = -3, /*!< */
LayoutFillWrap = -4, /*!< */
LayoutWrapFill = -5, /*!< */
LayoutFillFill = -6 /*!< */
};
///\brief Specifies the alignment of a Layout's child
enum LayoutAlignFlag
{
LayoutAlignLeft = 0, /*!< */
LayoutAlignRight = 1, /*!< */
LayoutAlignCenter = 2, /*!< */
LayoutAlignTop = 0, /*!< */
LayoutAlignBottom = 1, /*!< */
LayoutAlignMiddle = 2, /*!< */
};
///\brief Flags used for mouse related events emitted by Window.
enum MouseEventFlags
{
MouseShiftKey = MK_SHIFT, /*!< */
MouseCtrlKey = MK_CONTROL, /*!< */
MouseLeftButton = MK_LBUTTON, /*!< */
MouseMiddleButton = MK_MBUTTON, /*!< */
MouseRightButton = MK_RBUTTON, /*!< */
MouseX1Button = MK_XBUTTON1, /*!< */
MouseX2Button = MK_XBUTTON2 /*!< */
};
/*! */ typedef DWORD VirtualKeyCode;
/*! */ typedef DWORD KeyEventFlags;
/*! */ typedef sigslot::signal1<Window*> DestroyedEvent;
/*! */ typedef sigslot::signal1<Window*> CreatedEvent;
/*! */ typedef sigslot::signal2<Window*, Point> MovedEvent;
/*! */ typedef sigslot::signal2<Window*, Size> ResizedEvent;
/*! */ typedef sigslot::signal1<Window*> MouseEnterEvent;
/*! */ typedef sigslot::signal1<Window*> MouseExitEvent;
/*! */ typedef sigslot::signal3<Window*, MouseEventFlags, Point> MouseMovedEvent;
/*! */ typedef sigslot::signal3<Window*, MouseEventFlags, Point> MouseButtonEvent;
/*! */ typedef sigslot::signal1<Window*> ThemeChangedEvent;
/*! */ typedef sigslot::signal1<Window* /*this*/> FocusEvent;
/*! */ typedef sigslot::signal2<Window* /*old*/, Window* /*new*/> ParentChangedEvent;
/*! */ typedef sigslot::signal1<unsigned int> TimerEvent;
/*! */ typedef sigslot::signal3<Window*, VirtualKeyCode, KeyEventFlags> KeyEvent;
/*! */ typedef sigslot::signal2<Window*, bool> VisibilityChangedEvent;
/*! */ typedef sigslot::signal1<Window*> LayoutParamsChangedEvent;
///\brief
///Window is the abstract base class for all controls.
///
///Based on sigslot signals, Window follows the observer/notifier pattern
///and is able to "emit" notifications to listeners that are not
///necessarily GUI objects. This promotes use of the model/view/controller
///design pattern, which is highly recommended. Window also attempts to
///automatically double buffer all drawing, so controls don't flicker when
///they are moved or resized. This is accomplished using the MemoryDC
///and RedrawLock classes.
///
///The Window class also provides "stable" mouse events for derived
///classes, including consistant cursor enter and exit notifications.
/*abstract*/ class Window: public EventHandler
{
public: // types
///\brief
///This exception will be thrown if Initialize() is called on a
///Window that has already been created.
class WindowAlreadyCreatedException: public Exception { };
///\brief
///This exception may be thrown if operations are attempted on a
///Window that has not been created.
class WindowNotCreatedException: public Exception { };
///\brief
///This exception is thrown if a Window fails to be created.
class WindowCreationFailedException: public Exception { };
///\brief
///This exception is thrown if a Window parameter is NULL where it shouldn't be.
class WindowIsNullException: public Exception { };
///\brief
///This exception is thrown if an invalid (negative) LayoutWeight is specified.
class InvalidLayoutWeightException: public Exception { };
///\brief
///This exception is thrown if invalid layout flags are specified.
class InvalidLayoutFlagsException: public Exception { };
protected: // types
typedef WNDPROC WindowProcFunc;
typedef std::vector<Window*> WindowList;
typedef std::map<HWND, Window*> HandleToWindowMap;
typedef sigslot::_signal_base<sigslot::SIGSLOT_DEFAULT_MT_POLICY> SignalBase;
typedef std::set<SignalBase*> SignalList;
typedef std::unique_ptr<Color> ColorRef;
enum FocusDirection
{
FocusForward,
FocusBackward
};
public: // events
///\brief Emitted when the WM_DESTROY message is received.
DestroyedEvent Destroyed;
///\brief Emitted when the Window is created. This is not necessarily
///at construction time, as Windows are lazily created.
CreatedEvent Created;
///\brief Emitted when the Window is repositioned.
MovedEvent Moved;
///\brief Emitted when the Window is resized.
ResizedEvent Resized;
///\brief Emitted when the cursor is moved over the Window.
MouseMovedEvent MouseMoved;
///\brief Emitted when a mouse button has been pressed over the Window.
MouseButtonEvent MouseButtonDown;
///\brief Emitted when a mouse button has been released over the Window.
MouseButtonEvent MouseButtonUp;
///\brief Emitted when a mouse button has been double clicked over the Window.
MouseButtonEvent MouseButtonDoubleClicked;
///\brief Emitted when the cursor has entered the Window.
MouseEnterEvent MouseEnter;
///\brief Emitted when the cursor has left the Window.
MouseExitEvent MouseExit;
///\brief Emitted when the desktop theme has changed.
ThemeChangedEvent ThemeChanged;
///\brief Emitted when the Window has gained focus.
FocusEvent GainedFocus;
///\brief Emitted when the Window has lost focus.
FocusEvent LostFocus;
///\brief Emitted when the Window's parent has changed.
ParentChangedEvent ParentChanged;
///\brief Emitted when a timer gets a timeout.
TimerEvent TimerTimeout;
///\brief Emitted when a key on the keyboard is pressed down.
KeyEvent KeyDown;
///\brief Emitted when a key on the keyboard is released.
KeyEvent KeyUp;
///\brief Emitted when a key on the keyboard is pressed.
KeyEvent Char;
///\brief Emitted when a control has requested to focus the next control. This
///generally shouldn't be handled explicitly unless absolutely necessary.
FocusEvent RequestFocusNext;
///\brief Emitted when a control has requested to focus the previous control. This
///generally shouldn't be handled explicitly unless absolutely necessary.
FocusEvent RequestFocusPrev;
///\brief Emitted when a Window's visibility has changed
VisibilityChangedEvent VisibilityChanged;
///\brief Emitted when a Window's layout parameters have changed.
LayoutParamsChangedEvent LayoutParametersChanged;
public: // ctor, dtor
/*ctor*/ Window();
/*ctor*/ Window(LayoutFlags layoutFlags);
/*dtor*/ virtual ~Window();
public: // methods
void Initialize(Window* parent = NULL);
bool Show(int showCommand);
bool MoveTo(int x, int y);
bool MoveRelativeTo(int x, int y);
bool MoveTo(const Point& location);
bool Resize(int width, int height);
bool Resize(const Size& size);
bool SetRectangle(const Rect& rectangle);
bool Enable(bool enable);
uistring Caption() const;
bool SetCaption(const uistring& caption);
Rect ClientRect() const;
Rect WindowRect() const;
Size WindowSize() const;
virtual Size ClientSize() const;
Point Location() const;
Point CursorPosition() const;
LRESULT SendMessage(UINT message, WPARAM wParam, LPARAM lParam);
bool PostMessage(UINT message, WPARAM wParam, LPARAM lParam);
HWND Handle() const;
virtual bool Destroy();
Window* Parent() const;
void Redraw() const;
void SetFont(FontRef font);
FontRef Font() const;
void SetMenu(MenuRef menu);
MenuRef Menu();
void SetVisible(bool visible = true);
bool Visible();
void SetBackgroundColor(const Color& color);
Color BackgroundColor() const;
bool SetFocus();
bool TabStop();
void SetTabStop(bool enabled);
LayoutFlags LayoutWidth() const;
LayoutFlags LayoutHeight() const;
LayoutAlignFlag LayoutAlignment() const;
void SetLayoutFlags(LayoutFlags widthFlag, LayoutFlags heightFlag);
void SetLayoutFlags(LayoutFlags flags);
void SetLayoutAlignment(LayoutAlignFlag alignment);
float LayoutWeight() const;
void SetLayoutWeight(float weight);
static Window* SubclassedWindowFromHWND(HWND hwnd);
public: // operators
operator bool() { return (this->windowHandle != NULL); }
protected: // methods
// pure virtuals
virtual HWND Create(Window* parent = NULL) = 0;
// subclassing, mouse capture
static void SubclassWindowProc(Window* window);
static void UnSubclassWindowProc(Window* window);
static bool IsWindowSubclassed(Window* window);
static Window* WindowUnderCursor(HWND* targetHwnd = NULL);
static void BeginCapture(Window* window);
static void EndCapture(Window* window);
static void SetParent(Window* child, Window* newParent);
static void ForceMeasureItem(const Window* window);
static Window* Capture();
// win32 event wrappers (template pattern, effective c++ item 35)
void OnDestroyedBase();
void OnCreatedBase();
void OnMovedBase(const Point& location);
void OnResizedBase(const Size& newSize);
void OnMouseMovedBase(MouseEventFlags flags, const Point& location);
void OnMouseButtonDownBase(MouseEventFlags flags, const Point& location);
void OnMouseButtonUpBase(MouseEventFlags flags, const Point& location);
void OnMouseButtonDoubleClickedBase(MouseEventFlags flags, const Point& location);
void OnMouseEnterBase();
void OnMouseExitBase();
void OnGainedFocusBase();
void OnLostFocusBase();
void OnThemeChangedBase();
void OnParentChangedBase(Window* oldParent, Window* newParent);
bool OnKeyDownBase(VirtualKeyCode keyCode, KeyEventFlags flags);
bool OnKeyUpBase(VirtualKeyCode keyCode, KeyEventFlags flags);
bool OnCharBase(VirtualKeyCode keyCode, KeyEventFlags flags);
void OnVisibilityChangedBase(bool visible);
void OnLayoutParametersChangedBase();
// win32 event wrappers (virtual methods, for derived class use)
virtual void OnDestroyed() { }
virtual void OnCreated() { }
virtual void OnMoved(const Point& location) { }
virtual void OnResized(const Size& newSize) { }
virtual void OnMouseMoved(MouseEventFlags flags, const Point& location) { }
virtual void OnMouseButtonDown(MouseEventFlags flags, const Point& location) { }
virtual void OnMouseButtonUp(MouseEventFlags flags, const Point& location) { }
virtual void OnMouseButtonDoubleClicked(MouseEventFlags flags, const Point& location) { }
virtual void OnMouseEnter() { }
virtual void OnMouseExit() { }
virtual void OnGainedFocus() { }
virtual void OnLostFocus() { }
virtual void OnThemeChanged();
virtual void OnFontChanged() { }
virtual void OnMeasureItem(MEASUREITEMSTRUCT* measureItemStruct) { }
virtual void OnParentChanged(Window* oldParent, Window* newParent) { }
virtual void OnCaptionChanged() { }
virtual void OnLayoutParametersChanged() { }
virtual bool OnKeyDown(VirtualKeyCode keyCode, KeyEventFlags flags) { return false; }
virtual bool OnKeyUp(VirtualKeyCode keyCode, KeyEventFlags flags) { return false; }
virtual bool OnChar(VirtualKeyCode keyCode, KeyEventFlags flags) { return false; }
virtual void OnEraseBackground(HDC hdc);
virtual void OnPaint();
virtual void OnRequestFocusPrev();
virtual void OnRequestFocusNext();
virtual HBRUSH OnControlColor(HDC hdc);
virtual void OnVisibilityChanged(bool visible) { }
virtual LRESULT DrawItem(DRAWITEMSTRUCT& item) { return 0; }
// window proc related
virtual LRESULT PreWindowProcBase(UINT message, WPARAM wParam, LPARAM lParam, bool& discardMessage);
virtual LRESULT PreWindowProc(UINT message, WPARAM wParam, LPARAM lParam, bool& discardMessage);
void PostWindowProcBase(UINT message, WPARAM wParam, LPARAM lParam);
virtual void PostWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
LRESULT DefaultWindowProc(UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK StaticWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
// misc
virtual void PaintToHDC(HDC hdc, const Rect& rect);
void SuppressSignal(SignalBase& signal);
static bool WindowHasParent(Window* window);
static bool WindowIsValid(Window* window);
private:
void InitializeInstance();
protected: // instance data
WindowProcFunc defaultWindowProc;
HWND windowHandle;
HBRUSH backgroundBrush;
FontRef font;
MenuRef menu;
ColorRef backgroundColor;
bool usesDefaultFont;
SignalList suppressedSignals;
bool tabStop;
LayoutAlignFlag layoutAlignment;
LayoutFlags layoutWidth, layoutHeight;
float layoutWeight;
protected: // class data
static HandleToWindowMap sHandleToWindowMap;
static WindowList sAllChildWindows;
static FontRef sDefaultFont;
static FocusDirection sFocusDirection;
};
//////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,55 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include <pch.h>
#include <win32cpp/WindowGeometry.hpp>
//////////////////////////////////////////////////////////////////////////////
// Methods
//////////////////////////////////////////////////////////////////////////////
bool win32cpp::PointInRect(const Point& point, const Rect& rect)
{
if ((point.x >= rect.location.x) && (point.x <= rect.location.x + rect.size.width)
&& (point.y >= rect.location.y) && (point.y <= rect.location.y + rect.size.height))
{
return true;
}
return false;
}

View File

@ -0,0 +1,302 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp>
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
// Point
//////////////////////////////////////////////////////////////////////////////
///
///\brief
///Represents a point
///
struct Point
{
///
///\brief
///constructor.
///
/*ctor*/ Point()
: x(0)
, y(0)
{
}
///
///\brief
///Constructor
///
/*ctor*/ Point(int x, int y)
: x(x)
, y(y)
{
}
///
///\brief
///Constructor
///
/*ctor*/ Point(const POINT& pt)
: x(pt.x)
, y(pt.y)
{
}
///
///\brief
///Returns a Win32 POINT object representation of the Point.
///
operator POINT() const
{
POINT pt;
pt.x = this->x;
pt.y = this->y;
return pt;
}
bool operator==(const Point& point) const
{
return ((point.x == this->x) && (point.y == this->y));
}
bool operator!=(const Point& point) const
{
return ! (*this == point);
}
///
///\brief
///The X location of the point
///
int x;
///
///\brief
///The Y location of the point
///
int y;
};
//////////////////////////////////////////////////////////////////////////////
// Size
//////////////////////////////////////////////////////////////////////////////
///
///\brief
///Represents a size
///
struct Size
{
///
///\brief
///constructor.
///
/*ctor*/ Size()
: width(0)
, height(0)
{
}
///
///\brief
///constructor.
///
/*ctor*/ Size(int width, int height)
: width(width)
, height(height)
{
}
///
///\brief
///constructor.
///
/*ctor*/ Size(const SIZE& sz)
: width(sz.cx)
, height(sz.cy)
{
}
///
///\brief
///Returns a Win32 SIZE object representation of the Point.
///
operator SIZE() const
{
SIZE sz;
sz.cx = this->width;
sz.cy = this->height;
return sz;
}
bool operator==(const Size& size) const
{
return ((size.width == width) && (size.height == height));
}
bool operator!=(const Size& size) const
{
return ! (*this == size);
}
///
///\brief
///The width, in pixels
///
int width;
///
///\brief
///The height, in pixels
///
int height;
};
//////////////////////////////////////////////////////////////////////////////
// Rect
//////////////////////////////////////////////////////////////////////////////
///
///\brief
///Represents a rectangle
///
struct Rect
{
///
///\brief
///constructor.
///
/*ctor*/ Rect() { }
///
///\brief
///constructor.
///
/*ctor*/ Rect(const Point& location, const Size& size)
: location(location)
, size(size)
{
}
///
///\brief
///constructor.
///
/*ctor*/ Rect(const RECT& rect)
: location(rect.left, rect.top)
, size(rect.right - rect.left, rect.bottom - rect.top)
{
}
///
///\brief
///Returns a Win32 RECT object representation of the Point.
///
operator RECT() const
{
RECT rc;
rc.top = this->location.y;
rc.bottom = this->location.y + this->size.height;
rc.left = this->location.x;
rc.right = this->location.x + this->size.width;
return rc;
}
///
///\brief
///Returns the X coordinate of the upper-left corner
///
int X() { return this->location.x; }
///
///\brief
///Returns the Y coordinate of the upper-left corner
///
int Y() { return this->location.y; }
///
///\brief
///Returns the width of the rectangle
///
int Width() { return this->size.width; }
///
///\brief
///Returns the height of the rectangle
///
int Height() { return this->size.height; }
bool operator==(const Rect& rect) const
{
return true;
return ((rect.location == this->location) && (rect.size == this->size));
}
bool operator!=(const Rect& rect) const
{
return ! (*this == rect);
}
///
///\brief
///The location of the upper left corner of the rectangle
///
Point location;
///
///\brief
///The size of the rectangle
///
Size size;
};
//////////////////////////////////////////////////////////////////////////////
// Methods
//////////////////////////////////////////////////////////////////////////////
bool PointInRect(const Point& point, const Rect& rect);
//////////////////////////////////////////////////////////////////////////////
} // namespace win32cpp

View File

@ -0,0 +1,106 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
namespace win32cpp {
//////////////////////////////////////////////////////////////////////////////
///\brief
///WindowPadding is used by Frame to specify the padding around the child control.
///
///\see
///Frame.
struct WindowPadding
{
///\brief Constructor.
/*ctor*/ WindowPadding(int padding = 0)
: left(padding)
, right(padding)
, top(padding)
, bottom(padding)
{
}
///\brief Constructor.
/*ctor*/ WindowPadding(int left, int right, int top, int bottom)
: left(left)
, right(right)
, top(top)
, bottom(bottom)
{
}
///\brief Copy constructor.
/*ctor*/ WindowPadding(const WindowPadding& padding)
: left(padding.left)
, right(padding.right)
, top(padding.top)
, bottom(padding.bottom)
{
}
///\brief Equality operator
bool operator==(const WindowPadding& padding) const
{
return ((padding.left == this->left) && (padding.right == this->right)
&& (padding.top == this->top) && (padding.bottom == this->bottom));
}
///\brief Inequality operator
bool operator!=(const WindowPadding& padding) const
{
return ! (padding == *this);
}
///\brief Left padding, in pixels
int left;
///\brief Right padding, in pixels
int right;
///\brief Top padding, in pixels
int top;
///\brief Bottom padding, in pixels
int bottom;
};
/////////////////////////////////////////////////////////////////////////////
} // win32cpp

View File

@ -0,0 +1,39 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#include "pch.hpp"

View File

@ -0,0 +1,52 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
// dependencies
//////////////////////////////////////////////////////////////////////////////
#include <boost/shared_ptr.hpp>
#include <boost/scoped_ptr.hpp>
//////////////////////////////////////////////////////////////////////////////
//#include "vld/vld.h"
//////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,80 @@
//////////////////////////////////////////////////////////////////////////////
//
// License Agreement:
//
// The following are Copyright © 2007, Casey Langen
//
// Sources and Binaries of: win32cpp
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// * Neither the name of the author nor the names of other contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
//////////////////////////////////////////////////////////////////////////////
#include <win32cpp/Win32Config.hpp> // Must be first!
#include <win32cpp/Application.hpp>
#include <win32cpp/Button.hpp>
#include <win32cpp/Color.hpp>
#include <win32cpp/Config.hpp>
#include <win32cpp/Container.hpp>
#include <win32cpp/DateTime.hpp>
#include <win32cpp/DeviceContext.hpp>
#include <win32cpp/EditView.hpp>
#include <win32cpp/FolderBrowseDialog.hpp>
#include <win32cpp/Font.hpp>
#include <win32cpp/Frame.hpp>
#include <win32cpp/Image.hpp>
#include <win32cpp/Label.hpp>
#include <win32cpp/LinearLayout.hpp>
#include <win32cpp/ListView.hpp>
#include <win32cpp/Locale.hpp>
#include <win32cpp/MemoryDC.hpp>
#include <win32cpp/Menu.hpp>
#include <win32cpp/Panel.hpp>
#include <win32cpp/RedrawLock.hpp>
#include <win32cpp/Splitter.hpp>
#include <win32cpp/TabView.hpp>
#include <win32cpp/TopLevelWindow.hpp>
#include <win32cpp/Trackbar.hpp>
#include <win32cpp/Types.hpp>
#include <win32cpp/Utility.hpp>
#include <win32cpp/Window.hpp>
//////////////////////////////////////////////////////////////////////////////
///\brief
///namespace root
namespace win32cpp {
}
//////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "win32cpp", "win32cpp.vcproj", "{E618F29F-BF28-441A-B039-9E10A631D881}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E618F29F-BF28-441A-B039-9E10A631D881}.Debug|Win32.ActiveCfg = Debug|Win32
{E618F29F-BF28-441A-B039-9E10A631D881}.Debug|Win32.Build.0 = Debug|Win32
{E618F29F-BF28-441A-B039-9E10A631D881}.Release|Win32.ActiveCfg = Release|Win32
{E618F29F-BF28-441A-B039-9E10A631D881}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,563 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="win32cpp"
ProjectGUID="{E618F29F-BF28-441A-B039-9E10A631D881}"
RootNamespace="win32cpp"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="./bin/$(ConfigurationName)"
IntermediateDirectory="./obj/$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="./;../;../3rdparty/include/"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_SCL_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="1"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.hpp"
PrecompiledHeaderFile=".\obj\$(Configurationname)\$(TargetName).pch"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="./bin/$(ConfigurationName)"
IntermediateDirectory="./obj/$(ConfigurationName)"
ConfigurationType="4"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="./;../;../3rdparty/include/"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_SCL_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="pch.hpp"
PrecompiledHeaderFile=".\obj\$(Configurationname)\$(TargetName).pch"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="src"
>
<File
RelativePath="pch.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
<File
RelativePath="pch.hpp"
>
</File>
<Filter
Name="win32cpp"
>
<File
RelativePath=".\Application.cpp"
>
</File>
<File
RelativePath=".\Application.hpp"
>
</File>
<File
RelativePath=".\TrayIconManager.cpp"
>
</File>
<File
RelativePath=".\TrayIconManager.hpp"
>
</File>
<File
RelativePath=".\win32cpp.hpp"
>
</File>
<Filter
Name="drawing"
>
<File
RelativePath=".\Color.cpp"
>
</File>
<File
RelativePath=".\Color.hpp"
>
</File>
<File
RelativePath=".\Font.cpp"
>
</File>
<File
RelativePath=".\Font.hpp"
>
</File>
<File
RelativePath=".\Image.cpp"
>
</File>
<File
RelativePath=".\Image.hpp"
>
</File>
<File
RelativePath=".\MemoryDC.cpp"
>
</File>
<File
RelativePath=".\MemoryDC.hpp"
>
</File>
<File
RelativePath=".\RedrawLock.cpp"
>
</File>
<File
RelativePath=".\RedrawLock.hpp"
>
</File>
</Filter>
<Filter
Name="config"
>
<File
RelativePath=".\Types.hpp"
>
</File>
<File
RelativePath=".\Win32Config.hpp"
>
</File>
</Filter>
<Filter
Name="utility"
>
<File
RelativePath=".\ApplicationThread.cpp"
>
</File>
<File
RelativePath=".\ApplicationThread.hpp"
>
</File>
<File
RelativePath=".\Exception.cpp"
>
</File>
<File
RelativePath=".\Exception.hpp"
>
</File>
<File
RelativePath=".\Theme.cpp"
>
</File>
<File
RelativePath=".\Theme.hpp"
>
</File>
<File
RelativePath=".\Utility.cpp"
>
</File>
<File
RelativePath=".\Utility.hpp"
>
</File>
<File
RelativePath=".\Win32Exception.hpp"
>
</File>
<File
RelativePath=".\WindowGeometry.cpp"
>
</File>
<File
RelativePath=".\WindowGeometry.hpp"
>
</File>
<File
RelativePath=".\WindowPadding.hpp"
>
</File>
<Filter
Name="to document"
>
<File
RelativePath=".\DeviceContext.cpp"
>
</File>
<File
RelativePath=".\DeviceContext.hpp"
>
</File>
<File
RelativePath=".\ImageList.cpp"
>
</File>
<File
RelativePath=".\ImageList.hpp"
>
</File>
<File
RelativePath=".\Timer.cpp"
>
</File>
<File
RelativePath=".\Timer.hpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="views"
>
<File
RelativePath=".\Button.cpp"
>
</File>
<File
RelativePath=".\Button.hpp"
>
</File>
<File
RelativePath=".\CheckBox.cpp"
>
</File>
<File
RelativePath=".\CheckBox.hpp"
>
</File>
<File
RelativePath=".\EditView.cpp"
>
</File>
<File
RelativePath=".\EditView.hpp"
>
</File>
<File
RelativePath=".\Label.cpp"
>
</File>
<File
RelativePath=".\Label.hpp"
>
</File>
<File
RelativePath=".\ListView.cpp"
>
</File>
<File
RelativePath=".\ListView.hpp"
>
</File>
<File
RelativePath=".\ProgressBar.cpp"
>
</File>
<File
RelativePath=".\ProgressBar.hpp"
>
</File>
<File
RelativePath=".\RadioButton.cpp"
>
</File>
<File
RelativePath=".\RadioButton.hpp"
>
</File>
<File
RelativePath=".\VirtualWindow.cpp"
>
</File>
<File
RelativePath=".\VirtualWindow.hpp"
>
</File>
<File
RelativePath=".\Window.cpp"
>
</File>
<File
RelativePath=".\Window.hpp"
>
</File>
<Filter
Name="containers"
>
<File
RelativePath=".\Container.cpp"
>
</File>
<File
RelativePath=".\Container.hpp"
>
</File>
<File
RelativePath=".\Frame.cpp"
>
</File>
<File
RelativePath=".\Frame.hpp"
>
</File>
<File
RelativePath=".\GroupBox.cpp"
>
</File>
<File
RelativePath=".\GroupBox.hpp"
>
</File>
<File
RelativePath=".\ILayout.hpp"
>
</File>
<File
RelativePath=".\LinearLayout.cpp"
>
</File>
<File
RelativePath=".\LinearLayout.hpp"
>
</File>
<File
RelativePath=".\Panel.cpp"
>
</File>
<File
RelativePath=".\Panel.hpp"
>
</File>
<File
RelativePath=".\Splitter.cpp"
>
</File>
<File
RelativePath=".\Splitter.hpp"
>
</File>
<File
RelativePath=".\TabView.cpp"
>
</File>
<File
RelativePath=".\TabView.hpp"
>
</File>
<File
RelativePath=".\TopLevelWindow.cpp"
>
</File>
<File
RelativePath=".\TopLevelWindow.hpp"
>
</File>
</Filter>
<Filter
Name="to document"
>
<File
RelativePath=".\ComboBox.cpp"
>
</File>
<File
RelativePath=".\ComboBox.hpp"
>
</File>
<File
RelativePath=".\Menu.cpp"
>
</File>
<File
RelativePath=".\Menu.hpp"
>
</File>
<File
RelativePath=".\Trackbar.cpp"
>
</File>
<File
RelativePath=".\Trackbar.hpp"
>
</File>
</Filter>
<Filter
Name="common dialogs"
>
<File
RelativePath=".\FolderBrowseDialog.cpp"
>
</File>
<File
RelativePath=".\FolderBrowseDialog.hpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="localization"
>
<File
RelativePath=".\Config.cpp"
>
</File>
<File
RelativePath=".\Config.hpp"
>
</File>
<File
RelativePath=".\DateTime.cpp"
>
</File>
<File
RelativePath=".\DateTime.hpp"
>
</File>
<File
RelativePath=".\Locale.cpp"
>
</File>
<File
RelativePath=".\Locale.hpp"
>
</File>
</Filter>
</Filter>
</Filter>
<Filter
Name="resources"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>