diff options
author | Vadim Dashevskiy <watcherhd@gmail.com> | 2013-04-02 13:26:06 +0000 |
---|---|---|
committer | Vadim Dashevskiy <watcherhd@gmail.com> | 2013-04-02 13:26:06 +0000 |
commit | 8d3307adf7ba64b75fb4de363f873c97286b0e9b (patch) | |
tree | 1f89dccbcd641f2df5d793ee3a3a5c6c745d898c /plugins | |
parent | 626e01829f5d9946e831cbf66ad49a13103f91bb (diff) |
- XSoundNotify - adopted
git-svn-id: http://svn.miranda-ng.org/main/trunk@4284 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
34 files changed, 25413 insertions, 533 deletions
diff --git a/plugins/!NotAdopted/XSoundNotify/DebugLogger.hpp b/plugins/!NotAdopted/XSoundNotify/DebugLogger.hpp deleted file mode 100644 index 3b2c5a5fc1..0000000000 --- a/plugins/!NotAdopted/XSoundNotify/DebugLogger.hpp +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef _GRS_DEBUG_LOGGER_H -#define _GRS_DEBUG_LOGGER_H - -#include <fstream> -#include <sstream> -#include <ctime> -#include <memory> - -/** - * Простой логгер, который можно использовать в любом месте для вывода отладочной информации - * При выводе обычного сообщения надо использовать макрос GRS_DEBUG_LOG - * Для вывода сложного сообщения с использованием операторов ввода/вывода макрос GRS_DEBUG_FORMAT_LOG - * Лог сохраняется в рабочем каталоге под именем : grs_debug.log - */ - -namespace grs -{ - -class DebugLogger -{ -public: - class Except : public std::exception - { - public: - virtual const char * what() const throw() { return "pizda rulu"; } - }; - - DebugLogger() - { - try - { - _strm.open("D:\\grs_debug.log", std::ios::app); - } - catch (...) - { - throw Except(); - } - if (!_strm.is_open()) - throw Except(); - - log("Logger started"); - } - - void log(const std::string & str, const char * fileStr = 0, int line = 0) - { - if (!_strm.is_open()) - return ; - - time_t t(time(0)); - struct tm * timeinfo; - timeinfo = localtime (&t); - char timeStr[9]; - strftime (timeStr, 9, "%H:%M:%S", timeinfo); - _strm << "[" << timeStr << "] "; - if (fileStr) - _strm << fileStr << ":" << line<<" "; - _strm <<"# "<< str << std::endl; - } - - static DebugLogger * instance() - { - //static DebugLogger * logger = 0; - static std::auto_ptr<DebugLogger> loggerPtr; - if (loggerPtr.get() == 0) - loggerPtr.reset(new DebugLogger()); - return loggerPtr.get(); - } - -private: - std::ofstream _strm; -}; - -} - -#define GRS_DEBUG_FORMAT_LOG(data) {\ - grs::DebugLogger * l = grs::DebugLogger::instance();\ - if (l != 0) \ - {\ - std::stringstream strm;\ - strm << data;\ - l->log(strm.str(), __FILE__, __LINE__);\ - }\ - } - -#define GRS_DEBUG_LOG(data) {\ - grs::DebugLogger * l = grs::DebugLogger::instance();\ - if (l != 0)\ - l->log(data, __FILE__, __LINE__);\ - } - -#endif diff --git a/plugins/!NotAdopted/XSoundNotify/EventProcessor.cpp b/plugins/!NotAdopted/XSoundNotify/EventProcessor.cpp deleted file mode 100644 index 6a97b6b125..0000000000 --- a/plugins/!NotAdopted/XSoundNotify/EventProcessor.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "EventProcessor.h"
-#include <m_database.h>
-#include "m_protocols.h"
-#include <memory>
-#include "DebugLogger.hpp"
-
-// static area
-
-static std::unique_ptr<XSN_EventProcessor> XSN_EventProcessorPtr;
-
-void XSN_EventProcessor::make(PLUGINLINK * pl)
-{
- XSN_EventProcessorPtr.reset(new XSN_EventProcessor(pl));
-}
-
-XSN_EventProcessor & XSN_EventProcessor::instance()
-{
- return *XSN_EventProcessorPtr;
-}
-
-// class methods
-
-XSN_EventProcessor::XSN_EventProcessor(PLUGINLINK * pl) : pluginLink(pl)
-{
-
-}
-
-void XSN_EventProcessor::process(WPARAM wParam, LPARAM lParam)
-{
- if (!wParam || !lParam || !isReceiveMessage(lParam))
- return ;
- try
- {
- MessageBox(0, "Receive message", "INFO", MB_OK);
- /*GRS_DEBUG_LOG("Receive message");
- HANDLE contact = (HANDLE)wParam;
- MessageBox(0, "Get protocol", "INFO", MB_OK);
- GRS_DEBUG_LOG("Protocol : ");
- xsn_string proto = getProtocol(wParam);
- MessageBox(0, "Protocol is", proto.c_str(), MB_OK);
- GRS_DEBUG_FORMAT_LOG(proto)
- //xsn_string nick = getNick(wParam, proto.c_str());
- XSN_Variant sound;
- DBGetContactSettingTString(contact, proto.c_str(), "XSNPlugin_sound", &sound);
- if (!sound.empty())
- {
- GRS_DEBUG_LOG("Sound for user exist");
- GRS_DEBUG_FORMAT_LOG("Playing sound : " << sound.ptszVal << ", for user : " << getNick(wParam, proto.c_str()));
- PlaySound(sound.toString().c_str(), nullptr, SND_FILENAME | SND_ASYNC);
- }*/
- }
- catch (std::runtime_error &)
- {
- //MessageBoxA(0, e.what(), "Runtime error", MB_OK);
- }
- catch (...)
- {
- //MessageBoxA(0, "Unknown error occured", "Exception", MB_OK);
- }
-}
-
-bool XSN_EventProcessor::isReceiveMessage(LPARAM event)
-{
- DBEVENTINFO info ={ sizeof(info) };
- CallService(MS_DB_EVENT_GET, event, (LPARAM)&info);
-
- // TODO : rec msg flag : 16, send msg flag : 18 - WTF?
- // return (info.eventType == EVENTTYPE_MESSAGE) && (info.flags & DBEF_READ);
- // It's condition work well - magic?
- return !(((info.eventType != EVENTTYPE_MESSAGE) && !(info.flags & DBEF_READ)) || (info.flags & DBEF_SENT));
-}
-
-xsn_string XSN_EventProcessor::getProtocol(WPARAM contact)
-{
- char *pszProto = (char *)CallService(MS_PROTO_GETCONTACTBASEPROTO, contact, 0);
- return xsn_string(pszProto);
-}
-
-xsn_string XSN_EventProcessor::getNick(WPARAM contact, LPCTSTR protocol)
-{
- XSN_Variant nick;
- DBGetContactSettingTString((HANDLE)contact, protocol, "Nick", &nick);
- return nick.toString();
-}
diff --git a/plugins/!NotAdopted/XSoundNotify/EventProcessor.h b/plugins/!NotAdopted/XSoundNotify/EventProcessor.h deleted file mode 100644 index 6de14f8f98..0000000000 --- a/plugins/!NotAdopted/XSoundNotify/EventProcessor.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __XSN_EVENT_PROCESSOR
-#define __XSN_EVENT_PROCESSOR
-
-#include <windows.h>
-#include "xsn_types.h"
-#include <newpluginapi.h>
-
-
-class XSN_EventProcessor
-{
-public:
- static void make(PLUGINLINK * pl);
- static XSN_EventProcessor & instance();
-
- void process(WPARAM wParam, LPARAM lParam);
-
-protected:
- XSN_EventProcessor(PLUGINLINK * pl);
-
- bool isReceiveMessage(LPARAM event);
- xsn_string getProtocol(WPARAM contact);
- xsn_string getNick(WPARAM contact, LPCTSTR protocol);
-
- PLUGINLINK * pluginLink;
-};
-
-#endif
diff --git a/plugins/!NotAdopted/XSoundNotify/testplug.vcxproj b/plugins/!NotAdopted/XSoundNotify/testplug.vcxproj deleted file mode 100644 index ebd0a0009f..0000000000 --- a/plugins/!NotAdopted/XSoundNotify/testplug.vcxproj +++ /dev/null @@ -1,167 +0,0 @@ -п»ї<?xml version="1.0" encoding="utf-8"?>
-<Project DefaultTargets="Build" ToolsVersion="4.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>
- </ItemGroup>
- <PropertyGroup Label="Globals">
- <SccProjectName />
- <SccLocalPath />
- <ProjectName>XSoundNotify</ProjectName>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseOfMfc>false</UseOfMfc>
- <CharacterSet>MultiByte</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseOfMfc>false</UseOfMfc>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
- <ImportGroup Label="ExtensionSettings">
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
- </ImportGroup>
- <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- <Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
- </ImportGroup>
- <PropertyGroup Label="UserMacros" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <OutDir>.\Release\</OutDir>
- <IntDir>.\Release\</IntDir>
- <LinkIncremental>false</LinkIncremental>
- <IncludePath>E:\Programming\libs\WTL\Include;$(IncludePath)</IncludePath>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <OutDir>.\Debug\</OutDir>
- <IntDir>.\Debug\</IntDir>
- <LinkIncremental>true</LinkIncremental>
- </PropertyGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <ClCompile>
- <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
- <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
- <StringPooling>true</StringPooling>
- <FunctionLevelLinking>true</FunctionLevelLinking>
- <Optimization>MaxSpeed</Optimization>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <WarningLevel>Level3</WarningLevel>
- <AdditionalIncludeDirectories>e:\Programming\libs\boost_1_46_1\;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;TESTPLUG_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AssemblerListingLocation>.\Release\</AssemblerListingLocation>
- <PrecompiledHeaderOutputFile>.\Release\testplug.pch</PrecompiledHeaderOutputFile>
- <ObjectFileName>.\Release\</ObjectFileName>
- <ProgramDataBaseFileName>.\Release\</ProgramDataBaseFileName>
- </ClCompile>
- <Midl>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <TypeLibraryName>.\Release\testplug.tlb</TypeLibraryName>
- <MkTypLibCompatible>true</MkTypLibCompatible>
- <TargetEnvironment>Win32</TargetEnvironment>
- </Midl>
- <ResourceCompile>
- <Culture>0x0809</Culture>
- <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ResourceCompile>
- <Bscmake>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <OutputFile>.\Release\testplug.bsc</OutputFile>
- </Bscmake>
- <Link>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <LinkDLL>true</LinkDLL>
- <SubSystem>Console</SubSystem>
- <OutputFile>release/xsoundnotify.dll</OutputFile>
- <ImportLibrary>.\Release\testplug.lib</ImportLibrary>
- <AdditionalDependencies>odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <AdditionalLibraryDirectories>e:\Programming\libs\wxWidgets-2.9.3\lib\vc_lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <ClCompile>
- <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
- <InlineFunctionExpansion>Default</InlineFunctionExpansion>
- <FunctionLevelLinking>false</FunctionLevelLinking>
- <Optimization>Disabled</Optimization>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <WarningLevel>Level3</WarningLevel>
- <MinimalRebuild>true</MinimalRebuild>
- <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
- <AdditionalIncludeDirectories>e:\Programming\libs\wxWidgets-2.9.3\include\msvc\;e:\Programming\libs\wxWidgets-2.9.3\include\;../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
- <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;XSOUNDNOTIFY_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AssemblerListingLocation>.\Debug\</AssemblerListingLocation>
- <PrecompiledHeaderOutputFile>.\Debug\testplug.pch</PrecompiledHeaderOutputFile>
- <ObjectFileName>.\Debug\</ObjectFileName>
- <ProgramDataBaseFileName>.\Debug\</ProgramDataBaseFileName>
- <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
- </ClCompile>
- <Midl>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <TypeLibraryName>.\Debug\testplug.tlb</TypeLibraryName>
- <MkTypLibCompatible>true</MkTypLibCompatible>
- <TargetEnvironment>Win32</TargetEnvironment>
- </Midl>
- <ResourceCompile>
- <Culture>0x0809</Culture>
- <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- </ResourceCompile>
- <Bscmake>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <OutputFile>.\Debug\testplug.bsc</OutputFile>
- </Bscmake>
- <Link>
- <SuppressStartupBanner>true</SuppressStartupBanner>
- <LinkDLL>true</LinkDLL>
- <GenerateDebugInformation>true</GenerateDebugInformation>
- <SubSystem>Console</SubSystem>
- <OutputFile>.\Debug\xsoundnotify.dll</OutputFile>
- <ImportLibrary>.\Debug\xsoundnotify.lib</ImportLibrary>
- <AdditionalDependencies>wxmsw29u_adv.lib;wxmsw29u_core.lib;wxbase29u.lib;wxtiff.lib;wxjpeg.lib;wxpng.lib;wxzlib.lib;wxregexu.lib;wxexpat.lib;odbc32.lib;odbccp32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
- <IgnoreSpecificDefaultLibraries>
- </IgnoreSpecificDefaultLibraries>
- <AdditionalLibraryDirectories>e:\Programming\libs\wxWidgets-2.9.3\lib\vc_lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
- </Link>
- </ItemDefinitionGroup>
- <ItemGroup>
- <ClCompile Include="SettingsDialog.cpp" />
- <ClCompile Include="SoundNotifyData.cpp" />
- <ClCompile Include="SoundNotifyDataStorage.cpp" />
- <ClCompile Include="xsn_main.cpp" />
- <ClCompile Include="xsn_types.cpp" />
- <ClCompile Include="xsn_utils.cpp" />
- </ItemGroup>
- <ItemGroup>
- <ClInclude Include="DebugLogger.hpp" />
- <ClInclude Include="SettingsDialog.h" />
- <ClInclude Include="resource.h" />
- <ClInclude Include="SoundNotifyData.h" />
- <ClInclude Include="SoundNotifyDataStorage.h" />
- <ClInclude Include="xsn_types.h" />
- <ClInclude Include="xsn_utils.h" />
- </ItemGroup>
- <ItemGroup>
- <ResourceCompile Include="XSoundNotify.rc" />
- </ItemGroup>
- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
- <ImportGroup Label="ExtensionTargets">
- </ImportGroup>
- <ProjectExtensions>
- <VisualStudio>
- <UserProperties RESOURCE_FILE="XSoundNotify.rc" />
- </VisualStudio>
- </ProjectExtensions>
-</Project>
\ No newline at end of file diff --git a/plugins/!NotAdopted/XSoundNotify/xsn_main.cpp b/plugins/!NotAdopted/XSoundNotify/xsn_main.cpp deleted file mode 100644 index ebcf029143..0000000000 --- a/plugins/!NotAdopted/XSoundNotify/xsn_main.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/*
-Miranda plugin template, originally by Richard Hughes
-http://miranda-icq.sourceforge.net/
-
-This file is placed in the public domain. Anybody is free to use or
-modify it as they wish with no restriction.
-There is no warranty.
-*/
-
-#include "SettingsDialog.h"
-
-#include <windows.h>
-#include <newpluginapi.h>
-#include <m_langpack.h>
-#include <m_clist.h>
-#include <m_skin.h>
-#include <m_database.h>
-#include <m_protocols.h>
-#include "xsn_utils.h"
-//#include "DebugLogger.hpp"
-
-HINSTANCE hInst;
-PLUGINLINK *pluginLink;
-HANDLE AddEventHook;
-
-PLUGININFOEX pluginInfo = {
- sizeof(PLUGININFOEX), // Размер стуктуры
- "XSoundNotify", // Короткое имя плагинв
- PLUGIN_MAKE_VERSION(1,0,0,0), // Версия плагина
- "Provides extended options for sound notifications", // Описание плагина
- "Roman Torsten", // Автор
- "rs_torsten-public@yahoo.com", // Адресс автора
- "© 2011 Copyright", // Копирайт
- "https://plus.google.com/117081718640940130539", // Адресс сайта разработчика плагина
- 0,
- 0,
- {0x8b86253, 0xec6e, 0x4d09, { 0xb7, 0xa9, 0x64, 0xac, 0xdf, 0x6, 0x27, 0xb8 }} //{08B86253-EC6E-4d09-B7A9-64ACDF0627B8}
-};
-
-extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
-{
- hInst = hinstDLL;
- return TRUE;
-}
-
-static int PluginMenuCommand(WPARAM wParam,LPARAM lParam)
-{
- try
- {
- SoundNotifyDataStorage storage(pluginLink);
- storage.init();
- SettingsDialog dlg(storage);
- if (dlg.DoModal() == IDOK)
- storage.commit();
- }
- catch (...)
- {
- MessageBox(0, TEXT("Unknown error occured while configuring"), TEXT("XSoundNotify Error"), MB_OK | MB_ICONERROR);
- }
-
- return 0;
-}
-
-extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
-{
- return &pluginInfo;
-}
-
-extern "C" __declspec(dllexport) const MUUID interfaces[] = {MIID_TESTPLUGIN, MIID_LAST};
-extern "C" __declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
-{
- return interfaces;
-}
-
-INT processEvent(WPARAM wParam, LPARAM lParam)
-{
- try
- {
- if (!isReceiveMessage(lParam))
- return 0;
-
- xsn_string sound = getContactSound((HANDLE)wParam);
- if (!sound.empty())
- PlaySound(sound.c_str(), nullptr, SND_ASYNC | SND_FILENAME);
- }
- catch (std::exception & )
- {
- // log
- }
- catch (...)
- {
- // log
- }
-
- return 0;
-}
-
-extern "C" int __declspec(dllexport) Load(PLUGINLINK *link)
-{
- CLISTMENUITEM mi;
-
- pluginLink=link;
- CreateServiceFunction("XSoundNotify/MenuCommand", PluginMenuCommand);
- ZeroMemory(&mi,sizeof(mi));
- mi.cbSize=sizeof(mi);
- mi.position=-0x7FFFFFFF;
- mi.flags=0;
- mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
- mi.pszName=LPGEN("&XSoundNotify Plugin");
- mi.pszService="XSoundNotify/MenuCommand";
- CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&mi);
- AddEventHook = HookEvent(ME_DB_EVENT_ADDED, processEvent);
-
- return 0;
-}
-
-extern "C" int __declspec(dllexport) Unload(void)
-{
- UnhookEvent(AddEventHook);
- return 0;
-}
-
diff --git a/plugins/XSoundNotify/XSoundNotify_10.vcxproj b/plugins/XSoundNotify/XSoundNotify_10.vcxproj new file mode 100644 index 0000000000..bae742710a --- /dev/null +++ b/plugins/XSoundNotify/XSoundNotify_10.vcxproj @@ -0,0 +1,218 @@ +п»ї<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.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="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectName>XSoundNotify</ProjectName>
+ <ProjectGuid>{5935CC24-A1C9-4CF9-8B1C-1AA2321627DE}</ProjectGuid>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\Obj\$(ProjectName)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)64\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\Obj\$(ProjectName)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)64\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\</IntDir>
+ <IgnoreImportLibrary>true</IgnoreImportLibrary>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
+ <StringPooling>true</StringPooling>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <Optimization>Full</Optimization>
+ <WarningLevel>Level3</WarningLevel>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;..\..\..\boost;src\wtl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>Common.h</PrecompiledHeaderFile>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ <Link>
+ <LinkDLL>true</LinkDLL>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>$(ProfileDir)..\..\bin10\lib</AdditionalLibraryDirectories>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <AdditionalOptions>/PDBALTPATH:%_PDB% %(AdditionalOptions)</AdditionalOptions>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
+ <StringPooling>true</StringPooling>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <Optimization>Full</Optimization>
+ <WarningLevel>Level3</WarningLevel>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;..\..\..\boost;src\wtl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN64;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>Common.h</PrecompiledHeaderFile>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ <Link>
+ <LinkDLL>true</LinkDLL>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>$(ProfileDir)..\..\bin10\lib</AdditionalLibraryDirectories>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <AdditionalOptions>/PDBALTPATH:%_PDB% %(AdditionalOptions)</AdditionalOptions>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <FunctionLevelLinking>false</FunctionLevelLinking>
+ <Optimization>Disabled</Optimization>
+ <WarningLevel>Level3</WarningLevel>
+ <MinimalRebuild>true</MinimalRebuild>
+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;..\..\..\boost;src\wtl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>Common.h</PrecompiledHeaderFile>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ <Link>
+ <LinkDLL>true</LinkDLL>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>
+ </IgnoreSpecificDefaultLibraries>
+ <AdditionalLibraryDirectories>$(ProfileDir)..\..\bin10\lib</AdditionalLibraryDirectories>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <FunctionLevelLinking>false</FunctionLevelLinking>
+ <Optimization>Disabled</Optimization>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;..\..\..\boost;src\wtl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>Common.h</PrecompiledHeaderFile>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ <Link>
+ <LinkDLL>true</LinkDLL>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>
+ </IgnoreSpecificDefaultLibraries>
+ <AdditionalLibraryDirectories>$(ProfileDir)..\..\bin10\lib</AdditionalLibraryDirectories>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="src\Common.h" />
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\SettingsDialog.h" />
+ <ClInclude Include="src\SoundNotifyData.h" />
+ <ClInclude Include="src\SoundNotifyDataStorage.h" />
+ <ClInclude Include="src\Version.h" />
+ <ClInclude Include="src\xsn_types.h" />
+ <ClInclude Include="src\xsn_utils.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="src\SettingsDialog.cpp" />
+ <ClCompile Include="src\SoundNotifyData.cpp" />
+ <ClCompile Include="src\SoundNotifyDataStorage.cpp" />
+ <ClCompile Include="src\stdafx.cpp">
+ <PrecompiledHeader>Create</PrecompiledHeader>
+ </ClCompile>
+ <ClCompile Include="src\xsn_main.cpp" />
+ <ClCompile Include="src\xsn_types.cpp" />
+ <ClCompile Include="src\xsn_utils.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="res\Version.rc" />
+ <ResourceCompile Include="res\XSoundNotify.rc" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/plugins/XSoundNotify/XSoundNotify_10.vcxproj.filters b/plugins/XSoundNotify/XSoundNotify_10.vcxproj.filters new file mode 100644 index 0000000000..88ebdcf54f --- /dev/null +++ b/plugins/XSoundNotify/XSoundNotify_10.vcxproj.filters @@ -0,0 +1,71 @@ +п»ї<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{b2391aba-83eb-4e21-b831-6ebaf38ca1a7}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{bc6a0629-d782-4ba0-b23b-7691cfaf03fc}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{933468af-a762-4a74-8a66-e4e1d2d030a4}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="src\resource.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\SettingsDialog.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\SoundNotifyData.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\SoundNotifyDataStorage.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\xsn_types.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\xsn_utils.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Common.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Version.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="src\SettingsDialog.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\SoundNotifyData.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\SoundNotifyDataStorage.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\xsn_main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\xsn_types.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\xsn_utils.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\stdafx.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="res\XSoundNotify.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ <ResourceCompile Include="res\Version.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
+</Project>
\ No newline at end of file diff --git a/plugins/XSoundNotify/XSoundNotify_11.vcxproj b/plugins/XSoundNotify/XSoundNotify_11.vcxproj new file mode 100644 index 0000000000..b9be746aa8 --- /dev/null +++ b/plugins/XSoundNotify/XSoundNotify_11.vcxproj @@ -0,0 +1,226 @@ +п»ї<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.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="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectName>XSoundNotify</ProjectName>
+ <ProjectGuid>{5935CC24-A1C9-4CF9-8B1C-1AA2321627DE}</ProjectGuid>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v110_xp</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v110_xp</PlatformToolset>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v110_xp</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ <PlatformToolset>v110_xp</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\Obj\$(ProjectName)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)64\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\Obj\$(ProjectName)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)64\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\</IntDir>
+ <IgnoreImportLibrary>true</IgnoreImportLibrary>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
+ <StringPooling>true</StringPooling>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <Optimization>Full</Optimization>
+ <WarningLevel>Level3</WarningLevel>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;..\..\..\boost;src\wtl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>Common.h</PrecompiledHeaderFile>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ <Link>
+ <LinkDLL>true</LinkDLL>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>$(ProfileDir)..\..\bin11\lib</AdditionalLibraryDirectories>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <AdditionalOptions>/PDBALTPATH:%_PDB% %(AdditionalOptions)</AdditionalOptions>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
+ <StringPooling>true</StringPooling>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <Optimization>Full</Optimization>
+ <WarningLevel>Level3</WarningLevel>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;..\..\..\boost;src\wtl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN64;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>Common.h</PrecompiledHeaderFile>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ <Link>
+ <LinkDLL>true</LinkDLL>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>$(ProfileDir)..\..\bin11\lib</AdditionalLibraryDirectories>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <AdditionalOptions>/PDBALTPATH:%_PDB% %(AdditionalOptions)</AdditionalOptions>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <FunctionLevelLinking>false</FunctionLevelLinking>
+ <Optimization>Disabled</Optimization>
+ <WarningLevel>Level3</WarningLevel>
+ <MinimalRebuild>true</MinimalRebuild>
+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;..\..\..\boost;src\wtl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>Common.h</PrecompiledHeaderFile>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ <Link>
+ <LinkDLL>true</LinkDLL>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>
+ </IgnoreSpecificDefaultLibraries>
+ <AdditionalLibraryDirectories>$(ProfileDir)..\..\bin11\lib</AdditionalLibraryDirectories>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <FunctionLevelLinking>false</FunctionLevelLinking>
+ <Optimization>Disabled</Optimization>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;..\..\..\boost;src\wtl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN64;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <PrecompiledHeader>Use</PrecompiledHeader>
+ <PrecompiledHeaderFile>Common.h</PrecompiledHeaderFile>
+ </ClCompile>
+ <ResourceCompile>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ <Link>
+ <LinkDLL>true</LinkDLL>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <IgnoreSpecificDefaultLibraries>
+ </IgnoreSpecificDefaultLibraries>
+ <AdditionalLibraryDirectories>$(ProfileDir)..\..\bin11\lib</AdditionalLibraryDirectories>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClInclude Include="src\Common.h" />
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\SettingsDialog.h" />
+ <ClInclude Include="src\SoundNotifyData.h" />
+ <ClInclude Include="src\SoundNotifyDataStorage.h" />
+ <ClInclude Include="src\Version.h" />
+ <ClInclude Include="src\xsn_types.h" />
+ <ClInclude Include="src\xsn_utils.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="src\SettingsDialog.cpp" />
+ <ClCompile Include="src\SoundNotifyData.cpp" />
+ <ClCompile Include="src\SoundNotifyDataStorage.cpp" />
+ <ClCompile Include="src\stdafx.cpp">
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
+ <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
+ </ClCompile>
+ <ClCompile Include="src\xsn_main.cpp" />
+ <ClCompile Include="src\xsn_types.cpp" />
+ <ClCompile Include="src\xsn_utils.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="res\Version.rc" />
+ <ResourceCompile Include="res\XSoundNotify.rc" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/plugins/XSoundNotify/XSoundNotify_11.vcxproj.filters b/plugins/XSoundNotify/XSoundNotify_11.vcxproj.filters new file mode 100644 index 0000000000..88ebdcf54f --- /dev/null +++ b/plugins/XSoundNotify/XSoundNotify_11.vcxproj.filters @@ -0,0 +1,71 @@ +п»ї<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{b2391aba-83eb-4e21-b831-6ebaf38ca1a7}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{bc6a0629-d782-4ba0-b23b-7691cfaf03fc}</UniqueIdentifier>
+ </Filter>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{933468af-a762-4a74-8a66-e4e1d2d030a4}</UniqueIdentifier>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="src\resource.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\SettingsDialog.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\SoundNotifyData.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\SoundNotifyDataStorage.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\xsn_types.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\xsn_utils.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Common.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\Version.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="src\SettingsDialog.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\SoundNotifyData.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\SoundNotifyDataStorage.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\xsn_main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\xsn_types.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\xsn_utils.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\stdafx.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="res\XSoundNotify.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ <ResourceCompile Include="res\Version.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
+</Project>
\ No newline at end of file diff --git a/plugins/!NotAdopted/XSoundNotify/README b/plugins/XSoundNotify/docs/README index d855b95460..d855b95460 100644 --- a/plugins/!NotAdopted/XSoundNotify/README +++ b/plugins/XSoundNotify/docs/README diff --git a/plugins/XSoundNotify/res/Version.rc b/plugins/XSoundNotify/res/Version.rc new file mode 100644 index 0000000000..5bfbab4754 --- /dev/null +++ b/plugins/XSoundNotify/res/Version.rc @@ -0,0 +1,38 @@ +// Microsoft Visual C++ generated resource script.
+//
+#ifdef APSTUDIO_INVOKED
+#error this file is not editable by Microsoft Visual C++
+#endif //APSTUDIO_INVOKED
+
+#include "afxres.h"
+#include "..\src\version.h"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION __FILEVERSION_STRING
+ PRODUCTVERSION __FILEVERSION_STRING
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x0L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "000004b0"
+ BEGIN
+ VALUE "FileDescription", __DESCRIPTION
+ VALUE "InternalName", __PLUGIN_NAME
+ VALUE "LegalCopyright", __COPYRIGHT
+ VALUE "OriginalFilename", __FILENAME
+ VALUE "ProductName", __PLUGIN_NAME
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x0, 1200
+ END
+END
diff --git a/plugins/!NotAdopted/XSoundNotify/XSoundNotify.rc b/plugins/XSoundNotify/res/XSoundNotify.rc Binary files differindex ab42834a08..dd30c6b593 100644 --- a/plugins/!NotAdopted/XSoundNotify/XSoundNotify.rc +++ b/plugins/XSoundNotify/res/XSoundNotify.rc diff --git a/plugins/XSoundNotify/src/Common.h b/plugins/XSoundNotify/src/Common.h new file mode 100644 index 0000000000..7fd7dca140 --- /dev/null +++ b/plugins/XSoundNotify/src/Common.h @@ -0,0 +1,26 @@ +#include <windows.h>
+
+#include <unordered_map>
+
+#include <atlbase.h>
+#include <atlapp.h>
+#include <atlctrls.h>
+#include <atldlgs.h>
+
+#include <newpluginapi.h>
+#include <m_database.h>
+#include <m_protocols.h>
+#include <m_langpack.h>
+#include <m_clist.h>
+#include <m_skin.h>
+
+#include <boost/function.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include "resource.h"
+#include "Version.h"
+#include "xsn_types.h"
+#include "SoundNotifyData.h"
+#include "SoundNotifyDataStorage.h"
+#include "SettingsDialog.h"
+#include "xsn_utils.h"
diff --git a/plugins/!NotAdopted/XSoundNotify/SettingsDialog.cpp b/plugins/XSoundNotify/src/SettingsDialog.cpp index 69b64d776f..151e07225e 100644 --- a/plugins/!NotAdopted/XSoundNotify/SettingsDialog.cpp +++ b/plugins/XSoundNotify/src/SettingsDialog.cpp @@ -1,5 +1,4 @@ -#include "SettingsDialog.h"
-//#include "DebugLogger.hpp"
+#include "Common.h"
template <typename T>
T * GetComboBoxData(CComboBox & ctrl)
@@ -115,10 +114,11 @@ void SettingsDialog::setSoundLabelText(LPCTSTR text) _soundLabel.SetWindowText(PathFindFileName(text));
}
-void SettingsDialog::addProtocolItem(ProtocolTable::value_type & value)
+void SettingsDialog::addProtocolItem(ProtocolTable::value_type &value)
{
wchar_t protocol[30];
- mbstowcs(protocol, value.first.c_str(), 30);
+ size_t convertedChars = 0;
+ mbstowcs_s(&convertedChars, protocol, value.first.c_str(), 30);
int idx = _protoCombo.AddString(protocol);
_protoCombo.SetItemData(idx, (DWORD_PTR)(&value));
}
diff --git a/plugins/!NotAdopted/XSoundNotify/SettingsDialog.h b/plugins/XSoundNotify/src/SettingsDialog.h index c68503a6e8..8f22f1ea75 100644 --- a/plugins/!NotAdopted/XSoundNotify/SettingsDialog.h +++ b/plugins/XSoundNotify/src/SettingsDialog.h @@ -1,14 +1,6 @@ #ifndef __XSN_SETTINGS_DIALOG_H
#define __XSN_SETTINGS_DIALOG_H
-#include <atlbase.h>
-#include <atlwin.h>
-#include <atlapp.h>
-#include <atlctrls.h>
-#include <atldlgs.h>
-#include "resource.h"
-#include "SoundNotifyDataStorage.h"
-
class SettingsDialog : public CDialogImpl<SettingsDialog>
{
private:
diff --git a/plugins/!NotAdopted/XSoundNotify/SoundNotifyData.cpp b/plugins/XSoundNotify/src/SoundNotifyData.cpp index 1876db6ba0..29723384c7 100644 --- a/plugins/!NotAdopted/XSoundNotify/SoundNotifyData.cpp +++ b/plugins/XSoundNotify/src/SoundNotifyData.cpp @@ -1,4 +1,4 @@ -#include "SoundNotifyData.h"
+#include "Common.h"
SoundNotifyData::SoundNotifyData() : _contact(0), _soundChanged(false)
{
diff --git a/plugins/!NotAdopted/XSoundNotify/SoundNotifyData.h b/plugins/XSoundNotify/src/SoundNotifyData.h index 18cb4844a4..13076f76e2 100644 --- a/plugins/!NotAdopted/XSoundNotify/SoundNotifyData.h +++ b/plugins/XSoundNotify/src/SoundNotifyData.h @@ -1,10 +1,6 @@ #ifndef __XSN_DATA_H
#define __XSN_DATA_H
-#include <unordered_map>
-#include "xsn_types.h"
-#include <windows.h>
-
class SoundNotifyData
{
public:
diff --git a/plugins/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.cpp b/plugins/XSoundNotify/src/SoundNotifyDataStorage.cpp index bd1b90df52..93a81bfed6 100644 --- a/plugins/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.cpp +++ b/plugins/XSoundNotify/src/SoundNotifyDataStorage.cpp @@ -1,10 +1,6 @@ -#include "SoundNotifyDataStorage.h"
-#include <m_database.h>
-#include <m_protocols.h>
-#include "xsn_utils.h"
-//#include "DebugLogger.hpp"
+#include "Common.h"
-SoundNotifyDataStorage::SoundNotifyDataStorage(PLUGINLINK * pl) : pluginLink(pl)
+SoundNotifyDataStorage::SoundNotifyDataStorage()
{
}
diff --git a/plugins/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.h b/plugins/XSoundNotify/src/SoundNotifyDataStorage.h index 7dbf03c494..52d5c307a0 100644 --- a/plugins/!NotAdopted/XSoundNotify/SoundNotifyDataStorage.h +++ b/plugins/XSoundNotify/src/SoundNotifyDataStorage.h @@ -1,14 +1,10 @@ #ifndef _XSN_DATA_STORAGE
#define _XSN_DATA_STORAGE
-#include "SoundNotifyData.h"
-#include <newpluginapi.h>
-#include <boost/function.hpp>
-
class SoundNotifyDataStorage
{
public:
- SoundNotifyDataStorage(PLUGINLINK * pl);
+ SoundNotifyDataStorage();
void init();
void commit();
@@ -21,8 +17,6 @@ protected: void registerProtocols();
private:
- PLUGINLINK * pluginLink;
-
ProtocolTable _protocolTable;
ModuleConvertTable _moduleTable;
diff --git a/plugins/XSoundNotify/src/Version.h b/plugins/XSoundNotify/src/Version.h new file mode 100644 index 0000000000..a3918c6535 --- /dev/null +++ b/plugins/XSoundNotify/src/Version.h @@ -0,0 +1,14 @@ +#define __MAJOR_VERSION 1
+#define __MINOR_VERSION 0
+#define __RELEASE_NUM 0
+#define __BUILD_NUM 0
+
+#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM
+
+#define __PLUGIN_NAME "XSoundNotify"
+#define __FILENAME "XSoundNotify.dll"
+#define __DESCRIPTION "Provides extended options for sound notifications."
+#define __AUTHOR "Roman Torsten"
+#define __AUTHOREMAIL "rs_torsten-public@yahoo.com"
+#define __AUTHORWEB "http://miranda-ng.org/"
+#define __COPYRIGHT "© 2011 Roman Torsten"
diff --git a/plugins/!NotAdopted/XSoundNotify/resource.h b/plugins/XSoundNotify/src/resource.h Binary files differindex fcd39e7cf3..fcd39e7cf3 100644 --- a/plugins/!NotAdopted/XSoundNotify/resource.h +++ b/plugins/XSoundNotify/src/resource.h diff --git a/plugins/XSoundNotify/src/stdafx.cpp b/plugins/XSoundNotify/src/stdafx.cpp new file mode 100644 index 0000000000..1976d867da --- /dev/null +++ b/plugins/XSoundNotify/src/stdafx.cpp @@ -0,0 +1,18 @@ +/*
+Copyright (C) 2012-13 Miranda NG Project (http://miranda-ng.org)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "common.h"
\ No newline at end of file diff --git a/plugins/XSoundNotify/src/wtl/include/atlapp.h b/plugins/XSoundNotify/src/wtl/include/atlapp.h new file mode 100644 index 0000000000..504bc53aaa --- /dev/null +++ b/plugins/XSoundNotify/src/wtl/include/atlapp.h @@ -0,0 +1,2125 @@ +// Windows Template Library - WTL version 8.1
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//
+// This file is a part of the Windows Template Library.
+// The use and distribution terms for this software are covered by the
+// Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
+// which can be found in the file CPL.TXT at the root of this distribution.
+// By using this software in any fashion, you are agreeing to be bound by
+// the terms of this license. You must not remove this notice, or
+// any other, from this software.
+
+#ifndef __ATLAPP_H__
+#define __ATLAPP_H__
+
+#pragma once
+
+#ifndef __cplusplus
+ #error WTL requires C++ compilation (use a .cpp suffix)
+#endif
+
+#ifndef __ATLBASE_H__
+ #error atlapp.h requires atlbase.h to be included first
+#endif
+
+#ifndef _WIN32_WCE
+ #if (WINVER < 0x0400)
+ #error WTL requires Windows version 4.0 or higher
+ #endif
+
+ #if (_WIN32_IE < 0x0300)
+ #error WTL requires IE version 3.0 or higher
+ #endif
+#endif
+
+#ifdef _ATL_NO_COMMODULE
+ #error WTL requires that _ATL_NO_COMMODULE is not defined
+#endif
+
+#if (_ATL_VER >= 0x0900) && defined(_ATL_MIN_CRT)
+ #error _ATL_MIN_CRT is not supported with ATL 9.0 and higher
+#endif
+
+#if defined(_WIN32_WCE) && defined(_ATL_MIN_CRT)
+ #pragma message("Warning: WTL for Windows CE doesn't use _ATL_MIN_CRT")
+#endif
+
+#include <limits.h>
+#if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE)
+ #include <process.h> // for _beginthreadex
+#endif
+
+#if (_ATL_VER < 0x0800) && !defined(_DEBUG)
+ #include <stdio.h>
+#endif
+
+#include <commctrl.h>
+#ifndef _WIN32_WCE
+ #pragma comment(lib, "comctl32.lib")
+#endif
+
+#ifndef _WIN32_WCE
+ #include "atlres.h"
+#else // CE specific
+ #include "atlresce.h"
+#endif // _WIN32_WCE
+
+// We need to disable this warning because of template class arguments
+#pragma warning(disable: 4127)
+
+#if (_ATL_VER >= 0x0900) && !defined(_SECURE_ATL)
+ #define _SECURE_ATL 1
+#endif
+
+
+///////////////////////////////////////////////////////////////////////////////
+// WTL version number
+
+#define _WTL_VER 0x0810
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Classes in this file:
+//
+// CMessageFilter
+// CIdleHandler
+// CMessageLoop
+//
+// CAppModule
+// CServerAppModule
+//
+// CRegKeyEx
+//
+// Global functions:
+// AtlGetDefaultGuiFont()
+// AtlCreateControlFont()
+// AtlCreateBoldFont()
+// AtlInitCommonControls()
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Global support for Windows CE
+
+#ifdef _WIN32_WCE
+
+#ifndef SW_SHOWDEFAULT
+ #define SW_SHOWDEFAULT SW_SHOWNORMAL
+#endif // !SW_SHOWDEFAULT
+
+// These get's OR-ed in a constant and will have no effect.
+// Defining them reduces the number of #ifdefs required for CE.
+#define LR_DEFAULTSIZE 0
+#define LR_LOADFROMFILE 0
+
+#ifndef SM_CXCURSOR
+ #define SM_CXCURSOR 13
+#endif
+#ifndef SM_CYCURSOR
+ #define SM_CYCURSOR 14
+#endif
+
+inline BOOL IsMenu(HMENU hMenu)
+{
+ MENUITEMINFO mii = { sizeof(MENUITEMINFO) };
+ ::SetLastError(0);
+ BOOL bRet = ::GetMenuItemInfo(hMenu, 0, TRUE, &mii);
+ if(!bRet)
+ bRet = (::GetLastError() != ERROR_INVALID_MENU_HANDLE) ? TRUE : FALSE;
+ return bRet;
+}
+
+#if (_WIN32_WCE >= 410)
+extern "C" void WINAPI ListView_SetItemSpacing(HWND hwndLV, int iHeight);
+#endif // (_WIN32_WCE >= 410)
+
+inline int MulDiv(IN int nNumber, IN int nNumerator, IN int nDenominator)
+{
+ __int64 multiple = nNumber * nNumerator;
+ return static_cast<int>(multiple / nDenominator);
+}
+
+#if (_ATL_VER >= 0x0800)
+
+#ifndef _WTL_KEEP_WS_OVERLAPPEDWINDOW
+ #ifdef WS_OVERLAPPEDWINDOW
+ #undef WS_OVERLAPPEDWINDOW
+ #define WS_OVERLAPPEDWINDOW 0
+ #endif // WS_OVERLAPPEDWINDOW
+#endif // !_WTL_KEEP_WS_OVERLAPPEDWINDOW
+
+#ifndef RDW_FRAME
+ #define RDW_FRAME 0
+#endif // !RDW_FRAME
+
+#ifndef WM_WINDOWPOSCHANGING
+ #define WM_WINDOWPOSCHANGING 0
+#endif // !WM_WINDOWPOSCHANGING
+
+#define FreeResource(x)
+#define UnlockResource(x)
+
+namespace ATL
+{
+ inline HRESULT CComModule::RegisterClassObjects(DWORD /*dwClsContext*/, DWORD /*dwFlags*/) throw()
+ { return E_NOTIMPL; }
+ inline HRESULT CComModule::RevokeClassObjects() throw()
+ { return E_NOTIMPL; }
+}; // namespace ATL
+
+#ifndef lstrlenW
+ #define lstrlenW (int)ATL::lstrlenW
+#endif // lstrlenW
+
+inline int WINAPI lstrlenA(LPCSTR lpszString)
+{ return ATL::lstrlenA(lpszString); }
+
+#ifdef lstrcpyn
+ #undef lstrcpyn
+ #define lstrcpyn ATL::lstrcpynW
+#endif // lstrcpyn
+
+#ifndef SetWindowLongPtrW
+ inline LONG_PTR tmp_SetWindowLongPtrW( HWND hWnd, int nIndex, LONG_PTR dwNewLong )
+ {
+ return( ::SetWindowLongW( hWnd, nIndex, LONG( dwNewLong ) ) );
+ }
+ #define SetWindowLongPtrW tmp_SetWindowLongPtrW
+#endif
+
+#ifndef GetWindowLongPtrW
+ inline LONG_PTR tmp_GetWindowLongPtrW( HWND hWnd, int nIndex )
+ {
+ return( ::GetWindowLongW( hWnd, nIndex ) );
+ }
+ #define GetWindowLongPtrW tmp_GetWindowLongPtrW
+#endif
+
+#ifndef LongToPtr
+ #define LongToPtr(x) ((void*)x)
+#endif
+
+#ifndef PtrToInt
+ #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
+#endif
+
+#else // !(_ATL_VER >= 0x0800)
+
+#ifdef lstrlenW
+ #undef lstrlenW
+ #define lstrlenW (int)::wcslen
+#endif // lstrlenW
+
+#define lstrlenA (int)strlen
+
+#ifndef lstrcpyn
+ inline LPTSTR lstrcpyn(LPTSTR lpstrDest, LPCTSTR lpstrSrc, int nLength)
+ {
+ if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
+ return NULL;
+ int nLen = min(lstrlen(lpstrSrc), nLength - 1);
+ LPTSTR lpstrRet = (LPTSTR)memcpy(lpstrDest, lpstrSrc, nLen * sizeof(TCHAR));
+ lpstrDest[nLen] = 0;
+ return lpstrRet;
+ }
+#endif // !lstrcpyn
+
+#ifndef lstrcpynW
+ inline LPWSTR lstrcpynW(LPWSTR lpstrDest, LPCWSTR lpstrSrc, int nLength)
+ {
+ return lstrcpyn(lpstrDest, lpstrSrc, nLength); // WinCE is Unicode only
+ }
+#endif // !lstrcpynW
+
+#ifndef lstrcpynA
+ inline LPSTR lstrcpynA(LPSTR lpstrDest, LPCSTR lpstrSrc, int nLength)
+ {
+ if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
+ return NULL;
+ int nLen = min(lstrlenA(lpstrSrc), nLength - 1);
+ LPSTR lpstrRet = (LPSTR)memcpy(lpstrDest, lpstrSrc, nLen * sizeof(char));
+ lpstrDest[nLen] = 0;
+ return lpstrRet;
+ }
+#endif // !lstrcpyn
+
+#ifdef TrackPopupMenu
+ #undef TrackPopupMenu
+#endif // TrackPopupMenu
+
+#define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd) \
+static CWndClassInfo& GetWndClassInfo() \
+{ \
+ static CWndClassInfo wc = \
+ { \
+ { style, StartWindowProc, \
+ 0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName }, \
+ NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
+ }; \
+ return wc; \
+}
+
+#ifndef _MAX_FNAME
+ #define _MAX_FNAME _MAX_PATH
+#endif // _MAX_FNAME
+
+#if (_WIN32_WCE < 400)
+ #define MAKEINTATOM(i) (LPTSTR)((ULONG_PTR)((WORD)(i)))
+#endif // (_WIN32_WCE < 400)
+
+#if (_WIN32_WCE < 410)
+ #define WHEEL_PAGESCROLL (UINT_MAX)
+ #define WHEEL_DELTA 120
+#endif // (_WIN32_WCE < 410)
+
+#ifdef DrawIcon
+ #undef DrawIcon
+#endif
+
+#ifndef VARCMP_LT
+ #define VARCMP_LT 0
+#endif
+#ifndef VARCMP_EQ
+ #define VARCMP_EQ 1
+#endif
+#ifndef VARCMP_GT
+ #define VARCMP_GT 2
+#endif
+#ifndef VARCMP_NULL
+ #define VARCMP_NULL 3
+#endif
+
+#ifndef RDW_ALLCHILDREN
+ #define RDW_ALLCHILDREN 0
+#endif
+
+#endif // !(_ATL_VER >= 0x0800)
+
+#endif // _WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Global support for using original VC++ 6.0 headers with WTL
+
+#ifndef _ATL_NO_OLD_HEADERS_WIN64
+#if !defined(_WIN64) && (_ATL_VER < 0x0700)
+
+ #ifndef PSM_INSERTPAGE
+ #define PSM_INSERTPAGE (WM_USER + 119)
+ #endif // !PSM_INSERTPAGE
+
+ #ifndef GetClassLongPtr
+ #define GetClassLongPtrA GetClassLongA
+ #define GetClassLongPtrW GetClassLongW
+ #ifdef UNICODE
+ #define GetClassLongPtr GetClassLongPtrW
+ #else
+ #define GetClassLongPtr GetClassLongPtrA
+ #endif // !UNICODE
+ #endif // !GetClassLongPtr
+
+ #ifndef GCLP_HICONSM
+ #define GCLP_HICONSM (-34)
+ #endif // !GCLP_HICONSM
+
+ #ifndef GetWindowLongPtr
+ #define GetWindowLongPtrA GetWindowLongA
+ #define GetWindowLongPtrW GetWindowLongW
+ #ifdef UNICODE
+ #define GetWindowLongPtr GetWindowLongPtrW
+ #else
+ #define GetWindowLongPtr GetWindowLongPtrA
+ #endif // !UNICODE
+ #endif // !GetWindowLongPtr
+
+ #ifndef SetWindowLongPtr
+ #define SetWindowLongPtrA SetWindowLongA
+ #define SetWindowLongPtrW SetWindowLongW
+ #ifdef UNICODE
+ #define SetWindowLongPtr SetWindowLongPtrW
+ #else
+ #define SetWindowLongPtr SetWindowLongPtrA
+ #endif // !UNICODE
+ #endif // !SetWindowLongPtr
+
+ #ifndef GWLP_WNDPROC
+ #define GWLP_WNDPROC (-4)
+ #endif
+ #ifndef GWLP_HINSTANCE
+ #define GWLP_HINSTANCE (-6)
+ #endif
+ #ifndef GWLP_HWNDPARENT
+ #define GWLP_HWNDPARENT (-8)
+ #endif
+ #ifndef GWLP_USERDATA
+ #define GWLP_USERDATA (-21)
+ #endif
+ #ifndef GWLP_ID
+ #define GWLP_ID (-12)
+ #endif
+
+ #ifndef DWLP_MSGRESULT
+ #define DWLP_MSGRESULT 0
+ #endif
+
+ typedef long LONG_PTR;
+ typedef unsigned long ULONG_PTR;
+ typedef ULONG_PTR DWORD_PTR;
+
+ #ifndef HandleToUlong
+ #define HandleToUlong( h ) ((ULONG)(ULONG_PTR)(h) )
+ #endif
+ #ifndef HandleToLong
+ #define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
+ #endif
+ #ifndef LongToHandle
+ #define LongToHandle( h) ((HANDLE)(LONG_PTR) (h))
+ #endif
+ #ifndef PtrToUlong
+ #define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
+ #endif
+ #ifndef PtrToLong
+ #define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
+ #endif
+ #ifndef PtrToUint
+ #define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
+ #endif
+ #ifndef PtrToInt
+ #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
+ #endif
+ #ifndef PtrToUshort
+ #define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
+ #endif
+ #ifndef PtrToShort
+ #define PtrToShort( p ) ((short)(LONG_PTR)(p) )
+ #endif
+ #ifndef IntToPtr
+ #define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i))
+ #endif
+ #ifndef UIntToPtr
+ #define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui))
+ #endif
+ #ifndef LongToPtr
+ #define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l))
+ #endif
+ #ifndef ULongToPtr
+ #define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul))
+ #endif
+
+#endif // !defined(_WIN64) && (_ATL_VER < 0x0700)
+#endif // !_ATL_NO_OLD_HEADERS_WIN64
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Global support for SecureHelper functions
+
+#ifndef _TRUNCATE
+ #define _TRUNCATE ((size_t)-1)
+#endif
+
+#ifndef _ERRCODE_DEFINED
+ #define _ERRCODE_DEFINED
+ typedef int errno_t;
+#endif
+
+#ifndef _SECURECRT_ERRCODE_VALUES_DEFINED
+ #define _SECURECRT_ERRCODE_VALUES_DEFINED
+ #define EINVAL 22
+ #define STRUNCATE 80
+#endif
+
+#ifndef _countof
+ #define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
+#endif
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Miscellaneous global support
+
+// define useful macros from winuser.h
+#ifndef IS_INTRESOURCE
+ #define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0)
+#endif // IS_INTRESOURCE
+
+// protect template members from windowsx.h macros
+#ifdef _INC_WINDOWSX
+ #undef SubclassWindow
+#endif // _INC_WINDOWSX
+
+// define useful macros from windowsx.h
+#ifndef GET_X_LPARAM
+ #define GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam))
+#endif
+#ifndef GET_Y_LPARAM
+ #define GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam))
+#endif
+
+// Dummy structs for compiling with /CLR
+#if (_MSC_VER >= 1300) && defined(_MANAGED)
+ __if_not_exists(_IMAGELIST::_IMAGELIST) { struct _IMAGELIST { }; }
+ __if_not_exists(_TREEITEM::_TREEITEM) { struct _TREEITEM { }; }
+ __if_not_exists(_PSP::_PSP) { struct _PSP { }; }
+#endif
+
+// Define ATLVERIFY macro for ATL3
+#if (_ATL_VER < 0x0700)
+ #ifndef ATLVERIFY
+ #ifdef _DEBUG
+ #define ATLVERIFY(expr) ATLASSERT(expr)
+ #else
+ #define ATLVERIFY(expr) (expr)
+ #endif // DEBUG
+ #endif // ATLVERIFY
+#endif // (_ATL_VER < 0x0700)
+
+// Forward declaration for ATL3 and ATL11 fix
+#if (((_ATL_VER < 0x0700) && defined(_ATL_DLL)) || (_ATL_VER >= 0x0B00)) && !defined(_WIN32_WCE)
+ namespace ATL { HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor); };
+#endif
+
+#ifndef WM_MOUSEHWHEEL
+ #define WM_MOUSEHWHEEL 0x020E
+#endif
+
+
+namespace WTL
+{
+
+#if (_ATL_VER >= 0x0700)
+ DECLARE_TRACE_CATEGORY(atlTraceUI);
+ #ifdef _DEBUG
+ __declspec(selectany) ATL::CTraceCategory atlTraceUI(_T("atlTraceUI"));
+ #endif // _DEBUG
+#else // !(_ATL_VER >= 0x0700)
+ enum wtlTraceFlags
+ {
+ atlTraceUI = 0x10000000
+ };
+#endif // !(_ATL_VER >= 0x0700)
+
+// Windows version helper
+inline bool AtlIsOldWindows()
+{
+ OSVERSIONINFO ovi = { 0 };
+ ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ BOOL bRet = ::GetVersionEx(&ovi);
+ return (!bRet || !((ovi.dwMajorVersion >= 5) || (ovi.dwMajorVersion == 4 && ovi.dwMinorVersion >= 90)));
+}
+
+// Default GUI font helper - "MS Shell Dlg" stock font
+inline HFONT AtlGetDefaultGuiFont()
+{
+#ifndef _WIN32_WCE
+ return (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
+#else // CE specific
+ return (HFONT)::GetStockObject(SYSTEM_FONT);
+#endif // _WIN32_WCE
+}
+
+// Control font helper - default font for controls not in a dialog
+// (NOTE: Caller owns the font, and should destroy it when it's no longer needed)
+inline HFONT AtlCreateControlFont()
+{
+#ifndef _WIN32_WCE
+ LOGFONT lf = { 0 };
+ ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0) != FALSE);
+ HFONT hFont = ::CreateFontIndirect(&lf);
+ ATLASSERT(hFont != NULL);
+ return hFont;
+#else // CE specific
+ return (HFONT)::GetStockObject(SYSTEM_FONT);
+#endif // _WIN32_WCE
+}
+
+// Bold font helper
+// (NOTE: Caller owns the font, and should destroy it when it's no longer needed)
+inline HFONT AtlCreateBoldFont(HFONT hFont = NULL)
+{
+ LOGFONT lf = { 0 };
+#ifndef _WIN32_WCE
+ if(hFont == NULL)
+ ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0) != FALSE);
+ else
+ ATLVERIFY(::GetObject(hFont, sizeof(LOGFONT), &lf) == sizeof(LOGFONT));
+#else // CE specific
+ if(hFont == NULL)
+ hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
+ ATLVERIFY(::GetObject(hFont, sizeof(LOGFONT), &lf) == sizeof(LOGFONT));
+#endif // _WIN32_WCE
+ lf.lfWeight = FW_BOLD;
+ HFONT hFontBold = ::CreateFontIndirect(&lf);
+ ATLASSERT(hFontBold != NULL);
+ return hFontBold;
+}
+
+// Common Controls initialization helper
+inline BOOL AtlInitCommonControls(DWORD dwFlags)
+{
+ INITCOMMONCONTROLSEX iccx = { sizeof(INITCOMMONCONTROLSEX), dwFlags };
+ BOOL bRet = ::InitCommonControlsEx(&iccx);
+ ATLASSERT(bRet);
+ return bRet;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+// RunTimeHelper - helper functions for Windows version and structure sizes
+
+// Not for Windows CE
+#if defined(_WIN32_WCE) && !defined(_WTL_NO_RUNTIME_STRUCT_SIZE)
+ #define _WTL_NO_RUNTIME_STRUCT_SIZE
+#endif
+
+#ifndef _WTL_NO_RUNTIME_STRUCT_SIZE
+
+#ifndef _SIZEOF_STRUCT
+ #define _SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
+#endif
+
+#if (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
+ #define REBARBANDINFO_V6_SIZE _SIZEOF_STRUCT(REBARBANDINFO, cxHeader)
+#endif // (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
+
+#if (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
+ #define LVGROUP_V5_SIZE _SIZEOF_STRUCT(LVGROUP, uAlign)
+#endif // (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
+
+#if (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
+ #define LVTILEINFO_V5_SIZE _SIZEOF_STRUCT(LVTILEINFO, puColumns)
+#endif // (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
+
+#if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
+ #define MCHITTESTINFO_V1_SIZE _SIZEOF_STRUCT(MCHITTESTINFO, st)
+#endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
+
+#if !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
+ #define NONCLIENTMETRICS_V1_SIZE _SIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont)
+#endif // !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
+
+#endif // !_WTL_NO_RUNTIME_STRUCT_SIZE
+
+namespace RunTimeHelper
+{
+#ifndef _WIN32_WCE
+ inline bool IsCommCtrl6()
+ {
+ DWORD dwMajor = 0, dwMinor = 0;
+ HRESULT hRet = ATL::AtlGetCommCtrlVersion(&dwMajor, &dwMinor);
+ return (SUCCEEDED(hRet) && (dwMajor >= 6));
+ }
+
+ inline bool IsVista()
+ {
+ OSVERSIONINFO ovi = { sizeof(OSVERSIONINFO) };
+ BOOL bRet = ::GetVersionEx(&ovi);
+ return ((bRet != FALSE) && (ovi.dwMajorVersion >= 6));
+ }
+
+ inline bool IsThemeAvailable()
+ {
+ bool bRet = false;
+
+ if(IsCommCtrl6())
+ {
+ HMODULE hThemeDLL = ::LoadLibrary(_T("uxtheme.dll"));
+ if(hThemeDLL != NULL)
+ {
+ typedef BOOL (STDAPICALLTYPE *PFN_IsThemeActive)();
+ PFN_IsThemeActive pfnIsThemeActive = (PFN_IsThemeActive)::GetProcAddress(hThemeDLL, "IsThemeActive");
+ ATLASSERT(pfnIsThemeActive != NULL);
+ bRet = (pfnIsThemeActive != NULL) && (pfnIsThemeActive() != FALSE);
+ if(bRet)
+ {
+ typedef BOOL (STDAPICALLTYPE *PFN_IsAppThemed)();
+ PFN_IsAppThemed pfnIsAppThemed = (PFN_IsAppThemed)::GetProcAddress(hThemeDLL, "IsAppThemed");
+ ATLASSERT(pfnIsAppThemed != NULL);
+ bRet = (pfnIsAppThemed != NULL) && (pfnIsAppThemed() != FALSE);
+ }
+
+ ::FreeLibrary(hThemeDLL);
+ }
+ }
+
+ return bRet;
+ }
+
+ inline bool IsWin7()
+ {
+ OSVERSIONINFO ovi = { sizeof(OSVERSIONINFO) };
+ BOOL bRet = ::GetVersionEx(&ovi);
+ return ((bRet != FALSE) && (ovi.dwMajorVersion == 6) && (ovi.dwMinorVersion >= 1));
+ }
+
+ inline bool IsRibbonUIAvailable()
+ {
+ static INT iRibbonUI = -1;
+
+#if defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
+ if (iRibbonUI == -1)
+ {
+ HMODULE hRibbonDLL = ::LoadLibrary(_T("propsys.dll"));
+ if (hRibbonDLL != NULL)
+ {
+ const GUID CLSID_UIRibbonFramework = { 0x926749fa, 0x2615, 0x4987, { 0x88, 0x45, 0xc3, 0x3e, 0x65, 0xf2, 0xb9, 0x57 } };
+ // block - create instance
+ {
+ ATL::CComPtr<IUnknown> pIUIFramework;
+ iRibbonUI = SUCCEEDED(pIUIFramework.CoCreateInstance(CLSID_UIRibbonFramework)) ? 1 : 0;
+ }
+ ::FreeLibrary(hRibbonDLL);
+ }
+ else
+ {
+ iRibbonUI = 0;
+ }
+ }
+#endif // defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7)
+
+ return (iRibbonUI == 1);
+ }
+
+#endif // !_WIN32_WCE
+
+ inline int SizeOf_REBARBANDINFO()
+ {
+ int nSize = sizeof(REBARBANDINFO);
+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
+ if(!(IsVista() && IsCommCtrl6()))
+ nSize = REBARBANDINFO_V6_SIZE;
+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
+ return nSize;
+ }
+
+#if (_WIN32_WINNT >= 0x501)
+ inline int SizeOf_LVGROUP()
+ {
+ int nSize = sizeof(LVGROUP);
+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
+ if(!IsVista())
+ nSize = LVGROUP_V5_SIZE;
+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
+ return nSize;
+ }
+
+ inline int SizeOf_LVTILEINFO()
+ {
+ int nSize = sizeof(LVTILEINFO);
+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
+ if(!IsVista())
+ nSize = LVTILEINFO_V5_SIZE;
+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
+ return nSize;
+ }
+#endif // (_WIN32_WINNT >= 0x501)
+
+ inline int SizeOf_MCHITTESTINFO()
+ {
+ int nSize = sizeof(MCHITTESTINFO);
+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+ if(!(IsVista() && IsCommCtrl6()))
+ nSize = MCHITTESTINFO_V1_SIZE;
+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+ return nSize;
+ }
+
+#ifndef _WIN32_WCE
+ inline int SizeOf_NONCLIENTMETRICS()
+ {
+ int nSize = sizeof(NONCLIENTMETRICS);
+#if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
+ if(!IsVista())
+ nSize = NONCLIENTMETRICS_V1_SIZE;
+#endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
+ return nSize;
+ }
+#endif // !_WIN32_WCE
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// ModuleHelper - helper functions for ATL3 and ATL7 module classes
+
+namespace ModuleHelper
+{
+ inline HINSTANCE GetModuleInstance()
+ {
+#if (_ATL_VER >= 0x0700)
+ return ATL::_AtlBaseModule.GetModuleInstance();
+#else // !(_ATL_VER >= 0x0700)
+ return ATL::_pModule->GetModuleInstance();
+#endif // !(_ATL_VER >= 0x0700)
+ }
+
+ inline HINSTANCE GetResourceInstance()
+ {
+#if (_ATL_VER >= 0x0700)
+ return ATL::_AtlBaseModule.GetResourceInstance();
+#else // !(_ATL_VER >= 0x0700)
+ return ATL::_pModule->GetResourceInstance();
+#endif // !(_ATL_VER >= 0x0700)
+ }
+
+ inline void AddCreateWndData(ATL::_AtlCreateWndData* pData, void* pObject)
+ {
+#if (_ATL_VER >= 0x0700)
+ ATL::_AtlWinModule.AddCreateWndData(pData, pObject);
+#else // !(_ATL_VER >= 0x0700)
+ ATL::_pModule->AddCreateWndData(pData, pObject);
+#endif // !(_ATL_VER >= 0x0700)
+ }
+
+ inline void* ExtractCreateWndData()
+ {
+#if (_ATL_VER >= 0x0700)
+ return ATL::_AtlWinModule.ExtractCreateWndData();
+#else // !(_ATL_VER >= 0x0700)
+ return ATL::_pModule->ExtractCreateWndData();
+#endif // !(_ATL_VER >= 0x0700)
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// SecureHelper - helper functions for VS2005 secure CRT
+
+namespace SecureHelper
+{
+ inline void strcpyA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc)
+ {
+#if _SECURE_ATL
+ ATL::Checked::strcpy_s(lpstrDest, cchDest, lpstrSrc);
+#else
+ if(cchDest > (size_t)lstrlenA(lpstrSrc))
+ ATLVERIFY(lstrcpyA(lpstrDest, lpstrSrc) != NULL);
+ else
+ ATLASSERT(FALSE);
+#endif
+ }
+
+ inline void strcpyW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc)
+ {
+#if _SECURE_ATL
+ ATL::Checked::wcscpy_s(lpstrDest, cchDest, lpstrSrc);
+#else
+ if(cchDest > (size_t)lstrlenW(lpstrSrc))
+ ATLVERIFY(lstrcpyW(lpstrDest, lpstrSrc) != NULL);
+ else
+ ATLASSERT(FALSE);
+#endif
+ }
+
+ inline void strcpy_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc)
+ {
+#ifdef _UNICODE
+ strcpyW_x(lpstrDest, cchDest, lpstrSrc);
+#else
+ strcpyA_x(lpstrDest, cchDest, lpstrSrc);
+#endif
+ }
+
+ inline errno_t strncpyA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc, size_t cchCount)
+ {
+#if _SECURE_ATL
+ return ATL::Checked::strncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
+#else
+ errno_t nRet = 0;
+ if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
+ {
+ nRet = EINVAL;
+ }
+ else if(cchCount == _TRUNCATE)
+ {
+ cchCount = min(cchDest - 1, size_t(lstrlenA(lpstrSrc)));
+ nRet = STRUNCATE;
+ }
+ else if(cchDest <= cchCount)
+ {
+ lpstrDest[0] = 0;
+ nRet = EINVAL;
+ }
+ if(nRet == 0 || nRet == STRUNCATE)
+ nRet = (lstrcpynA(lpstrDest, lpstrSrc, (int)cchCount + 1) != NULL) ? nRet : EINVAL;
+ ATLASSERT(nRet == 0 || nRet == STRUNCATE);
+ return nRet;
+#endif
+ }
+
+ inline errno_t strncpyW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc, size_t cchCount)
+ {
+#if _SECURE_ATL
+ return ATL::Checked::wcsncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
+#else
+ errno_t nRet = 0;
+ if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
+ {
+ nRet = EINVAL;
+ }
+ else if(cchCount == _TRUNCATE)
+ {
+ cchCount = min(cchDest - 1, size_t(lstrlenW(lpstrSrc)));
+ nRet = STRUNCATE;
+ }
+ else if(cchDest <= cchCount)
+ {
+ lpstrDest[0] = 0;
+ nRet = EINVAL;
+ }
+ if(nRet == 0 || nRet == STRUNCATE)
+ nRet = (lstrcpynW(lpstrDest, lpstrSrc, (int)cchCount + 1) != NULL) ? nRet : EINVAL;
+ ATLASSERT(nRet == 0 || nRet == STRUNCATE);
+ return nRet;
+#endif
+ }
+
+ inline errno_t strncpy_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc, size_t cchCount)
+ {
+#ifdef _UNICODE
+ return strncpyW_x(lpstrDest, cchDest, lpstrSrc, cchCount);
+#else
+ return strncpyA_x(lpstrDest, cchDest, lpstrSrc, cchCount);
+#endif
+ }
+
+ inline void strcatA_x(char* lpstrDest, size_t cchDest, const char* lpstrSrc)
+ {
+#if _SECURE_ATL
+ ATL::Checked::strcat_s(lpstrDest, cchDest, lpstrSrc);
+#else
+ if(cchDest > (size_t)lstrlenA(lpstrSrc))
+ ATLVERIFY(lstrcatA(lpstrDest, lpstrSrc) != NULL);
+ else
+ ATLASSERT(FALSE);
+#endif
+ }
+
+ inline void strcatW_x(wchar_t* lpstrDest, size_t cchDest, const wchar_t* lpstrSrc)
+ {
+#if _SECURE_ATL
+ ATL::Checked::wcscat_s(lpstrDest, cchDest, lpstrSrc);
+#else
+ if(cchDest > (size_t)lstrlenW(lpstrSrc))
+ ATLVERIFY(lstrcatW(lpstrDest, lpstrSrc) != NULL);
+ else
+ ATLASSERT(FALSE);
+#endif
+ }
+
+ inline void strcat_x(LPTSTR lpstrDest, size_t cchDest, LPCTSTR lpstrSrc)
+ {
+#ifdef _UNICODE
+ strcatW_x(lpstrDest, cchDest, lpstrSrc);
+#else
+ strcatA_x(lpstrDest, cchDest, lpstrSrc);
+#endif
+ }
+
+ inline void memcpy_x(void* pDest, size_t cbDest, const void* pSrc, size_t cbSrc)
+ {
+#if _SECURE_ATL
+ ATL::Checked::memcpy_s(pDest, cbDest, pSrc, cbSrc);
+#else
+ if(cbDest >= cbSrc)
+ memcpy(pDest, pSrc, cbSrc);
+ else
+ ATLASSERT(FALSE);
+#endif
+ }
+
+ inline void memmove_x(void* pDest, size_t cbDest, const void* pSrc, size_t cbSrc)
+ {
+#if _SECURE_ATL
+ ATL::Checked::memmove_s(pDest, cbDest, pSrc, cbSrc);
+#else
+ if(cbDest >= cbSrc)
+ memmove(pDest, pSrc, cbSrc);
+ else
+ ATLASSERT(FALSE);
+#endif
+ }
+
+ inline int vsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
+ {
+#if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE)
+ return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
+#else
+ cchBuff; // Avoid unused argument warning
+#pragma warning(disable: 4996)
+ return _vstprintf(lpstrBuff, lpstrFormat, args);
+#pragma warning(default: 4996)
+#endif
+ }
+
+ inline int wvsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
+ {
+#if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE)
+ return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
+#else
+ cchBuff; // Avoid unused argument warning
+ return ::wvsprintf(lpstrBuff, lpstrFormat, args);
+#endif
+ }
+
+ inline int sprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, ...)
+ {
+ va_list args;
+ va_start(args, lpstrFormat);
+ int nRes = vsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
+ va_end(args);
+ return nRes;
+ }
+
+ inline int wsprintf_x(LPTSTR lpstrBuff, size_t cchBuff, LPCTSTR lpstrFormat, ...)
+ {
+ va_list args;
+ va_start(args, lpstrFormat);
+ int nRes = wvsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
+ va_end(args);
+ return nRes;
+ }
+}; // namespace SecureHelper
+
+
+///////////////////////////////////////////////////////////////////////////////
+// MinCrtHelper - helper functions for using _ATL_MIN_CRT
+
+namespace MinCrtHelper
+{
+ inline int _isspace(TCHAR ch)
+ {
+#ifndef _ATL_MIN_CRT
+ return _istspace(ch);
+#else // _ATL_MIN_CRT
+ WORD type = 0;
+ ::GetStringTypeEx(::GetThreadLocale(), CT_CTYPE1, &ch, 1, &type);
+ return (type & C1_SPACE) == C1_SPACE;
+#endif // _ATL_MIN_CRT
+ }
+
+ inline int _isdigit(TCHAR ch)
+ {
+#ifndef _ATL_MIN_CRT
+ return _istdigit(ch);
+#else // _ATL_MIN_CRT
+ WORD type = 0;
+ ::GetStringTypeEx(::GetThreadLocale(), CT_CTYPE1, &ch, 1, &type);
+ return (type & C1_DIGIT) == C1_DIGIT;
+#endif // _ATL_MIN_CRT
+ }
+
+ inline int _atoi(LPCTSTR str)
+ {
+#ifndef _ATL_MIN_CRT
+ return _ttoi(str);
+#else // _ATL_MIN_CRT
+ while(_isspace(*str) != 0)
+ ++str;
+
+ TCHAR ch = *str++;
+ TCHAR sign = ch; // save sign indication
+ if(ch == _T('-') || ch == _T('+'))
+ ch = *str++; // skip sign
+
+ int total = 0;
+ while(_isdigit(ch) != 0)
+ {
+ total = 10 * total + (ch - '0'); // accumulate digit
+ ch = *str++; // get next char
+ }
+
+ return (sign == '-') ? -total : total; // return result, negated if necessary
+#endif // _ATL_MIN_CRT
+ }
+
+ inline LPCTSTR _strrchr(LPCTSTR str, TCHAR ch)
+ {
+#ifndef _ATL_MIN_CRT
+ return _tcsrchr(str, ch);
+#else // _ATL_MIN_CRT
+ LPCTSTR lpsz = NULL;
+ while(*str != 0)
+ {
+ if(*str == ch)
+ lpsz = str;
+ str = ::CharNext(str);
+ }
+ return lpsz;
+#endif // _ATL_MIN_CRT
+ }
+
+ inline LPTSTR _strrchr(LPTSTR str, TCHAR ch)
+ {
+#ifndef _ATL_MIN_CRT
+ return _tcsrchr(str, ch);
+#else // _ATL_MIN_CRT
+ LPTSTR lpsz = NULL;
+ while(*str != 0)
+ {
+ if(*str == ch)
+ lpsz = str;
+ str = ::CharNext(str);
+ }
+ return lpsz;
+#endif // _ATL_MIN_CRT
+ }
+}; // namespace MinCrtHelper
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CMessageFilter - Interface for message filter support
+
+class CMessageFilter
+{
+public:
+ virtual BOOL PreTranslateMessage(MSG* pMsg) = 0;
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CIdleHandler - Interface for idle processing
+
+class CIdleHandler
+{
+public:
+ virtual BOOL OnIdle() = 0;
+};
+
+#ifndef _ATL_NO_OLD_NAMES
+ // for compatilibility with old names only
+ typedef CIdleHandler CUpdateUIObject;
+ #define DoUpdate OnIdle
+#endif // !_ATL_NO_OLD_NAMES
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CMessageLoop - message loop implementation
+
+class CMessageLoop
+{
+public:
+ ATL::CSimpleArray<CMessageFilter*> m_aMsgFilter;
+ ATL::CSimpleArray<CIdleHandler*> m_aIdleHandler;
+ MSG m_msg;
+
+// Message filter operations
+ BOOL AddMessageFilter(CMessageFilter* pMessageFilter)
+ {
+ return m_aMsgFilter.Add(pMessageFilter);
+ }
+
+ BOOL RemoveMessageFilter(CMessageFilter* pMessageFilter)
+ {
+ return m_aMsgFilter.Remove(pMessageFilter);
+ }
+
+// Idle handler operations
+ BOOL AddIdleHandler(CIdleHandler* pIdleHandler)
+ {
+ return m_aIdleHandler.Add(pIdleHandler);
+ }
+
+ BOOL RemoveIdleHandler(CIdleHandler* pIdleHandler)
+ {
+ return m_aIdleHandler.Remove(pIdleHandler);
+ }
+
+#ifndef _ATL_NO_OLD_NAMES
+ // for compatilibility with old names only
+ BOOL AddUpdateUI(CIdleHandler* pIdleHandler)
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("CUpdateUIObject and AddUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
+ return AddIdleHandler(pIdleHandler);
+ }
+
+ BOOL RemoveUpdateUI(CIdleHandler* pIdleHandler)
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("CUpdateUIObject and RemoveUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
+ return RemoveIdleHandler(pIdleHandler);
+ }
+#endif // !_ATL_NO_OLD_NAMES
+
+// message loop
+ int Run()
+ {
+ BOOL bDoIdle = TRUE;
+ int nIdleCount = 0;
+ BOOL bRet;
+
+ for(;;)
+ {
+ while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
+ {
+ if(!OnIdle(nIdleCount++))
+ bDoIdle = FALSE;
+ }
+
+ bRet = ::GetMessage(&m_msg, NULL, 0, 0);
+
+ if(bRet == -1)
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("::GetMessage returned -1 (error)\n"));
+ continue; // error, don't process
+ }
+ else if(!bRet)
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("CMessageLoop::Run - exiting\n"));
+ break; // WM_QUIT, exit message loop
+ }
+
+ if(!PreTranslateMessage(&m_msg))
+ {
+ ::TranslateMessage(&m_msg);
+ ::DispatchMessage(&m_msg);
+ }
+
+ if(IsIdleMessage(&m_msg))
+ {
+ bDoIdle = TRUE;
+ nIdleCount = 0;
+ }
+ }
+
+ return (int)m_msg.wParam;
+ }
+
+ static BOOL IsIdleMessage(MSG* pMsg)
+ {
+ // These messages should NOT cause idle processing
+ switch(pMsg->message)
+ {
+ case WM_MOUSEMOVE:
+#ifndef _WIN32_WCE
+ case WM_NCMOUSEMOVE:
+#endif // !_WIN32_WCE
+ case WM_PAINT:
+ case 0x0118: // WM_SYSTIMER (caret blink)
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+// Overrideables
+ // Override to change message filtering
+ virtual BOOL PreTranslateMessage(MSG* pMsg)
+ {
+ // loop backwards
+ for(int i = m_aMsgFilter.GetSize() - 1; i >= 0; i--)
+ {
+ CMessageFilter* pMessageFilter = m_aMsgFilter[i];
+ if(pMessageFilter != NULL && pMessageFilter->PreTranslateMessage(pMsg))
+ return TRUE;
+ }
+ return FALSE; // not translated
+ }
+
+ // override to change idle processing
+ virtual BOOL OnIdle(int /*nIdleCount*/)
+ {
+ for(int i = 0; i < m_aIdleHandler.GetSize(); i++)
+ {
+ CIdleHandler* pIdleHandler = m_aIdleHandler[i];
+ if(pIdleHandler != NULL)
+ pIdleHandler->OnIdle();
+ }
+ return FALSE; // don't continue
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CStaticDataInitCriticalSectionLock and CWindowCreateCriticalSectionLock
+// internal classes to manage critical sections for both ATL3 and ATL7
+
+class CStaticDataInitCriticalSectionLock
+{
+public:
+#if (_ATL_VER >= 0x0700)
+ ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
+
+ CStaticDataInitCriticalSectionLock() : m_cslock(ATL::_pAtlModule->m_csStaticDataInitAndTypeInfo, false)
+ { }
+#endif // (_ATL_VER >= 0x0700)
+
+ HRESULT Lock()
+ {
+#if (_ATL_VER >= 0x0700)
+ return m_cslock.Lock();
+#else // !(_ATL_VER >= 0x0700)
+ ::EnterCriticalSection(&ATL::_pModule->m_csStaticDataInit);
+ return S_OK;
+#endif // !(_ATL_VER >= 0x0700)
+ }
+
+ void Unlock()
+ {
+#if (_ATL_VER >= 0x0700)
+ m_cslock.Unlock();
+#else // !(_ATL_VER >= 0x0700)
+ ::LeaveCriticalSection(&ATL::_pModule->m_csStaticDataInit);
+#endif // !(_ATL_VER >= 0x0700)
+ }
+};
+
+
+class CWindowCreateCriticalSectionLock
+{
+public:
+#if (_ATL_VER >= 0x0700)
+ ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
+
+ CWindowCreateCriticalSectionLock() : m_cslock(ATL::_AtlWinModule.m_csWindowCreate, false)
+ { }
+#endif // (_ATL_VER >= 0x0700)
+
+ HRESULT Lock()
+ {
+#if (_ATL_VER >= 0x0700)
+ return m_cslock.Lock();
+#else // !(_ATL_VER >= 0x0700)
+ ::EnterCriticalSection(&ATL::_pModule->m_csWindowCreate);
+ return S_OK;
+#endif // !(_ATL_VER >= 0x0700)
+ }
+
+ void Unlock()
+ {
+#if (_ATL_VER >= 0x0700)
+ m_cslock.Unlock();
+#else // !(_ATL_VER >= 0x0700)
+ ::LeaveCriticalSection(&ATL::_pModule->m_csWindowCreate);
+#endif // !(_ATL_VER >= 0x0700)
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CTempBuffer - helper class for stack allocations for ATL3
+
+#ifndef _WTL_STACK_ALLOC_THRESHOLD
+ #define _WTL_STACK_ALLOC_THRESHOLD 512
+#endif
+
+#if (_ATL_VER >= 0x0700)
+
+using ATL::CTempBuffer;
+
+#else // !(_ATL_VER >= 0x0700)
+
+#ifndef SIZE_MAX
+ #ifdef _WIN64
+ #define SIZE_MAX _UI64_MAX
+ #else
+ #define SIZE_MAX UINT_MAX
+ #endif
+#endif
+
+#pragma warning(disable: 4284) // warning for operator ->
+
+template<typename T, int t_nFixedBytes = 128>
+class CTempBuffer
+{
+public:
+ CTempBuffer() : m_p(NULL)
+ {
+ }
+
+ CTempBuffer(size_t nElements) : m_p(NULL)
+ {
+ Allocate(nElements);
+ }
+
+ ~CTempBuffer()
+ {
+ if(m_p != reinterpret_cast<T*>(m_abFixedBuffer))
+ free(m_p);
+ }
+
+ operator T*() const
+ {
+ return m_p;
+ }
+
+ T* operator ->() const
+ {
+ ATLASSERT(m_p != NULL);
+ return m_p;
+ }
+
+ T* Allocate(size_t nElements)
+ {
+ ATLASSERT(nElements <= (SIZE_MAX / sizeof(T)));
+ return AllocateBytes(nElements * sizeof(T));
+ }
+
+ T* AllocateBytes(size_t nBytes)
+ {
+ ATLASSERT(m_p == NULL);
+ if(nBytes > t_nFixedBytes)
+ m_p = static_cast<T*>(malloc(nBytes));
+ else
+ m_p = reinterpret_cast<T*>(m_abFixedBuffer);
+
+ return m_p;
+ }
+
+private:
+ T* m_p;
+ BYTE m_abFixedBuffer[t_nFixedBytes];
+};
+
+#pragma warning(default: 4284)
+
+#endif // !(_ATL_VER >= 0x0700)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAppModule - module class for an application
+
+class CAppModule : public ATL::CComModule
+{
+public:
+ DWORD m_dwMainThreadID;
+ ATL::CSimpleMap<DWORD, CMessageLoop*>* m_pMsgLoopMap;
+ ATL::CSimpleArray<HWND>* m_pSettingChangeNotify;
+
+// Overrides of CComModule::Init and Term
+ HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
+ {
+ HRESULT hRet = CComModule::Init(pObjMap, hInstance, pLibID);
+ if(FAILED(hRet))
+ return hRet;
+
+ m_dwMainThreadID = ::GetCurrentThreadId();
+ typedef ATL::CSimpleMap<DWORD, CMessageLoop*> _mapClass;
+ m_pMsgLoopMap = NULL;
+ ATLTRY(m_pMsgLoopMap = new _mapClass);
+ if(m_pMsgLoopMap == NULL)
+ return E_OUTOFMEMORY;
+ m_pSettingChangeNotify = NULL;
+
+ return hRet;
+ }
+
+ void Term()
+ {
+ TermSettingChangeNotify();
+ delete m_pMsgLoopMap;
+ CComModule::Term();
+ }
+
+// Message loop map methods
+ BOOL AddMessageLoop(CMessageLoop* pMsgLoop)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddMessageLoop.\n"));
+ ATLASSERT(FALSE);
+ return FALSE;
+ }
+
+ ATLASSERT(pMsgLoop != NULL);
+ ATLASSERT(m_pMsgLoopMap->Lookup(::GetCurrentThreadId()) == NULL); // not in map yet
+
+ BOOL bRet = m_pMsgLoopMap->Add(::GetCurrentThreadId(), pMsgLoop);
+
+ lock.Unlock();
+
+ return bRet;
+ }
+
+ BOOL RemoveMessageLoop()
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveMessageLoop.\n"));
+ ATLASSERT(FALSE);
+ return FALSE;
+ }
+
+ BOOL bRet = m_pMsgLoopMap->Remove(::GetCurrentThreadId());
+
+ lock.Unlock();
+
+ return bRet;
+ }
+
+ CMessageLoop* GetMessageLoop(DWORD dwThreadID = ::GetCurrentThreadId()) const
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::GetMessageLoop.\n"));
+ ATLASSERT(FALSE);
+ return NULL;
+ }
+
+ CMessageLoop* pLoop = m_pMsgLoopMap->Lookup(dwThreadID);
+
+ lock.Unlock();
+
+ return pLoop;
+ }
+
+// Setting change notify methods
+ // Note: Call this from the main thread for MSDI apps
+ BOOL InitSettingChangeNotify(DLGPROC pfnDlgProc = _SettingChangeDlgProc)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::InitSettingChangeNotify.\n"));
+ ATLASSERT(FALSE);
+ return FALSE;
+ }
+
+ if(m_pSettingChangeNotify == NULL)
+ {
+ typedef ATL::CSimpleArray<HWND> _notifyClass;
+ ATLTRY(m_pSettingChangeNotify = new _notifyClass);
+ ATLASSERT(m_pSettingChangeNotify != NULL);
+ }
+
+ BOOL bRet = (m_pSettingChangeNotify != NULL);
+ if(bRet && m_pSettingChangeNotify->GetSize() == 0)
+ {
+ // init everything
+ _ATL_EMPTY_DLGTEMPLATE templ;
+ HWND hNtfWnd = ::CreateDialogIndirect(GetModuleInstance(), &templ, NULL, pfnDlgProc);
+ ATLASSERT(::IsWindow(hNtfWnd));
+ if(::IsWindow(hNtfWnd))
+ {
+// need conditional code because types don't match in winuser.h
+#ifdef _WIN64
+ ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, (LONG_PTR)this);
+#else
+ ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, PtrToLong(this));
+#endif
+ bRet = m_pSettingChangeNotify->Add(hNtfWnd);
+ }
+ else
+ {
+ bRet = FALSE;
+ }
+ }
+
+ lock.Unlock();
+
+ return bRet;
+ }
+
+ void TermSettingChangeNotify()
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::TermSettingChangeNotify.\n"));
+ ATLASSERT(FALSE);
+ return;
+ }
+
+ if(m_pSettingChangeNotify != NULL && m_pSettingChangeNotify->GetSize() > 0)
+ ::DestroyWindow((*m_pSettingChangeNotify)[0]);
+ delete m_pSettingChangeNotify;
+ m_pSettingChangeNotify = NULL;
+
+ lock.Unlock();
+ }
+
+ BOOL AddSettingChangeNotify(HWND hWnd)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddSettingChangeNotify.\n"));
+ ATLASSERT(FALSE);
+ return FALSE;
+ }
+
+ ATLASSERT(::IsWindow(hWnd));
+ BOOL bRet = FALSE;
+ if(InitSettingChangeNotify() != FALSE)
+ bRet = m_pSettingChangeNotify->Add(hWnd);
+
+ lock.Unlock();
+
+ return bRet;
+ }
+
+ BOOL RemoveSettingChangeNotify(HWND hWnd)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveSettingChangeNotify.\n"));
+ ATLASSERT(FALSE);
+ return FALSE;
+ }
+
+ BOOL bRet = FALSE;
+ if(m_pSettingChangeNotify != NULL)
+ bRet = m_pSettingChangeNotify->Remove(hWnd);
+
+ lock.Unlock();
+
+ return bRet;
+ }
+
+// Implementation - setting change notify dialog template and dialog procedure
+ struct _ATL_EMPTY_DLGTEMPLATE : DLGTEMPLATE
+ {
+ _ATL_EMPTY_DLGTEMPLATE()
+ {
+ memset(this, 0, sizeof(_ATL_EMPTY_DLGTEMPLATE));
+ style = WS_POPUP;
+ }
+ WORD wMenu, wClass, wTitle;
+ };
+
+#ifdef _WIN64
+ static INT_PTR CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+#else
+ static BOOL CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+#endif
+ {
+ if(uMsg == WM_SETTINGCHANGE)
+ {
+// need conditional code because types don't match in winuser.h
+#ifdef _WIN64
+ CAppModule* pModule = (CAppModule*)::GetWindowLongPtr(hWnd, GWLP_USERDATA);
+#else
+ CAppModule* pModule = (CAppModule*)LongToPtr(::GetWindowLongPtr(hWnd, GWLP_USERDATA));
+#endif
+ ATLASSERT(pModule != NULL);
+ ATLASSERT(pModule->m_pSettingChangeNotify != NULL);
+ const UINT uTimeout = 1500; // ms
+ for(int i = 1; i < pModule->m_pSettingChangeNotify->GetSize(); i++)
+ {
+#if !defined(_WIN32_WCE)
+ ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_ABORTIFHUNG, uTimeout, NULL);
+#elif(_WIN32_WCE >= 400) // CE specific
+ ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_NORMAL, uTimeout, NULL);
+#else // _WIN32_WCE < 400 specific
+ uTimeout;
+ ::SendMessage((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam);
+#endif
+ }
+ return TRUE;
+ }
+ return FALSE;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CServerAppModule - module class for a COM server application
+
+class CServerAppModule : public CAppModule
+{
+public:
+ HANDLE m_hEventShutdown;
+ bool m_bActivity;
+ DWORD m_dwTimeOut;
+ DWORD m_dwPause;
+
+// Override of CAppModule::Init
+ HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance, const GUID* pLibID = NULL)
+ {
+ m_dwTimeOut = 5000;
+ m_dwPause = 1000;
+ return CAppModule::Init(pObjMap, hInstance, pLibID);
+ }
+
+ void Term()
+ {
+ if(m_hEventShutdown != NULL && ::CloseHandle(m_hEventShutdown))
+ m_hEventShutdown = NULL;
+ CAppModule::Term();
+ }
+
+// COM Server methods
+ LONG Unlock()
+ {
+ LONG lRet = CComModule::Unlock();
+ if(lRet == 0)
+ {
+ m_bActivity = true;
+ ::SetEvent(m_hEventShutdown); // tell monitor that we transitioned to zero
+ }
+ return lRet;
+ }
+
+ void MonitorShutdown()
+ {
+ for(;;)
+ {
+ ::WaitForSingleObject(m_hEventShutdown, INFINITE);
+ DWORD dwWait = 0;
+ do
+ {
+ m_bActivity = false;
+ dwWait = ::WaitForSingleObject(m_hEventShutdown, m_dwTimeOut);
+ }
+ while(dwWait == WAIT_OBJECT_0);
+ // timed out
+ if(!m_bActivity && m_nLockCnt == 0) // if no activity let's really bail
+ {
+#if ((_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM)) && defined(_ATL_FREE_THREADED) && !defined(_WIN32_WCE)
+ ::CoSuspendClassObjects();
+ if(!m_bActivity && m_nLockCnt == 0)
+#endif
+ break;
+ }
+ }
+ // This handle should be valid now. If it isn't,
+ // check if _Module.Term was called first (it shouldn't)
+ if(::CloseHandle(m_hEventShutdown))
+ m_hEventShutdown = NULL;
+ ::PostThreadMessage(m_dwMainThreadID, WM_QUIT, 0, 0);
+ }
+
+ bool StartMonitor()
+ {
+ m_hEventShutdown = ::CreateEvent(NULL, false, false, NULL);
+ if(m_hEventShutdown == NULL)
+ return false;
+ DWORD dwThreadID = 0;
+#if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE)
+ HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, (UINT (WINAPI*)(void*))MonitorProc, this, 0, (UINT*)&dwThreadID);
+#else
+ HANDLE hThread = ::CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID);
+#endif
+ bool bRet = (hThread != NULL);
+ if(bRet)
+ ::CloseHandle(hThread);
+ return bRet;
+ }
+
+ static DWORD WINAPI MonitorProc(void* pv)
+ {
+ CServerAppModule* p = (CServerAppModule*)pv;
+ p->MonitorShutdown();
+ return 0;
+ }
+
+#if (_ATL_VER < 0x0700)
+ // search for an occurence of string p2 in string p1
+ static LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
+ {
+ while(p1 != NULL && *p1 != NULL)
+ {
+ LPCTSTR p = p2;
+ while(p != NULL && *p != NULL)
+ {
+ if(*p1 == *p)
+ return ::CharNext(p1);
+ p = ::CharNext(p);
+ }
+ p1 = ::CharNext(p1);
+ }
+ return NULL;
+ }
+#endif // (_ATL_VER < 0x0700)
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CRegKeyEx - adds type-specific methods to ATL3 CRegKey
+
+#if (_ATL_VER < 0x0700)
+
+class CRegKeyEx : public ATL::CRegKey
+{
+public:
+// Constructors and operators
+ CRegKeyEx(HKEY hKey = NULL)
+ {
+ m_hKey = hKey;
+ }
+
+ CRegKeyEx(CRegKeyEx& key)
+ {
+ Attach(key.Detach());
+ }
+
+ CRegKeyEx& operator =(CRegKeyEx& key)
+ {
+ Close();
+ Attach(key.Detach());
+ return *this;
+ }
+
+// Methods
+ LONG SetValue(LPCTSTR pszValueName, DWORD dwType, const void* pValue, ULONG nBytes)
+ {
+ ATLASSERT(m_hKey != NULL);
+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, dwType, static_cast<const BYTE*>(pValue), nBytes);
+ }
+
+ LONG SetGUIDValue(LPCTSTR pszValueName, REFGUID guidValue)
+ {
+ ATLASSERT(m_hKey != NULL);
+
+ OLECHAR szGUID[64] = { 0 };
+ ::StringFromGUID2(guidValue, szGUID, 64);
+
+ USES_CONVERSION;
+ LPCTSTR lpstr = OLE2CT(szGUID);
+#ifndef _UNICODE
+ if(lpstr == NULL)
+ return E_OUTOFMEMORY;
+#endif
+ return SetStringValue(pszValueName, lpstr);
+ }
+
+ LONG SetBinaryValue(LPCTSTR pszValueName, const void* pValue, ULONG nBytes)
+ {
+ ATLASSERT(m_hKey != NULL);
+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_BINARY, reinterpret_cast<const BYTE*>(pValue), nBytes);
+ }
+
+ LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue)
+ {
+ ATLASSERT(m_hKey != NULL);
+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_DWORD, reinterpret_cast<const BYTE*>(&dwValue), sizeof(DWORD));
+ }
+
+#ifndef _WIN32_WCE
+ LONG SetQWORDValue(LPCTSTR pszValueName, ULONGLONG qwValue)
+ {
+ ATLASSERT(m_hKey != NULL);
+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_QWORD, reinterpret_cast<const BYTE*>(&qwValue), sizeof(ULONGLONG));
+ }
+#endif
+
+ LONG SetStringValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwType = REG_SZ)
+ {
+ ATLASSERT(m_hKey != NULL);
+ if(pszValue == NULL)
+ {
+ ATLASSERT(FALSE);
+ return ERROR_INVALID_DATA;
+ }
+ ATLASSERT((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ));
+
+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, dwType, reinterpret_cast<const BYTE*>(pszValue), (lstrlen(pszValue) + 1) * sizeof(TCHAR));
+ }
+
+ LONG SetMultiStringValue(LPCTSTR pszValueName, LPCTSTR pszValue)
+ {
+ ATLASSERT(m_hKey != NULL);
+ if(pszValue == NULL)
+ {
+ ATLASSERT(FALSE);
+ return ERROR_INVALID_DATA;
+ }
+
+ ULONG nBytes = 0;
+ ULONG nLength = 0;
+ LPCTSTR pszTemp = pszValue;
+ do
+ {
+ nLength = lstrlen(pszTemp) + 1;
+ pszTemp += nLength;
+ nBytes += nLength * sizeof(TCHAR);
+ } while (nLength != 1);
+
+ return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_MULTI_SZ, reinterpret_cast<const BYTE*>(pszValue), nBytes);
+ }
+
+ LONG QueryValue(LPCTSTR pszValueName, DWORD* pdwType, void* pData, ULONG* pnBytes)
+ {
+ ATLASSERT(m_hKey != NULL);
+ return ::RegQueryValueEx(m_hKey, pszValueName, NULL, pdwType, static_cast<LPBYTE>(pData), pnBytes);
+ }
+
+ LONG QueryGUIDValue(LPCTSTR pszValueName, GUID& guidValue)
+ {
+ ATLASSERT(m_hKey != NULL);
+
+ guidValue = GUID_NULL;
+
+ TCHAR szGUID[64] = { 0 };
+ ULONG nCount = 64;
+ LONG lRes = QueryStringValue(pszValueName, szGUID, &nCount);
+
+ if (lRes != ERROR_SUCCESS)
+ return lRes;
+
+ if(szGUID[0] != _T('{'))
+ return ERROR_INVALID_DATA;
+
+ USES_CONVERSION;
+ LPOLESTR lpstr = T2OLE(szGUID);
+#ifndef _UNICODE
+ if(lpstr == NULL)
+ return E_OUTOFMEMORY;
+#endif
+
+ HRESULT hr = ::CLSIDFromString(lpstr, &guidValue);
+ if (FAILED(hr))
+ return ERROR_INVALID_DATA;
+
+ return ERROR_SUCCESS;
+ }
+
+ LONG QueryBinaryValue(LPCTSTR pszValueName, void* pValue, ULONG* pnBytes)
+ {
+ ATLASSERT(pnBytes != NULL);
+ ATLASSERT(m_hKey != NULL);
+
+ DWORD dwType = 0;
+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pValue), pnBytes);
+ if (lRes != ERROR_SUCCESS)
+ return lRes;
+ if (dwType != REG_BINARY)
+ return ERROR_INVALID_DATA;
+
+ return ERROR_SUCCESS;
+ }
+
+ LONG QueryDWORDValue(LPCTSTR pszValueName, DWORD& dwValue)
+ {
+ ATLASSERT(m_hKey != NULL);
+
+ ULONG nBytes = sizeof(DWORD);
+ DWORD dwType = 0;
+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(&dwValue), &nBytes);
+ if (lRes != ERROR_SUCCESS)
+ return lRes;
+ if (dwType != REG_DWORD)
+ return ERROR_INVALID_DATA;
+
+ return ERROR_SUCCESS;
+ }
+
+ LONG QueryQWORDValue(LPCTSTR pszValueName, ULONGLONG& qwValue)
+ {
+ ATLASSERT(m_hKey != NULL);
+
+ ULONG nBytes = sizeof(ULONGLONG);
+ DWORD dwType = 0;
+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(&qwValue), &nBytes);
+ if (lRes != ERROR_SUCCESS)
+ return lRes;
+ if (dwType != REG_QWORD)
+ return ERROR_INVALID_DATA;
+
+ return ERROR_SUCCESS;
+ }
+
+ LONG QueryStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars)
+ {
+ ATLASSERT(m_hKey != NULL);
+ ATLASSERT(pnChars != NULL);
+
+ ULONG nBytes = (*pnChars) * sizeof(TCHAR);
+ DWORD dwType = 0;
+ *pnChars = 0;
+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
+
+ if (lRes != ERROR_SUCCESS)
+ {
+ return lRes;
+ }
+
+ if(dwType != REG_SZ && dwType != REG_EXPAND_SZ)
+ {
+ return ERROR_INVALID_DATA;
+ }
+
+ if (pszValue != NULL)
+ {
+ if(nBytes != 0)
+ {
+ if ((nBytes % sizeof(TCHAR) != 0) || (pszValue[nBytes / sizeof(TCHAR) -1] != 0))
+ return ERROR_INVALID_DATA;
+ }
+ else
+ {
+ pszValue[0] = _T('\0');
+ }
+ }
+
+ *pnChars = nBytes / sizeof(TCHAR);
+
+ return ERROR_SUCCESS;
+ }
+
+ LONG QueryMultiStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars)
+ {
+ ATLASSERT(m_hKey != NULL);
+ ATLASSERT(pnChars != NULL);
+
+ if (pszValue != NULL && *pnChars < 2)
+ return ERROR_INSUFFICIENT_BUFFER;
+
+ ULONG nBytes = (*pnChars) * sizeof(TCHAR);
+ DWORD dwType = 0;
+ *pnChars = 0;
+ LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
+ if (lRes != ERROR_SUCCESS)
+ return lRes;
+ if (dwType != REG_MULTI_SZ)
+ return ERROR_INVALID_DATA;
+ if (pszValue != NULL && (nBytes % sizeof(TCHAR) != 0 || nBytes / sizeof(TCHAR) < 1 || pszValue[nBytes / sizeof(TCHAR) - 1] != 0 || ((nBytes / sizeof(TCHAR)) > 1 && pszValue[nBytes / sizeof(TCHAR) - 2] != 0)))
+ return ERROR_INVALID_DATA;
+
+ *pnChars = nBytes / sizeof(TCHAR);
+
+ return ERROR_SUCCESS;
+ }
+};
+
+#else // !(_ATL_VER < 0x0700)
+
+typedef ATL::CRegKey CRegKeyEx;
+
+#endif // !(_ATL_VER < 0x0700)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CString forward reference (enables CString use in atluser.h and atlgdi.h)
+
+#if defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING)
+ #define _WTL_USE_CSTRING
+#endif // defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING)
+
+#ifdef _WTL_USE_CSTRING
+ class CString; // forward declaration (include atlmisc.h for the whole class)
+#endif // _WTL_USE_CSTRING
+
+// CString namespace
+#ifndef _CSTRING_NS
+ #ifdef __ATLSTR_H__
+ #define _CSTRING_NS ATL
+ #else
+ #define _CSTRING_NS WTL
+ #endif
+#endif // _CSTRING_NS
+
+// Type classes namespace
+#ifndef _WTYPES_NS
+ #ifdef __ATLTYPES_H__
+ #define _WTYPES_NS
+ #else
+ #define _WTYPES_NS WTL
+ #endif
+#endif // _WTYPES_NS
+
+}; // namespace WTL
+
+
+///////////////////////////////////////////////////////////////////////////////
+// General DLL version helpers
+// (ATL3: excluded from atlbase.h if _ATL_DLL is defined; ATL11: removed)
+
+#if (((_ATL_VER < 0x0700) && defined(_ATL_DLL)) || (_ATL_VER >= 0x0B00)) && !defined(_WIN32_WCE)
+
+namespace ATL
+{
+
+inline HRESULT AtlGetDllVersion(HINSTANCE hInstDLL, DLLVERSIONINFO* pDllVersionInfo)
+{
+ ATLASSERT(pDllVersionInfo != NULL);
+ if(pDllVersionInfo == NULL)
+ return E_INVALIDARG;
+
+ // We must get this function explicitly because some DLLs don't implement it.
+ DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hInstDLL, "DllGetVersion");
+ if(pfnDllGetVersion == NULL)
+ return E_NOTIMPL;
+
+ return (*pfnDllGetVersion)(pDllVersionInfo);
+}
+
+inline HRESULT AtlGetDllVersion(LPCTSTR lpstrDllName, DLLVERSIONINFO* pDllVersionInfo)
+{
+ HINSTANCE hInstDLL = ::LoadLibrary(lpstrDllName);
+ if(hInstDLL == NULL)
+ return E_FAIL;
+ HRESULT hRet = AtlGetDllVersion(hInstDLL, pDllVersionInfo);
+ ::FreeLibrary(hInstDLL);
+ return hRet;
+}
+
+// Common Control Versions:
+// Win95/WinNT 4.0 maj=4 min=00
+// IE 3.x maj=4 min=70
+// IE 4.0 maj=4 min=71
+inline HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
+{
+ ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
+ if(pdwMajor == NULL || pdwMinor == NULL)
+ return E_INVALIDARG;
+
+ DLLVERSIONINFO dvi;
+ ::ZeroMemory(&dvi, sizeof(dvi));
+ dvi.cbSize = sizeof(dvi);
+ HRESULT hRet = AtlGetDllVersion(_T("comctl32.dll"), &dvi);
+
+ if(SUCCEEDED(hRet))
+ {
+ *pdwMajor = dvi.dwMajorVersion;
+ *pdwMinor = dvi.dwMinorVersion;
+ }
+ else if(hRet == E_NOTIMPL)
+ {
+ // If DllGetVersion is not there, then the DLL is a version
+ // previous to the one shipped with IE 3.x
+ *pdwMajor = 4;
+ *pdwMinor = 0;
+ hRet = S_OK;
+ }
+
+ return hRet;
+}
+
+// Shell Versions:
+// Win95/WinNT 4.0 maj=4 min=00
+// IE 3.x, IE 4.0 without Web Integrated Desktop maj=4 min=00
+// IE 4.0 with Web Integrated Desktop maj=4 min=71
+// IE 4.01 with Web Integrated Desktop maj=4 min=72
+inline HRESULT AtlGetShellVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
+{
+ ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
+ if(pdwMajor == NULL || pdwMinor == NULL)
+ return E_INVALIDARG;
+
+ DLLVERSIONINFO dvi;
+ ::ZeroMemory(&dvi, sizeof(dvi));
+ dvi.cbSize = sizeof(dvi);
+ HRESULT hRet = AtlGetDllVersion(_T("shell32.dll"), &dvi);
+
+ if(SUCCEEDED(hRet))
+ {
+ *pdwMajor = dvi.dwMajorVersion;
+ *pdwMinor = dvi.dwMinorVersion;
+ }
+ else if(hRet == E_NOTIMPL)
+ {
+ // If DllGetVersion is not there, then the DLL is a version
+ // previous to the one shipped with IE 4.x
+ *pdwMajor = 4;
+ *pdwMinor = 0;
+ hRet = S_OK;
+ }
+
+ return hRet;
+}
+
+}; // namespace ATL
+
+#endif // (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE)
+
+
+// These are always included
+#include "atlwinx.h"
+#include "atluser.h"
+#include "atlgdi.h"
+
+#ifndef _WTL_NO_AUTOMATIC_NAMESPACE
+using namespace WTL;
+#endif // !_WTL_NO_AUTOMATIC_NAMESPACE
+
+#endif // __ATLAPP_H__
diff --git a/plugins/XSoundNotify/src/wtl/include/atlctrls.h b/plugins/XSoundNotify/src/wtl/include/atlctrls.h new file mode 100644 index 0000000000..e6aca7deec --- /dev/null +++ b/plugins/XSoundNotify/src/wtl/include/atlctrls.h @@ -0,0 +1,10035 @@ +// Windows Template Library - WTL version 8.1
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//
+// This file is a part of the Windows Template Library.
+// The use and distribution terms for this software are covered by the
+// Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
+// which can be found in the file CPL.TXT at the root of this distribution.
+// By using this software in any fashion, you are agreeing to be bound by
+// the terms of this license. You must not remove this notice, or
+// any other, from this software.
+
+#ifndef __ATLCTRLS_H__
+#define __ATLCTRLS_H__
+
+#pragma once
+
+#ifndef __ATLAPP_H__
+ #error atlctrls.h requires atlapp.h to be included first
+#endif
+
+#ifndef __ATLWIN_H__
+ #error atlctrls.h requires atlwin.h to be included first
+#endif
+
+#ifndef _WIN32_WCE
+ #include <richedit.h>
+ #include <richole.h>
+#elif defined(WIN32_PLATFORM_WFSP) && !defined(_WINUSERM_H_)
+ #include <winuserm.h>
+#endif // !_WIN32_WCE
+
+// protect template members from windowsx.h macros
+#ifdef _INC_WINDOWSX
+ #undef GetNextSibling
+ #undef GetPrevSibling
+#endif // _INC_WINDOWSX
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Classes in this file:
+//
+// CStaticT<TBase> - CStatic
+// CButtonT<TBase> - CButton
+// CListBoxT<TBase> - CListBox
+// CComboBoxT<TBase> - CComboBox
+// CEditT<TBase> - CEdit
+// CEditCommands<T>
+// CScrollBarT<TBase> - CScrollBar
+//
+// CImageList
+// CListViewCtrlT<TBase> - CListViewCtrl
+// CTreeViewCtrlT<TBase> - CTreeViewCtrl
+// CTreeItemT<TBase> - CTreeItem
+// CTreeViewCtrlExT<TBase> - CTreeViewCtrlEx
+// CHeaderCtrlT<TBase> - CHeaderCtrl
+// CToolBarCtrlT<TBase> - CToolBarCtrl
+// CStatusBarCtrlT<TBase> - CStatusBarCtrl
+// CTabCtrlT<TBase> - CTabCtrl
+// CToolInfo
+// CToolTipCtrlT<TBase> - CToolTipCtrl
+// CTrackBarCtrlT<TBase> - CTrackBarCtrl
+// CUpDownCtrlT<TBase> - CUpDownCtrl
+// CProgressBarCtrlT<TBase> - CProgressBarCtrl
+// CHotKeyCtrlT<TBase> - CHotKeyCtrl
+// CAnimateCtrlT<TBase> - CAnimateCtrl
+// CRichEditCtrlT<TBase> - CRichEditCtrl
+// CRichEditCommands<T>
+// CDragListBoxT<TBase> - CDragListBox
+// CDragListNotifyImpl<T>
+// CReBarCtrlT<TBase> - CReBarCtrl
+// CComboBoxExT<TBase> - CComboBoxEx
+// CDateTimePickerCtrlT<TBase> - CDateTimePickerCtrl
+// CMonthCalendarCtrlT<TBase> - CMonthCalendarCtrl
+// CFlatScrollBarImpl<T>
+// CFlatScrollBarT<TBase> - CFlatScrollBar
+// CIPAddressCtrlT<TBase> - CIPAddressCtrl
+// CPagerCtrlT<TBase> - CPagerCtrl
+// CLinkCtrlT<TBase> - CLinkCtrl
+//
+// CCustomDraw<T>
+//
+// CCECommandBarCtrlT<TBase> - CCECommandBarCtrl
+// CCECommandBandsCtrlT<TBase> - CCECommandBandsCtrl
+
+
+namespace WTL
+{
+
+// These are wrapper classes for Windows standard and common controls.
+// To implement a window based on a control, use following:
+// Example: Implementing a window based on a list box
+//
+// class CMyListBox : CWindowImpl<CMyListBox, CListBox>
+// {
+// public:
+// BEGIN_MSG_MAP(CMyListBox)
+// // put your message handler entries here
+// END_MSG_MAP()
+// };
+
+
+
+// --- Standard Windows controls ---
+
+///////////////////////////////////////////////////////////////////////////////
+// CStatic - client side for a Windows STATIC control
+
+template <class TBase>
+class CStaticT : public TBase
+{
+public:
+// Constructors
+ CStaticT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CStaticT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return _T("STATIC");
+ }
+
+#ifndef _WIN32_WCE
+ HICON GetIcon() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HICON)::SendMessage(m_hWnd, STM_GETICON, 0, 0L);
+ }
+
+ HICON SetIcon(HICON hIcon)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HICON)::SendMessage(m_hWnd, STM_SETICON, (WPARAM)hIcon, 0L);
+ }
+
+ HENHMETAFILE GetEnhMetaFile() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HENHMETAFILE)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ENHMETAFILE, 0L);
+ }
+
+ HENHMETAFILE SetEnhMetaFile(HENHMETAFILE hMetaFile)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HENHMETAFILE)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ENHMETAFILE, (LPARAM)hMetaFile);
+ }
+#else // CE specific
+ HICON GetIcon() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HICON)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_ICON, 0L);
+ }
+
+ HICON SetIcon(HICON hIcon)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HICON)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
+ }
+#endif // _WIN32_WCE
+
+ CBitmapHandle GetBitmap() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_BITMAP, 0L));
+ }
+
+ CBitmapHandle SetBitmap(HBITMAP hBitmap)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
+ }
+
+ HCURSOR GetCursor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HCURSOR)::SendMessage(m_hWnd, STM_GETIMAGE, IMAGE_CURSOR, 0L);
+ }
+
+ HCURSOR SetCursor(HCURSOR hCursor)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HCURSOR)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_CURSOR, (LPARAM)hCursor);
+ }
+};
+
+typedef CStaticT<ATL::CWindow> CStatic;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CButton - client side for a Windows BUTTON control
+
+template <class TBase>
+class CButtonT : public TBase
+{
+public:
+// Constructors
+ CButtonT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CButtonT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return _T("BUTTON");
+ }
+
+ UINT GetState() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, BM_GETSTATE, 0, 0L);
+ }
+
+ void SetState(BOOL bHighlight)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, BM_SETSTATE, bHighlight, 0L);
+ }
+
+ int GetCheck() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, BM_GETCHECK, 0, 0L);
+ }
+
+ void SetCheck(int nCheck)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, BM_SETCHECK, nCheck, 0L);
+ }
+
+ UINT GetButtonStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::GetWindowLong(m_hWnd, GWL_STYLE) & 0xFFFF;
+ }
+
+ void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, BM_SETSTYLE, nStyle, (LPARAM)bRedraw);
+ }
+
+#ifndef _WIN32_WCE
+ HICON GetIcon() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HICON)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_ICON, 0L);
+ }
+
+ HICON SetIcon(HICON hIcon)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HICON)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon);
+ }
+
+ CBitmapHandle GetBitmap() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_GETIMAGE, IMAGE_BITMAP, 0L));
+ }
+
+ CBitmapHandle SetBitmap(HBITMAP hBitmap)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CBitmapHandle((HBITMAP)::SendMessage(m_hWnd, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap));
+ }
+#endif // !_WIN32_WCE
+
+#if (_WIN32_WINNT >= 0x0501)
+ BOOL GetIdealSize(LPSIZE lpSize) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, BCM_GETIDEALSIZE, 0, (LPARAM)lpSize);
+ }
+
+ BOOL GetImageList(PBUTTON_IMAGELIST pButtonImagelist) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, BCM_GETIMAGELIST, 0, (LPARAM)pButtonImagelist);
+ }
+
+ BOOL SetImageList(PBUTTON_IMAGELIST pButtonImagelist)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, BCM_SETIMAGELIST, 0, (LPARAM)pButtonImagelist);
+ }
+
+ BOOL GetTextMargin(LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, BCM_GETTEXTMARGIN, 0, (LPARAM)lpRect);
+ }
+
+ BOOL SetTextMargin(LPRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, BCM_SETTEXTMARGIN, 0, (LPARAM)lpRect);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+#if (WINVER >= 0x0600)
+ void SetDontClick(BOOL bDontClick)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, BM_SETDONTCLICK, (WPARAM)bDontClick, 0L);
+ }
+#endif // (WINVER >= 0x0600)
+
+#if (_WIN32_WINNT >= 0x0600)
+ BOOL SetDropDownState(BOOL bDropDown)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
+ return (BOOL)::SendMessage(m_hWnd, BCM_SETDROPDOWNSTATE, (WPARAM)bDropDown, 0L);
+ }
+
+ BOOL GetSplitInfo(PBUTTON_SPLITINFO pSplitInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
+ return (BOOL)::SendMessage(m_hWnd, BCM_GETSPLITINFO, 0, (LPARAM)pSplitInfo);
+ }
+
+ BOOL SetSplitInfo(PBUTTON_SPLITINFO pSplitInfo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (BS_SPLITBUTTON | BS_DEFSPLITBUTTON)) != 0);
+ return (BOOL)::SendMessage(m_hWnd, BCM_SETSPLITINFO, 0, (LPARAM)pSplitInfo);
+ }
+
+ int GetNoteLength() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
+ return (int)::SendMessage(m_hWnd, BCM_GETNOTELENGTH, 0, 0L);
+ }
+
+ BOOL GetNote(LPWSTR lpstrNoteText, int cchNoteText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
+ return (BOOL)::SendMessage(m_hWnd, BCM_GETNOTE, cchNoteText, (LPARAM)lpstrNoteText);
+ }
+
+ BOOL SetNote(LPCWSTR lpstrNoteText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (BS_COMMANDLINK | BS_DEFCOMMANDLINK)) != 0);
+ return (BOOL)::SendMessage(m_hWnd, BCM_SETNOTE, 0, (LPARAM)lpstrNoteText);
+ }
+
+ LRESULT SetElevationRequiredState(BOOL bSet)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::SendMessage(m_hWnd, BCM_SETSHIELD, 0, (LPARAM)bSet);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+// Operations
+ void Click()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, BM_CLICK, 0, 0L);
+ }
+};
+
+typedef CButtonT<ATL::CWindow> CButton;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CListBox - client side for a Windows LISTBOX control
+
+template <class TBase>
+class CListBoxT : public TBase
+{
+public:
+// Constructors
+ CListBoxT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CListBoxT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return _T("LISTBOX");
+ }
+
+ // for entire listbox
+ int GetCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETCOUNT, 0, 0L);
+ }
+
+#ifndef _WIN32_WCE
+ int SetCount(int cItems)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(((GetStyle() & LBS_NODATA) != 0) && ((GetStyle() & LBS_HASSTRINGS) == 0));
+ return (int)::SendMessage(m_hWnd, LB_SETCOUNT, cItems, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ int GetHorizontalExtent() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETHORIZONTALEXTENT, 0, 0L);
+ }
+
+ void SetHorizontalExtent(int cxExtent)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LB_SETHORIZONTALEXTENT, cxExtent, 0L);
+ }
+
+ int GetTopIndex() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETTOPINDEX, 0, 0L);
+ }
+
+ int SetTopIndex(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_SETTOPINDEX, nIndex, 0L);
+ }
+
+ LCID GetLocale() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LCID)::SendMessage(m_hWnd, LB_GETLOCALE, 0, 0L);
+ }
+
+ LCID SetLocale(LCID nNewLocale)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LCID)::SendMessage(m_hWnd, LB_SETLOCALE, (WPARAM)nNewLocale, 0L);
+ }
+
+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+ DWORD GetListBoxInfo() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+#if (_WIN32_WINNT >= 0x0501)
+ return (DWORD)::SendMessage(m_hWnd, LB_GETLISTBOXINFO, 0, 0L);
+#else // !(_WIN32_WINNT >= 0x0501)
+ return ::GetListBoxInfo(m_hWnd);
+#endif // !(_WIN32_WINNT >= 0x0501)
+ }
+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+
+ // for single-selection listboxes
+ int GetCurSel() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
+ return (int)::SendMessage(m_hWnd, LB_GETCURSEL, 0, 0L);
+ }
+
+ int SetCurSel(int nSelect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
+ return (int)::SendMessage(m_hWnd, LB_SETCURSEL, nSelect, 0L);
+ }
+
+ // for multiple-selection listboxes
+ int GetSel(int nIndex) const // also works for single-selection
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETSEL, nIndex, 0L);
+ }
+
+ int SetSel(int nIndex, BOOL bSelect = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
+ return (int)::SendMessage(m_hWnd, LB_SETSEL, bSelect, nIndex);
+ }
+
+ int GetSelCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
+ return (int)::SendMessage(m_hWnd, LB_GETSELCOUNT, 0, 0L);
+ }
+
+ int GetSelItems(int nMaxItems, LPINT rgIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
+ return (int)::SendMessage(m_hWnd, LB_GETSELITEMS, nMaxItems, (LPARAM)rgIndex);
+ }
+
+ int GetAnchorIndex() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
+ return (int)::SendMessage(m_hWnd, LB_GETANCHORINDEX, 0, 0L);
+ }
+
+ void SetAnchorIndex(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
+ ::SendMessage(m_hWnd, LB_SETANCHORINDEX, nIndex, 0L);
+ }
+
+ int GetCaretIndex() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETCARETINDEX, 0, 0);
+ }
+
+ int SetCaretIndex(int nIndex, BOOL bScroll = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_SETCARETINDEX, nIndex, MAKELONG(bScroll, 0));
+ }
+
+ // for listbox items
+ DWORD_PTR GetItemData(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD_PTR)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
+ }
+
+ int SetItemData(int nIndex, DWORD_PTR dwItemData)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
+ }
+
+ void* GetItemDataPtr(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (void*)::SendMessage(m_hWnd, LB_GETITEMDATA, nIndex, 0L);
+ }
+
+ int SetItemDataPtr(int nIndex, void* pData)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItemData(nIndex, (DWORD_PTR)pData);
+ }
+
+ int GetItemRect(int nIndex, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETITEMRECT, nIndex, (LPARAM)lpRect);
+ }
+
+ int GetText(int nIndex, LPTSTR lpszBuffer) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETTEXT, nIndex, (LPARAM)lpszBuffer);
+ }
+
+#ifndef _ATL_NO_COM
+#ifdef _OLEAUTO_H_
+ BOOL GetTextBSTR(int nIndex, BSTR& bstrText) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(bstrText == NULL);
+
+ int nLen = GetTextLen(nIndex);
+ if(nLen == LB_ERR)
+ return FALSE;
+
+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPTSTR lpstrText = buff.Allocate(nLen + 1);
+ if(lpstrText == NULL)
+ return FALSE;
+
+ if(GetText(nIndex, lpstrText) == LB_ERR)
+ return FALSE;
+
+ bstrText = ::SysAllocString(T2OLE(lpstrText));
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+#endif // _OLEAUTO_H_
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ int GetText(int nIndex, _CSTRING_NS::CString& strText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ int cchLen = GetTextLen(nIndex);
+ if(cchLen == LB_ERR)
+ return LB_ERR;
+ int nRet = LB_ERR;
+ LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
+ if(lpstr != NULL)
+ {
+ nRet = GetText(nIndex, lpstr);
+ strText.ReleaseBuffer();
+ }
+ return nRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ int GetTextLen(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETTEXTLEN, nIndex, 0L);
+ }
+
+ int GetItemHeight(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_GETITEMHEIGHT, nIndex, 0L);
+ }
+
+ int SetItemHeight(int nIndex, UINT cyItemHeight)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
+ }
+
+ // Settable only attributes
+ void SetColumnWidth(int cxWidth)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LB_SETCOLUMNWIDTH, cxWidth, 0L);
+ }
+
+ BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
+ return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
+ }
+
+ BOOL SetTabStops()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
+ return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 0, 0L);
+ }
+
+ BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & LBS_USETABSTOPS) != 0);
+ return (BOOL)::SendMessage(m_hWnd, LB_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
+ }
+
+// Operations
+ int InitStorage(int nItems, UINT nBytes)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_INITSTORAGE, (WPARAM)nItems, nBytes);
+ }
+
+ void ResetContent()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LB_RESETCONTENT, 0, 0L);
+ }
+
+ UINT ItemFromPoint(POINT pt, BOOL& bOutside) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dw = (DWORD)::SendMessage(m_hWnd, LB_ITEMFROMPOINT, 0, MAKELPARAM(pt.x, pt.y));
+ bOutside = (BOOL)HIWORD(dw);
+ return (UINT)LOWORD(dw);
+ }
+
+ // manipulating listbox items
+ int AddString(LPCTSTR lpszItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_ADDSTRING, 0, (LPARAM)lpszItem);
+ }
+
+ int DeleteString(UINT nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_DELETESTRING, nIndex, 0L);
+ }
+
+ int InsertString(int nIndex, LPCTSTR lpszItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_INSERTSTRING, nIndex, (LPARAM)lpszItem);
+ }
+
+#ifndef _WIN32_WCE
+ int Dir(UINT attr, LPCTSTR lpszWildCard)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_DIR, attr, (LPARAM)lpszWildCard);
+ }
+
+ int AddFile(LPCTSTR lpstrFileName)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_ADDFILE, 0, (LPARAM)lpstrFileName);
+ }
+#endif // !_WIN32_WCE
+
+ // selection helpers
+ int FindString(int nStartAfter, LPCTSTR lpszItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_FINDSTRING, nStartAfter, (LPARAM)lpszItem);
+ }
+
+ int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
+ }
+
+ int SelectString(int nStartAfter, LPCTSTR lpszItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LB_SELECTSTRING, nStartAfter, (LPARAM)lpszItem);
+ }
+
+ int SelItemRange(BOOL bSelect, int nFirstItem, int nLastItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != 0);
+ ATLASSERT(nFirstItem <= nLastItem);
+ return bSelect ? (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nFirstItem, nLastItem) : (int)::SendMessage(m_hWnd, LB_SELITEMRANGEEX, nLastItem, nFirstItem);
+ }
+
+#ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
+ DWORD GetInputMode(BOOL bCurrentMode = TRUE)
+ {
+ return SendMessage(LB_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
+ }
+
+ BOOL SetInputMode(DWORD dwMode)
+ {
+ return SendMessage(LB_SETINPUTMODE, 0, (LPARAM)dwMode);
+ }
+#endif // WIN32_PLATFORM_WFSP
+};
+
+typedef CListBoxT<ATL::CWindow> CListBox;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CComboBox - client side for a Windows COMBOBOX control
+
+#ifndef WIN32_PLATFORM_WFSP // No COMBOBOX on SmartPhones
+
+template <class TBase>
+class CComboBoxT : public TBase
+{
+public:
+// Constructors
+ CComboBoxT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CComboBoxT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return _T("COMBOBOX");
+ }
+
+ // for entire combo box
+ int GetCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_GETCOUNT, 0, 0L);
+ }
+
+ int GetCurSel() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_GETCURSEL, 0, 0L);
+ }
+
+ int SetCurSel(int nSelect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_SETCURSEL, nSelect, 0L);
+ }
+
+ LCID GetLocale() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LCID)::SendMessage(m_hWnd, CB_GETLOCALE, 0, 0L);
+ }
+
+ LCID SetLocale(LCID nNewLocale)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LCID)::SendMessage(m_hWnd, CB_SETLOCALE, (WPARAM)nNewLocale, 0L);
+ }
+
+ int GetTopIndex() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_GETTOPINDEX, 0, 0L);
+ }
+
+ int SetTopIndex(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_SETTOPINDEX, nIndex, 0L);
+ }
+
+ UINT GetHorizontalExtent() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, CB_GETHORIZONTALEXTENT, 0, 0L);
+ }
+
+ void SetHorizontalExtent(UINT nExtent)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, CB_SETHORIZONTALEXTENT, nExtent, 0L);
+ }
+
+ int GetDroppedWidth() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_GETDROPPEDWIDTH, 0, 0L);
+ }
+
+ int SetDroppedWidth(UINT nWidth)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_SETDROPPEDWIDTH, nWidth, 0L);
+ }
+
+#if ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
+ BOOL GetComboBoxInfo(PCOMBOBOXINFO pComboBoxInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+#if ((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
+ return (BOOL)::SendMessage(m_hWnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)pComboBoxInfo);
+#else // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
+ return ::GetComboBoxInfo(m_hWnd, pComboBoxInfo);
+#endif // !((_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
+ }
+#endif // ((WINVER >= 0x0500) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 420))
+
+ // for edit control
+ DWORD GetEditSel() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, CB_GETEDITSEL, 0, 0L);
+ }
+
+ BOOL SetEditSel(int nStartChar, int nEndChar)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CB_SETEDITSEL, 0, MAKELONG(nStartChar, nEndChar));
+ }
+
+ // for combobox item
+ DWORD_PTR GetItemData(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD_PTR)::SendMessage(m_hWnd, CB_GETITEMDATA, nIndex, 0L);
+ }
+
+ int SetItemData(int nIndex, DWORD_PTR dwItemData)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_SETITEMDATA, nIndex, (LPARAM)dwItemData);
+ }
+
+ void* GetItemDataPtr(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (void*)GetItemData(nIndex);
+ }
+
+ int SetItemDataPtr(int nIndex, void* pData)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItemData(nIndex, (DWORD_PTR)pData);
+ }
+
+ int GetLBText(int nIndex, LPTSTR lpszText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_GETLBTEXT, nIndex, (LPARAM)lpszText);
+ }
+
+#ifndef _ATL_NO_COM
+ BOOL GetLBTextBSTR(int nIndex, BSTR& bstrText) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(bstrText == NULL);
+
+ int nLen = GetLBTextLen(nIndex);
+ if(nLen == CB_ERR)
+ return FALSE;
+
+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPTSTR lpstrText = buff.Allocate(nLen + 1);
+ if(lpstrText == NULL)
+ return FALSE;
+
+ if(GetLBText(nIndex, lpstrText) == CB_ERR)
+ return FALSE;
+
+ bstrText = ::SysAllocString(T2OLE(lpstrText));
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ int GetLBText(int nIndex, _CSTRING_NS::CString& strText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ int cchLen = GetLBTextLen(nIndex);
+ if(cchLen == CB_ERR)
+ return CB_ERR;
+ int nRet = CB_ERR;
+ LPTSTR lpstr = strText.GetBufferSetLength(cchLen);
+ if(lpstr != NULL)
+ {
+ nRet = GetLBText(nIndex, lpstr);
+ strText.ReleaseBuffer();
+ }
+ return nRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ int GetLBTextLen(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_GETLBTEXTLEN, nIndex, 0L);
+ }
+
+ int GetItemHeight(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_GETITEMHEIGHT, nIndex, 0L);
+ }
+
+ int SetItemHeight(int nIndex, UINT cyItemHeight)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_SETITEMHEIGHT, nIndex, MAKELONG(cyItemHeight, 0));
+ }
+
+ BOOL GetExtendedUI() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CB_GETEXTENDEDUI, 0, 0L);
+ }
+
+ int SetExtendedUI(BOOL bExtended = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_SETEXTENDEDUI, bExtended, 0L);
+ }
+
+ void GetDroppedControlRect(LPRECT lprect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)lprect);
+ }
+
+ BOOL GetDroppedState() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CB_GETDROPPEDSTATE, 0, 0L);
+ }
+
+#if (_WIN32_WINNT >= 0x0501)
+ int GetMinVisible() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_GETMINVISIBLE, 0, 0L);
+ }
+
+ BOOL SetMinVisible(int nMinVisible)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CB_SETMINVISIBLE, nMinVisible, 0L);
+ }
+
+ // Vista only
+ BOOL GetCueBannerText(LPWSTR lpwText, int cchText) const
+ {
+#ifndef CB_GETCUEBANNER
+ const UINT CB_GETCUEBANNER = (CBM_FIRST + 4);
+#endif
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CB_GETCUEBANNER, (WPARAM)lpwText, cchText);
+ }
+
+ // Vista only
+ BOOL SetCueBannerText(LPCWSTR lpcwText)
+ {
+#ifndef CB_SETCUEBANNER
+ const UINT CB_SETCUEBANNER = (CBM_FIRST + 3);
+#endif
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CB_SETCUEBANNER, 0, (LPARAM)lpcwText);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+// Operations
+ int InitStorage(int nItems, UINT nBytes)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_INITSTORAGE, (WPARAM)nItems, nBytes);
+ }
+
+ void ResetContent()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0L);
+ }
+
+ // for edit control
+ BOOL LimitText(int nMaxChars)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CB_LIMITTEXT, nMaxChars, 0L);
+ }
+
+ // for drop-down combo boxes
+ void ShowDropDown(BOOL bShowIt = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, CB_SHOWDROPDOWN, bShowIt, 0L);
+ }
+
+ // manipulating listbox items
+ int AddString(LPCTSTR lpszString)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_ADDSTRING, 0, (LPARAM)lpszString);
+ }
+
+ int DeleteString(UINT nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_DELETESTRING, nIndex, 0L);
+ }
+
+ int InsertString(int nIndex, LPCTSTR lpszString)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_INSERTSTRING, nIndex, (LPARAM)lpszString);
+ }
+
+#ifndef _WIN32_WCE
+ int Dir(UINT attr, LPCTSTR lpszWildCard)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_DIR, attr, (LPARAM)lpszWildCard);
+ }
+#endif // !_WIN32_WCE
+
+ // selection helpers
+ int FindString(int nStartAfter, LPCTSTR lpszString) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_FINDSTRING, nStartAfter, (LPARAM)lpszString);
+ }
+
+ int FindStringExact(int nIndexStart, LPCTSTR lpszFind) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_FINDSTRINGEXACT, nIndexStart, (LPARAM)lpszFind);
+ }
+
+ int SelectString(int nStartAfter, LPCTSTR lpszString)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CB_SELECTSTRING, nStartAfter, (LPARAM)lpszString);
+ }
+
+ // Clipboard operations
+ void Clear()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
+ }
+
+ void Copy()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
+ }
+
+ void Cut()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
+ }
+
+ void Paste()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
+ }
+};
+
+typedef CComboBoxT<ATL::CWindow> CComboBox;
+
+#endif // !WIN32_PLATFORM_WFSP
+
+///////////////////////////////////////////////////////////////////////////////
+// CEdit - client side for a Windows EDIT control
+
+template <class TBase>
+class CEditT : public TBase
+{
+public:
+// Constructors
+ CEditT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CEditT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return _T("EDIT");
+ }
+
+ BOOL CanUndo() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
+ }
+
+ int GetLineCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
+ }
+
+ BOOL GetModify() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
+ }
+
+ void SetModify(BOOL bModified = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETMODIFY, bModified, 0L);
+ }
+
+ void GetRect(LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
+ }
+
+ DWORD GetSel() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, EM_GETSEL, 0, 0L);
+ }
+
+ void GetSel(int& nStartChar, int& nEndChar) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_GETSEL, (WPARAM)&nStartChar, (LPARAM)&nEndChar);
+ }
+
+#ifndef _WIN32_WCE
+ HLOCAL GetHandle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HLOCAL)::SendMessage(m_hWnd, EM_GETHANDLE, 0, 0L);
+ }
+
+ void SetHandle(HLOCAL hBuffer)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETHANDLE, (WPARAM)hBuffer, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ DWORD GetMargins() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, EM_GETMARGINS, 0, 0L);
+ }
+
+ void SetMargins(UINT nLeft, UINT nRight)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, MAKELONG(nLeft, nRight));
+ }
+
+ UINT GetLimitText() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, EM_GETLIMITTEXT, 0, 0L);
+ }
+
+ void SetLimitText(UINT nMax)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETLIMITTEXT, nMax, 0L);
+ }
+
+ POINT PosFromChar(UINT nChar) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_POSFROMCHAR, nChar, 0);
+ POINT point = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
+ return point;
+ }
+
+ int CharFromPos(POINT pt, int* pLine = NULL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_CHARFROMPOS, 0, MAKELPARAM(pt.x, pt.y));
+ if(pLine != NULL)
+ *pLine = (int)(short)HIWORD(dwRet);
+ return (int)(short)LOWORD(dwRet);
+ }
+
+ // NOTE: first word in lpszBuffer must contain the size of the buffer!
+ int GetLine(int nIndex, LPTSTR lpszBuffer) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
+ }
+
+ int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ *(LPWORD)lpszBuffer = (WORD)nMaxLength;
+ return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
+ }
+
+ TCHAR GetPasswordChar() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (TCHAR)::SendMessage(m_hWnd, EM_GETPASSWORDCHAR, 0, 0L);
+ }
+
+ void SetPasswordChar(TCHAR ch)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETPASSWORDCHAR, ch, 0L);
+ }
+
+#ifndef _WIN32_WCE
+ EDITWORDBREAKPROC GetWordBreakProc() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (EDITWORDBREAKPROC)::SendMessage(m_hWnd, EM_GETWORDBREAKPROC, 0, 0L);
+ }
+
+ void SetWordBreakProc(EDITWORDBREAKPROC ewbprc)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETWORDBREAKPROC, 0, (LPARAM)ewbprc);
+ }
+#endif // !_WIN32_WCE
+
+ int GetFirstVisibleLine() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
+ }
+
+#ifndef _WIN32_WCE
+ int GetThumb() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
+ return (int)::SendMessage(m_hWnd, EM_GETTHUMB, 0, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL SetReadOnly(BOOL bReadOnly = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
+ }
+
+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+ UINT GetImeStatus(UINT uStatus) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, EM_GETIMESTATUS, uStatus, 0L);
+ }
+
+ UINT SetImeStatus(UINT uStatus, UINT uData)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, EM_SETIMESTATUS, uStatus, uData);
+ }
+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+
+#if (_WIN32_WINNT >= 0x0501)
+ BOOL GetCueBannerText(LPCWSTR lpstrText, int cchText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_GETCUEBANNER, (WPARAM)lpstrText, cchText);
+ }
+
+ // bKeepWithFocus - Vista only
+ BOOL SetCueBannerText(LPCWSTR lpstrText, BOOL bKeepWithFocus = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCUEBANNER, (WPARAM)bKeepWithFocus, (LPARAM)(lpstrText));
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+// Operations
+ void EmptyUndoBuffer()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
+ }
+
+ BOOL FmtLines(BOOL bAddEOL)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_FMTLINES, bAddEOL, 0L);
+ }
+
+ void LimitText(int nChars = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_LIMITTEXT, nChars, 0L);
+ }
+
+ int LineFromChar(int nIndex = -1) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_LINEFROMCHAR, nIndex, 0L);
+ }
+
+ int LineIndex(int nLine = -1) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0L);
+ }
+
+ int LineLength(int nLine = -1) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0L);
+ }
+
+ void LineScroll(int nLines, int nChars = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
+ }
+
+ void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
+ }
+
+ void SetRect(LPCRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
+ }
+
+ void SetRectNP(LPCRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETRECTNP, 0, (LPARAM)lpRect);
+ }
+
+ void SetSel(DWORD dwSelection, BOOL bNoScroll = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETSEL, LOWORD(dwSelection), HIWORD(dwSelection));
+ if(!bNoScroll)
+ ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
+ }
+
+ void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETSEL, nStartChar, nEndChar);
+ if(!bNoScroll)
+ ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
+ }
+
+ void SetSelAll(BOOL bNoScroll = FALSE)
+ {
+ SetSel(0, -1, bNoScroll);
+ }
+
+ void SetSelNone(BOOL bNoScroll = FALSE)
+ {
+ SetSel(-1, 0, bNoScroll);
+ }
+
+ BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
+ }
+
+ BOOL SetTabStops()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 0, 0L);
+ }
+
+ BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
+ }
+
+ void ScrollCaret()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
+ }
+
+ int Scroll(int nScrollAction)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & ES_MULTILINE) != 0);
+ LRESULT lRet = ::SendMessage(m_hWnd, EM_SCROLL, nScrollAction, 0L);
+ if(!(BOOL)HIWORD(lRet))
+ return -1; // failed
+ return (int)(short)LOWORD(lRet);
+
+ }
+
+ void InsertText(int nInsertAfterChar, LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
+ {
+ SetSel(nInsertAfterChar, nInsertAfterChar, bNoScroll);
+ ReplaceSel(lpstrText, bCanUndo);
+ }
+
+ void AppendText(LPCTSTR lpstrText, BOOL bNoScroll = FALSE, BOOL bCanUndo = FALSE)
+ {
+ InsertText(GetWindowTextLength(), lpstrText, bNoScroll, bCanUndo);
+ }
+
+#if (_WIN32_WINNT >= 0x0501)
+ BOOL ShowBalloonTip(PEDITBALLOONTIP pEditBaloonTip)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SHOWBALLOONTIP, 0, (LPARAM)pEditBaloonTip);
+ }
+
+ BOOL HideBalloonTip()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_HIDEBALLOONTIP, 0, 0L);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+#if (_WIN32_WINNT >= 0x0600)
+ DWORD GetHilite() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, EM_GETHILITE, 0, 0L);
+ }
+
+ void GetHilite(int& nStartChar, int& nEndChar) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, EM_GETHILITE, 0, 0L);
+ nStartChar = (int)(short)LOWORD(dwRet);
+ nEndChar = (int)(short)HIWORD(dwRet);
+ }
+
+ void SetHilite(int nStartChar, int nEndChar)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETHILITE, nStartChar, nEndChar);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+ // Clipboard operations
+ BOOL Undo()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_UNDO, 0, 0L);
+ }
+
+ void Clear()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
+ }
+
+ void Copy()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
+ }
+
+ void Cut()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
+ }
+
+ void Paste()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
+ }
+
+#ifdef WIN32_PLATFORM_WFSP // SmartPhone only messages
+ DWORD GetExtendedStyle()
+ {
+ return SendMessage(EM_GETEXTENDEDSTYLE);
+ }
+
+ DWORD SetExtendedStyle(DWORD dwMask, DWORD dwExStyle)
+ {
+ return SendMessage(EM_SETEXTENDEDSTYLE, (WPARAM)dwMask, (LPARAM)dwExStyle);
+ }
+
+ DWORD GetInputMode(BOOL bCurrentMode = TRUE)
+ {
+ return SendMessage(EM_GETINPUTMODE, 0, (LPARAM)bCurrentMode);
+ }
+
+ BOOL SetInputMode(DWORD dwMode)
+ {
+ return SendMessage(EM_SETINPUTMODE, 0, (LPARAM)dwMode);
+ }
+
+ BOOL SetSymbols(LPCTSTR szSymbols)
+ {
+ return SendMessage(EM_SETSYMBOLS, 0, (LPARAM)szSymbols);
+ }
+
+ BOOL ResetSymbols()
+ {
+ return SendMessage(EM_SETSYMBOLS);
+ }
+#endif // WIN32_PLATFORM_WFSP
+};
+
+typedef CEditT<ATL::CWindow> CEdit;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CEditCommands - message handlers for standard EDIT commands
+
+// Chain to CEditCommands message map. Your class must also derive from CEdit.
+// Example:
+// class CMyEdit : public CWindowImpl<CMyEdit, CEdit>,
+// public CEditCommands<CMyEdit>
+// {
+// public:
+// BEGIN_MSG_MAP(CMyEdit)
+// // your handlers...
+// CHAIN_MSG_MAP_ALT(CEditCommands<CMyEdit>, 1)
+// END_MSG_MAP()
+// // other stuff...
+// };
+
+template <class T>
+class CEditCommands
+{
+public:
+ BEGIN_MSG_MAP(CEditCommands< T >)
+ ALT_MSG_MAP(1)
+ COMMAND_ID_HANDLER(ID_EDIT_CLEAR, OnEditClear)
+ COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, OnEditClearAll)
+ COMMAND_ID_HANDLER(ID_EDIT_COPY, OnEditCopy)
+ COMMAND_ID_HANDLER(ID_EDIT_CUT, OnEditCut)
+ COMMAND_ID_HANDLER(ID_EDIT_PASTE, OnEditPaste)
+ COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, OnEditSelectAll)
+ COMMAND_ID_HANDLER(ID_EDIT_UNDO, OnEditUndo)
+ END_MSG_MAP()
+
+ LRESULT OnEditClear(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->Clear();
+ return 0;
+ }
+
+ LRESULT OnEditClearAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->SetSel(0, -1);
+ pT->Clear();
+ return 0;
+ }
+
+ LRESULT OnEditCopy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->Copy();
+ return 0;
+ }
+
+ LRESULT OnEditCut(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->Cut();
+ return 0;
+ }
+
+ LRESULT OnEditPaste(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->Paste();
+ return 0;
+ }
+
+ LRESULT OnEditSelectAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->SetSel(0, -1);
+ return 0;
+ }
+
+ LRESULT OnEditUndo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->Undo();
+ return 0;
+ }
+
+// State (update UI) helpers
+ BOOL CanCut() const
+ { return HasSelection(); }
+
+ BOOL CanCopy() const
+ { return HasSelection(); }
+
+ BOOL CanClear() const
+ { return HasSelection(); }
+
+ BOOL CanSelectAll() const
+ { return HasText(); }
+
+ BOOL CanFind() const
+ { return HasText(); }
+
+ BOOL CanRepeat() const
+ { return HasText(); }
+
+ BOOL CanReplace() const
+ { return HasText(); }
+
+ BOOL CanClearAll() const
+ { return HasText(); }
+
+// Implementation
+ BOOL HasSelection() const
+ {
+ const T* pT = static_cast<const T*>(this);
+ int nMin, nMax;
+ ::SendMessage(pT->m_hWnd, EM_GETSEL, (WPARAM)&nMin, (LPARAM)&nMax);
+ return (nMin != nMax);
+ }
+
+ BOOL HasText() const
+ {
+ const T* pT = static_cast<const T*>(this);
+ return (pT->GetWindowTextLength() > 0);
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CScrollBar - client side for a Windows SCROLLBAR control
+
+template <class TBase>
+class CScrollBarT : public TBase
+{
+public:
+// Constructors
+ CScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CScrollBarT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return _T("SCROLLBAR");
+ }
+
+#ifndef _WIN32_WCE
+ int GetScrollPos() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::GetScrollPos(m_hWnd, SB_CTL);
+ }
+#endif // !_WIN32_WCE
+
+ int SetScrollPos(int nPos, BOOL bRedraw = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::SetScrollPos(m_hWnd, SB_CTL, nPos, bRedraw);
+ }
+
+#ifndef _WIN32_WCE
+ void GetScrollRange(LPINT lpMinPos, LPINT lpMaxPos) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::GetScrollRange(m_hWnd, SB_CTL, lpMinPos, lpMaxPos);
+ }
+#endif // !_WIN32_WCE
+
+ void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SetScrollRange(m_hWnd, SB_CTL, nMinPos, nMaxPos, bRedraw);
+ }
+
+ BOOL GetScrollInfo(LPSCROLLINFO lpScrollInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::GetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo);
+ }
+
+ int SetScrollInfo(LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::SetScrollInfo(m_hWnd, SB_CTL, lpScrollInfo, bRedraw);
+ }
+
+#ifndef _WIN32_WCE
+ int GetScrollLimit() const
+ {
+ int nMin = 0, nMax = 0;
+ ::GetScrollRange(m_hWnd, SB_CTL, &nMin, &nMax);
+ SCROLLINFO info = { 0 };
+ info.cbSize = sizeof(SCROLLINFO);
+ info.fMask = SIF_PAGE;
+ if(::GetScrollInfo(m_hWnd, SB_CTL, &info))
+ nMax -= ((info.nPage - 1) > 0) ? (info.nPage - 1) : 0;
+
+ return nMax;
+ }
+
+#if (WINVER >= 0x0500)
+ BOOL GetScrollBarInfo(PSCROLLBARINFO pScrollBarInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+#if (_WIN32_WINNT >= 0x0501)
+ return (BOOL)::SendMessage(m_hWnd, SBM_GETSCROLLBARINFO, 0, (LPARAM)pScrollBarInfo);
+#else // !(_WIN32_WINNT >= 0x0501)
+ return ::GetScrollBarInfo(m_hWnd, OBJID_CLIENT, pScrollBarInfo);
+#endif // !(_WIN32_WINNT >= 0x0501)
+ }
+#endif // (WINVER >= 0x0500)
+
+// Operations
+ void ShowScrollBar(BOOL bShow = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::ShowScrollBar(m_hWnd, SB_CTL, bShow);
+ }
+
+ BOOL EnableScrollBar(UINT nArrowFlags = ESB_ENABLE_BOTH)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::EnableScrollBar(m_hWnd, SB_CTL, nArrowFlags);
+ }
+#endif // !_WIN32_WCE
+};
+
+typedef CScrollBarT<ATL::CWindow> CScrollBar;
+
+
+// --- Windows Common Controls ---
+
+///////////////////////////////////////////////////////////////////////////////
+// CImageList
+
+class CImageList
+{
+public:
+ HIMAGELIST m_hImageList;
+
+// Constructor
+ CImageList(HIMAGELIST hImageList = NULL) : m_hImageList(hImageList)
+ { }
+
+// Operators, etc.
+ CImageList& operator =(HIMAGELIST hImageList)
+ {
+ m_hImageList = hImageList;
+ return *this;
+ }
+
+ operator HIMAGELIST() const { return m_hImageList; }
+
+ void Attach(HIMAGELIST hImageList)
+ {
+ ATLASSERT(m_hImageList == NULL);
+ ATLASSERT(hImageList != NULL);
+ m_hImageList = hImageList;
+ }
+
+ HIMAGELIST Detach()
+ {
+ HIMAGELIST hImageList = m_hImageList;
+ m_hImageList = NULL;
+ return hImageList;
+ }
+
+ bool IsNull() const { return (m_hImageList == NULL); }
+
+// Attributes
+ int GetImageCount() const
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_GetImageCount(m_hImageList);
+ }
+
+ COLORREF GetBkColor() const
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_GetBkColor(m_hImageList);
+ }
+
+ COLORREF SetBkColor(COLORREF cr)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_SetBkColor(m_hImageList, cr);
+ }
+
+ BOOL GetImageInfo(int nImage, IMAGEINFO* pImageInfo) const
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_GetImageInfo(m_hImageList, nImage, pImageInfo);
+ }
+
+ HICON GetIcon(int nIndex, UINT uFlags = ILD_NORMAL) const
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_GetIcon(m_hImageList, nIndex, uFlags);
+ }
+
+ BOOL GetIconSize(int& cx, int& cy) const
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_GetIconSize(m_hImageList, &cx, &cy);
+ }
+
+ BOOL GetIconSize(SIZE& size) const
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_GetIconSize(m_hImageList, (int*)&size.cx, (int*)&size.cy);
+ }
+
+ BOOL SetIconSize(int cx, int cy)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_SetIconSize(m_hImageList, cx, cy);
+ }
+
+ BOOL SetIconSize(SIZE size)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_SetIconSize(m_hImageList, size.cx, size.cy);
+ }
+
+ BOOL SetImageCount(UINT uNewCount)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_SetImageCount(m_hImageList, uNewCount);
+ }
+
+ BOOL SetOverlayImage(int nImage, int nOverlay)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_SetOverlayImage(m_hImageList, nImage, nOverlay);
+ }
+
+// Operations
+ BOOL Create(int cx, int cy, UINT nFlags, int nInitial, int nGrow)
+ {
+ ATLASSERT(m_hImageList == NULL);
+ m_hImageList = ImageList_Create(cx, cy, nFlags, nInitial, nGrow);
+ return (m_hImageList != NULL) ? TRUE : FALSE;
+ }
+
+ BOOL Create(ATL::_U_STRINGorID bitmap, int cx, int nGrow, COLORREF crMask)
+ {
+ ATLASSERT(m_hImageList == NULL);
+ m_hImageList = ImageList_LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap.m_lpstr, cx, nGrow, crMask);
+ return (m_hImageList != NULL) ? TRUE : FALSE;
+ }
+
+ BOOL CreateFromImage(ATL::_U_STRINGorID image, int cx, int nGrow, COLORREF crMask, UINT uType, UINT uFlags = LR_DEFAULTCOLOR | LR_DEFAULTSIZE)
+ {
+ ATLASSERT(m_hImageList == NULL);
+ m_hImageList = ImageList_LoadImage(ModuleHelper::GetResourceInstance(), image.m_lpstr, cx, nGrow, crMask, uType, uFlags);
+ return (m_hImageList != NULL) ? TRUE : FALSE;
+ }
+
+ BOOL Merge(HIMAGELIST hImageList1, int nImage1, HIMAGELIST hImageList2, int nImage2, int dx, int dy)
+ {
+ ATLASSERT(m_hImageList == NULL);
+ m_hImageList = ImageList_Merge(hImageList1, nImage1, hImageList2, nImage2, dx, dy);
+ return (m_hImageList != NULL) ? TRUE : FALSE;
+ }
+
+#ifndef _WIN32_WCE
+#ifdef __IStream_INTERFACE_DEFINED__
+ BOOL CreateFromStream(LPSTREAM lpStream)
+ {
+ ATLASSERT(m_hImageList == NULL);
+ m_hImageList = ImageList_Read(lpStream);
+ return (m_hImageList != NULL) ? TRUE : FALSE;
+ }
+#endif // __IStream_INTERFACE_DEFINED__
+#endif // !_WIN32_WCE
+
+ BOOL Destroy()
+ {
+ if (m_hImageList == NULL)
+ return FALSE;
+ BOOL bRet = ImageList_Destroy(m_hImageList);
+ if(bRet)
+ m_hImageList = NULL;
+ return bRet;
+ }
+
+ int Add(HBITMAP hBitmap, HBITMAP hBitmapMask = NULL)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_Add(m_hImageList, hBitmap, hBitmapMask);
+ }
+
+ int Add(HBITMAP hBitmap, COLORREF crMask)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_AddMasked(m_hImageList, hBitmap, crMask);
+ }
+
+ BOOL Remove(int nImage)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_Remove(m_hImageList, nImage);
+ }
+
+ BOOL RemoveAll()
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_RemoveAll(m_hImageList);
+ }
+
+ BOOL Replace(int nImage, HBITMAP hBitmap, HBITMAP hBitmapMask)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_Replace(m_hImageList, nImage, hBitmap, hBitmapMask);
+ }
+
+ int AddIcon(HICON hIcon)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_AddIcon(m_hImageList, hIcon);
+ }
+
+ int ReplaceIcon(int nImage, HICON hIcon)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_ReplaceIcon(m_hImageList, nImage, hIcon);
+ }
+
+ HICON ExtractIcon(int nImage)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_ExtractIcon(NULL, m_hImageList, nImage);
+ }
+
+ BOOL Draw(HDC hDC, int nImage, int x, int y, UINT nStyle)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ ATLASSERT(hDC != NULL);
+ return ImageList_Draw(m_hImageList, nImage, hDC, x, y, nStyle);
+ }
+
+ BOOL Draw(HDC hDC, int nImage, POINT pt, UINT nStyle)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ ATLASSERT(hDC != NULL);
+ return ImageList_Draw(m_hImageList, nImage, hDC, pt.x, pt.y, nStyle);
+ }
+
+ BOOL DrawEx(int nImage, HDC hDC, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ ATLASSERT(hDC != NULL);
+ return ImageList_DrawEx(m_hImageList, nImage, hDC, x, y, dx, dy, rgbBk, rgbFg, fStyle);
+ }
+
+ BOOL DrawEx(int nImage, HDC hDC, RECT& rect, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ ATLASSERT(hDC != NULL);
+ return ImageList_DrawEx(m_hImageList, nImage, hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, rgbBk, rgbFg, fStyle);
+ }
+
+ static BOOL DrawIndirect(IMAGELISTDRAWPARAMS* pimldp)
+ {
+ return ImageList_DrawIndirect(pimldp);
+ }
+
+ BOOL Copy(int nSrc, int nDst, UINT uFlags = ILCF_MOVE)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_Copy(m_hImageList, nDst, m_hImageList, nSrc, uFlags);
+ }
+
+#ifdef __IStream_INTERFACE_DEFINED__
+#ifndef _WIN32_WCE
+ static HIMAGELIST Read(LPSTREAM lpStream)
+ {
+ return ImageList_Read(lpStream);
+ }
+
+ BOOL Write(LPSTREAM lpStream)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_Write(m_hImageList, lpStream);
+ }
+#endif // !_WIN32_WCE
+
+#if (_WIN32_WINNT >= 0x0501)
+ static HRESULT ReadEx(DWORD dwFlags, LPSTREAM lpStream, REFIID riid, PVOID* ppv)
+ {
+ return ImageList_ReadEx(dwFlags, lpStream, riid, ppv);
+ }
+
+ HRESULT WriteEx(DWORD dwFlags, LPSTREAM lpStream)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_WriteEx(m_hImageList, dwFlags, lpStream);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+#endif // __IStream_INTERFACE_DEFINED__
+
+ // Drag operations
+ BOOL BeginDrag(int nImage, POINT ptHotSpot)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_BeginDrag(m_hImageList, nImage, ptHotSpot.x, ptHotSpot.y);
+ }
+
+ BOOL BeginDrag(int nImage, int xHotSpot, int yHotSpot)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_BeginDrag(m_hImageList, nImage, xHotSpot, yHotSpot);
+ }
+
+ static void EndDrag()
+ {
+ ImageList_EndDrag();
+ }
+
+ static BOOL DragMove(POINT pt)
+ {
+ return ImageList_DragMove(pt.x, pt.y);
+ }
+
+ static BOOL DragMove(int x, int y)
+ {
+ return ImageList_DragMove(x, y);
+ }
+
+ BOOL SetDragCursorImage(int nDrag, POINT ptHotSpot)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_SetDragCursorImage(m_hImageList, nDrag, ptHotSpot.x, ptHotSpot.y);
+ }
+
+ BOOL SetDragCursorImage(int nDrag, int xHotSpot, int yHotSpot)
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return ImageList_SetDragCursorImage(m_hImageList, nDrag, xHotSpot, yHotSpot);
+ }
+
+ static BOOL DragShowNolock(BOOL bShow = TRUE)
+ {
+ return ImageList_DragShowNolock(bShow);
+ }
+
+ static CImageList GetDragImage(LPPOINT lpPoint, LPPOINT lpPointHotSpot)
+ {
+ return CImageList(ImageList_GetDragImage(lpPoint, lpPointHotSpot));
+ }
+
+ static BOOL DragEnter(HWND hWnd, POINT point)
+ {
+ return ImageList_DragEnter(hWnd, point.x, point.y);
+ }
+
+ static BOOL DragEnter(HWND hWnd, int x, int y)
+ {
+ return ImageList_DragEnter(hWnd, x, y);
+ }
+
+ static BOOL DragLeave(HWND hWnd)
+ {
+ return ImageList_DragLeave(hWnd);
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ CImageList Duplicate() const
+ {
+ ATLASSERT(m_hImageList != NULL);
+ return CImageList(ImageList_Duplicate(m_hImageList));
+ }
+
+ static CImageList Duplicate(HIMAGELIST hImageList)
+ {
+ ATLASSERT(hImageList != NULL);
+ return CImageList(ImageList_Duplicate(hImageList));
+ }
+#endif // (_WIN32_IE >= 0x0400)
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CToolTipCtrl
+
+#ifndef _WIN32_WCE
+
+class CToolInfo : public TOOLINFO
+{
+public:
+ CToolInfo(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
+ {
+ Init(nFlags, hWnd, nIDTool, lpRect, lpstrText, lUserParam);
+ }
+
+ operator LPTOOLINFO() { return this; }
+
+ operator LPARAM() { return (LPARAM)this; }
+
+ void Init(UINT nFlags, HWND hWnd, UINT nIDTool = 0, LPRECT lpRect = NULL, LPTSTR lpstrText = LPSTR_TEXTCALLBACK, LPARAM lUserParam = NULL)
+ {
+ ATLASSERT(::IsWindow(hWnd));
+ memset(this, 0, sizeof(TOOLINFO));
+ cbSize = sizeof(TOOLINFO);
+ uFlags = nFlags;
+ if(nIDTool == 0)
+ {
+ hwnd = ::GetParent(hWnd);
+ uFlags |= TTF_IDISHWND;
+ uId = (UINT_PTR)hWnd;
+ }
+ else
+ {
+ hwnd = hWnd;
+ uId = nIDTool;
+ }
+ if(lpRect != NULL)
+ rect = *lpRect;
+ hinst = ModuleHelper::GetResourceInstance();
+ lpszText = lpstrText;
+ lParam = lUserParam;
+ }
+};
+
+template <class TBase>
+class CToolTipCtrlT : public TBase
+{
+public:
+// Constructors
+ CToolTipCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CToolTipCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return TOOLTIPS_CLASS;
+ }
+
+ void GetText(LPTOOLINFO lpToolInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_GETTEXT, 0, (LPARAM)&lpToolInfo);
+ }
+
+ void GetText(LPTSTR lpstrText, HWND hWnd, UINT nIDTool = 0) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hWnd != NULL);
+ CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
+ ::SendMessage(m_hWnd, TTM_GETTEXT, 0, ti);
+ }
+
+ BOOL GetToolInfo(LPTOOLINFO lpToolInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, (LPARAM)lpToolInfo);
+ }
+
+ BOOL GetToolInfo(HWND hWnd, UINT nIDTool, UINT* puFlags, LPRECT lpRect, LPTSTR lpstrText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hWnd != NULL);
+ ATLASSERT(puFlags != NULL);
+ ATLASSERT(lpRect != NULL);
+ CToolInfo ti(0, hWnd, nIDTool, NULL, lpstrText);
+ BOOL bRet = (BOOL)::SendMessage(m_hWnd, TTM_GETTOOLINFO, 0, ti);
+ if(bRet != FALSE)
+ {
+ *puFlags = ti.uFlags;
+ *lpRect = ti.rect;
+ }
+ return bRet;
+ }
+
+ void SetToolInfo(LPTOOLINFO lpToolInfo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_SETTOOLINFO, 0, (LPARAM)lpToolInfo);
+ }
+
+ void SetToolRect(LPTOOLINFO lpToolInfo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, (LPARAM)lpToolInfo);
+ }
+
+ void SetToolRect(HWND hWnd, UINT nIDTool, LPCRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hWnd != NULL);
+ ATLASSERT(nIDTool != 0);
+
+ CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRect, NULL);
+ ::SendMessage(m_hWnd, TTM_NEWTOOLRECT, 0, ti);
+ }
+
+ int GetToolCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TTM_GETTOOLCOUNT, 0, 0L);
+ }
+
+ int GetDelayTime(DWORD dwType) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TTM_GETDELAYTIME, dwType, 0L);
+ }
+
+ void SetDelayTime(DWORD dwType, int nTime)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_SETDELAYTIME, dwType, MAKELPARAM(nTime, 0));
+ }
+
+ void GetMargin(LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_GETMARGIN, 0, (LPARAM)lpRect);
+ }
+
+ void SetMargin(LPRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_SETMARGIN, 0, (LPARAM)lpRect);
+ }
+
+ int GetMaxTipWidth() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TTM_GETMAXTIPWIDTH, 0, 0L);
+ }
+
+ int SetMaxTipWidth(int nWidth)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TTM_SETMAXTIPWIDTH, 0, nWidth);
+ }
+
+ COLORREF GetTipBkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPBKCOLOR, 0, 0L);
+ }
+
+ void SetTipBkColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_SETTIPBKCOLOR, (WPARAM)clr, 0L);
+ }
+
+ COLORREF GetTipTextColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TTM_GETTIPTEXTCOLOR, 0, 0L);
+ }
+
+ void SetTipTextColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_SETTIPTEXTCOLOR, (WPARAM)clr, 0L);
+ }
+
+ BOOL GetCurrentTool(LPTOOLINFO lpToolInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TTM_GETCURRENTTOOL, 0, (LPARAM)lpToolInfo);
+ }
+
+#if (_WIN32_IE >= 0x0500)
+ SIZE GetBubbleSize(LPTOOLINFO lpToolInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TTM_GETBUBBLESIZE, 0, (LPARAM)lpToolInfo);
+ SIZE size = { GET_X_LPARAM(dwRet), GET_Y_LPARAM(dwRet) };
+ return size;
+ }
+
+ BOOL SetTitle(UINT uIcon, LPCTSTR lpstrTitle)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TTM_SETTITLE, uIcon, (LPARAM)lpstrTitle);
+ }
+#endif // (_WIN32_IE >= 0x0500)
+
+#if (_WIN32_WINNT >= 0x0501)
+ void GetTitle(PTTGETTITLE pTTGetTitle) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_GETTITLE, 0, (LPARAM)pTTGetTitle);
+ }
+
+ void SetWindowTheme(LPCWSTR lpstrTheme)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+// Operations
+ void Activate(BOOL bActivate)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_ACTIVATE, bActivate, 0L);
+ }
+
+ BOOL AddTool(LPTOOLINFO lpToolInfo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, (LPARAM)lpToolInfo);
+ }
+
+ BOOL AddTool(HWND hWnd, ATL::_U_STRINGorID text = LPSTR_TEXTCALLBACK, LPCRECT lpRectTool = NULL, UINT nIDTool = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hWnd != NULL);
+ // the toolrect and toolid must both be zero or both valid
+ ATLASSERT((lpRectTool != NULL && nIDTool != 0) || (lpRectTool == NULL && nIDTool == 0));
+
+ CToolInfo ti(0, hWnd, nIDTool, (LPRECT)lpRectTool, (LPTSTR)text.m_lpstr);
+ return (BOOL)::SendMessage(m_hWnd, TTM_ADDTOOL, 0, ti);
+ }
+
+ void DelTool(LPTOOLINFO lpToolInfo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_DELTOOL, 0, (LPARAM)lpToolInfo);
+ }
+
+ void DelTool(HWND hWnd, UINT nIDTool = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hWnd != NULL);
+
+ CToolInfo ti(0, hWnd, nIDTool, NULL, NULL);
+ ::SendMessage(m_hWnd, TTM_DELTOOL, 0, ti);
+ }
+
+ BOOL HitTest(LPTTHITTESTINFO lpHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)lpHitTestInfo);
+ }
+
+ BOOL HitTest(HWND hWnd, POINT pt, LPTOOLINFO lpToolInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hWnd != NULL);
+ ATLASSERT(lpToolInfo != NULL);
+
+ TTHITTESTINFO hti = { 0 };
+ hti.ti.cbSize = sizeof(TOOLINFO);
+ hti.hwnd = hWnd;
+ hti.pt.x = pt.x;
+ hti.pt.y = pt.y;
+ if((BOOL)::SendMessage(m_hWnd, TTM_HITTEST, 0, (LPARAM)&hti) != FALSE)
+ {
+ *lpToolInfo = hti.ti;
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ void RelayEvent(LPMSG lpMsg)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)lpMsg);
+ }
+
+ void UpdateTipText(LPTOOLINFO lpToolInfo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, (LPARAM)lpToolInfo);
+ }
+
+ void UpdateTipText(ATL::_U_STRINGorID text, HWND hWnd, UINT nIDTool = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hWnd != NULL);
+
+ CToolInfo ti(0, hWnd, nIDTool, NULL, (LPTSTR)text.m_lpstr);
+ ::SendMessage(m_hWnd, TTM_UPDATETIPTEXT, 0, ti);
+ }
+
+ BOOL EnumTools(UINT nTool, LPTOOLINFO lpToolInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TTM_ENUMTOOLS, nTool, (LPARAM)lpToolInfo);
+ }
+
+ void Pop()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_POP, 0, 0L);
+ }
+
+ void TrackActivate(LPTOOLINFO lpToolInfo, BOOL bActivate)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_TRACKACTIVATE, bActivate, (LPARAM)lpToolInfo);
+ }
+
+ void TrackPosition(int xPos, int yPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_TRACKPOSITION, 0, MAKELPARAM(xPos, yPos));
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ void Update()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_UPDATE, 0, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0500)
+ BOOL AdjustRect(LPRECT lpRect, BOOL bLarger /*= TRUE*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TTM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
+ }
+#endif // (_WIN32_IE >= 0x0500)
+
+#if (_WIN32_WINNT >= 0x0501)
+ void Popup()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TTM_POPUP, 0, 0L);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+};
+
+typedef CToolTipCtrlT<ATL::CWindow> CToolTipCtrl;
+
+#endif // !_WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CHeaderCtrl
+
+template <class TBase>
+class CHeaderCtrlT : public TBase
+{
+public:
+// Constructors
+ CHeaderCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CHeaderCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return WC_HEADER;
+ }
+
+ int GetItemCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_GETITEMCOUNT, 0, 0L);
+ }
+
+ BOOL GetItem(int nIndex, LPHDITEM pHeaderItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_GETITEM, nIndex, (LPARAM)pHeaderItem);
+ }
+
+ BOOL SetItem(int nIndex, LPHDITEM pHeaderItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_SETITEM, nIndex, (LPARAM)pHeaderItem);
+ }
+
+ CImageList GetImageList() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_GETIMAGELIST, 0, 0L));
+ }
+
+ CImageList SetImageList(HIMAGELIST hImageList)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_SETIMAGELIST, 0, (LPARAM)hImageList));
+ }
+
+ BOOL GetOrderArray(int nSize, int* lpnArray) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_GETORDERARRAY, nSize, (LPARAM)lpnArray);
+ }
+
+ BOOL SetOrderArray(int nSize, int* lpnArray)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_SETORDERARRAY, nSize, (LPARAM)lpnArray);
+ }
+
+ BOOL GetItemRect(int nIndex, LPRECT lpItemRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_GETITEMRECT, nIndex, (LPARAM)lpItemRect);
+ }
+
+ int SetHotDivider(BOOL bPos, DWORD dwInputValue)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_SETHOTDIVIDER, bPos, dwInputValue);
+ }
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ int GetBitmapMargin() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_GETBITMAPMARGIN, 0, 0L);
+ }
+
+ int SetBitmapMargin(int nWidth)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_SETBITMAPMARGIN, nWidth, 0L);
+ }
+
+ int SetFilterChangeTimeout(DWORD dwTimeOut)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_SETFILTERCHANGETIMEOUT, 0, dwTimeOut);
+ }
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+#if (_WIN32_WINNT >= 0x0600)
+ BOOL GetItemDropDownRect(int nIndex, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_GETITEMDROPDOWNRECT, nIndex, (LPARAM)lpRect);
+ }
+
+ BOOL GetOverflowRect(LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_GETOVERFLOWRECT, 0, (LPARAM)lpRect);
+ }
+
+ int GetFocusedItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_GETFOCUSEDITEM, 0, 0L);
+ }
+
+ BOOL SetFocusedItem(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_SETFOCUSEDITEM, 0, nIndex);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+// Operations
+ int InsertItem(int nIndex, LPHDITEM phdi)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_INSERTITEM, nIndex, (LPARAM)phdi);
+ }
+
+ int AddItem(LPHDITEM phdi)
+ {
+ return InsertItem(GetItemCount(), phdi);
+ }
+
+ BOOL DeleteItem(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_DELETEITEM, nIndex, 0L);
+ }
+
+ BOOL Layout(HD_LAYOUT* pHeaderLayout)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, HDM_LAYOUT, 0, (LPARAM)pHeaderLayout);
+ }
+
+ int HitTest(LPHDHITTESTINFO lpHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_HITTEST, 0, (LPARAM)lpHitTestInfo);
+ }
+
+ int OrderToIndex(int nOrder)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_ORDERTOINDEX, nOrder, 0L);
+ }
+
+ CImageList CreateDragImage(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, HDM_CREATEDRAGIMAGE, nIndex, 0L));
+ }
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ int EditFilter(int nColumn, BOOL bDiscardChanges)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_EDITFILTER, nColumn, MAKELPARAM(bDiscardChanges, 0));
+ }
+
+ int ClearFilter(int nColumn)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_CLEARFILTER, nColumn, 0L);
+ }
+
+ int ClearAllFilters()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, HDM_CLEARFILTER, (WPARAM)-1, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+};
+
+typedef CHeaderCtrlT<ATL::CWindow> CHeaderCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CListViewCtrl
+
+template <class TBase>
+class CListViewCtrlT : public TBase
+{
+public:
+// Constructors
+ CListViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CListViewCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return WC_LISTVIEW;
+ }
+
+ COLORREF GetBkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETBKCOLOR, 0, 0L);
+ }
+
+ BOOL SetBkColor(COLORREF cr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETBKCOLOR, 0, cr);
+ }
+
+ CImageList GetImageList(int nImageListType) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_GETIMAGELIST, nImageListType, 0L));
+ }
+
+ CImageList SetImageList(HIMAGELIST hImageList, int nImageList)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_SETIMAGELIST, nImageList, (LPARAM)hImageList));
+ }
+
+ int GetItemCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETITEMCOUNT, 0, 0L);
+ }
+
+ BOOL SetItemCount(int nItems)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMCOUNT, nItems, 0L);
+ }
+
+ BOOL GetItem(LPLVITEM pItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
+ }
+
+ BOOL SetItem(const LVITEM* pItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)pItem);
+ }
+
+ BOOL SetItem(int nItem, int nSubItem, UINT nMask, LPCTSTR lpszItem,
+ int nImage, UINT nState, UINT nStateMask, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVITEM lvi = { 0 };
+ lvi.mask = nMask;
+ lvi.iItem = nItem;
+ lvi.iSubItem = nSubItem;
+ lvi.stateMask = nStateMask;
+ lvi.state = nState;
+ lvi.pszText = (LPTSTR) lpszItem;
+ lvi.iImage = nImage;
+ lvi.lParam = lParam;
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEM, 0, (LPARAM)&lvi);
+ }
+
+ UINT GetItemState(int nItem, UINT nMask) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, LVM_GETITEMSTATE, nItem, nMask);
+ }
+
+ BOOL SetItemState(int nItem, UINT nState, UINT nStateMask)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVITEM lvi = { 0 };
+ lvi.state = nState;
+ lvi.stateMask = nStateMask;
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)&lvi);
+ }
+
+ BOOL SetItemState(int nItem, LPLVITEM pItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMSTATE, nItem, (LPARAM)pItem);
+ }
+
+#ifndef _ATL_NO_COM
+ BOOL GetItemText(int nItem, int nSubItem, BSTR& bstrText) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(bstrText == NULL);
+ LVITEM lvi = { 0 };
+ lvi.iSubItem = nSubItem;
+
+ LPTSTR lpstrText = NULL;
+ int nRes = 0;
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ ATLTRY(lpstrText = new TCHAR[nLen]);
+ if(lpstrText == NULL)
+ break;
+ lpstrText[0] = NULL;
+ lvi.cchTextMax = nLen;
+ lvi.pszText = lpstrText;
+ nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
+ if(nRes < nLen - 1)
+ break;
+ delete [] lpstrText;
+ lpstrText = NULL;
+ }
+
+ if(lpstrText != NULL)
+ {
+ if(nRes != 0)
+ bstrText = ::SysAllocString(T2OLE(lpstrText));
+ delete [] lpstrText;
+ }
+
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ int GetItemText(int nItem, int nSubItem, _CSTRING_NS::CString& strText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVITEM lvi = { 0 };
+ lvi.iSubItem = nSubItem;
+
+ strText.Empty();
+ int nRes = 0;
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ lvi.cchTextMax = nLen;
+ lvi.pszText = strText.GetBufferSetLength(nLen);
+ if(lvi.pszText == NULL)
+ {
+ nRes = 0;
+ break;
+ }
+ nRes = (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
+ if(nRes < nLen - 1)
+ break;
+ }
+ strText.ReleaseBuffer();
+ return nRes;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ int GetItemText(int nItem, int nSubItem, LPTSTR lpszText, int nLen) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVITEM lvi = { 0 };
+ lvi.iSubItem = nSubItem;
+ lvi.cchTextMax = nLen;
+ lvi.pszText = lpszText;
+ return (int)::SendMessage(m_hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi);
+ }
+
+ BOOL SetItemText(int nItem, int nSubItem, LPCTSTR lpszText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItem(nItem, nSubItem, LVIF_TEXT, lpszText, 0, 0, 0, 0);
+ }
+
+ DWORD_PTR GetItemData(int nItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVITEM lvi = { 0 };
+ lvi.iItem = nItem;
+ lvi.mask = LVIF_PARAM;
+ BOOL bRet = (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)&lvi);
+ return (DWORD_PTR)(bRet ? lvi.lParam : NULL);
+ }
+
+ BOOL SetItemData(int nItem, DWORD_PTR dwData)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItem(nItem, 0, LVIF_PARAM, NULL, 0, 0, 0, (LPARAM)dwData);
+ }
+
+ UINT GetCallbackMask() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, LVM_GETCALLBACKMASK, 0, 0L);
+ }
+
+ BOOL SetCallbackMask(UINT nMask)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETCALLBACKMASK, nMask, 0L);
+ }
+
+ BOOL GetItemPosition(int nItem, LPPOINT lpPoint) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMPOSITION, nItem, (LPARAM)lpPoint);
+ }
+
+ BOOL SetItemPosition(int nItem, POINT pt)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(((GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
+ }
+
+ BOOL SetItemPosition(int nItem, int x, int y)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(((GetStyle() & LVS_TYPEMASK) == LVS_ICON) || ((GetStyle() & LVS_TYPEMASK) == LVS_SMALLICON));
+ POINT pt = { x, y };
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMPOSITION32, nItem, (LPARAM)&pt);
+ }
+
+ int GetStringWidth(LPCTSTR lpsz) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETSTRINGWIDTH, 0, (LPARAM)lpsz);
+ }
+
+ CEdit GetEditControl() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CEdit((HWND)::SendMessage(m_hWnd, LVM_GETEDITCONTROL, 0, 0L));
+ }
+
+ BOOL GetColumn(int nCol, LVCOLUMN* pColumn) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETCOLUMN, nCol, (LPARAM)pColumn);
+ }
+
+ BOOL SetColumn(int nCol, const LVCOLUMN* pColumn)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMN, nCol, (LPARAM)pColumn);
+ }
+
+ int GetColumnWidth(int nCol) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETCOLUMNWIDTH, nCol, 0L);
+ }
+
+ BOOL SetColumnWidth(int nCol, int cx)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMNWIDTH, nCol, MAKELPARAM(cx, 0));
+ }
+
+ BOOL GetViewRect(LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETVIEWRECT, 0, (LPARAM)lpRect);
+ }
+
+ COLORREF GetTextColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETTEXTCOLOR, 0, 0L);
+ }
+
+ BOOL SetTextColor(COLORREF cr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETTEXTCOLOR, 0, cr);
+ }
+
+ COLORREF GetTextBkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETTEXTBKCOLOR, 0, 0L);
+ }
+
+ BOOL SetTextBkColor(COLORREF cr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETTEXTBKCOLOR, 0, cr);
+ }
+
+ int GetTopIndex() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETTOPINDEX, 0, 0L);
+ }
+
+ int GetCountPerPage() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETCOUNTPERPAGE, 0, 0L);
+ }
+
+ BOOL GetOrigin(LPPOINT lpPoint) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETORIGIN, 0, (LPARAM)lpPoint);
+ }
+
+ UINT GetSelectedCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, LVM_GETSELECTEDCOUNT, 0, 0L);
+ }
+
+ BOOL GetItemRect(int nItem, LPRECT lpRect, UINT nCode) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ lpRect->left = nCode;
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMRECT, (WPARAM)nItem, (LPARAM)lpRect);
+ }
+
+#ifndef _WIN32_WCE
+ HCURSOR GetHotCursor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HCURSOR)::SendMessage(m_hWnd, LVM_GETHOTCURSOR, 0, 0L);
+ }
+
+ HCURSOR SetHotCursor(HCURSOR hHotCursor)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HCURSOR)::SendMessage(m_hWnd, LVM_SETHOTCURSOR, 0, (LPARAM)hHotCursor);
+ }
+
+ int GetHotItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETHOTITEM, 0, 0L);
+ }
+
+ int SetHotItem(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_SETHOTITEM, nIndex, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL GetColumnOrderArray(int nCount, int* lpnArray) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
+ }
+
+ BOOL SetColumnOrderArray(int nCount, int* lpnArray)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETCOLUMNORDERARRAY, nCount, (LPARAM)lpnArray);
+ }
+
+ CHeaderCtrl GetHeader() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CHeaderCtrl((HWND)::SendMessage(m_hWnd, LVM_GETHEADER, 0, 0L));
+ }
+
+ BOOL GetSubItemRect(int nItem, int nSubItem, int nFlag, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & LVS_TYPEMASK) == LVS_REPORT);
+ ATLASSERT(lpRect != NULL);
+ lpRect->top = nSubItem;
+ lpRect->left = nFlag;
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETSUBITEMRECT, nItem, (LPARAM)lpRect);
+ }
+
+ DWORD SetIconSpacing(int cx, int cy)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & LVS_TYPEMASK) == LVS_ICON);
+ return (DWORD)::SendMessage(m_hWnd, LVM_SETICONSPACING, 0, MAKELPARAM(cx, cy));
+ }
+
+ int GetISearchString(LPTSTR lpstr) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
+ }
+
+ void GetItemSpacing(SIZE& sizeSpacing, BOOL bSmallIconView = FALSE) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, LVM_GETITEMSPACING, bSmallIconView, 0L);
+ sizeSpacing.cx = GET_X_LPARAM(dwRet);
+ sizeSpacing.cy = GET_Y_LPARAM(dwRet);
+ }
+
+#if (_WIN32_WCE >= 410)
+ void SetItemSpacing(INT cySpacing)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ListView_SetItemSpacing(m_hWnd, cySpacing);
+ }
+#endif // (_WIN32_WCE >= 410)
+
+ // single-selection only
+ int GetSelectedIndex() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
+ return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
+ }
+
+ BOOL GetSelectedItem(LPLVITEM pItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & LVS_SINGLESEL) != 0);
+ ATLASSERT(pItem != NULL);
+ pItem->iItem = (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, (WPARAM)-1, MAKELPARAM(LVNI_ALL | LVNI_SELECTED, 0));
+ if(pItem->iItem == -1)
+ return FALSE;
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEM, 0, (LPARAM)pItem);
+ }
+
+ // extended list view styles
+ DWORD GetExtendedListViewStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0L);
+ }
+
+ // dwExMask = 0 means all styles
+ DWORD SetExtendedListViewStyle(DWORD dwExStyle, DWORD dwExMask = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, dwExMask, dwExStyle);
+ }
+
+ // checkboxes only
+ BOOL GetCheckState(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetExtendedListViewStyle() & LVS_EX_CHECKBOXES) != 0);
+ UINT uRet = GetItemState(nIndex, LVIS_STATEIMAGEMASK);
+ return (uRet >> 12) - 1;
+ }
+
+ BOOL SetCheckState(int nItem, BOOL bCheck)
+ {
+ int nCheck = bCheck ? 2 : 1; // one based index
+ return SetItemState(nItem, INDEXTOSTATEIMAGEMASK(nCheck), LVIS_STATEIMAGEMASK);
+ }
+
+ // view type
+ DWORD GetViewType() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (GetStyle() & LVS_TYPEMASK);
+ }
+
+ DWORD SetViewType(DWORD dwType)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(dwType == LVS_ICON || dwType == LVS_SMALLICON || dwType == LVS_LIST || dwType == LVS_REPORT);
+ DWORD dwOldType = GetViewType();
+ if(dwType != dwOldType)
+ ModifyStyle(LVS_TYPEMASK, (dwType & LVS_TYPEMASK));
+ return dwOldType;
+ }
+
+#if (_WIN32_IE >= 0x0400)
+#ifndef _WIN32_WCE
+ BOOL GetBkImage(LPLVBKIMAGE plvbki) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETBKIMAGE, 0, (LPARAM)plvbki);
+ }
+
+ BOOL SetBkImage(LPLVBKIMAGE plvbki)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETBKIMAGE, 0, (LPARAM)plvbki);
+ }
+#endif // !_WIN32_WCE
+
+ int GetSelectionMark() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETSELECTIONMARK, 0, 0L);
+ }
+
+ int SetSelectionMark(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_SETSELECTIONMARK, 0, nIndex);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL GetWorkAreas(int nWorkAreas, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
+ }
+
+ BOOL SetWorkAreas(int nWorkAreas, LPRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETWORKAREAS, nWorkAreas, (LPARAM)lpRect);
+ }
+
+ DWORD GetHoverTime() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
+ return (DWORD)::SendMessage(m_hWnd, LVM_GETHOVERTIME, 0, 0L);
+ }
+
+ DWORD SetHoverTime(DWORD dwHoverTime)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetExtendedListViewStyle() & (LVS_EX_TRACKSELECT | LVS_EX_ONECLICKACTIVATE | LVS_EX_TWOCLICKACTIVATE)) != 0);
+ return (DWORD)::SendMessage(m_hWnd, LVM_SETHOVERTIME, 0, dwHoverTime);
+ }
+
+ BOOL GetNumberOfWorkAreas(int* pnWorkAreas) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETNUMBEROFWORKAREAS, 0, (LPARAM)pnWorkAreas);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL SetItemCountEx(int nItems, DWORD dwFlags)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(((GetStyle() & LVS_OWNERDATA) != 0) && (((GetStyle() & LVS_TYPEMASK) == LVS_REPORT) || ((GetStyle() & LVS_TYPEMASK) == LVS_LIST)));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMCOUNT, nItems, dwFlags);
+ }
+
+#ifndef _WIN32_WCE
+ CToolTipCtrl GetToolTips() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, LVM_GETTOOLTIPS, 0, 0L));
+ }
+
+ CToolTipCtrl SetToolTips(HWND hWndTT)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, LVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
+ }
+
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // !_WIN32_WCE
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_WINNT >= 0x0501)
+ int GetSelectedColumn() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETSELECTEDCOLUMN, 0, 0L);
+ }
+
+ void SetSelectedColumn(int nColumn)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_SETSELECTEDCOLUMN, nColumn, 0L);
+ }
+
+ DWORD GetView() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, LVM_GETVIEW, 0, 0L);
+ }
+
+ int SetView(DWORD dwView)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_SETVIEW, dwView, 0L);
+ }
+
+ BOOL IsGroupViewEnabled() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_ISGROUPVIEWENABLED, 0, 0L);
+ }
+
+ int GetGroupInfo(int nGroupID, PLVGROUP pGroup) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETGROUPINFO, nGroupID, (LPARAM)pGroup);
+ }
+
+ int SetGroupInfo(int nGroupID, PLVGROUP pGroup)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_SETGROUPINFO, nGroupID, (LPARAM)pGroup);
+ }
+
+ void GetGroupMetrics(PLVGROUPMETRICS pGroupMetrics) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_GETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
+ }
+
+ void SetGroupMetrics(PLVGROUPMETRICS pGroupMetrics)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_SETGROUPMETRICS, 0, (LPARAM)pGroupMetrics);
+ }
+
+ void GetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_GETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
+ }
+
+ BOOL SetTileViewInfo(PLVTILEVIEWINFO pTileViewInfo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETTILEVIEWINFO, 0, (LPARAM)pTileViewInfo);
+ }
+
+ void GetTileInfo(PLVTILEINFO pTileInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_GETTILEINFO, 0, (LPARAM)pTileInfo);
+ }
+
+ BOOL SetTileInfo(PLVTILEINFO pTileInfo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETTILEINFO, 0, (LPARAM)pTileInfo);
+ }
+
+ BOOL GetInsertMark(LPLVINSERTMARK pInsertMark) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETINSERTMARK, 0, (LPARAM)pInsertMark);
+ }
+
+ BOOL SetInsertMark(LPLVINSERTMARK pInsertMark)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETINSERTMARK, 0, (LPARAM)pInsertMark);
+ }
+
+ int GetInsertMarkRect(LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETINSERTMARKRECT, 0, (LPARAM)lpRect);
+ }
+
+ COLORREF GetInsertMarkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETINSERTMARKCOLOR, 0, 0L);
+ }
+
+ COLORREF SetInsertMarkColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, LVM_SETINSERTMARKCOLOR, 0, clr);
+ }
+
+ COLORREF GetOutlineColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, LVM_GETOUTLINECOLOR, 0, 0L);
+ }
+
+ COLORREF SetOutlineColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, LVM_SETOUTLINECOLOR, 0, clr);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+#if (_WIN32_WINNT >= 0x0600)
+ int GetGroupCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETGROUPCOUNT, 0, 0L);
+ }
+
+ BOOL GetGroupInfoByIndex(int nIndex, PLVGROUP pGroup) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETGROUPINFOBYINDEX, nIndex, (LPARAM)pGroup);
+ }
+
+ BOOL GetGroupRect(int nGroupID, int nType, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpRect != NULL);
+ if(lpRect != NULL)
+ lpRect->top = nType;
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETGROUPRECT, nGroupID, (LPARAM)lpRect);
+ }
+
+ UINT GetGroupState(int nGroupID, UINT uMask) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, LVM_GETGROUPSTATE, nGroupID, (LPARAM)uMask);
+ }
+
+ int GetFocusedGroup() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETFOCUSEDGROUP, 0, 0L);
+ }
+
+ BOOL GetEmptyText(LPWSTR lpstrText, int cchText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETEMPTYTEXT, cchText, (LPARAM)lpstrText);
+ }
+
+ BOOL GetFooterRect(LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERRECT, 0, (LPARAM)lpRect);
+ }
+
+ BOOL GetFooterInfo(LPLVFOOTERINFO lpFooterInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERINFO, 0, (LPARAM)lpFooterInfo);
+ }
+
+ BOOL GetFooterItemRect(int nItem, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERITEMRECT, nItem, (LPARAM)lpRect);
+ }
+
+ BOOL GetFooterItem(int nItem, LPLVFOOTERITEM lpFooterItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETFOOTERITEM, nItem, (LPARAM)lpFooterItem);
+ }
+
+ BOOL GetItemIndexRect(PLVITEMINDEX pItemIndex, int nSubItem, int nType, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(pItemIndex != NULL);
+ ATLASSERT(lpRect != NULL);
+ if(lpRect != NULL)
+ {
+ lpRect->top = nSubItem;
+ lpRect->left = nType;
+ }
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETITEMINDEXRECT, (WPARAM)pItemIndex, (LPARAM)lpRect);
+ }
+
+ BOOL SetItemIndexState(PLVITEMINDEX pItemIndex, UINT uState, UINT dwMask)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVITEM lvi = { 0 };
+ lvi.state = uState;
+ lvi.stateMask = dwMask;
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETITEMINDEXSTATE, (WPARAM)pItemIndex, (LPARAM)&lvi);
+ }
+
+ BOOL GetNextItemIndex(PLVITEMINDEX pItemIndex, WORD wFlags) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_GETNEXTITEMINDEX, (WPARAM)pItemIndex, MAKELPARAM(wFlags, 0));
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+// Operations
+ int InsertColumn(int nCol, const LVCOLUMN* pColumn)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn);
+ }
+
+ int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT,
+ int nWidth = -1, int nSubItem = -1, int iImage = -1, int iOrder = -1)
+ {
+ LVCOLUMN column = { 0 };
+ column.mask = LVCF_TEXT|LVCF_FMT;
+ column.pszText = (LPTSTR)lpszColumnHeading;
+ column.fmt = nFormat;
+ if (nWidth != -1)
+ {
+ column.mask |= LVCF_WIDTH;
+ column.cx = nWidth;
+ }
+ if (nSubItem != -1)
+ {
+ column.mask |= LVCF_SUBITEM;
+ column.iSubItem = nSubItem;
+ }
+ if (iImage != -1)
+ {
+ column.mask |= LVCF_IMAGE;
+ column.iImage = iImage;
+ }
+ if (iOrder != -1)
+ {
+ column.mask |= LVCF_ORDER;
+ column.iOrder = iOrder;
+ }
+ return InsertColumn(nCol, &column);
+ }
+
+ BOOL DeleteColumn(int nCol)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_DELETECOLUMN, nCol, 0L);
+ }
+
+ int InsertItem(UINT nMask, int nItem, LPCTSTR lpszItem, UINT nState, UINT nStateMask, int nImage, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVITEM item = { 0 };
+ item.mask = nMask;
+ item.iItem = nItem;
+ item.iSubItem = 0;
+ item.pszText = (LPTSTR)lpszItem;
+ item.state = nState;
+ item.stateMask = nStateMask;
+ item.iImage = nImage;
+ item.lParam = lParam;
+ return InsertItem(&item);
+ }
+
+ int InsertItem(const LVITEM* pItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_INSERTITEM, 0, (LPARAM)pItem);
+ }
+
+ int InsertItem(int nItem, LPCTSTR lpszItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return InsertItem(LVIF_TEXT, nItem, lpszItem, 0, 0, 0, 0);
+ }
+
+ int InsertItem(int nItem, LPCTSTR lpszItem, int nImage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return InsertItem(LVIF_TEXT|LVIF_IMAGE, nItem, lpszItem, 0, 0, nImage, 0);
+ }
+
+ int GetNextItem(int nItem, int nFlags) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_GETNEXTITEM, nItem, MAKELPARAM(nFlags, 0));
+ }
+
+ BOOL DeleteItem(int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_DELETEITEM, nItem, 0L);
+ }
+
+ BOOL DeleteAllItems()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_DELETEALLITEMS, 0, 0L);
+ }
+
+ int FindItem(LVFINDINFO* pFindInfo, int nStart) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_FINDITEM, nStart, (LPARAM)pFindInfo);
+ }
+
+ int HitTest(LVHITTESTINFO* pHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_HITTEST, 0, (LPARAM)pHitTestInfo);
+ }
+
+ int HitTest(POINT pt, UINT* pFlags) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVHITTESTINFO hti = { 0 };
+ hti.pt = pt;
+ int nRes = (int)::SendMessage(m_hWnd, LVM_HITTEST, 0, (LPARAM)&hti);
+ if (pFlags != NULL)
+ *pFlags = hti.flags;
+ return nRes;
+ }
+
+ BOOL EnsureVisible(int nItem, BOOL bPartialOK)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_ENSUREVISIBLE, nItem, MAKELPARAM(bPartialOK, 0));
+ }
+
+ BOOL Scroll(SIZE size)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SCROLL, size.cx, size.cy);
+ }
+
+ BOOL RedrawItems(int nFirst, int nLast)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_REDRAWITEMS, nFirst, nLast);
+ }
+
+ BOOL Arrange(UINT nCode)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_ARRANGE, nCode, 0L);
+ }
+
+ CEdit EditLabel(int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CEdit((HWND)::SendMessage(m_hWnd, LVM_EDITLABEL, nItem, 0L));
+ }
+
+ BOOL Update(int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_UPDATE, nItem, 0L);
+ }
+
+ BOOL SortItems(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SORTITEMS, (WPARAM)lParamSort, (LPARAM)pfnCompare);
+ }
+
+ CImageList RemoveImageList(int nImageList)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
+ }
+
+ CImageList CreateDragImage(int nItem, LPPOINT lpPoint)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, LVM_CREATEDRAGIMAGE, nItem, (LPARAM)lpPoint));
+ }
+
+ DWORD ApproximateViewRect(int cx = -1, int cy = -1, int nCount = -1)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, LVM_APPROXIMATEVIEWRECT, nCount, MAKELPARAM(cx, cy));
+ }
+
+ int SubItemHitTest(LPLVHITTESTINFO lpInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_SUBITEMHITTEST, 0, (LPARAM)lpInfo);
+ }
+
+ int AddColumn(LPCTSTR strItem, int nItem, int nSubItem = -1,
+ int nMask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM,
+ int nFmt = LVCFMT_LEFT)
+ {
+ const int cxOffset = 15;
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVCOLUMN lvc = { 0 };
+ lvc.mask = nMask;
+ lvc.fmt = nFmt;
+ lvc.pszText = (LPTSTR)strItem;
+ lvc.cx = GetStringWidth(lvc.pszText) + cxOffset;
+ if(nMask & LVCF_SUBITEM)
+ lvc.iSubItem = (nSubItem != -1) ? nSubItem : nItem;
+ return InsertColumn(nItem, &lvc);
+ }
+
+ int AddItem(int nItem, int nSubItem, LPCTSTR strItem, int nImageIndex = -1)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVITEM lvItem = { 0 };
+ lvItem.mask = LVIF_TEXT;
+ lvItem.iItem = nItem;
+ lvItem.iSubItem = nSubItem;
+ lvItem.pszText = (LPTSTR)strItem;
+ if(nImageIndex != -1)
+ {
+ lvItem.mask |= LVIF_IMAGE;
+ lvItem.iImage = nImageIndex;
+ }
+ if(nSubItem == 0)
+ return InsertItem(&lvItem);
+ return SetItem(&lvItem) ? nItem : -1;
+ }
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ BOOL SortItemsEx(PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SORTITEMSEX, (WPARAM)lParamSort, (LPARAM)pfnCompare);
+ }
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+#if (_WIN32_WINNT >= 0x0501)
+ int InsertGroup(int nItem, PLVGROUP pGroup)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_INSERTGROUP, nItem, (LPARAM)pGroup);
+ }
+
+ int AddGroup(PLVGROUP pGroup)
+ {
+ return InsertGroup(-1, pGroup);
+ }
+
+ int RemoveGroup(int nGroupID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_REMOVEGROUP, nGroupID, 0L);
+ }
+
+ void MoveGroup(int nGroupID, int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_MOVEGROUP, nGroupID, nItem);
+ }
+
+ void MoveItemToGroup(int nItem, int nGroupID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_MOVEITEMTOGROUP, nItem, nGroupID);
+ }
+
+ int EnableGroupView(BOOL bEnable)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_ENABLEGROUPVIEW, bEnable, 0L);
+ }
+
+ int SortGroups(PFNLVGROUPCOMPARE pCompareFunc, LPVOID lpVoid = NULL)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_SORTGROUPS, (WPARAM)pCompareFunc, (LPARAM)lpVoid);
+ }
+
+ void InsertGroupSorted(PLVINSERTGROUPSORTED pInsertGroupSorted)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_INSERTGROUPSORTED, (WPARAM)pInsertGroupSorted, 0L);
+ }
+
+ void RemoveAllGroups()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_REMOVEALLGROUPS, 0, 0L);
+ }
+
+ BOOL HasGroup(int nGroupID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_HASGROUP, nGroupID, 0L);
+ }
+
+ BOOL InsertMarkHitTest(LPPOINT lpPoint, LPLVINSERTMARK pInsertMark) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)pInsertMark);
+ }
+
+ BOOL SetInfoTip(PLVSETINFOTIP pSetInfoTip)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LVM_SETINFOTIP, 0, (LPARAM)pSetInfoTip);
+ }
+
+ void CancelEditLabel()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, LVM_CANCELEDITLABEL, 0, 0L);
+ }
+
+ UINT MapIndexToID(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, LVM_MAPINDEXTOID, nIndex, 0L);
+ }
+
+ int MapIDToIndex(UINT uID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_MAPIDTOINDEX, uID, 0L);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+#if (_WIN32_WINNT >= 0x0600)
+ int HitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
+ }
+
+ int HitTestEx(POINT pt, UINT* pFlags) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ LVHITTESTINFO hti = { 0 };
+ hti.pt = pt;
+ int nRes = (int)::SendMessage(m_hWnd, LVM_HITTEST, (WPARAM)-1, (LPARAM)&hti);
+ if (pFlags != NULL)
+ *pFlags = hti.flags;
+ return nRes;
+ }
+
+ int SubItemHitTestEx(LPLVHITTESTINFO lpHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LVM_SUBITEMHITTEST, (WPARAM)-1, (LPARAM)lpHitTestInfo);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+ // Note: selects only one item
+ BOOL SelectItem(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+
+ // multi-selection only: de-select all items
+ if((GetStyle() & LVS_SINGLESEL) == 0)
+ SetItemState(-1, 0, LVIS_SELECTED);
+
+ BOOL bRet = SetItemState(nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
+ if(bRet)
+ bRet = EnsureVisible(nIndex, FALSE);
+
+ return bRet;
+ }
+};
+
+typedef CListViewCtrlT<ATL::CWindow> CListViewCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CTreeViewCtrl
+
+template <class TBase>
+class CTreeViewCtrlT : public TBase
+{
+public:
+// Constructors
+ CTreeViewCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CTreeViewCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return WC_TREEVIEW;
+ }
+
+ UINT GetCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, TVM_GETCOUNT, 0, 0L);
+ }
+
+ UINT GetIndent() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, TVM_GETINDENT, 0, 0L);
+ }
+
+ void SetIndent(UINT nIndent)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TVM_SETINDENT, nIndent, 0L);
+ }
+
+ CImageList GetImageList(int nImageListType = TVSIL_NORMAL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_GETIMAGELIST, (WPARAM)nImageListType, 0L));
+ }
+
+ CImageList SetImageList(HIMAGELIST hImageList, int nImageListType = TVSIL_NORMAL)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageListType, (LPARAM)hImageList));
+ }
+
+ BOOL GetItem(LPTVITEM pItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
+ }
+
+ BOOL SetItem(LPTVITEM pItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
+ }
+
+ BOOL SetItem(HTREEITEM hItem, UINT nMask, LPCTSTR lpszItem, int nImage,
+ int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVITEM item = { 0 };
+ item.hItem = hItem;
+ item.mask = nMask;
+ item.pszText = (LPTSTR) lpszItem;
+ item.iImage = nImage;
+ item.iSelectedImage = nSelectedImage;
+ item.state = nState;
+ item.stateMask = nStateMask;
+ item.lParam = lParam;
+ return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)&item);
+ }
+
+ BOOL GetItemText(HTREEITEM hItem, LPTSTR lpstrText, int nLen) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpstrText != NULL);
+
+ TVITEM item = { 0 };
+ item.hItem = hItem;
+ item.mask = TVIF_TEXT;
+ item.pszText = lpstrText;
+ item.cchTextMax = nLen;
+
+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
+ }
+
+#ifndef _ATL_NO_COM
+ BOOL GetItemText(HTREEITEM hItem, BSTR& bstrText) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(bstrText == NULL);
+ TVITEM item = { 0 };
+ item.hItem = hItem;
+ item.mask = TVIF_TEXT;
+
+ LPTSTR lpstrText = NULL;
+ BOOL bRet = FALSE;
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ ATLTRY(lpstrText = new TCHAR[nLen]);
+ if(lpstrText == NULL)
+ break;
+ lpstrText[0] = NULL;
+ item.pszText = lpstrText;
+ item.cchTextMax = nLen;
+ bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
+ if(!bRet || (lstrlen(item.pszText) < nLen - 1))
+ break;
+ delete [] lpstrText;
+ lpstrText = NULL;
+ }
+
+ if(lpstrText != NULL)
+ {
+ if(bRet)
+ bstrText = ::SysAllocString(T2OLE(lpstrText));
+ delete [] lpstrText;
+ }
+
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ BOOL GetItemText(HTREEITEM hItem, _CSTRING_NS::CString& strText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVITEM item = { 0 };
+ item.hItem = hItem;
+ item.mask = TVIF_TEXT;
+
+ strText.Empty();
+ BOOL bRet = FALSE;
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ item.pszText = strText.GetBufferSetLength(nLen);
+ if(item.pszText == NULL)
+ {
+ bRet = FALSE;
+ break;
+ }
+ item.cchTextMax = nLen;
+ bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
+ if(!bRet || (lstrlen(item.pszText) < nLen - 1))
+ break;
+ }
+ strText.ReleaseBuffer();
+ return bRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ BOOL SetItemText(HTREEITEM hItem, LPCTSTR lpszItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItem(hItem, TVIF_TEXT, lpszItem, 0, 0, 0, 0, NULL);
+ }
+
+ BOOL GetItemImage(HTREEITEM hItem, int& nImage, int& nSelectedImage) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVITEM item = { 0 };
+ item.hItem = hItem;
+ item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
+ BOOL bRes = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
+ if (bRes)
+ {
+ nImage = item.iImage;
+ nSelectedImage = item.iSelectedImage;
+ }
+ return bRes;
+ }
+
+ BOOL SetItemImage(HTREEITEM hItem, int nImage, int nSelectedImage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItem(hItem, TVIF_IMAGE|TVIF_SELECTEDIMAGE, NULL, nImage, nSelectedImage, 0, 0, NULL);
+ }
+
+ UINT GetItemState(HTREEITEM hItem, UINT nStateMask) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ return (((UINT)::SendMessage(m_hWnd, TVM_GETITEMSTATE, (WPARAM)hItem, (LPARAM)nStateMask)) & nStateMask);
+#else // !((_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE))
+ TVITEM item = { 0 };
+ item.hItem = hItem;
+ item.mask = TVIF_STATE;
+ item.state = 0;
+ item.stateMask = nStateMask;
+ ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
+ return (item.state & nStateMask);
+#endif // !((_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE))
+ }
+
+ BOOL SetItemState(HTREEITEM hItem, UINT nState, UINT nStateMask)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItem(hItem, TVIF_STATE, NULL, 0, 0, nState, nStateMask, NULL);
+ }
+
+ DWORD_PTR GetItemData(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVITEM item = { 0 };
+ item.hItem = hItem;
+ item.mask = TVIF_PARAM;
+ BOOL bRet = (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
+ return (DWORD_PTR)(bRet ? item.lParam : NULL);
+ }
+
+ BOOL SetItemData(HTREEITEM hItem, DWORD_PTR dwData)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItem(hItem, TVIF_PARAM, NULL, 0, 0, 0, 0, (LPARAM)dwData);
+ }
+
+ CEdit GetEditControl() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CEdit((HWND)::SendMessage(m_hWnd, TVM_GETEDITCONTROL, 0, 0L));
+ }
+
+ UINT GetVisibleCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, TVM_GETVISIBLECOUNT, 0, 0L);
+ }
+
+ BOOL GetItemRect(HTREEITEM hItem, LPRECT lpRect, BOOL bTextOnly) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ *(HTREEITEM*)lpRect = hItem;
+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEMRECT, (WPARAM)bTextOnly, (LPARAM)lpRect);
+ }
+
+ BOOL ItemHasChildren(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVITEM item = { 0 };
+ item.hItem = hItem;
+ item.mask = TVIF_CHILDREN;
+ ::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)&item);
+ return item.cChildren;
+ }
+
+#ifndef _WIN32_WCE
+ CToolTipCtrl GetToolTips() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TVM_GETTOOLTIPS, 0, 0L));
+ }
+
+ CToolTipCtrl SetToolTips(HWND hWndTT)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TVM_SETTOOLTIPS, (WPARAM)hWndTT, 0L));
+ }
+#endif // !_WIN32_WCE
+
+ int GetISearchString(LPTSTR lpstr) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TVM_GETISEARCHSTRING, 0, (LPARAM)lpstr);
+ }
+
+ // checkboxes only
+ BOOL GetCheckState(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & TVS_CHECKBOXES) != 0);
+ UINT uRet = GetItemState(hItem, TVIS_STATEIMAGEMASK);
+ return (uRet >> 12) - 1;
+ }
+
+ BOOL SetCheckState(HTREEITEM hItem, BOOL bCheck)
+ {
+ int nCheck = bCheck ? 2 : 1; // one based index
+ return SetItemState(hItem, INDEXTOSTATEIMAGEMASK(nCheck), TVIS_STATEIMAGEMASK);
+ }
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ COLORREF GetBkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TVM_GETBKCOLOR, 0, 0L);
+ }
+
+ COLORREF SetBkColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TVM_SETBKCOLOR, 0, (LPARAM)clr);
+ }
+
+ COLORREF GetInsertMarkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TVM_GETINSERTMARKCOLOR, 0, 0L);
+ }
+
+ COLORREF SetInsertMarkColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TVM_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
+ }
+
+ int GetItemHeight() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TVM_GETITEMHEIGHT, 0, 0L);
+ }
+
+ int SetItemHeight(int cyHeight)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TVM_SETITEMHEIGHT, cyHeight, 0L);
+ }
+
+ int GetScrollTime() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TVM_GETSCROLLTIME, 0, 0L);
+ }
+
+ int SetScrollTime(int nScrollTime)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TVM_SETSCROLLTIME, nScrollTime, 0L);
+ }
+
+ COLORREF GetTextColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TVM_GETTEXTCOLOR, 0, 0L);
+ }
+
+ COLORREF SetTextColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TVM_SETTEXTCOLOR, 0, (LPARAM)clr);
+ }
+
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ COLORREF GetLineColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TVM_GETLINECOLOR, 0, 0L);
+ }
+
+ COLORREF SetLineColor(COLORREF clrNew /*= CLR_DEFAULT*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TVM_SETLINECOLOR, 0, (LPARAM)clrNew);
+ }
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ BOOL GetItem(LPTVITEMEX pItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEM, 0, (LPARAM)pItem);
+ }
+
+ BOOL SetItem(LPTVITEMEX pItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SETITEM, 0, (LPARAM)pItem);
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+ DWORD GetExtendedStyle() const
+ {
+#ifndef TVM_GETEXTENDEDSTYLE
+ const UINT TVM_GETEXTENDEDSTYLE = (TV_FIRST + 45);
+#endif
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TVM_GETEXTENDEDSTYLE, 0, 0L);
+ }
+
+ DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
+ {
+#ifndef TVM_SETEXTENDEDSTYLE
+ const UINT TVM_SETEXTENDEDSTYLE = (TV_FIRST + 44);
+#endif
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TVM_SETEXTENDEDSTYLE, dwMask, dwStyle);
+ }
+
+#if (_WIN32_WINNT >= 0x0600)
+ BOOL SetAutoScrollInfo(UINT uPixPerSec, UINT uUpdateTime)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SETAUTOSCROLLINFO, (WPARAM)uPixPerSec, (LPARAM)uUpdateTime);
+ }
+
+ DWORD GetSelectedCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TVM_GETSELECTEDCOUNT, 0, 0L);
+ }
+
+ BOOL GetItemPartRect(HTREEITEM hItem, TVITEMPART partID, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVGETITEMPARTRECTINFO gipri = { hItem, lpRect, partID };
+ return (BOOL)::SendMessage(m_hWnd, TVM_GETITEMPARTRECT, 0, (LPARAM)&gipri);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+// Operations
+ HTREEITEM InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
+ }
+
+ HTREEITEM InsertItem(LPCTSTR lpszItem, int nImage,
+ int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
+ }
+
+ HTREEITEM InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
+ }
+
+ HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
+ int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
+ HTREEITEM hParent, HTREEITEM hInsertAfter)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVINSERTSTRUCT tvis = { 0 };
+ tvis.hParent = hParent;
+ tvis.hInsertAfter = hInsertAfter;
+ tvis.item.mask = nMask;
+ tvis.item.pszText = (LPTSTR) lpszItem;
+ tvis.item.iImage = nImage;
+ tvis.item.iSelectedImage = nSelectedImage;
+ tvis.item.state = nState;
+ tvis.item.stateMask = nStateMask;
+ tvis.item.lParam = lParam;
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
+ }
+
+ BOOL DeleteItem(HTREEITEM hItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_DELETEITEM, 0, (LPARAM)hItem);
+ }
+
+ BOOL DeleteAllItems()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_DELETEITEM, 0, (LPARAM)TVI_ROOT);
+ }
+
+ BOOL Expand(HTREEITEM hItem, UINT nCode = TVE_EXPAND)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_EXPAND, nCode, (LPARAM)hItem);
+ }
+
+ HTREEITEM GetNextItem(HTREEITEM hItem, UINT nCode) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
+ }
+
+ HTREEITEM GetChildItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
+ }
+
+ HTREEITEM GetNextSiblingItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
+ }
+
+ HTREEITEM GetPrevSiblingItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
+ }
+
+ HTREEITEM GetParentItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
+ }
+
+ HTREEITEM GetFirstVisibleItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
+ }
+
+ HTREEITEM GetNextVisibleItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
+ }
+
+ HTREEITEM GetPrevVisibleItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
+ }
+
+ HTREEITEM GetSelectedItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
+ }
+
+ HTREEITEM GetDropHilightItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
+ }
+
+ HTREEITEM GetRootItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
+ }
+
+#if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
+ HTREEITEM GetLastVisibleItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
+ }
+#endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0600)
+ HTREEITEM GetNextSelectedItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0600)
+
+ BOOL Select(HTREEITEM hItem, UINT nCode)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, nCode, (LPARAM)hItem);
+ }
+
+ BOOL SelectItem(HTREEITEM hItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
+ }
+
+ BOOL SelectDropTarget(HTREEITEM hItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_DROPHILITE, (LPARAM)hItem);
+ }
+
+ BOOL SelectSetFirstVisible(HTREEITEM hItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SELECTITEM, TVGN_FIRSTVISIBLE, (LPARAM)hItem);
+ }
+
+ CEdit EditLabel(HTREEITEM hItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CEdit((HWND)::SendMessage(m_hWnd, TVM_EDITLABEL, 0, (LPARAM)hItem));
+ }
+
+ BOOL EndEditLabelNow(BOOL bCancel)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_ENDEDITLABELNOW, bCancel, 0L);
+ }
+
+ HTREEITEM HitTest(TVHITTESTINFO* pHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
+ }
+
+ HTREEITEM HitTest(POINT pt, UINT* pFlags) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVHITTESTINFO hti = { 0 };
+ hti.pt = pt;
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
+ if (pFlags != NULL)
+ *pFlags = hti.flags;
+ return hTreeItem;
+ }
+
+ BOOL SortChildren(HTREEITEM hItem, BOOL bRecurse = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SORTCHILDREN, (WPARAM)bRecurse, (LPARAM)hItem);
+ }
+
+ BOOL EnsureVisible(HTREEITEM hItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
+ }
+
+ BOOL SortChildrenCB(LPTVSORTCB pSort, BOOL bRecurse = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SORTCHILDRENCB, (WPARAM)bRecurse, (LPARAM)pSort);
+ }
+
+ CImageList RemoveImageList(int nImageList)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM)nImageList, NULL));
+ }
+
+ CImageList CreateDragImage(HTREEITEM hItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TVM_CREATEDRAGIMAGE, 0, (LPARAM)hItem));
+ }
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ BOOL SetInsertMark(HTREEITEM hTreeItem, BOOL bAfter)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SETINSERTMARK, bAfter, (LPARAM)hTreeItem);
+ }
+
+ BOOL RemoveInsertMark()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TVM_SETINSERTMARK, 0, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+#if (_WIN32_WINNT >= 0x0501)
+ HTREEITEM MapAccIDToHTREEITEM(UINT uID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HTREEITEM)::SendMessage(m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
+ }
+
+ UINT MapHTREEITEMToAccID(HTREEITEM hTreeItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, TVM_MAPHTREEITEMTOACCID, (WPARAM)hTreeItem, 0L);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+#if (_WIN32_WINNT >= 0x0600)
+ void ShowInfoTip(HTREEITEM hItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TVM_SHOWINFOTIP, 0, (LPARAM)hItem);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+};
+
+typedef CTreeViewCtrlT<ATL::CWindow> CTreeViewCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CTreeViewCtrlEx
+
+// forward declaration
+template <class TBase> class CTreeViewCtrlExT;
+
+// Note: TBase here is for CTreeViewCtrlExT, and not for CTreeItemT itself
+template <class TBase>
+class CTreeItemT
+{
+public:
+ HTREEITEM m_hTreeItem;
+ CTreeViewCtrlExT<TBase>* m_pTreeView;
+
+// Construction
+ CTreeItemT(HTREEITEM hTreeItem = NULL, CTreeViewCtrlExT<TBase>* pTreeView = NULL) : m_hTreeItem(hTreeItem), m_pTreeView(pTreeView)
+ { }
+
+ CTreeItemT(const CTreeItemT<TBase>& posSrc)
+ {
+ *this = posSrc;
+ }
+
+ operator HTREEITEM() { return m_hTreeItem; }
+
+ CTreeItemT<TBase>& operator =(const CTreeItemT<TBase>& itemSrc)
+ {
+ m_hTreeItem = itemSrc.m_hTreeItem;
+ m_pTreeView = itemSrc.m_pTreeView;
+ return *this;
+ }
+
+// Attributes
+ CTreeViewCtrlExT<TBase>* GetTreeView() const { return m_pTreeView; }
+
+ BOOL operator !() const { return m_hTreeItem == NULL; }
+
+ BOOL IsNull() const { return m_hTreeItem == NULL; }
+
+ BOOL GetRect(LPRECT lpRect, BOOL bTextOnly) const;
+ BOOL GetText(LPTSTR lpstrText, int nLen) const;
+#ifndef _ATL_NO_COM
+ BOOL GetText(BSTR& bstrText) const;
+#endif // !_ATL_NO_COM
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ BOOL GetText(_CSTRING_NS::CString& strText) const;
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ BOOL SetText(LPCTSTR lpszItem);
+ BOOL GetImage(int& nImage, int& nSelectedImage) const;
+ BOOL SetImage(int nImage, int nSelectedImage);
+ UINT GetState(UINT nStateMask) const;
+ BOOL SetState(UINT nState, UINT nStateMask);
+ DWORD_PTR GetData() const;
+ BOOL SetData(DWORD_PTR dwData);
+ BOOL SetItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam);
+
+// Operations
+ CTreeItemT<TBase> InsertAfter(LPCTSTR lpstrItem, HTREEITEM hItemAfter, int nImageIndex)
+ {
+ return _Insert(lpstrItem, nImageIndex, hItemAfter);
+ }
+
+ CTreeItemT<TBase> AddHead(LPCTSTR lpstrItem, int nImageIndex)
+ {
+ return _Insert(lpstrItem, nImageIndex, TVI_FIRST);
+ }
+
+ CTreeItemT<TBase> AddTail(LPCTSTR lpstrItem, int nImageIndex)
+ {
+ return _Insert(lpstrItem, nImageIndex, TVI_LAST);
+ }
+
+ CTreeItemT<TBase> GetChild() const;
+ CTreeItemT<TBase> GetNext(UINT nCode) const;
+ CTreeItemT<TBase> GetNextSibling() const;
+ CTreeItemT<TBase> GetPrevSibling() const;
+ CTreeItemT<TBase> GetParent() const;
+ CTreeItemT<TBase> GetFirstVisible() const;
+ CTreeItemT<TBase> GetNextVisible() const;
+ CTreeItemT<TBase> GetPrevVisible() const;
+ CTreeItemT<TBase> GetSelected() const;
+ CTreeItemT<TBase> GetDropHilight() const;
+ CTreeItemT<TBase> GetRoot() const;
+#if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
+ CTreeItemT<TBase> GetLastVisible() const;
+#endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
+#if (_WIN32_IE >= 0x0600)
+ CTreeItemT<TBase> GetNextSelected() const;
+#endif // (_WIN32_IE >= 0x0600)
+ BOOL HasChildren() const;
+ BOOL Delete();
+ BOOL Expand(UINT nCode = TVE_EXPAND);
+ BOOL Select(UINT nCode);
+ BOOL Select();
+ BOOL SelectDropTarget();
+ BOOL SelectSetFirstVisible();
+ HWND EditLabel();
+ HIMAGELIST CreateDragImage();
+ BOOL SortChildren(BOOL bRecurse = FALSE);
+ BOOL EnsureVisible();
+ CTreeItemT<TBase> _Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter);
+ int GetImageIndex() const;
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ BOOL SetInsertMark(BOOL bAfter);
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+#if (_WIN32_WINNT >= 0x0501)
+ UINT MapHTREEITEMToAccID() const;
+#endif // (_WIN32_WINNT >= 0x0501)
+#if (_WIN32_WINNT >= 0x0600)
+ void ShowInfoTip();
+ BOOL GetPartRect(TVITEMPART partID, LPRECT lpRect) const;
+#endif // (_WIN32_WINNT >= 0x0600)
+};
+
+typedef CTreeItemT<ATL::CWindow> CTreeItem;
+
+
+template <class TBase>
+class CTreeViewCtrlExT : public CTreeViewCtrlT< TBase >
+{
+public:
+// Constructors
+ CTreeViewCtrlExT(HWND hWnd = NULL) : CTreeViewCtrlT< TBase >(hWnd)
+ { }
+
+ CTreeViewCtrlExT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Operations (overides that return CTreeItem)
+ CTreeItemT<TBase> InsertItem(LPTVINSERTSTRUCT lpInsertStruct)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)lpInsertStruct);
+ return CTreeItemT<TBase>(hTreeItem, this);
+ }
+
+ CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, int nImage,
+ int nSelectedImage, HTREEITEM hParent, HTREEITEM hInsertAfter)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE, lpszItem, nImage, nSelectedImage, 0, 0, 0, hParent, hInsertAfter);
+ }
+
+ CTreeItemT<TBase> InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return InsertItem(TVIF_TEXT, lpszItem, 0, 0, 0, 0, 0, hParent, hInsertAfter);
+ }
+
+ CTreeItemT<TBase> GetNextItem(HTREEITEM hItem, UINT nCode) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, nCode, (LPARAM)hItem);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetChildItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CHILD, (LPARAM)hItem);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetNextSiblingItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXT, (LPARAM)hItem);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetPrevSiblingItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUS, (LPARAM)hItem);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetParentItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PARENT, (LPARAM)hItem);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetFirstVisibleItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_FIRSTVISIBLE, 0L);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetNextVisibleItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTVISIBLE, (LPARAM)hItem);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetPrevVisibleItem(HTREEITEM hItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_PREVIOUSVISIBLE, (LPARAM)hItem);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetSelectedItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_CARET, 0L);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetDropHilightItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_DROPHILITE, 0L);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> GetRootItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_ROOT, 0L);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+#if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
+ CTreeItemT<TBase> GetLastVisibleItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_LASTVISIBLE, 0L);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+#endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0600)
+ CTreeItemT<TBase> GetNextSelectedItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_GETNEXTITEM, TVGN_NEXTSELECTED, 0L);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+#endif // (_WIN32_IE >= 0x0600)
+
+ CTreeItemT<TBase> HitTest(TVHITTESTINFO* pHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)pHitTestInfo);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+ CTreeItemT<TBase> InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage,
+ int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam,
+ HTREEITEM hParent, HTREEITEM hInsertAfter)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVINSERTSTRUCT tvis = { 0 };
+ tvis.hParent = hParent;
+ tvis.hInsertAfter = hInsertAfter;
+ tvis.item.mask = nMask;
+ tvis.item.pszText = (LPTSTR) lpszItem;
+ tvis.item.iImage = nImage;
+ tvis.item.iSelectedImage = nSelectedImage;
+ tvis.item.state = nState;
+ tvis.item.stateMask = nStateMask;
+ tvis.item.lParam = lParam;
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEM, 0, (LPARAM)&tvis);
+ return CTreeItemT<TBase>(hTreeItem, this);
+ }
+
+ CTreeItemT<TBase> HitTest(POINT pt, UINT* pFlags) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TVHITTESTINFO hti = { 0 };
+ hti.pt = pt;
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_HITTEST, 0, (LPARAM)&hti);
+ if (pFlags != NULL)
+ *pFlags = hti.flags;
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+
+#if (_WIN32_WINNT >= 0x0501)
+ CTreeItemT<TBase> MapAccIDToHTREEITEM(UINT uID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HTREEITEM hTreeItem = (HTREEITEM)::SendMessage(m_hWnd, TVM_MAPACCIDTOHTREEITEM, uID, 0L);
+ return CTreeItemT<TBase>(hTreeItem, (CTreeViewCtrlExT<TBase>*)this);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+};
+
+typedef CTreeViewCtrlExT<ATL::CWindow> CTreeViewCtrlEx;
+
+
+// CTreeItem inline methods
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::GetRect(LPRECT lpRect, BOOL bTextOnly) const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetItemRect(m_hTreeItem,lpRect,bTextOnly);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNext(UINT nCode) const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetNextItem(m_hTreeItem,nCode);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetChild() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetChildItem(m_hTreeItem);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSibling() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetNextSiblingItem(m_hTreeItem);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevSibling() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetPrevSiblingItem(m_hTreeItem);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetParent() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetParentItem(m_hTreeItem);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetFirstVisible() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetFirstVisibleItem();
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextVisible() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetNextVisibleItem(m_hTreeItem);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetPrevVisible() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetPrevVisibleItem(m_hTreeItem);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetSelected() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetSelectedItem();
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetDropHilight() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetDropHilightItem();
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetRoot() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetRootItem();
+}
+
+#if !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetLastVisible() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetLastVisibleItem();
+}
+#endif // !defined(_WIN32_WCE) && (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0600)
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::GetNextSelected() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetNextSelectedItem();
+}
+#endif // (_WIN32_IE >= 0x0600)
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::GetText(LPTSTR lpstrText, int nLen) const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetItemText(m_hTreeItem, lpstrText, nLen);
+}
+
+#ifndef _ATL_NO_COM
+#ifdef _OLEAUTO_H_
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::GetText(BSTR& bstrText) const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetItemText(m_hTreeItem, bstrText);
+}
+#endif // _OLEAUTO_H_
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::GetText(_CSTRING_NS::CString& strText) const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetItemText(m_hTreeItem, strText);
+}
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::GetImage(int& nImage, int& nSelectedImage) const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetItemImage(m_hTreeItem,nImage,nSelectedImage);
+}
+
+template <class TBase>
+inline UINT CTreeItemT<TBase>::GetState(UINT nStateMask) const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetItemState(m_hTreeItem,nStateMask);
+}
+
+template <class TBase>
+inline DWORD_PTR CTreeItemT<TBase>::GetData() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetItemData(m_hTreeItem);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SetItem(UINT nMask, LPCTSTR lpszItem, int nImage,
+ int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SetItem(m_hTreeItem, nMask, lpszItem, nImage, nSelectedImage, nState, nStateMask, lParam);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SetText(LPCTSTR lpszItem)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SetItemText(m_hTreeItem,lpszItem);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SetImage(int nImage, int nSelectedImage)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SetItemImage(m_hTreeItem,nImage,nSelectedImage);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SetState(UINT nState, UINT nStateMask)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SetItemState(m_hTreeItem,nState,nStateMask);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SetData(DWORD_PTR dwData)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SetItemData(m_hTreeItem,dwData);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::HasChildren() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->ItemHasChildren(m_hTreeItem);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::Delete()
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->DeleteItem(m_hTreeItem);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::Expand(UINT nCode /*= TVE_EXPAND*/)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->Expand(m_hTreeItem,nCode);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::Select(UINT nCode)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->Select(m_hTreeItem,nCode);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::Select()
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SelectItem(m_hTreeItem);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SelectDropTarget()
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SelectDropTarget(m_hTreeItem);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SelectSetFirstVisible()
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SelectSetFirstVisible(m_hTreeItem);
+}
+
+template <class TBase>
+inline HWND CTreeItemT<TBase>::EditLabel()
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->EditLabel(m_hTreeItem);
+}
+
+template <class TBase>
+inline HIMAGELIST CTreeItemT<TBase>::CreateDragImage()
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->CreateDragImage(m_hTreeItem);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SortChildren(BOOL bRecurse /*= FALSE*/)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SortChildren(m_hTreeItem, bRecurse);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::EnsureVisible()
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->EnsureVisible(m_hTreeItem);
+}
+
+template <class TBase>
+inline CTreeItemT<TBase> CTreeItemT<TBase>::_Insert(LPCTSTR lpstrItem, int nImageIndex, HTREEITEM hItemAfter)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ TVINSERTSTRUCT ins = { 0 };
+ ins.hParent = m_hTreeItem;
+ ins.hInsertAfter = hItemAfter;
+ ins.item.mask = TVIF_TEXT;
+ ins.item.pszText = (LPTSTR)lpstrItem;
+ if(nImageIndex != -1)
+ {
+ ins.item.mask |= TVIF_IMAGE | TVIF_SELECTEDIMAGE;
+ ins.item.iImage = nImageIndex;
+ ins.item.iSelectedImage = nImageIndex;
+ }
+ return CTreeItemT<TBase>(m_pTreeView->InsertItem(&ins), m_pTreeView);
+}
+
+template <class TBase>
+inline int CTreeItemT<TBase>::GetImageIndex() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ TVITEM item = { 0 };
+ item.mask = TVIF_HANDLE | TVIF_IMAGE;
+ item.hItem = m_hTreeItem;
+ m_pTreeView->GetItem(&item);
+ return item.iImage;
+}
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::SetInsertMark(BOOL bAfter)
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->SetInsertMark(m_hTreeItem, bAfter);
+}
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+#if (_WIN32_WINNT >= 0x0501)
+template <class TBase>
+inline UINT CTreeItemT<TBase>::MapHTREEITEMToAccID() const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->MapHTREEITEMToAccID(m_hTreeItem);
+}
+#endif // (_WIN32_WINNT >= 0x0501)
+
+#if (_WIN32_WINNT >= 0x0600)
+template <class TBase>
+inline void CTreeItemT<TBase>::ShowInfoTip()
+{
+ ATLASSERT(m_pTreeView != NULL);
+ m_pTreeView->ShowInfoTip(m_hTreeItem);
+}
+
+template <class TBase>
+inline BOOL CTreeItemT<TBase>::GetPartRect(TVITEMPART partID, LPRECT lpRect) const
+{
+ ATLASSERT(m_pTreeView != NULL);
+ return m_pTreeView->GetItemPartRect(m_hTreeItem, partID, lpRect);
+}
+#endif // (_WIN32_WINNT >= 0x0600)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CToolBarCtrl
+
+template <class TBase>
+class CToolBarCtrlT : public TBase
+{
+public:
+// Construction
+ CToolBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CToolBarCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return TOOLBARCLASSNAME;
+ }
+
+ BOOL IsButtonEnabled(int nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONENABLED, nID, 0L);
+ }
+
+ BOOL IsButtonChecked(int nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONCHECKED, nID, 0L);
+ }
+
+ BOOL IsButtonPressed(int nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONPRESSED, nID, 0L);
+ }
+
+ BOOL IsButtonHidden(int nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return(BOOL) ::SendMessage(m_hWnd, TB_ISBUTTONHIDDEN, nID, 0L);
+ }
+
+ BOOL IsButtonIndeterminate(int nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONINDETERMINATE, nID, 0L);
+ }
+
+ int GetState(int nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_GETSTATE, nID, 0L);
+ }
+
+ BOOL SetState(int nID, UINT nState)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETSTATE, nID, MAKELPARAM(nState, 0));
+ }
+
+ BOOL GetButton(int nIndex, LPTBBUTTON lpButton) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_GETBUTTON, nIndex, (LPARAM)lpButton);
+ }
+
+ int GetButtonCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_BUTTONCOUNT, 0, 0L);
+ }
+
+ BOOL GetItemRect(int nIndex, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_GETITEMRECT, nIndex, (LPARAM)lpRect);
+ }
+
+ void SetButtonStructSize(int nSize = sizeof(TBBUTTON))
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_BUTTONSTRUCTSIZE, nSize, 0L);
+ }
+
+ BOOL SetButtonSize(SIZE size)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(size.cx, size.cy));
+ }
+
+ BOOL SetButtonSize(int cx, int cy)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONSIZE, 0, MAKELPARAM(cx, cy));
+ }
+
+ BOOL SetBitmapSize(SIZE size)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(size.cx, size.cy));
+ }
+
+ BOOL SetBitmapSize(int cx, int cy)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETBITMAPSIZE, 0, MAKELPARAM(cx, cy));
+ }
+
+#ifndef _WIN32_WCE
+ CToolTipCtrl GetToolTips() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TB_GETTOOLTIPS, 0, 0L));
+ }
+
+ void SetToolTips(HWND hWndToolTip)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ void SetNotifyWnd(HWND hWnd)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_SETPARENT, (WPARAM)hWnd, 0L);
+ }
+
+ int GetRows() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_GETROWS, 0, 0L);
+ }
+
+ void SetRows(int nRows, BOOL bLarger, LPRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_SETROWS, MAKELPARAM(nRows, bLarger), (LPARAM)lpRect);
+ }
+
+ BOOL SetCmdID(int nIndex, UINT nID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETCMDID, nIndex, nID);
+ }
+
+ DWORD GetBitmapFlags() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TB_GETBITMAPFLAGS, 0, 0L);
+ }
+
+ int GetBitmap(int nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_GETBITMAP, nID, 0L);
+ }
+
+ int GetButtonText(int nID, LPTSTR lpstrText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_GETBUTTONTEXT, nID, (LPARAM)lpstrText);
+ }
+
+ // nIndex - IE5 or higher only
+ CImageList GetImageList(int nIndex = 0) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETIMAGELIST, nIndex, 0L));
+ }
+
+ // nIndex - IE5 or higher only
+ CImageList SetImageList(HIMAGELIST hImageList, int nIndex = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETIMAGELIST, nIndex, (LPARAM)hImageList));
+ }
+
+ // nIndex - IE5 or higher only
+ CImageList GetDisabledImageList(int nIndex = 0) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETDISABLEDIMAGELIST, nIndex, 0L));
+ }
+
+ // nIndex - IE5 or higher only
+ CImageList SetDisabledImageList(HIMAGELIST hImageList, int nIndex = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETDISABLEDIMAGELIST, nIndex, (LPARAM)hImageList));
+ }
+
+#ifndef _WIN32_WCE
+ // nIndex - IE5 or higher only
+ CImageList GetHotImageList(int nIndex = 0) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETHOTIMAGELIST, nIndex, 0L));
+ }
+
+ // nIndex - IE5 or higher only
+ CImageList SetHotImageList(HIMAGELIST hImageList, int nIndex = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETHOTIMAGELIST, nIndex, (LPARAM)hImageList));
+ }
+#endif // !_WIN32_WCE
+
+ DWORD GetStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TB_GETSTYLE, 0, 0L);
+ }
+
+ void SetStyle(DWORD dwStyle)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_SETSTYLE, 0, dwStyle);
+ }
+
+ DWORD GetButtonSize() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
+ }
+
+ void GetButtonSize(SIZE& size) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_GETBUTTONSIZE, 0, 0L);
+ size.cx = LOWORD(dwRet);
+ size.cy = HIWORD(dwRet);
+ }
+
+ BOOL GetRect(int nID, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_GETRECT, nID, (LPARAM)lpRect);
+ }
+
+ int GetTextRows() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_GETTEXTROWS, 0, 0L);
+ }
+
+ BOOL SetButtonWidth(int cxMin, int cxMax)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONWIDTH, 0, MAKELPARAM(cxMin, cxMax));
+ }
+
+ BOOL SetIndent(int nIndent)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETINDENT, nIndent, 0L);
+ }
+
+ BOOL SetMaxTextRows(int nMaxTextRows)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETMAXTEXTROWS, nMaxTextRows, 0L);
+ }
+
+#if (_WIN32_IE >= 0x0400)
+#ifndef _WIN32_WCE
+ BOOL GetAnchorHighlight() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_GETANCHORHIGHLIGHT, 0, 0L);
+ }
+
+ BOOL SetAnchorHighlight(BOOL bEnable = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETANCHORHIGHLIGHT, bEnable, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ int GetButtonInfo(int nID, LPTBBUTTONINFO lptbbi) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_GETBUTTONINFO, nID, (LPARAM)lptbbi);
+ }
+
+ BOOL SetButtonInfo(int nID, LPTBBUTTONINFO lptbbi)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)lptbbi);
+ }
+
+ BOOL SetButtonInfo(int nID, DWORD dwMask, BYTE Style, BYTE State, LPCTSTR lpszItem,
+ int iImage, WORD cx, int iCommand, DWORD_PTR lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TBBUTTONINFO tbbi = { 0 };
+ tbbi.cbSize = sizeof(TBBUTTONINFO);
+ tbbi.dwMask = dwMask;
+ tbbi.idCommand = iCommand;
+ tbbi.iImage = iImage;
+ tbbi.fsState = State;
+ tbbi.fsStyle = Style;
+ tbbi.cx = cx;
+ tbbi.pszText = (LPTSTR) lpszItem;
+ tbbi.lParam = lParam;
+ return (BOOL)::SendMessage(m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)&tbbi);
+ }
+
+#ifndef _WIN32_WCE
+ int GetHotItem() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_GETHOTITEM, 0, 0L);
+ }
+
+ int SetHotItem(int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_SETHOTITEM, nItem, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL IsButtonHighlighted(int nButtonID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_ISBUTTONHIGHLIGHTED, nButtonID, 0L);
+ }
+
+ DWORD SetDrawTextFlags(DWORD dwMask, DWORD dwFlags)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TB_SETDRAWTEXTFLAGS, dwMask, dwFlags);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL GetColorScheme(LPCOLORSCHEME lpcs) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_GETCOLORSCHEME, 0, (LPARAM)lpcs);
+ }
+
+ void SetColorScheme(LPCOLORSCHEME lpcs)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_SETCOLORSCHEME, 0, (LPARAM)lpcs);
+ }
+
+ DWORD GetExtendedStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TB_GETEXTENDEDSTYLE, 0, 0L);
+ }
+
+ DWORD SetExtendedStyle(DWORD dwStyle)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TB_SETEXTENDEDSTYLE, 0, dwStyle);
+ }
+
+ void GetInsertMark(LPTBINSERTMARK lptbim) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_GETINSERTMARK, 0, (LPARAM)lptbim);
+ }
+
+ void SetInsertMark(LPTBINSERTMARK lptbim)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_SETINSERTMARK, 0, (LPARAM)lptbim);
+ }
+
+ COLORREF GetInsertMarkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TB_GETINSERTMARKCOLOR, 0, 0L);
+ }
+
+ COLORREF SetInsertMarkColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, TB_SETINSERTMARKCOLOR, 0, (LPARAM)clr);
+ }
+
+ BOOL GetMaxSize(LPSIZE lpSize) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_GETMAXSIZE, 0, (LPARAM)lpSize);
+ }
+
+ void GetPadding(LPSIZE lpSizePadding) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpSizePadding != NULL);
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_GETPADDING, 0, 0L);
+ lpSizePadding->cx = GET_X_LPARAM(dwRet);
+ lpSizePadding->cy = GET_Y_LPARAM(dwRet);
+ }
+
+ void SetPadding(int cx, int cy, LPSIZE lpSizePadding = NULL)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, TB_SETPADDING, 0, MAKELPARAM(cx, cy));
+ if(lpSizePadding != NULL)
+ {
+ lpSizePadding->cx = GET_X_LPARAM(dwRet);
+ lpSizePadding->cy = GET_Y_LPARAM(dwRet);
+ }
+ }
+
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // !_WIN32_WCE
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ int GetString(int nString, LPTSTR lpstrString, int cchMaxLen) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(cchMaxLen, nString), (LPARAM)lpstrString);
+ }
+
+ int GetStringBSTR(int nString, BSTR& bstrString) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(bstrString == NULL);
+ int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
+ if(nLength != -1)
+ {
+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPTSTR lpstrText = buff.Allocate(nLength + 1);
+ if(lpstrText != NULL)
+ {
+ nLength = (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstrText);
+ if(nLength != -1)
+ bstrString = ::SysAllocString(T2OLE(lpstrText));
+ }
+ else
+ {
+ nLength = -1;
+ }
+ }
+
+ return nLength;
+ }
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ int GetString(int nString, _CSTRING_NS::CString& str) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(0, nString), NULL));
+ if(nLength != -1)
+ {
+ LPTSTR lpstr = str.GetBufferSetLength(nLength + 1);
+ if(lpstr != NULL)
+ nLength = (int)::SendMessage(m_hWnd, TB_GETSTRING, MAKEWPARAM(nLength + 1, nString), (LPARAM)lpstr);
+ else
+ nLength = -1;
+ str.ReleaseBuffer();
+ }
+ return nLength;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+#if (_WIN32_WINNT >= 0x0501)
+ void GetMetrics(LPTBMETRICS lptbm) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_GETMETRICS, 0, (LPARAM)lptbm);
+ }
+
+ void SetMetrics(LPTBMETRICS lptbm)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_SETMETRICS, 0, (LPARAM)lptbm);
+ }
+
+ void SetWindowTheme(LPCWSTR lpstrTheme)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+#if (_WIN32_WINNT >= 0x0600)
+ CImageList GetPressedImageList(int nIndex = 0) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_GETPRESSEDIMAGELIST, nIndex, 0L));
+ }
+
+ CImageList SetPressedImageList(HIMAGELIST hImageList, int nIndex = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TB_SETPRESSEDIMAGELIST, nIndex, (LPARAM)hImageList));
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+// Operations
+ BOOL EnableButton(int nID, BOOL bEnable = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_ENABLEBUTTON, nID, MAKELPARAM(bEnable, 0));
+ }
+
+ BOOL CheckButton(int nID, BOOL bCheck = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_CHECKBUTTON, nID, MAKELPARAM(bCheck, 0));
+ }
+
+ BOOL PressButton(int nID, BOOL bPress = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_PRESSBUTTON, nID, MAKELPARAM(bPress, 0));
+ }
+
+ BOOL HideButton(int nID, BOOL bHide = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_HIDEBUTTON, nID, MAKELPARAM(bHide, 0));
+ }
+
+ BOOL Indeterminate(int nID, BOOL bIndeterminate = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_INDETERMINATE, nID, MAKELPARAM(bIndeterminate, 0));
+ }
+
+ int AddBitmap(int nNumButtons, UINT nBitmapID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TBADDBITMAP tbab = { 0 };
+ tbab.hInst = ModuleHelper::GetResourceInstance();
+ ATLASSERT(tbab.hInst != NULL);
+ tbab.nID = nBitmapID;
+ return (int)::SendMessage(m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
+ }
+
+ int AddBitmap(int nNumButtons, HBITMAP hBitmap)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TBADDBITMAP tbab = { 0 };
+ tbab.hInst = NULL;
+ tbab.nID = (UINT_PTR)hBitmap;
+ return (int)::SendMessage(m_hWnd, TB_ADDBITMAP, (WPARAM)nNumButtons, (LPARAM)&tbab);
+ }
+
+ BOOL AddButtons(int nNumButtons, LPTBBUTTON lpButtons)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_ADDBUTTONS, nNumButtons, (LPARAM)lpButtons);
+ }
+
+ BOOL InsertButton(int nIndex, LPTBBUTTON lpButton)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)lpButton);
+ }
+
+ BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
+ INT_PTR iString, DWORD_PTR lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TBBUTTON tbb = { 0 };
+ tbb.fsStyle = Style;
+ tbb.fsState = State;
+ tbb.idCommand = iCommand;
+ tbb.iBitmap = iBitmap;
+ tbb.iString = iString;
+ tbb.dwData = lParam;
+ return (BOOL)::SendMessage(m_hWnd, TB_INSERTBUTTON, nIndex, (LPARAM)&tbb);
+ }
+
+ BOOL InsertButton(int nIndex, int iCommand, BYTE Style, BYTE State, int iBitmap,
+ LPCTSTR lpszItem, DWORD_PTR lParam)
+ {
+ return InsertButton(nIndex, iCommand, Style, State, iBitmap, (INT_PTR)lpszItem, lParam);
+ }
+
+ BOOL AddButton(LPTBBUTTON lpButton)
+ {
+ return InsertButton(-1, lpButton);
+ }
+
+ BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, INT_PTR iString, DWORD_PTR lParam)
+ {
+ return InsertButton(-1, iCommand, Style, State, iBitmap, iString, lParam);
+ }
+
+ BOOL AddButton(int iCommand, BYTE Style, BYTE State, int iBitmap, LPCTSTR lpszItem, DWORD_PTR lParam)
+ {
+ return InsertButton(-1, iCommand, Style, State, iBitmap, lpszItem, lParam);
+ }
+
+ BOOL DeleteButton(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_DELETEBUTTON, nIndex, 0L);
+ }
+
+ UINT CommandToIndex(UINT nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, TB_COMMANDTOINDEX, nID, 0L);
+ }
+
+#ifndef _WIN32_WCE
+ void SaveState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TBSAVEPARAMS tbs = { 0 };
+ tbs.hkr = hKeyRoot;
+ tbs.pszSubKey = lpszSubKey;
+ tbs.pszValueName = lpszValueName;
+ ::SendMessage(m_hWnd, TB_SAVERESTORE, (WPARAM)TRUE, (LPARAM)&tbs);
+ }
+
+ void RestoreState(HKEY hKeyRoot, LPCTSTR lpszSubKey, LPCTSTR lpszValueName)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TBSAVEPARAMS tbs = { 0 };
+ tbs.hkr = hKeyRoot;
+ tbs.pszSubKey = lpszSubKey;
+ tbs.pszValueName = lpszValueName;
+ ::SendMessage(m_hWnd, TB_SAVERESTORE, (WPARAM)FALSE, (LPARAM)&tbs);
+ }
+
+ void Customize()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_CUSTOMIZE, 0, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ int AddString(UINT nStringID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_ADDSTRING, (WPARAM)ModuleHelper::GetResourceInstance(), (LPARAM)nStringID);
+ }
+
+ int AddStrings(LPCTSTR lpszStrings)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_ADDSTRING, 0, (LPARAM)lpszStrings);
+ }
+
+ void AutoSize()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TB_AUTOSIZE, 0, 0L);
+ }
+
+ BOOL ChangeBitmap(int nID, int nBitmap)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_CHANGEBITMAP, nID, MAKELPARAM(nBitmap, 0));
+ }
+
+ int LoadImages(int nBitmapID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)ModuleHelper::GetResourceInstance());
+ }
+
+ int LoadStdImages(int nBitmapID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_LOADIMAGES, nBitmapID, (LPARAM)HINST_COMMCTRL);
+ }
+
+ BOOL ReplaceBitmap(LPTBREPLACEBITMAP ptbrb)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_REPLACEBITMAP, 0, (LPARAM)ptbrb);
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ int HitTest(LPPOINT lpPoint) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TB_HITTEST, 0, (LPARAM)lpPoint);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL InsertMarkHitTest(LPPOINT lpPoint, LPTBINSERTMARK lptbim) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)lpPoint, (LPARAM)lptbim);
+ }
+
+ BOOL InsertMarkHitTest(int x, int y, LPTBINSERTMARK lptbim) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ POINT pt = { x, y };
+ return (BOOL)::SendMessage(m_hWnd, TB_INSERTMARKHITTEST, (WPARAM)&pt, (LPARAM)lptbim);
+ }
+
+ BOOL MapAccelerator(TCHAR chAccel, int& nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_MAPACCELERATOR, (WPARAM)chAccel, (LPARAM)&nID);
+ }
+
+ BOOL MarkButton(int nID, BOOL bHighlight = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_MARKBUTTON, nID, MAKELPARAM(bHighlight, 0));
+ }
+
+ BOOL MoveButton(int nOldPos, int nNewPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TB_MOVEBUTTON, nOldPos, nNewPos);
+ }
+
+ HRESULT GetObject(REFIID iid, LPVOID* ppvObject)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HRESULT)::SendMessage(m_hWnd, TB_GETOBJECT, (WPARAM)&iid, (LPARAM)ppvObject);
+ }
+#endif // !_WIN32_WCE
+#endif // (_WIN32_IE >= 0x0400)
+};
+
+typedef CToolBarCtrlT<ATL::CWindow> CToolBarCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CStatusBarCtrl
+
+template <class TBase>
+class CStatusBarCtrlT : public TBase
+{
+public:
+// Constructors
+ CStatusBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CStatusBarCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Methods
+ static LPCTSTR GetWndClassName()
+ {
+ return STATUSCLASSNAME;
+ }
+
+ int GetParts(int nParts, int* pParts) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, SB_GETPARTS, nParts, (LPARAM)pParts);
+ }
+
+ BOOL SetParts(int nParts, int* pWidths)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, SB_SETPARTS, nParts, (LPARAM)pWidths);
+ }
+
+ int GetTextLength(int nPane, int* pType = NULL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L);
+ if (pType != NULL)
+ *pType = (int)(short)HIWORD(dwRet);
+ return (int)(short)LOWORD(dwRet);
+ }
+
+ int GetText(int nPane, LPTSTR lpszText, int* pType = NULL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, SB_GETTEXT, (WPARAM)nPane, (LPARAM)lpszText);
+ if(pType != NULL)
+ *pType = (int)(short)HIWORD(dwRet);
+ return (int)(short)LOWORD(dwRet);
+ }
+
+#ifndef _ATL_NO_COM
+ BOOL GetTextBSTR(int nPane, BSTR& bstrText, int* pType = NULL) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ ATLASSERT(bstrText == NULL);
+ int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
+ if(nLength == 0)
+ return FALSE;
+
+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPTSTR lpstrText = buff.Allocate(nLength + 1);
+ if(lpstrText == NULL)
+ return FALSE;
+
+ if(!GetText(nPane, lpstrText, pType))
+ return FALSE;
+
+ bstrText = ::SysAllocString(T2OLE(lpstrText));
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ int GetText(int nPane, _CSTRING_NS::CString& strText, int* pType = NULL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ int nLength = (int)(short)LOWORD(::SendMessage(m_hWnd, SB_GETTEXTLENGTH, (WPARAM)nPane, 0L));
+ if(nLength == 0)
+ return 0;
+
+ LPTSTR lpstr = strText.GetBufferSetLength(nLength);
+ if(lpstr == NULL)
+ return 0;
+ return GetText(nPane, lpstr, pType);
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ BOOL SetText(int nPane, LPCTSTR lpszText, int nType = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ return (BOOL)::SendMessage(m_hWnd, SB_SETTEXT, (nPane | nType), (LPARAM)lpszText);
+ }
+
+ BOOL GetRect(int nPane, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ return (BOOL)::SendMessage(m_hWnd, SB_GETRECT, nPane, (LPARAM)lpRect);
+ }
+
+ BOOL GetBorders(int* pBorders) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, SB_GETBORDERS, 0, (LPARAM)pBorders);
+ }
+
+ BOOL GetBorders(int& nHorz, int& nVert, int& nSpacing) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ int borders[3] = { 0, 0, 0 };
+ BOOL bResult = (BOOL)::SendMessage(m_hWnd, SB_GETBORDERS, 0, (LPARAM)&borders);
+ if(bResult)
+ {
+ nHorz = borders[0];
+ nVert = borders[1];
+ nSpacing = borders[2];
+ }
+ return bResult;
+ }
+
+ void SetMinHeight(int nMin)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, SB_SETMINHEIGHT, nMin, 0L);
+ }
+
+ BOOL SetSimple(BOOL bSimple = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, SB_SIMPLE, bSimple, 0L);
+ }
+
+ BOOL IsSimple() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, SB_ISSIMPLE, 0, 0L);
+ }
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, SB_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, SB_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+
+ void GetTipText(int nPane, LPTSTR lpstrText, int nSize) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ ::SendMessage(m_hWnd, SB_GETTIPTEXT, MAKEWPARAM(nPane, nSize), (LPARAM)lpstrText);
+ }
+
+ void SetTipText(int nPane, LPCTSTR lpstrText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ ::SendMessage(m_hWnd, SB_SETTIPTEXT, nPane, (LPARAM)lpstrText);
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+#if ((_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 0x0500))
+ COLORREF SetBkColor(COLORREF clrBk)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, SB_SETBKCOLOR, 0, (LPARAM)clrBk);
+ }
+
+ HICON GetIcon(int nPane) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ return (HICON)::SendMessage(m_hWnd, SB_GETICON, nPane, 0L);
+ }
+
+ BOOL SetIcon(int nPane, HICON hIcon)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nPane < 256);
+ return (BOOL)::SendMessage(m_hWnd, SB_SETICON, nPane, (LPARAM)hIcon);
+ }
+#endif // ((_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)) || (defined(_WIN32_WCE) && (_WIN32_WCE >= 0x0500))
+};
+
+typedef CStatusBarCtrlT<ATL::CWindow> CStatusBarCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CTabCtrl
+
+template <class TBase>
+class CTabCtrlT : public TBase
+{
+public:
+// Constructors
+ CTabCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CTabCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return WC_TABCONTROL;
+ }
+
+ CImageList GetImageList() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TCM_GETIMAGELIST, 0, 0L));
+ }
+
+ CImageList SetImageList(HIMAGELIST hImageList)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, TCM_SETIMAGELIST, 0, (LPARAM)hImageList));
+ }
+
+ int GetItemCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TCM_GETITEMCOUNT, 0, 0L);
+ }
+
+ BOOL GetItem(int nItem, LPTCITEM pTabCtrlItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TCM_GETITEM, nItem, (LPARAM)pTabCtrlItem);
+ }
+
+ BOOL SetItem(int nItem, LPTCITEM pTabCtrlItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TCM_SETITEM, nItem, (LPARAM)pTabCtrlItem);
+ }
+
+ int SetItem(int nItem, UINT mask, LPCTSTR lpszItem, DWORD dwState, DWORD dwStateMask, int iImage, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TCITEM tci = { 0 };
+ tci.mask = mask;
+ tci.pszText = (LPTSTR) lpszItem;
+ tci.dwState = dwState;
+ tci.dwStateMask = dwStateMask;
+ tci.iImage = iImage;
+ tci.lParam = lParam;
+ return (int)::SendMessage(m_hWnd, TCM_SETITEM, nItem, (LPARAM)&tci);
+ }
+
+ BOOL GetItemRect(int nItem, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TCM_GETITEMRECT, nItem, (LPARAM)lpRect);
+ }
+
+ int GetCurSel() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TCM_GETCURSEL, 0, 0L);
+ }
+
+ int SetCurSel(int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TCM_SETCURSEL, nItem, 0L);
+ }
+
+ SIZE SetItemSize(SIZE size)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwSize = (DWORD)::SendMessage(m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(size.cx, size.cy));
+ SIZE sizeRet = { GET_X_LPARAM(dwSize), GET_Y_LPARAM(dwSize) };
+ return sizeRet;
+ }
+
+ void SetItemSize(int cx, int cy)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TCM_SETITEMSIZE, 0, MAKELPARAM(cx, cy));
+ }
+
+ void SetPadding(SIZE size)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TCM_SETPADDING, 0, MAKELPARAM(size.cx, size.cy));
+ }
+
+ int GetRowCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TCM_GETROWCOUNT, 0, 0L);
+ }
+
+#ifndef _WIN32_WCE
+ CToolTipCtrl GetTooltips() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TCM_GETTOOLTIPS, 0, 0L));
+ }
+
+ void SetTooltips(HWND hWndToolTip)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TCM_SETTOOLTIPS, (WPARAM)hWndToolTip, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ int GetCurFocus() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TCM_GETCURFOCUS, 0, 0L);
+ }
+
+ void SetCurFocus(int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TCM_SETCURFOCUS, nItem, 0L);
+ }
+
+ BOOL SetItemExtra(int cbExtra)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetItemCount() == 0); // must be empty
+ return (BOOL)::SendMessage(m_hWnd, TCM_SETITEMEXTRA, cbExtra, 0L);
+ }
+
+ int SetMinTabWidth(int nWidth = -1)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TCM_SETMINTABWIDTH, 0, nWidth);
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ DWORD GetExtendedStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TCM_GETEXTENDEDSTYLE, 0, 0L);
+ }
+
+ DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, TCM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TCM_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TCM_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // !_WIN32_WCE
+#endif // (_WIN32_IE >= 0x0400)
+
+// Operations
+ int InsertItem(int nItem, LPTCITEM pTabCtrlItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)pTabCtrlItem);
+ }
+
+ int InsertItem(int nItem, UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TCITEM tci = { 0 };
+ tci.mask = mask;
+ tci.pszText = (LPTSTR) lpszItem;
+ tci.iImage = iImage;
+ tci.lParam = lParam;
+ return (int)::SendMessage(m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
+ }
+
+ int InsertItem(int nItem, LPCTSTR lpszItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TCITEM tci = { 0 };
+ tci.mask = TCIF_TEXT;
+ tci.pszText = (LPTSTR) lpszItem;
+ return (int)::SendMessage(m_hWnd, TCM_INSERTITEM, nItem, (LPARAM)&tci);
+ }
+
+ int AddItem(LPTCITEM pTabCtrlItem)
+ {
+ return InsertItem(GetItemCount(), pTabCtrlItem);
+ }
+
+ int AddItem(UINT mask, LPCTSTR lpszItem, int iImage, LPARAM lParam)
+ {
+ return InsertItem(GetItemCount(), mask, lpszItem, iImage, lParam);
+ }
+
+ int AddItem(LPCTSTR lpszItem)
+ {
+ return InsertItem(GetItemCount(), lpszItem);
+ }
+
+ BOOL DeleteItem(int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TCM_DELETEITEM, nItem, 0L);
+ }
+
+ BOOL DeleteAllItems()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TCM_DELETEALLITEMS, 0, 0L);
+ }
+
+ void AdjustRect(BOOL bLarger, LPRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TCM_ADJUSTRECT, bLarger, (LPARAM)lpRect);
+ }
+
+ void RemoveImage(int nImage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TCM_REMOVEIMAGE, nImage, 0L);
+ }
+
+ int HitTest(TC_HITTESTINFO* pHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TCM_HITTEST, 0, (LPARAM)pHitTestInfo);
+ }
+
+ void DeselectAll(BOOL bExcludeFocus = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TCM_DESELECTALL, bExcludeFocus, 0L);
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ BOOL HighlightItem(int nIndex, BOOL bHighlight = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TCM_HIGHLIGHTITEM, nIndex, MAKELPARAM(bHighlight, 0));
+ }
+#endif // (_WIN32_IE >= 0x0400)
+};
+
+typedef CTabCtrlT<ATL::CWindow> CTabCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CTrackBarCtrl
+
+template <class TBase>
+class CTrackBarCtrlT : public TBase
+{
+public:
+// Constructors
+ CTrackBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CTrackBarCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return TRACKBAR_CLASS;
+ }
+
+ int GetLineSize() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETLINESIZE, 0, 0L);
+ }
+
+ int SetLineSize(int nSize)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_SETLINESIZE, 0, nSize);
+ }
+
+ int GetPageSize() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETPAGESIZE, 0, 0L);
+ }
+
+ int SetPageSize(int nSize)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_SETPAGESIZE, 0, nSize);
+ }
+
+ int GetRangeMin() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETRANGEMIN, 0, 0L);
+ }
+
+ void SetRangeMin(int nMin, BOOL bRedraw = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETRANGEMIN, bRedraw, nMin);
+ }
+
+ int GetRangeMax() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETRANGEMAX, 0, 0L);
+ }
+
+ void SetRangeMax(int nMax, BOOL bRedraw = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETRANGEMAX, bRedraw, nMax);
+ }
+
+ void GetRange(int& nMin, int& nMax) const
+ {
+ nMin = GetRangeMin();
+ nMax = GetRangeMax();
+ }
+
+ void SetRange(int nMin, int nMax, BOOL bRedraw = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETRANGE, bRedraw, MAKELPARAM(nMin, nMax));
+ }
+
+ int GetSelStart() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETSELSTART, 0, 0L);
+ }
+
+ void SetSelStart(int nMin)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETSELSTART, 0, (LPARAM)nMin);
+ }
+
+ int GetSelEnd() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETSELEND, 0, 0L);
+ }
+
+ void SetSelEnd(int nMax)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETSELEND, 0, (LPARAM)nMax);
+ }
+
+ void GetSelection(int& nMin, int& nMax) const
+ {
+ nMin = GetSelStart();
+ nMax = GetSelEnd();
+ }
+
+ void SetSelection(int nMin, int nMax)
+ {
+ SetSelStart(nMin);
+ SetSelEnd(nMax);
+ }
+
+ void GetChannelRect(LPRECT lprc) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_GETCHANNELRECT, 0, (LPARAM)lprc);
+ }
+
+ void GetThumbRect(LPRECT lprc) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_GETTHUMBRECT, 0, (LPARAM)lprc);
+ }
+
+ int GetPos() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETPOS, 0, 0L);
+ }
+
+ void SetPos(int nPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETPOS, TRUE, nPos);
+ }
+
+ UINT GetNumTics() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, TBM_GETNUMTICS, 0, 0L);
+ }
+
+ DWORD* GetTicArray() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD*)::SendMessage(m_hWnd, TBM_GETPTICS, 0, 0L);
+ }
+
+ int GetTic(int nTic) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETTIC, nTic, 0L);
+ }
+
+ BOOL SetTic(int nTic)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TBM_SETTIC, 0, nTic);
+ }
+
+ int GetTicPos(int nTic) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETTICPOS, nTic, 0L);
+ }
+
+ void SetTicFreq(int nFreq)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETTICFREQ, nFreq, 0L);
+ }
+
+ int GetThumbLength() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_GETTHUMBLENGTH, 0, 0L);
+ }
+
+ void SetThumbLength(int nLength)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETTHUMBLENGTH, nLength, 0L);
+ }
+
+ void SetSel(int nStart, int nEnd, BOOL bRedraw = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & TBS_ENABLESELRANGE) != 0);
+ ::SendMessage(m_hWnd, TBM_SETSEL, bRedraw, MAKELPARAM(nStart, nEnd));
+ }
+
+ ATL::CWindow GetBuddy(BOOL bLeft = TRUE) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ATL::CWindow((HWND)::SendMessage(m_hWnd, TBM_GETBUDDY, bLeft, 0L));
+ }
+
+ ATL::CWindow SetBuddy(HWND hWndBuddy, BOOL bLeft = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ATL::CWindow((HWND)::SendMessage(m_hWnd, TBM_SETBUDDY, bLeft, (LPARAM)hWndBuddy));
+ }
+
+#ifndef _WIN32_WCE
+ CToolTipCtrl GetToolTips() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, TBM_GETTOOLTIPS, 0, 0L));
+ }
+
+ void SetToolTips(HWND hWndTT)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETTOOLTIPS, (WPARAM)hWndTT, 0L);
+ }
+
+ int SetTipSide(int nSide)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, TBM_SETTIPSIDE, nSide, 0L);
+ }
+#endif // !_WIN32_WCE
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TBM_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, TBM_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+// Operations
+ void ClearSel(BOOL bRedraw = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_CLEARSEL, bRedraw, 0L);
+ }
+
+ void VerifyPos()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_SETPOS, FALSE, 0L);
+ }
+
+ void ClearTics(BOOL bRedraw = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, TBM_CLEARTICS, bRedraw, 0L);
+ }
+};
+
+typedef CTrackBarCtrlT<ATL::CWindow> CTrackBarCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CUpDownCtrl
+
+template <class TBase>
+class CUpDownCtrlT : public TBase
+{
+public:
+// Constructors
+ CUpDownCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CUpDownCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return UPDOWN_CLASS;
+ }
+
+ UINT GetAccel(int nAccel, UDACCEL* pAccel) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)LOWORD(::SendMessage(m_hWnd, UDM_GETACCEL, nAccel, (LPARAM)pAccel));
+ }
+
+ BOOL SetAccel(int nAccel, UDACCEL* pAccel)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)LOWORD(::SendMessage(m_hWnd, UDM_SETACCEL, nAccel, (LPARAM)pAccel));
+ }
+
+ UINT GetBase() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)LOWORD(::SendMessage(m_hWnd, UDM_GETBASE, 0, 0L));
+ }
+
+ int SetBase(int nBase)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, UDM_SETBASE, nBase, 0L);
+ }
+
+ ATL::CWindow GetBuddy() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ATL::CWindow((HWND)::SendMessage(m_hWnd, UDM_GETBUDDY, 0, 0L));
+ }
+
+ ATL::CWindow SetBuddy(HWND hWndBuddy)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ATL::CWindow((HWND)::SendMessage(m_hWnd, UDM_SETBUDDY, (WPARAM)hWndBuddy, 0L));
+ }
+
+ int GetPos(LPBOOL lpbError = NULL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, UDM_GETPOS, 0, 0L);
+ // Note: Seems that Windows always sets error to TRUE if
+ // UDS_SETBUDDYINT style is not used
+ if(lpbError != NULL)
+ *lpbError = (HIWORD(dwRet) != 0) ? TRUE : FALSE;
+ return (int)(short)LOWORD(dwRet);
+ }
+
+ int SetPos(int nPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)(short)LOWORD(::SendMessage(m_hWnd, UDM_SETPOS, 0, MAKELPARAM(nPos, 0)));
+ }
+
+ DWORD GetRange() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, UDM_GETRANGE, 0, 0L);
+ }
+
+ void GetRange(int& nLower, int& nUpper) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, UDM_GETRANGE, 0, 0L);
+ nLower = (int)(short)HIWORD(dwRet);
+ nUpper = (int)(short)LOWORD(dwRet);
+ }
+
+ void SetRange(int nLower, int nUpper)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, UDM_SETRANGE, 0, MAKELPARAM(nUpper, nLower));
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ void SetRange32(int nLower, int nUpper)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, UDM_SETRANGE32, nLower, nUpper);
+ }
+
+ void GetRange32(int& nLower, int& nUpper) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, UDM_GETRANGE32, (WPARAM)&nLower, (LPARAM)&nUpper);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, UDM_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, UDM_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // !_WIN32_WCE
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ int GetPos32(LPBOOL lpbError = NULL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ // Note: Seems that Windows always sets error to TRUE if
+ // UDS_SETBUDDYINT style is not used
+ return (int)::SendMessage(m_hWnd, UDM_GETPOS32, 0, (LPARAM)lpbError);
+ }
+
+ int SetPos32(int nPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, UDM_SETPOS32, 0, (LPARAM)nPos);
+ }
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+};
+
+typedef CUpDownCtrlT<ATL::CWindow> CUpDownCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CProgressBarCtrl
+
+template <class TBase>
+class CProgressBarCtrlT : public TBase
+{
+public:
+// Constructors
+ CProgressBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CProgressBarCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return PROGRESS_CLASS;
+ }
+
+ DWORD SetRange(int nLower, int nUpper)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, PBM_SETRANGE, 0, MAKELPARAM(nLower, nUpper));
+ }
+
+ int SetPos(int nPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_SETPOS, nPos, 0L));
+ }
+
+ int OffsetPos(int nPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_DELTAPOS, nPos, 0L));
+ }
+
+ int SetStep(int nStep)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_SETSTEP, nStep, 0L));
+ }
+
+ UINT GetPos() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, PBM_GETPOS, 0, 0L);
+ }
+
+ void GetRange(PPBRANGE pPBRange) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(pPBRange != NULL);
+ ::SendMessage(m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)pPBRange);
+ }
+
+ void GetRange(int& nLower, int& nUpper) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ PBRANGE range = { 0 };
+ ::SendMessage(m_hWnd, PBM_GETRANGE, TRUE, (LPARAM)&range);
+ nLower = range.iLow;
+ nUpper = range.iHigh;
+ }
+
+ int GetRangeLimit(BOOL bLowLimit) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PBM_GETRANGE, bLowLimit, (LPARAM)NULL);
+ }
+
+ DWORD SetRange32(int nMin, int nMax)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, PBM_SETRANGE32, nMin, nMax);
+ }
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ COLORREF SetBarColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, PBM_SETBARCOLOR, 0, (LPARAM)clr);
+ }
+
+ COLORREF SetBkColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, PBM_SETBKCOLOR, 0, (LPARAM)clr);
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+#if (_WIN32_WINNT >= 0x0501) && defined(PBM_SETMARQUEE)
+ BOOL SetMarquee(BOOL bMarquee, UINT uUpdateTime = 0U)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, PBM_SETMARQUEE, (WPARAM)bMarquee, (LPARAM)uUpdateTime);
+ }
+#endif // (_WIN32_WINNT >= 0x0501) && defined(PBM_SETMARQUEE)
+
+#if (_WIN32_WINNT >= 0x0600)
+ int GetStep() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PBM_GETSTEP, 0, 0L);
+ }
+
+ COLORREF GetBkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, PBM_GETBKCOLOR, 0, 0L);
+ }
+
+ COLORREF GetBarColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, PBM_GETBARCOLOR, 0, 0L);
+ }
+
+ int GetState() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PBM_GETSTATE, 0, 0L);
+ }
+
+ int SetState(int nState)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PBM_SETSTATE, nState, 0L);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+// Operations
+ int StepIt()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)(short)LOWORD(::SendMessage(m_hWnd, PBM_STEPIT, 0, 0L));
+ }
+};
+
+typedef CProgressBarCtrlT<ATL::CWindow> CProgressBarCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CHotKeyCtrl
+
+#ifndef _WIN32_WCE
+
+template <class TBase>
+class CHotKeyCtrlT : public TBase
+{
+public:
+// Constructors
+ CHotKeyCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CHotKeyCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return HOTKEY_CLASS;
+ }
+
+ DWORD GetHotKey() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, HKM_GETHOTKEY, 0, 0L);
+ }
+
+ void GetHotKey(WORD &wVirtualKeyCode, WORD &wModifiers) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dw = (DWORD)::SendMessage(m_hWnd, HKM_GETHOTKEY, 0, 0L);
+ wVirtualKeyCode = LOBYTE(LOWORD(dw));
+ wModifiers = HIBYTE(LOWORD(dw));
+ }
+
+ void SetHotKey(WORD wVirtualKeyCode, WORD wModifiers)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, HKM_SETHOTKEY, MAKEWORD(wVirtualKeyCode, wModifiers), 0L);
+ }
+
+ void SetRules(WORD wInvalidComb, WORD wModifiers)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, HKM_SETRULES, wInvalidComb, MAKELPARAM(wModifiers, 0));
+ }
+};
+
+typedef CHotKeyCtrlT<ATL::CWindow> CHotKeyCtrl;
+
+#endif // !_WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAnimateCtrl
+
+#ifndef _WIN32_WCE
+
+template <class TBase>
+class CAnimateCtrlT : public TBase
+{
+public:
+// Constructors
+ CAnimateCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CAnimateCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return ANIMATE_CLASS;
+ }
+
+// Operations
+ BOOL Open(ATL::_U_STRINGorID FileName)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, ACM_OPEN, 0, (LPARAM)FileName.m_lpstr);
+ }
+
+ BOOL Play(UINT nFrom, UINT nTo, UINT nRep)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, ACM_PLAY, nRep, MAKELPARAM(nFrom, nTo));
+ }
+
+ BOOL Stop()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, ACM_STOP, 0, 0L);
+ }
+
+ BOOL Close()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, ACM_OPEN, 0, 0L);
+ }
+
+ BOOL Seek(UINT nTo)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, ACM_PLAY, 0, MAKELPARAM(nTo, nTo));
+ }
+
+ // Vista only
+ BOOL IsPlaying() const
+ {
+#ifndef ACM_ISPLAYING
+ const UINT ACM_ISPLAYING = (WM_USER+104);
+#endif
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, ACM_ISPLAYING, 0, 0L);
+ }
+};
+
+typedef CAnimateCtrlT<ATL::CWindow> CAnimateCtrl;
+
+#endif // !_WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CRichEditCtrl
+
+#ifndef _WIN32_WCE
+
+#ifdef _UNICODE
+#if (_RICHEDIT_VER == 0x0100)
+#undef RICHEDIT_CLASS
+#define RICHEDIT_CLASS L"RICHEDIT"
+#endif // (_RICHEDIT_VER == 0x0100)
+#endif // _UNICODE
+
+template <class TBase>
+class CRichEditCtrlT : public TBase
+{
+public:
+// Constructors
+ CRichEditCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CRichEditCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return RICHEDIT_CLASS;
+ }
+
+ static LPCTSTR GetLibraryName()
+ {
+#if (_RICHEDIT_VER >= 0x0200)
+ return _T("RICHED20.DLL");
+#else
+ return _T("RICHED32.DLL");
+#endif
+ }
+
+ int GetLineCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETLINECOUNT, 0, 0L);
+ }
+
+ BOOL GetModify() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_GETMODIFY, 0, 0L);
+ }
+
+ void SetModify(BOOL bModified = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETMODIFY, bModified, 0L);
+ }
+
+ void GetRect(LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_GETRECT, 0, (LPARAM)lpRect);
+ }
+
+ DWORD GetOptions() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, EM_GETOPTIONS, 0, 0L);
+ }
+
+ DWORD SetOptions(WORD wOperation, DWORD dwOptions)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, EM_SETOPTIONS, wOperation, dwOptions);
+ }
+
+ // NOTE: first word in lpszBuffer must contain the size of the buffer!
+ int GetLine(int nIndex, LPTSTR lpszBuffer) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
+ }
+
+ int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ *(LPWORD)lpszBuffer = (WORD)nMaxLength;
+ return (int)::SendMessage(m_hWnd, EM_GETLINE, nIndex, (LPARAM)lpszBuffer);
+ }
+
+ BOOL CanUndo() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_CANUNDO, 0, 0L);
+ }
+
+ BOOL CanPaste(UINT nFormat = 0) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_CANPASTE, nFormat, 0L);
+ }
+
+ void GetSel(LONG& nStartChar, LONG& nEndChar) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ CHARRANGE cr = { 0, 0 };
+ ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
+ nStartChar = cr.cpMin;
+ nEndChar = cr.cpMax;
+ }
+
+ void GetSel(CHARRANGE &cr) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
+ }
+
+ int SetSel(LONG nStartChar, LONG nEndChar)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ CHARRANGE cr = { nStartChar, nEndChar };
+ return (int)::SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
+ }
+
+ int SetSel(CHARRANGE &cr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_EXSETSEL, 0, (LPARAM)&cr);
+ }
+
+ int SetSelAll()
+ {
+ return SetSel(0, -1);
+ }
+
+ int SetSelNone()
+ {
+ return SetSel(-1, 0);
+ }
+
+ DWORD GetDefaultCharFormat(CHARFORMAT& cf) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT);
+ return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
+ }
+
+ DWORD GetSelectionCharFormat(CHARFORMAT& cf) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT);
+ return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
+ }
+
+ DWORD GetEventMask() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, EM_GETEVENTMASK, 0, 0L);
+ }
+
+ LONG GetLimitText() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LONG)::SendMessage(m_hWnd, EM_GETLIMITTEXT, 0, 0L);
+ }
+
+ DWORD GetParaFormat(PARAFORMAT& pf) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ pf.cbSize = sizeof(PARAFORMAT);
+ return (DWORD)::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
+ }
+
+#if (_RICHEDIT_VER >= 0x0200)
+ LONG GetSelText(LPTSTR lpstrBuff) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrBuff);
+ }
+#else // !(_RICHEDIT_VER >= 0x0200)
+ // RichEdit 1.0 EM_GETSELTEXT is ANSI only
+ LONG GetSelText(LPSTR lpstrBuff) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrBuff);
+ }
+#endif // !(_RICHEDIT_VER >= 0x0200)
+
+#ifndef _ATL_NO_COM
+ BOOL GetSelTextBSTR(BSTR& bstrText) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(bstrText == NULL);
+
+ CHARRANGE cr = { 0, 0 };
+ ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
+
+#if (_RICHEDIT_VER >= 0x0200)
+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPTSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
+ if(lpstrText == NULL)
+ return FALSE;
+ if(::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText) == 0)
+ return FALSE;
+
+ bstrText = ::SysAllocString(T2W(lpstrText));
+#else // !(_RICHEDIT_VER >= 0x0200)
+ CTempBuffer<char, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
+ if(lpstrText == NULL)
+ return FALSE;
+ if(::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText) == 0)
+ return FALSE;
+
+ bstrText = ::SysAllocString(A2W(lpstrText));
+#endif // !(_RICHEDIT_VER >= 0x0200)
+
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ LONG GetSelText(_CSTRING_NS::CString& strText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+
+ CHARRANGE cr = { 0, 0 };
+ ::SendMessage(m_hWnd, EM_EXGETSEL, 0, (LPARAM)&cr);
+
+#if (_RICHEDIT_VER >= 0x0200)
+ LONG lLen = 0;
+ LPTSTR lpstrText = strText.GetBufferSetLength(cr.cpMax - cr.cpMin);
+ if(lpstrText != NULL)
+ {
+ lLen = (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText);
+ strText.ReleaseBuffer();
+ }
+#else // !(_RICHEDIT_VER >= 0x0200)
+ CTempBuffer<char, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPSTR lpstrText = buff.Allocate(cr.cpMax - cr.cpMin + 1);
+ if(lpstrText == NULL)
+ return 0;
+ LONG lLen = (LONG)::SendMessage(m_hWnd, EM_GETSELTEXT, 0, (LPARAM)lpstrText);
+ if(lLen == 0)
+ return 0;
+
+ USES_CONVERSION;
+ strText = A2T(lpstrText);
+#endif // !(_RICHEDIT_VER >= 0x0200)
+
+ return lLen;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ WORD GetSelectionType() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (WORD)::SendMessage(m_hWnd, EM_SELECTIONTYPE, 0, 0L);
+ }
+
+ COLORREF SetBackgroundColor(COLORREF cr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, EM_SETBKGNDCOLOR, 0, cr);
+ }
+
+ COLORREF SetBackgroundColor() // sets to system background
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, EM_SETBKGNDCOLOR, 1, 0);
+ }
+
+ BOOL SetCharFormat(CHARFORMAT& cf, WORD wFlags)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
+ }
+
+ BOOL SetDefaultCharFormat(CHARFORMAT& cf)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
+ }
+
+ BOOL SetSelectionCharFormat(CHARFORMAT& cf)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+ }
+
+ BOOL SetWordCharFormat(CHARFORMAT& cf)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
+ }
+
+ DWORD SetEventMask(DWORD dwEventMask)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, EM_SETEVENTMASK, 0, dwEventMask);
+ }
+
+ BOOL SetParaFormat(PARAFORMAT& pf)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ pf.cbSize = sizeof(PARAFORMAT);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
+ }
+
+ BOOL SetTargetDevice(HDC hDC, int cxLineWidth)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETTARGETDEVICE, (WPARAM)hDC, cxLineWidth);
+ }
+
+ int GetTextLength() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, WM_GETTEXTLENGTH, 0, 0L);
+ }
+
+ BOOL SetReadOnly(BOOL bReadOnly = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETREADONLY, bReadOnly, 0L);
+ }
+
+ int GetFirstVisibleLine() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETFIRSTVISIBLELINE, 0, 0L);
+ }
+
+ EDITWORDBREAKPROCEX GetWordBreakProcEx() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (EDITWORDBREAKPROCEX)::SendMessage(m_hWnd, EM_GETWORDBREAKPROCEX, 0, 0L);
+ }
+
+ EDITWORDBREAKPROCEX SetWordBreakProcEx(EDITWORDBREAKPROCEX pfnEditWordBreakProcEx)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (EDITWORDBREAKPROCEX)::SendMessage(m_hWnd, EM_SETWORDBREAKPROCEX, 0, (LPARAM)pfnEditWordBreakProcEx);
+ }
+
+ int GetTextRange(TEXTRANGE* pTextRange) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)pTextRange);
+ }
+
+#if (_RICHEDIT_VER >= 0x0200)
+ int GetTextRange(LONG nStartChar, LONG nEndChar, LPTSTR lpstrText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TEXTRANGE tr = { 0 };
+ tr.chrg.cpMin = nStartChar;
+ tr.chrg.cpMax = nEndChar;
+ tr.lpstrText = lpstrText;
+ return (int)::SendMessage(m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
+ }
+#else // !(_RICHEDIT_VER >= 0x0200)
+
+ int GetTextRange(LONG nStartChar, LONG nEndChar, LPSTR lpstrText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ TEXTRANGE tr = { 0 };
+ tr.chrg.cpMin = nStartChar;
+ tr.chrg.cpMax = nEndChar;
+ tr.lpstrText = lpstrText;
+ return (int)::SendMessage(m_hWnd, EM_GETTEXTRANGE, 0, (LPARAM)&tr);
+ }
+#endif // !(_RICHEDIT_VER >= 0x0200)
+
+#if (_RICHEDIT_VER >= 0x0200)
+ DWORD GetDefaultCharFormat(CHARFORMAT2& cf) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT2);
+ return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 0, (LPARAM)&cf);
+ }
+
+ BOOL SetCharFormat(CHARFORMAT2& cf, WORD wFlags)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT2);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, (WPARAM)wFlags, (LPARAM)&cf);
+ }
+
+ BOOL SetDefaultCharFormat(CHARFORMAT2& cf)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT2);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf);
+ }
+
+ DWORD GetSelectionCharFormat(CHARFORMAT2& cf) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT2);
+ return (DWORD)::SendMessage(m_hWnd, EM_GETCHARFORMAT, 1, (LPARAM)&cf);
+ }
+
+ BOOL SetSelectionCharFormat(CHARFORMAT2& cf)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT2);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
+ }
+
+ BOOL SetWordCharFormat(CHARFORMAT2& cf)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ cf.cbSize = sizeof(CHARFORMAT2);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETCHARFORMAT, SCF_SELECTION | SCF_WORD, (LPARAM)&cf);
+ }
+
+ DWORD GetParaFormat(PARAFORMAT2& pf) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ pf.cbSize = sizeof(PARAFORMAT2);
+ return (DWORD)::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
+ }
+
+ BOOL SetParaFormat(PARAFORMAT2& pf)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ pf.cbSize = sizeof(PARAFORMAT2);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
+ }
+
+ TEXTMODE GetTextMode() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (TEXTMODE)::SendMessage(m_hWnd, EM_GETTEXTMODE, 0, 0L);
+ }
+
+ BOOL SetTextMode(TEXTMODE enumTextMode)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return !(BOOL)::SendMessage(m_hWnd, EM_SETTEXTMODE, enumTextMode, 0L);
+ }
+
+ UNDONAMEID GetUndoName() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UNDONAMEID)::SendMessage(m_hWnd, EM_GETUNDONAME, 0, 0L);
+ }
+
+ UNDONAMEID GetRedoName() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UNDONAMEID)::SendMessage(m_hWnd, EM_GETREDONAME, 0, 0L);
+ }
+
+ BOOL CanRedo() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_CANREDO, 0, 0L);
+ }
+
+ BOOL GetAutoURLDetect() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_GETAUTOURLDETECT, 0, 0L);
+ }
+
+ BOOL SetAutoURLDetect(BOOL bAutoDetect = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return !(BOOL)::SendMessage(m_hWnd, EM_AUTOURLDETECT, bAutoDetect, 0L);
+ }
+
+ // this method is deprecated, please use SetAutoURLDetect
+ BOOL EnableAutoURLDetect(BOOL bEnable = TRUE) { return SetAutoURLDetect(bEnable); }
+
+ UINT SetUndoLimit(UINT uUndoLimit)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, EM_SETUNDOLIMIT, uUndoLimit, 0L);
+ }
+
+ void SetPalette(HPALETTE hPalette)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETPALETTE, (WPARAM)hPalette, 0L);
+ }
+
+ int GetTextEx(GETTEXTEX* pGetTextEx, LPTSTR lpstrText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETTEXTEX, (WPARAM)pGetTextEx, (LPARAM)lpstrText);
+ }
+
+ int GetTextEx(LPTSTR lpstrText, int nTextLen, DWORD dwFlags = GT_DEFAULT, UINT uCodePage = CP_ACP, LPCSTR lpDefaultChar = NULL, LPBOOL lpUsedDefChar = NULL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ GETTEXTEX gte = { 0 };
+ gte.cb = nTextLen * sizeof(TCHAR);
+ gte.codepage = uCodePage;
+ gte.flags = dwFlags;
+ gte.lpDefaultChar = lpDefaultChar;
+ gte.lpUsedDefChar = lpUsedDefChar;
+ return (int)::SendMessage(m_hWnd, EM_GETTEXTEX, (WPARAM)>e, (LPARAM)lpstrText);
+ }
+
+ int GetTextLengthEx(GETTEXTLENGTHEX* pGetTextLengthEx) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)pGetTextLengthEx, 0L);
+ }
+
+ int GetTextLengthEx(DWORD dwFlags = GTL_DEFAULT, UINT uCodePage = CP_ACP) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ GETTEXTLENGTHEX gtle = { 0 };
+ gtle.codepage = uCodePage;
+ gtle.flags = dwFlags;
+ return (int)::SendMessage(m_hWnd, EM_GETTEXTLENGTHEX, (WPARAM)>le, 0L);
+ }
+#endif // (_RICHEDIT_VER >= 0x0200)
+
+#if (_RICHEDIT_VER >= 0x0300)
+ int SetTextEx(SETTEXTEX* pSetTextEx, LPCTSTR lpstrText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_SETTEXTEX, (WPARAM)pSetTextEx, (LPARAM)lpstrText);
+ }
+
+ int SetTextEx(LPCTSTR lpstrText, DWORD dwFlags = ST_DEFAULT, UINT uCodePage = CP_ACP)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ SETTEXTEX ste = { 0 };
+ ste.flags = dwFlags;
+ ste.codepage = uCodePage;
+ return (int)::SendMessage(m_hWnd, EM_SETTEXTEX, (WPARAM)&ste, (LPARAM)lpstrText);
+ }
+
+ int GetEditStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_GETEDITSTYLE, 0, 0L);
+ }
+
+ int SetEditStyle(int nStyle, int nMask = -1)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ if(nMask == -1)
+ nMask = nStyle; // set everything specified
+ return (int)::SendMessage(m_hWnd, EM_SETEDITSTYLE, nStyle, nMask);
+ }
+
+ BOOL SetFontSize(int nFontSizeDelta)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nFontSizeDelta >= -1637 && nFontSizeDelta <= 1638);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETFONTSIZE, nFontSizeDelta, 0L);
+ }
+
+ void GetScrollPos(LPPOINT lpPoint) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpPoint != NULL);
+ ::SendMessage(m_hWnd, EM_GETSCROLLPOS, 0, (LPARAM)lpPoint);
+ }
+
+ void SetScrollPos(LPPOINT lpPoint)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpPoint != NULL);
+ ::SendMessage(m_hWnd, EM_SETSCROLLPOS, 0, (LPARAM)lpPoint);
+ }
+
+ BOOL GetZoom(int& nNum, int& nDen) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_GETZOOM, (WPARAM)&nNum, (LPARAM)&nDen);
+ }
+
+ BOOL SetZoom(int nNum, int nDen)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nNum >= 0 && nNum <= 64);
+ ATLASSERT(nDen >= 0 && nDen <= 64);
+ return (BOOL)::SendMessage(m_hWnd, EM_SETZOOM, nNum, nDen);
+ }
+
+ BOOL SetZoomOff()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETZOOM, 0, 0L);
+ }
+#endif // (_RICHEDIT_VER >= 0x0300)
+
+// Operations
+ void LimitText(LONG nChars = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_EXLIMITTEXT, 0, nChars);
+ }
+
+ int LineFromChar(LONG nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_EXLINEFROMCHAR, 0, nIndex);
+ }
+
+ POINT PosFromChar(LONG nChar) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ POINT point = { 0, 0 };
+ ::SendMessage(m_hWnd, EM_POSFROMCHAR, (WPARAM)&point, nChar);
+ return point;
+ }
+
+ int CharFromPos(POINT pt) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ POINTL ptl = { pt.x, pt.y };
+ return (int)::SendMessage(m_hWnd, EM_CHARFROMPOS, 0, (LPARAM)&ptl);
+ }
+
+ void EmptyUndoBuffer()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_EMPTYUNDOBUFFER, 0, 0L);
+ }
+
+ int LineIndex(int nLine = -1) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_LINEINDEX, nLine, 0L);
+ }
+
+ int LineLength(int nLine = -1) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, EM_LINELENGTH, nLine, 0L);
+ }
+
+ BOOL LineScroll(int nLines, int nChars = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_LINESCROLL, nChars, nLines);
+ }
+
+ void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_REPLACESEL, (WPARAM) bCanUndo, (LPARAM)lpszNewText);
+ }
+
+ void SetRect(LPCRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SETRECT, 0, (LPARAM)lpRect);
+ }
+
+ BOOL DisplayBand(LPRECT pDisplayRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_DISPLAYBAND, 0, (LPARAM)pDisplayRect);
+ }
+
+ LONG FindText(DWORD dwFlags, FINDTEXT& ft) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+#if (_RICHEDIT_VER >= 0x0200) && defined(_UNICODE)
+ return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTW, dwFlags, (LPARAM)&ft);
+#else
+ return (LONG)::SendMessage(m_hWnd, EM_FINDTEXT, dwFlags, (LPARAM)&ft);
+#endif
+ }
+
+ LONG FindText(DWORD dwFlags, FINDTEXTEX& ft) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+#if (_RICHEDIT_VER >= 0x0200) && defined(_UNICODE)
+ return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTEXW, dwFlags, (LPARAM)&ft);
+#else
+ return (LONG)::SendMessage(m_hWnd, EM_FINDTEXTEX, dwFlags, (LPARAM)&ft);
+#endif
+ }
+
+ LONG FormatRange(FORMATRANGE& fr, BOOL bDisplay = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LONG)::SendMessage(m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)&fr);
+ }
+
+ LONG FormatRange(FORMATRANGE* pFormatRange, BOOL bDisplay = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LONG)::SendMessage(m_hWnd, EM_FORMATRANGE, bDisplay, (LPARAM)pFormatRange);
+ }
+
+ void HideSelection(BOOL bHide = TRUE, BOOL bChangeStyle = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_HIDESELECTION, bHide, bChangeStyle);
+ }
+
+ void PasteSpecial(UINT uClipFormat, DWORD dwAspect = 0, HMETAFILE hMF = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ REPASTESPECIAL reps = { dwAspect, (DWORD_PTR)hMF };
+ ::SendMessage(m_hWnd, EM_PASTESPECIAL, uClipFormat, (LPARAM)&reps);
+ }
+
+ void RequestResize()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_REQUESTRESIZE, 0, 0L);
+ }
+
+ LONG StreamIn(UINT uFormat, EDITSTREAM& es)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LONG)::SendMessage(m_hWnd, EM_STREAMIN, uFormat, (LPARAM)&es);
+ }
+
+ LONG StreamOut(UINT uFormat, EDITSTREAM& es)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (LONG)::SendMessage(m_hWnd, EM_STREAMOUT, uFormat, (LPARAM)&es);
+ }
+
+ DWORD FindWordBreak(int nCode, LONG nStartChar)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, EM_FINDWORDBREAK, nCode, nStartChar);
+ }
+
+ // Additional operations
+ void ScrollCaret()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SCROLLCARET, 0, 0L);
+ }
+
+ int InsertText(long nInsertAfterChar, LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
+ {
+ int nRet = SetSel(nInsertAfterChar, nInsertAfterChar);
+ ReplaceSel(lpstrText, bCanUndo);
+ return nRet;
+ }
+
+ int AppendText(LPCTSTR lpstrText, BOOL bCanUndo = FALSE)
+ {
+ return InsertText(GetWindowTextLength(), lpstrText, bCanUndo);
+ }
+
+ // Clipboard operations
+ BOOL Undo()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_UNDO, 0, 0L);
+ }
+
+ void Clear()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_CLEAR, 0, 0L);
+ }
+
+ void Copy()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_COPY, 0, 0L);
+ }
+
+ void Cut()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_CUT, 0, 0L);
+ }
+
+ void Paste()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, WM_PASTE, 0, 0L);
+ }
+
+ // OLE support
+ IRichEditOle* GetOleInterface() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ IRichEditOle *pRichEditOle = NULL;
+ ::SendMessage(m_hWnd, EM_GETOLEINTERFACE, 0, (LPARAM)&pRichEditOle);
+ return pRichEditOle;
+ }
+
+ BOOL SetOleCallback(IRichEditOleCallback* pCallback)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETOLECALLBACK, 0, (LPARAM)pCallback);
+ }
+
+#if (_RICHEDIT_VER >= 0x0200)
+ BOOL Redo()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_REDO, 0, 0L);
+ }
+
+ void StopGroupTyping()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_STOPGROUPTYPING, 0, 0L);
+ }
+
+ void ShowScrollBar(int nBarType, BOOL bVisible = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, EM_SHOWSCROLLBAR, nBarType, bVisible);
+ }
+#endif // (_RICHEDIT_VER >= 0x0200)
+
+#if (_RICHEDIT_VER >= 0x0300)
+ BOOL SetTabStops(int nTabStops, LPINT rgTabStops)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, nTabStops, (LPARAM)rgTabStops);
+ }
+
+ BOOL SetTabStops()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 0, 0L);
+ }
+
+ BOOL SetTabStops(const int& cxEachStop) // takes an 'int'
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, EM_SETTABSTOPS, 1, (LPARAM)(LPINT)&cxEachStop);
+ }
+#endif // (_RICHEDIT_VER >= 0x0300)
+};
+
+typedef CRichEditCtrlT<ATL::CWindow> CRichEditCtrl;
+
+#endif // !_WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CRichEditCommands - message handlers for standard EDIT commands
+
+#ifndef _WIN32_WCE
+
+// Chain to CRichEditCommands message map. Your class must also derive from CRichEditCtrl.
+// Example:
+// class CMyRichEdit : public CWindowImpl<CMyRichEdit, CRichEditCtrl>,
+// public CRichEditCommands<CMyRichEdit>
+// {
+// public:
+// BEGIN_MSG_MAP(CMyRichEdit)
+// // your handlers...
+// CHAIN_MSG_MAP_ALT(CRichEditCommands<CMyRichEdit>, 1)
+// END_MSG_MAP()
+// // other stuff...
+// };
+
+template <class T>
+class CRichEditCommands : public CEditCommands< T >
+{
+public:
+ BEGIN_MSG_MAP(CRichEditCommands< T >)
+ ALT_MSG_MAP(1)
+ COMMAND_ID_HANDLER(ID_EDIT_CLEAR, CEditCommands< T >::OnEditClear)
+ COMMAND_ID_HANDLER(ID_EDIT_CLEAR_ALL, CEditCommands< T >::OnEditClearAll)
+ COMMAND_ID_HANDLER(ID_EDIT_COPY, CEditCommands< T >::OnEditCopy)
+ COMMAND_ID_HANDLER(ID_EDIT_CUT, CEditCommands< T >::OnEditCut)
+ COMMAND_ID_HANDLER(ID_EDIT_PASTE, CEditCommands< T >::OnEditPaste)
+ COMMAND_ID_HANDLER(ID_EDIT_SELECT_ALL, CEditCommands< T >::OnEditSelectAll)
+ COMMAND_ID_HANDLER(ID_EDIT_UNDO, CEditCommands< T >::OnEditUndo)
+#if (_RICHEDIT_VER >= 0x0200)
+ COMMAND_ID_HANDLER(ID_EDIT_REDO, OnEditRedo)
+#endif // (_RICHEDIT_VER >= 0x0200)
+ END_MSG_MAP()
+
+#if (_RICHEDIT_VER >= 0x0200)
+ LRESULT OnEditRedo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->Redo();
+ return 0;
+ }
+#endif // (_RICHEDIT_VER >= 0x0200)
+
+// State (update UI) helpers
+ BOOL CanCut() const
+ { return HasSelection(); }
+
+ BOOL CanCopy() const
+ { return HasSelection(); }
+
+ BOOL CanClear() const
+ { return HasSelection(); }
+
+// Implementation
+ BOOL HasSelection() const
+ {
+ const T* pT = static_cast<const T*>(this);
+ return (pT->GetSelectionType() != SEL_EMPTY);
+ }
+};
+
+#endif // _WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CDragListBox
+
+#ifndef _WIN32_WCE
+
+template <class TBase>
+class CDragListBoxT : public CListBoxT< TBase >
+{
+public:
+// Constructors
+ CDragListBoxT(HWND hWnd = NULL) : CListBoxT< TBase >(hWnd)
+ { }
+
+ CDragListBoxT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ HWND hWnd = TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ if(hWnd != NULL)
+ MakeDragList();
+ return hWnd;
+ }
+
+// Operations
+ BOOL MakeDragList()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((GetStyle() & (LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) == 0);
+ return ::MakeDragList(m_hWnd);
+ }
+
+ int LBItemFromPt(POINT pt, BOOL bAutoScroll = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::LBItemFromPt(m_hWnd, pt, bAutoScroll);
+ }
+
+ void DrawInsert(int nItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::DrawInsert(GetParent(), m_hWnd, nItem);
+ }
+
+ static UINT GetDragListMessage()
+ {
+ static UINT uDragListMessage = 0;
+ if(uDragListMessage == 0)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CDragListBox::GetDragListMessage.\n"));
+ ATLASSERT(FALSE);
+ return 0;
+ }
+
+ if(uDragListMessage == 0)
+ uDragListMessage = ::RegisterWindowMessage(DRAGLISTMSGSTRING);
+
+ lock.Unlock();
+ }
+ ATLASSERT(uDragListMessage != 0);
+ return uDragListMessage;
+ }
+};
+
+typedef CDragListBoxT<ATL::CWindow> CDragListBox;
+
+template <class T>
+class CDragListNotifyImpl
+{
+public:
+ BEGIN_MSG_MAP(CDragListNotifyImpl< T >)
+ MESSAGE_HANDLER(CDragListBox::GetDragListMessage(), OnDragListNotify)
+ END_MSG_MAP()
+
+ LRESULT OnDragListNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+ {
+ uMsg; // avoid level 4 warning
+ ATLASSERT(uMsg == CDragListBox::GetDragListMessage());
+ T* pT = static_cast<T*>(this);
+ LPDRAGLISTINFO lpDragListInfo = (LPDRAGLISTINFO)lParam;
+ LRESULT lRet = 0;
+ switch(lpDragListInfo->uNotification)
+ {
+ case DL_BEGINDRAG:
+ lRet = (LPARAM)pT->OnBeginDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
+ break;
+ case DL_CANCELDRAG:
+ pT->OnCancelDrag((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
+ break;
+ case DL_DRAGGING:
+ lRet = (LPARAM)pT->OnDragging((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
+ break;
+ case DL_DROPPED:
+ pT->OnDropped((int)wParam, lpDragListInfo->hWnd, lpDragListInfo->ptCursor);
+ break;
+ default:
+ ATLTRACE2(atlTraceUI, 0, _T("Unknown DragListBox notification\n"));
+ bHandled = FALSE; // don't handle it
+ break;
+ }
+ return lRet;
+ }
+
+// Overrideables
+ BOOL OnBeginDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
+ {
+ return TRUE; // allow dragging
+ }
+
+ void OnCancelDrag(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
+ {
+ // nothing to do
+ }
+
+ int OnDragging(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
+ {
+ return 0; // don't change cursor
+ }
+
+ void OnDropped(int /*nCtlID*/, HWND /*hWndDragList*/, POINT /*ptCursor*/)
+ {
+ // nothing to do
+ }
+};
+
+#endif // _WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CReBarCtrl
+
+template <class TBase>
+class CReBarCtrlT : public TBase
+{
+public:
+// Constructors
+ CReBarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CReBarCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return REBARCLASSNAME;
+ }
+
+ UINT GetBandCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, RB_GETBANDCOUNT, 0, 0L);
+ }
+
+ BOOL GetBandInfo(int nBand, LPREBARBANDINFO lprbbi) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_GETBANDINFO, nBand, (LPARAM)lprbbi);
+ }
+
+ BOOL SetBandInfo(int nBand, LPREBARBANDINFO lprbbi)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_SETBANDINFO, nBand, (LPARAM)lprbbi);
+ }
+
+ BOOL GetBarInfo(LPREBARINFO lprbi) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_GETBARINFO, 0, (LPARAM)lprbi);
+ }
+
+ BOOL SetBarInfo(LPREBARINFO lprbi)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_SETBARINFO, 0, (LPARAM)lprbi);
+ }
+
+ CImageList GetImageList() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ REBARINFO rbi = { 0 };
+ rbi.cbSize = sizeof(REBARINFO);
+ rbi.fMask = RBIM_IMAGELIST;
+ if( (BOOL)::SendMessage(m_hWnd, RB_GETBARINFO, 0, (LPARAM)&rbi) == FALSE ) return CImageList();
+ return CImageList(rbi.himl);
+ }
+
+ BOOL SetImageList(HIMAGELIST hImageList)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ REBARINFO rbi = { 0 };
+ rbi.cbSize = sizeof(REBARINFO);
+ rbi.fMask = RBIM_IMAGELIST;
+ rbi.himl = hImageList;
+ return (BOOL)::SendMessage(m_hWnd, RB_SETBARINFO, 0, (LPARAM)&rbi);
+ }
+
+ UINT GetRowCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, RB_GETROWCOUNT, 0, 0L);
+ }
+
+ UINT GetRowHeight(int nBand) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, RB_GETROWHEIGHT, nBand, 0L);
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ COLORREF GetTextColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, RB_GETTEXTCOLOR, 0, 0L);
+ }
+
+ COLORREF SetTextColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, RB_SETTEXTCOLOR, 0, (LPARAM)clr);
+ }
+
+ COLORREF GetBkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, RB_GETBKCOLOR, 0, 0L);
+ }
+
+ COLORREF SetBkColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, RB_SETBKCOLOR, 0, (LPARAM)clr);
+ }
+
+ UINT GetBarHeight() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (UINT)::SendMessage(m_hWnd, RB_GETBARHEIGHT, 0, 0L);
+ }
+
+ BOOL GetRect(int nBand, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_GETRECT, nBand, (LPARAM)lpRect);
+ }
+
+#ifndef _WIN32_WCE
+ CToolTipCtrl GetToolTips() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CToolTipCtrl((HWND)::SendMessage(m_hWnd, RB_GETTOOLTIPS, 0, 0L));
+ }
+
+ void SetToolTips(HWND hwndToolTip)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_SETTOOLTIPS, (WPARAM)hwndToolTip, 0L);
+ }
+#endif // !_WIN32_WCE
+
+ void GetBandBorders(int nBand, LPRECT lpRect) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpRect != NULL);
+ ::SendMessage(m_hWnd, RB_GETBANDBORDERS, nBand, (LPARAM)lpRect);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL GetColorScheme(LPCOLORSCHEME lpColorScheme) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpColorScheme != NULL);
+ return (BOOL)::SendMessage(m_hWnd, RB_GETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
+ }
+
+ void SetColorScheme(LPCOLORSCHEME lpColorScheme)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpColorScheme != NULL);
+ ::SendMessage(m_hWnd, RB_SETCOLORSCHEME, 0, (LPARAM)lpColorScheme);
+ }
+
+ HPALETTE GetPalette() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HPALETTE)::SendMessage(m_hWnd, RB_GETPALETTE, 0, 0L);
+ }
+
+ HPALETTE SetPalette(HPALETTE hPalette)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HPALETTE)::SendMessage(m_hWnd, RB_SETPALETTE, 0, (LPARAM)hPalette);
+ }
+
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // !_WIN32_WCE
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_WINNT >= 0x0501)
+ // requires uxtheme.h to be included to use MARGINS struct
+#ifndef _UXTHEME_H_
+ typedef struct _MARGINS* PMARGINS;
+#endif // !_UXTHEME_H_
+ void GetBandMargins(PMARGINS pMargins) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_GETBANDMARGINS, 0, (LPARAM)pMargins);
+ }
+
+ void SetWindowTheme(LPCWSTR lpstrTheme)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+#if (_WIN32_IE >= 0x0600)
+ DWORD GetExtendedStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, RB_GETEXTENDEDSTYLE, 0, 0L);
+ }
+
+ DWORD SetExtendedStyle(DWORD dwStyle, DWORD dwMask)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, RB_SETEXTENDEDSTYLE, dwMask, dwStyle);
+ }
+#endif // (_WIN32_IE >= 0x0600)
+
+// Operations
+ BOOL InsertBand(int nBand, LPREBARBANDINFO lprbbi)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_INSERTBAND, nBand, (LPARAM)lprbbi);
+ }
+
+ BOOL AddBand(LPREBARBANDINFO lprbbi)
+ {
+ return InsertBand(-1, lprbbi);
+ }
+
+ BOOL DeleteBand(int nBand)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_DELETEBAND, nBand, 0L);
+ }
+
+ ATL::CWindow SetNotifyWnd(HWND hWnd)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ATL::CWindow((HWND)::SendMessage(m_hWnd, RB_SETPARENT, (WPARAM)hWnd, 0L));
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ void BeginDrag(int nBand, DWORD dwPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_BEGINDRAG, nBand, dwPos);
+ }
+
+ void BeginDrag(int nBand, int xPos, int yPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_BEGINDRAG, nBand, MAKELPARAM(xPos, yPos));
+ }
+
+ void EndDrag()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_ENDDRAG, 0, 0L);
+ }
+
+ void DragMove(DWORD dwPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_DRAGMOVE, 0, dwPos);
+ }
+
+ void DragMove(int xPos, int yPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_DRAGMOVE, 0, MAKELPARAM(xPos, yPos));
+ }
+
+#ifndef _WIN32_WCE
+ void GetDropTarget(IDropTarget** ppDropTarget) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
+ }
+#endif // !_WIN32_WCE
+
+ void MaximizeBand(int nBand, BOOL bIdeal = FALSE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_MAXIMIZEBAND, nBand, bIdeal);
+ }
+
+ void MinimizeBand(int nBand)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_MINIMIZEBAND, nBand, 0L);
+ }
+
+ BOOL SizeToRect(LPRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_SIZETORECT, 0, (LPARAM)lpRect);
+ }
+
+ int IdToIndex(UINT uBandID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, RB_IDTOINDEX, uBandID, 0L);
+ }
+
+ int HitTest(LPRBHITTESTINFO lprbht) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, RB_HITTEST, 0, (LPARAM)lprbht);
+ }
+
+ BOOL ShowBand(int nBand, BOOL bShow)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_SHOWBAND, nBand, bShow);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL MoveBand(int nBand, int nNewPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nNewPos >= 0 && nNewPos <= ((int)GetBandCount() - 1));
+ return (BOOL)::SendMessage(m_hWnd, RB_MOVEBAND, nBand, nNewPos);
+ }
+#endif // !_WIN32_WCE
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ void PushChevron(int nBand, LPARAM lAppValue)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, RB_PUSHCHEVRON, nBand, lAppValue);
+ }
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+// Extra operations
+#if (_WIN32_IE >= 0x0400)
+ void LockBands(bool bLock)
+ {
+ int nBandCount = GetBandCount();
+ for(int i =0; i < nBandCount; i++)
+ {
+ REBARBANDINFO rbbi = { RunTimeHelper::SizeOf_REBARBANDINFO() };
+ rbbi.fMask = RBBIM_STYLE;
+ BOOL bRet = GetBandInfo(i, &rbbi);
+ ATLASSERT(bRet);
+
+ if((rbbi.fStyle & RBBS_GRIPPERALWAYS) == 0)
+ {
+ rbbi.fStyle |= RBBS_GRIPPERALWAYS;
+ bRet = SetBandInfo(i, &rbbi);
+ ATLASSERT(bRet);
+ rbbi.fStyle &= ~RBBS_GRIPPERALWAYS;
+ }
+
+ if(bLock)
+ rbbi.fStyle |= RBBS_NOGRIPPER;
+ else
+ rbbi.fStyle &= ~RBBS_NOGRIPPER;
+
+ bRet = SetBandInfo(i, &rbbi);
+ ATLASSERT(bRet);
+ }
+ }
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_WINNT >= 0x0600)
+ BOOL SetBandWidth(int nBand, int cxWidth)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, RB_SETBANDWIDTH, nBand, cxWidth);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+};
+
+typedef CReBarCtrlT<ATL::CWindow> CReBarCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CComboBoxEx
+
+#ifndef _WIN32_WCE
+
+template <class TBase>
+class CComboBoxExT : public CComboBoxT< TBase >
+{
+public:
+// Constructors
+ CComboBoxExT(HWND hWnd = NULL) : CComboBoxT< TBase >(hWnd)
+ { }
+
+ CComboBoxExT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return WC_COMBOBOXEX;
+ }
+
+ CImageList GetImageList() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, CBEM_GETIMAGELIST, 0, 0L));
+ }
+
+ CImageList SetImageList(HIMAGELIST hImageList)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CImageList((HIMAGELIST)::SendMessage(m_hWnd, CBEM_SETIMAGELIST, 0, (LPARAM)hImageList));
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ DWORD GetExtendedStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, CBEM_GETEXTENDEDSTYLE, 0, 0L);
+ }
+
+ DWORD SetExtendedStyle(DWORD dwExMask, DWORD dwExStyle)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, CBEM_SETEXTENDEDSTYLE, dwExMask, dwExStyle);
+ }
+
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CBEM_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CBEM_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_WINNT >= 0x0501)
+ void SetWindowTheme(LPCWSTR lpstrTheme)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, CBEM_SETWINDOWTHEME, 0, (LPARAM)lpstrTheme);
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+// Operations
+ int InsertItem(const COMBOBOXEXITEM* lpcCBItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)lpcCBItem);
+ }
+
+ int InsertItem(UINT nMask, int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage,
+ int iIndent, int iOverlay, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ COMBOBOXEXITEM cbex = { 0 };
+ cbex.mask = nMask;
+ cbex.iItem = nIndex;
+ cbex.pszText = (LPTSTR) lpszItem;
+ cbex.iImage = nImage;
+ cbex.iSelectedImage = nSelImage;
+ cbex.iIndent = iIndent;
+ cbex.iOverlay = iOverlay;
+ cbex.lParam = lParam;
+ return (int)::SendMessage(m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
+ }
+
+ int InsertItem(int nIndex, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ COMBOBOXEXITEM cbex = { 0 };
+ cbex.mask = CBEIF_TEXT | CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_INDENT | CBEIF_LPARAM;
+ cbex.iItem = nIndex;
+ cbex.pszText = (LPTSTR) lpszItem;
+ cbex.iImage = nImage;
+ cbex.iSelectedImage = nSelImage;
+ cbex.iIndent = iIndent;
+ cbex.lParam = lParam;
+ return (int)::SendMessage(m_hWnd, CBEM_INSERTITEM, 0, (LPARAM)&cbex);
+ }
+
+ int AddItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, int iOverlay, LPARAM lParam)
+ {
+ return InsertItem(nMask, -1, lpszItem, nImage, nSelImage, iIndent, iOverlay, lParam);
+ }
+
+ int AddItem(LPCTSTR lpszItem, int nImage, int nSelImage, int iIndent, LPARAM lParam = 0)
+ {
+ return InsertItem(-1, lpszItem, nImage, nSelImage, iIndent, lParam);
+ }
+
+ int DeleteItem(int nIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, CBEM_DELETEITEM, nIndex, 0L);
+ }
+
+ BOOL GetItem(PCOMBOBOXEXITEM pCBItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)pCBItem);
+ }
+
+ BOOL SetItem(const COMBOBOXEXITEM* lpcCBItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CBEM_SETITEM, 0, (LPARAM)lpcCBItem);
+ }
+
+ int SetItem(int nIndex, UINT nMask, LPCTSTR lpszItem, int nImage, int nSelImage,
+ int iIndent, int iOverlay, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ COMBOBOXEXITEM cbex = { 0 };
+ cbex.mask = nMask;
+ cbex.iItem = nIndex;
+ cbex.pszText = (LPTSTR) lpszItem;
+ cbex.iImage = nImage;
+ cbex.iSelectedImage = nSelImage;
+ cbex.iIndent = iIndent;
+ cbex.iOverlay = iOverlay;
+ cbex.lParam = lParam;
+ return (int)::SendMessage(m_hWnd, CBEM_SETITEM, 0, (LPARAM)&cbex);
+ }
+
+ BOOL GetItemText(int nIndex, LPTSTR lpszItem, int nLen) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(lpszItem != NULL);
+
+ COMBOBOXEXITEM cbex = { 0 };
+ cbex.mask = CBEIF_TEXT;
+ cbex.iItem = nIndex;
+ cbex.pszText = lpszItem;
+ cbex.cchTextMax = nLen;
+
+ return (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
+ }
+
+#ifndef _ATL_NO_COM
+ BOOL GetItemText(int nIndex, BSTR& bstrText) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(bstrText == NULL);
+
+ COMBOBOXEXITEM cbex = { 0 };
+ cbex.mask = CBEIF_TEXT;
+ cbex.iItem = nIndex;
+
+ LPTSTR lpstrText = NULL;
+ BOOL bRet = FALSE;
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ ATLTRY(lpstrText = new TCHAR[nLen]);
+ if(lpstrText == NULL)
+ break;
+ lpstrText[0] = NULL;
+ cbex.pszText = lpstrText;
+ cbex.cchTextMax = nLen;
+ bRet = (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
+ if(!bRet || (lstrlen(cbex.pszText) < nLen - 1))
+ break;
+ delete [] lpstrText;
+ lpstrText = NULL;
+ }
+
+ if(lpstrText != NULL)
+ {
+ if(bRet)
+ bstrText = ::SysAllocString(T2OLE(lpstrText));
+ delete [] lpstrText;
+ }
+
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ BOOL GetItemText(int nIndex, _CSTRING_NS::CString& strText) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+
+ COMBOBOXEXITEM cbex = { 0 };
+ cbex.mask = CBEIF_TEXT;
+ cbex.iItem = nIndex;
+
+ strText.Empty();
+ BOOL bRet = FALSE;
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ cbex.pszText = strText.GetBufferSetLength(nLen);
+ if(cbex.pszText == NULL)
+ {
+ bRet = FALSE;
+ break;
+ }
+ cbex.cchTextMax = nLen;
+ bRet = (BOOL)::SendMessage(m_hWnd, CBEM_GETITEM, 0, (LPARAM)&cbex);
+ if(!bRet || (lstrlen(cbex.pszText) < nLen - 1))
+ break;
+ }
+ strText.ReleaseBuffer();
+ return bRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ BOOL SetItemText(int nIndex, LPCTSTR lpszItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return SetItem(nIndex, CBEIF_TEXT, lpszItem, 0, 0, 0, 0, 0);
+ }
+
+ CComboBox GetComboCtrl() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CComboBox((HWND)::SendMessage(m_hWnd, CBEM_GETCOMBOCONTROL, 0, 0L));
+ }
+
+ CEdit GetEditCtrl() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CEdit((HWND)::SendMessage(m_hWnd, CBEM_GETEDITCONTROL, 0, 0L));
+ }
+
+ BOOL HasEditChanged() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, CBEM_HASEDITCHANGED, 0, 0L);
+ }
+
+// Non-functional
+ int AddString(LPCTSTR /*lpszItem*/)
+ {
+ ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
+ return 0;
+ }
+
+ int InsertString(int /*nIndex*/, LPCTSTR /*lpszString*/)
+ {
+ ATLASSERT(FALSE); // Not available in CComboBoxEx; use InsertItem
+ return 0;
+ }
+
+ int Dir(UINT /*attr*/, LPCTSTR /*lpszWildCard*/)
+ {
+ ATLASSERT(FALSE); // Not available in CComboBoxEx
+ return 0;
+ }
+
+ int FindString(int /*nStartAfter*/, LPCTSTR /*lpszString*/) const
+ {
+ ATLASSERT(FALSE); // Not available in CComboBoxEx; try FindStringExact
+ return 0;
+ }
+};
+
+typedef CComboBoxExT<ATL::CWindow> CComboBoxEx;
+
+#endif // !_WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CMonthCalendarCtrl
+
+template <class TBase>
+class CMonthCalendarCtrlT : public TBase
+{
+public:
+// Constructors
+ CMonthCalendarCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CMonthCalendarCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return MONTHCAL_CLASS;
+ }
+
+ COLORREF GetColor(int nColorType) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, MCM_GETCOLOR, nColorType, 0L);
+ }
+
+ COLORREF SetColor(int nColorType, COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, MCM_SETCOLOR, nColorType, clr);
+ }
+
+ BOOL GetCurSel(LPSYSTEMTIME lpSysTime) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_GETCURSEL, 0, (LPARAM)lpSysTime);
+ }
+
+ BOOL SetCurSel(LPSYSTEMTIME lpSysTime)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_SETCURSEL, 0, (LPARAM)lpSysTime);
+ }
+
+ int GetFirstDayOfWeek(BOOL* pbLocaleVal = NULL) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, MCM_GETFIRSTDAYOFWEEK, 0, 0L);
+ if(pbLocaleVal != NULL)
+ *pbLocaleVal = (BOOL)HIWORD(dwRet);
+ return (int)(short)LOWORD(dwRet);
+ }
+
+ int SetFirstDayOfWeek(int nDay, BOOL* pbLocaleVal = NULL)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ DWORD dwRet = (DWORD)::SendMessage(m_hWnd, MCM_SETFIRSTDAYOFWEEK, 0, nDay);
+ if(pbLocaleVal != NULL)
+ *pbLocaleVal = (BOOL)HIWORD(dwRet);
+ return (int)(short)LOWORD(dwRet);
+ }
+
+ int GetMaxSelCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, MCM_GETMAXSELCOUNT, 0, 0L);
+ }
+
+ BOOL SetMaxSelCount(int nMax)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_SETMAXSELCOUNT, nMax, 0L);
+ }
+
+ int GetMonthDelta() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, MCM_GETMONTHDELTA, 0, 0L);
+ }
+
+ int SetMonthDelta(int nDelta)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, MCM_SETMONTHDELTA, nDelta, 0L);
+ }
+
+ DWORD GetRange(LPSYSTEMTIME lprgSysTimeArray) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, MCM_GETRANGE, 0, (LPARAM)lprgSysTimeArray);
+ }
+
+ BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_SETRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
+ }
+
+ BOOL GetSelRange(LPSYSTEMTIME lprgSysTimeArray) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_GETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
+ }
+
+ BOOL SetSelRange(LPSYSTEMTIME lprgSysTimeArray)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_SETSELRANGE, 0, (LPARAM)lprgSysTimeArray);
+ }
+
+ BOOL GetToday(LPSYSTEMTIME lpSysTime) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_GETTODAY, 0, (LPARAM)lpSysTime);
+ }
+
+ void SetToday(LPSYSTEMTIME lpSysTime)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, MCM_SETTODAY, 0, (LPARAM)lpSysTime);
+ }
+
+ BOOL GetMinReqRect(LPRECT lpRectInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_GETMINREQRECT, 0, (LPARAM)lpRectInfo);
+ }
+
+ int GetMaxTodayWidth() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, MCM_GETMAXTODAYWIDTH, 0, 0L);
+ }
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ BOOL GetUnicodeFormat() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_GETUNICODEFORMAT, 0, 0L);
+ }
+
+ BOOL SetUnicodeFormat(BOOL bUnicode = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_SETUNICODEFORMAT, bUnicode, 0L);
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+#if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+ DWORD GetCurrentView() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, MCM_GETCURRENTVIEW, 0, 0L);
+ }
+
+ BOOL SetCurrentView(DWORD dwView)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_SETCURRENTVIEW, 0, dwView);
+ }
+
+ DWORD GetCalendarCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, MCM_GETCALENDARCOUNT, 0, 0L);
+ }
+
+ BOOL GetCalendarGridInfo(PMCGRIDINFO pGridInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_GETCALENDARGRIDINFO, 0, (LPARAM)pGridInfo);
+ }
+
+ CALID GetCALID() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (CALID)::SendMessage(m_hWnd, MCM_GETCALID, 0, 0L);
+ }
+
+ void SetCALID(CALID calid)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, MCM_SETCALID, (LPARAM)calid, 0L);
+ }
+
+ int GetCalendarBorder() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, MCM_GETCALENDARBORDER, 0, 0L);
+ }
+
+ void SetCalendarBorder(int cxyBorder, BOOL bSet = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, MCM_SETCALENDARBORDER, (WPARAM)bSet, (LPARAM)cxyBorder);
+ }
+#endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+
+// Operations
+ int GetMonthRange(DWORD dwFlags, LPSYSTEMTIME lprgSysTimeArray) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, MCM_GETMONTHRANGE, dwFlags, (LPARAM)lprgSysTimeArray);
+ }
+
+ BOOL SetDayState(int nMonths, LPMONTHDAYSTATE lpDayStateArray)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, MCM_SETDAYSTATE, nMonths, (LPARAM)lpDayStateArray);
+ }
+
+ DWORD HitTest(PMCHITTESTINFO pMCHitTest) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, MCM_HITTEST, 0, (LPARAM)pMCHitTest);
+ }
+
+#if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+ void SizeRectToMin(LPRECT lpRect)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, MCM_SIZERECTTOMIN, 0, (LPARAM)lpRect);
+ }
+#endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+};
+
+typedef CMonthCalendarCtrlT<ATL::CWindow> CMonthCalendarCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CDateTimePickerCtrl
+
+template <class TBase>
+class CDateTimePickerCtrlT : public TBase
+{
+public:
+// Constructors
+ CDateTimePickerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CDateTimePickerCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Operations
+ static LPCTSTR GetWndClassName()
+ {
+ return DATETIMEPICK_CLASS;
+ }
+
+ BOOL SetFormat(LPCTSTR lpszFormat)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, DTM_SETFORMAT, 0, (LPARAM)lpszFormat);
+ }
+
+ COLORREF GetMonthCalColor(int nColorType) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, DTM_GETMCCOLOR, nColorType, 0L);
+ }
+
+ COLORREF SetMonthCalColor(int nColorType, COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, DTM_SETMCCOLOR, nColorType, clr);
+ }
+
+ DWORD GetRange(LPSYSTEMTIME lpSysTimeArray) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, DTM_GETRANGE, 0, (LPARAM)lpSysTimeArray);
+ }
+
+ BOOL SetRange(DWORD dwFlags, LPSYSTEMTIME lpSysTimeArray)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, DTM_SETRANGE, dwFlags, (LPARAM)lpSysTimeArray);
+ }
+
+ DWORD GetSystemTime(LPSYSTEMTIME lpSysTime) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, DTM_GETSYSTEMTIME, 0, (LPARAM)lpSysTime);
+ }
+
+ BOOL SetSystemTime(DWORD dwFlags, LPSYSTEMTIME lpSysTime)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, DTM_SETSYSTEMTIME, dwFlags, (LPARAM)lpSysTime);
+ }
+
+ CMonthCalendarCtrl GetMonthCal() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CMonthCalendarCtrl((HWND)::SendMessage(m_hWnd, DTM_GETMONTHCAL, 0, 0L));
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ CFontHandle GetMonthCalFont() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CFontHandle((HFONT)::SendMessage(m_hWnd, DTM_GETMCFONT, 0, 0L));
+ }
+
+ void SetMonthCalFont(HFONT hFont, BOOL bRedraw = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, DTM_SETMCFONT, (WPARAM)hFont, MAKELPARAM(bRedraw, 0));
+ }
+#endif // (_WIN32_IE >= 0x0400)
+
+#if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+ DWORD GetMonthCalStyle() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, DTM_GETMCSTYLE, 0, 0L);
+ }
+
+ DWORD SetMonthCalStyle(DWORD dwStyle)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (DWORD)::SendMessage(m_hWnd, DTM_SETMCSTYLE, 0, (LPARAM)dwStyle);
+ }
+
+ void GetDateTimePickerInfo(LPDATETIMEPICKERINFO lpPickerInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, DTM_GETDATETIMEPICKERINFO, 0, (LPARAM)lpPickerInfo);
+ }
+
+ BOOL GetIdealSize(LPSIZE lpSize) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, DTM_GETIDEALSIZE, 0, (LPARAM)lpSize);
+ }
+
+ void CloseMonthCal()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, DTM_CLOSEMONTHCAL, 0, 0L);
+ }
+#endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+};
+
+typedef CDateTimePickerCtrlT<ATL::CWindow> CDateTimePickerCtrl;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CFlatScrollBarImpl - support for flat scroll bars
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+template <class T>
+class CFlatScrollBarImpl
+{
+public:
+// Initialization
+ BOOL FlatSB_Initialize()
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::InitializeFlatSB(pT->m_hWnd);
+ }
+
+ HRESULT FlatSB_Uninitialize()
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::UninitializeFlatSB(pT->m_hWnd);
+ }
+
+// Flat scroll bar properties
+ BOOL FlatSB_GetScrollProp(UINT uIndex, LPINT lpnValue) const
+ {
+ const T* pT = static_cast<const T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_GetScrollProp(pT->m_hWnd, uIndex, lpnValue);
+ }
+
+ BOOL FlatSB_SetScrollProp(UINT uIndex, int nValue, BOOL bRedraw = TRUE)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_SetScrollProp(pT->m_hWnd, uIndex, nValue, bRedraw);
+ }
+
+// Attributes
+ int FlatSB_GetScrollPos(int nBar) const
+ {
+ const T* pT = static_cast<const T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_GetScrollPos(pT->m_hWnd, nBar);
+ }
+
+ int FlatSB_SetScrollPos(int nBar, int nPos, BOOL bRedraw = TRUE)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_SetScrollPos(pT->m_hWnd, nBar, nPos, bRedraw);
+ }
+
+ BOOL FlatSB_GetScrollRange(int nBar, LPINT lpMinPos, LPINT lpMaxPos) const
+ {
+ const T* pT = static_cast<const T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_GetScrollRange(pT->m_hWnd, nBar, lpMinPos, lpMaxPos);
+ }
+
+ BOOL FlatSB_SetScrollRange(int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_SetScrollRange(pT->m_hWnd, nBar, nMinPos, nMaxPos, bRedraw);
+ }
+
+ BOOL FlatSB_GetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo) const
+ {
+ const T* pT = static_cast<const T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_GetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo);
+ }
+
+ int FlatSB_SetScrollInfo(int nBar, LPSCROLLINFO lpScrollInfo, BOOL bRedraw = TRUE)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_SetScrollInfo(pT->m_hWnd, nBar, lpScrollInfo, bRedraw);
+ }
+
+// Operations
+ BOOL FlatSB_ShowScrollBar(UINT nBar, BOOL bShow = TRUE)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_ShowScrollBar(pT->m_hWnd, nBar, bShow);
+ }
+
+ BOOL FlatSB_EnableScrollBar(UINT uSBFlags, UINT uArrowFlags = ESB_ENABLE_BOTH)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ return ::FlatSB_EnableScrollBar(pT->m_hWnd, uSBFlags, uArrowFlags);
+ }
+};
+
+template <class TBase>
+class CFlatScrollBarT : public TBase, public CFlatScrollBarImpl<CFlatScrollBarT< TBase > >
+{
+public:
+ CFlatScrollBarT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CFlatScrollBarT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+};
+
+typedef CFlatScrollBarT<ATL::CWindow> CFlatScrollBar;
+
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CIPAddressCtrl
+
+#if (_WIN32_IE >= 0x0400)
+
+template <class TBase>
+class CIPAddressCtrlT : public TBase
+{
+public:
+// Constructors
+ CIPAddressCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CIPAddressCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Atteributes
+ static LPCTSTR GetWndClassName()
+ {
+ return WC_IPADDRESS;
+ }
+
+ BOOL IsBlank() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, IPM_ISBLANK, 0, 0L);
+ }
+
+ int GetAddress(LPDWORD lpdwAddress) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, IPM_GETADDRESS, 0, (LPARAM)lpdwAddress);
+ }
+
+ void SetAddress(DWORD dwAddress)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, IPM_SETADDRESS, 0, dwAddress);
+ }
+
+ void ClearAddress()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, IPM_CLEARADDRESS, 0, 0L);
+ }
+
+ void SetRange(int nField, WORD wRange)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, IPM_SETRANGE, nField, wRange);
+ }
+
+ void SetRange(int nField, BYTE nMin, BYTE nMax)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, IPM_SETRANGE, nField, MAKEIPRANGE(nMin, nMax));
+ }
+
+ void SetFocus(int nField)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, IPM_SETFOCUS, nField, 0L);
+ }
+};
+
+typedef CIPAddressCtrlT<ATL::CWindow> CIPAddressCtrl;
+
+#endif // (_WIN32_IE >= 0x0400)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CPagerCtrl
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+template <class TBase>
+class CPagerCtrlT : public TBase
+{
+public:
+// Constructors
+ CPagerCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CPagerCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+ return WC_PAGESCROLLER;
+ }
+
+ int GetButtonSize() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PGM_GETBUTTONSIZE, 0, 0L);
+ }
+
+ int SetButtonSize(int nButtonSize)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PGM_SETBUTTONSIZE, 0, nButtonSize);
+ }
+
+ DWORD GetButtonState(int nButton) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(nButton == PGB_TOPORLEFT || nButton == PGB_BOTTOMORRIGHT);
+ return (DWORD)::SendMessage(m_hWnd, PGM_GETBUTTONSTATE, 0, nButton);
+ }
+
+ COLORREF GetBkColor() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, PGM_GETBKCOLOR, 0, 0L);
+ }
+
+ COLORREF SetBkColor(COLORREF clrBk)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (COLORREF)::SendMessage(m_hWnd, PGM_SETBKCOLOR, 0, (LPARAM)clrBk);
+ }
+
+ int GetBorder() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PGM_GETBORDER, 0, 0L);
+ }
+
+ int SetBorder(int nBorderSize)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PGM_SETBORDER, 0, nBorderSize);
+ }
+
+ int GetPos() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PGM_GETPOS, 0, 0L);
+ }
+
+ int SetPos(int nPos)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PGM_SETPOS, 0, nPos);
+ }
+
+// Operations
+ void SetChild(HWND hWndChild)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PGM_SETCHILD, 0, (LPARAM)hWndChild);
+ }
+
+ void ForwardMouse(BOOL bForward = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PGM_FORWARDMOUSE, bForward, 0L);
+ }
+
+ void RecalcSize()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PGM_RECALCSIZE, 0, 0L);
+ }
+
+ void GetDropTarget(IDropTarget** ppDropTarget)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(ppDropTarget != NULL);
+ ::SendMessage(m_hWnd, PGM_GETDROPTARGET, 0, (LPARAM)ppDropTarget);
+ }
+};
+
+typedef CPagerCtrlT<ATL::CWindow> CPagerCtrl;
+
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CLinkCtrl - Windows SYSLINK control
+
+#if (_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)
+
+template <class TBase>
+class CLinkCtrlT : public TBase
+{
+public:
+// Constructors
+ CLinkCtrlT(HWND hWnd = NULL) : TBase(hWnd)
+ { }
+
+ CLinkCtrlT< TBase >& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+ HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
+ DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ ATL::_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
+ {
+ return TBase::Create(GetWndClassName(), hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, MenuOrID.m_hMenu, lpCreateParam);
+ }
+
+// Attributes
+ static LPCTSTR GetWndClassName()
+ {
+#ifdef _UNICODE
+ return WC_LINK;
+#else // !_UNICODE
+ return "SysLink";
+#endif // !_UNICODE
+ }
+
+ int GetIdealHeight(int cxMaxWidth = 0) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LM_GETIDEALHEIGHT, cxMaxWidth, 0L);
+ }
+
+ BOOL GetItem(PLITEM pLItem) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LM_GETITEM, 0, (LPARAM)pLItem);
+ }
+
+ BOOL SetItem(PLITEM pLItem)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LM_SETITEM, 0, (LPARAM)pLItem);
+ }
+
+ // Vista only
+ int GetIdealSize(SIZE& size, int cxMaxWidth = 0) const
+ {
+#ifndef LM_GETIDEALSIZE
+ const UINT LM_GETIDEALSIZE = LM_GETIDEALHEIGHT;
+#endif
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, LM_GETIDEALSIZE, cxMaxWidth, (LPARAM)&size);
+ }
+
+// Operations
+ BOOL HitTest(PLHITTESTINFO pLHitTestInfo) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, LM_HITTEST, 0, (LPARAM)pLHitTestInfo);
+ }
+};
+
+typedef CLinkCtrlT<ATL::CWindow> CLinkCtrl;
+
+#endif // (_WIN32_WINNT >= 0x0501) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CCustomDraw - MI class for custom-draw support
+
+template <class T>
+class CCustomDraw
+{
+public:
+#if (_ATL_VER < 0x0700)
+ BOOL m_bHandledCD;
+
+ BOOL IsMsgHandled() const
+ {
+ return m_bHandledCD;
+ }
+
+ void SetMsgHandled(BOOL bHandled)
+ {
+ m_bHandledCD = bHandled;
+ }
+#endif // !(_ATL_VER < 0x0700)
+
+// Message map and handlers
+ BEGIN_MSG_MAP(CCustomDraw< T >)
+ NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
+ ALT_MSG_MAP(1)
+ REFLECTED_NOTIFY_CODE_HANDLER(NM_CUSTOMDRAW, OnCustomDraw)
+ END_MSG_MAP()
+
+// message handler
+ LRESULT OnCustomDraw(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
+ {
+ T* pT = static_cast<T*>(this);
+ pT->SetMsgHandled(TRUE);
+ LPNMCUSTOMDRAW lpNMCustomDraw = (LPNMCUSTOMDRAW)pnmh;
+ DWORD dwRet = 0;
+ switch(lpNMCustomDraw->dwDrawStage)
+ {
+ case CDDS_PREPAINT:
+ dwRet = pT->OnPrePaint(idCtrl, lpNMCustomDraw);
+ break;
+ case CDDS_POSTPAINT:
+ dwRet = pT->OnPostPaint(idCtrl, lpNMCustomDraw);
+ break;
+ case CDDS_PREERASE:
+ dwRet = pT->OnPreErase(idCtrl, lpNMCustomDraw);
+ break;
+ case CDDS_POSTERASE:
+ dwRet = pT->OnPostErase(idCtrl, lpNMCustomDraw);
+ break;
+ case CDDS_ITEMPREPAINT:
+ dwRet = pT->OnItemPrePaint(idCtrl, lpNMCustomDraw);
+ break;
+ case CDDS_ITEMPOSTPAINT:
+ dwRet = pT->OnItemPostPaint(idCtrl, lpNMCustomDraw);
+ break;
+ case CDDS_ITEMPREERASE:
+ dwRet = pT->OnItemPreErase(idCtrl, lpNMCustomDraw);
+ break;
+ case CDDS_ITEMPOSTERASE:
+ dwRet = pT->OnItemPostErase(idCtrl, lpNMCustomDraw);
+ break;
+#if (_WIN32_IE >= 0x0400)
+ case (CDDS_ITEMPREPAINT | CDDS_SUBITEM):
+ dwRet = pT->OnSubItemPrePaint(idCtrl, lpNMCustomDraw);
+ break;
+#endif // (_WIN32_IE >= 0x0400)
+ default:
+ pT->SetMsgHandled(FALSE);
+ break;
+ }
+ bHandled = pT->IsMsgHandled();
+ return dwRet;
+ }
+
+// Overrideables
+ DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+
+ DWORD OnPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+
+ DWORD OnPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+
+ DWORD OnPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+
+ DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+
+ DWORD OnItemPostPaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+
+ DWORD OnItemPreErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+
+ DWORD OnItemPostErase(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ DWORD OnSubItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW /*lpNMCustomDraw*/)
+ {
+ return CDRF_DODEFAULT;
+ }
+#endif // (_WIN32_IE >= 0x0400)
+};
+
+
+// --- Windows CE common controls ---
+
+#ifdef _WIN32_WCE
+
+///////////////////////////////////////////////////////////////////////////////
+// CCECommandBarCtrl
+
+template <class TBase>
+class CCECommandBarCtrlT : public TBase
+{
+public:
+// Constructors
+ CCECommandBarCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
+
+ CCECommandBarCtrlT< TBase >& operator=(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Attributes
+ BOOL IsVisible() const
+ {
+ return IsWindowVisible();
+ }
+
+ int GetHeight() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_Height(m_hWnd);
+ }
+
+ HMENU GetMenu(WORD wButton) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_GetMenu(m_hWnd, wButton);
+ }
+
+// Operations
+ HWND Create(HWND hWndParent, int nCmdBarID)
+ {
+ m_hWnd = ::CommandBar_Create(ModuleHelper::GetModuleInstance(), hWndParent, nCmdBarID);
+ ATLASSERT(::IsWindow(m_hWnd));
+ return m_hWnd;
+ }
+
+ void Destroy()
+ {
+ DestroyWindow();
+ }
+
+ BOOL Show(BOOL bShow = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_Show(m_hWnd, bShow);
+ }
+
+ BOOL DrawMenuBar(WORD wButton)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_DrawMenuBar(m_hWnd, wButton);
+ }
+
+ BOOL AddAdornments(DWORD dwFlags = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_AddAdornments(m_hWnd, dwFlags, 0);
+ }
+
+ int AddBitmap(int nBitmapID, int nNumImages)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_AddBitmap(m_hWnd, ModuleHelper::GetResourceInstance(), nBitmapID, nNumImages, 16, 16);
+ }
+
+ BOOL AddButtons(UINT uNumButtons, LPTBBUTTON lpButtons)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CommandBar_AddButtons(m_hWnd, uNumButtons, lpButtons);
+ }
+
+ BOOL AddToolTips(UINT uNumToolTips, LPTSTR lpToolTips)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CommandBar_AddToolTips(m_hWnd, uNumToolTips, lpToolTips);
+ }
+
+ BOOL InsertButton(int nButton, LPTBBUTTON lpButton)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CommandBar_InsertButton(m_hWnd, nButton, lpButton);
+ }
+
+ HWND InsertComboBox(int nWidth, UINT dwStyle, WORD wComboBoxID, WORD wButton)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_InsertComboBox(m_hWnd, ModuleHelper::GetModuleInstance(), nWidth, dwStyle, wComboBoxID, wButton);
+ }
+
+ BOOL InsertMenubar(WORD wMenuID, WORD wButton)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_InsertMenubar(m_hWnd, ModuleHelper::GetResourceInstance(), wMenuID, wButton);
+ }
+
+ BOOL InsertMenubarEx(ATL::_U_STRINGorID menu, WORD wButton)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBar_InsertMenubarEx(m_hWnd, ModuleHelper::GetResourceInstance(), (LPTSTR)menu.m_lpstr, wButton);
+ }
+
+ BOOL IsCommandBarMessage(LPMSG lpMsg)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::IsCommandBarMessage(m_hWnd, lpMsg);
+ }
+};
+
+#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC MenuBar
+ typedef CCECommandBarCtrlT<CToolBarCtrl> CMenuBarCtrl;
+#else
+ typedef CCECommandBarCtrlT<CToolBarCtrl> CCECommandBarCtrl;
+#endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
+
+///////////////////////////////////////////////////////////////////////////////
+// CCECommandBandsCtrl
+
+template <class TBase>
+class CCECommandBandsCtrlT : public TBase
+{
+public:
+// Constructors
+ CCECommandBandsCtrlT(HWND hWnd = NULL) : TBase(hWnd) { }
+
+ CCECommandBandsCtrlT< TBase >& operator=(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Attributes
+ BOOL IsVisible() const
+ {
+ return IsWindowVisible();
+ }
+
+#if (_WIN32_IE >= 0x0400)
+ UINT GetHeight() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CommandBands_Height(m_hWnd);
+ }
+#endif // (_WIN32_IE >= 0x0400)
+
+ HWND GetCommandBar(UINT uBand) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBands_GetCommandBar(m_hWnd, uBand);
+ }
+
+ BOOL GetRestoreInformation(UINT uBand, LPCOMMANDBANDSRESTOREINFO pcbr) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBands_GetRestoreInformation(m_hWnd, uBand, pcbr);
+ }
+
+// Operations
+ HWND Create(HWND hWndParent, UINT wID, DWORD dwStyles, HIMAGELIST hImageList = NULL)
+ {
+ m_hWnd = ::CommandBands_Create(ModuleHelper::GetModuleInstance(), hWndParent, wID, dwStyles, hImageList);
+ ATLASSERT(::IsWindow(m_hWnd));
+ return m_hWnd;
+ }
+
+ BOOL AddAdornments(DWORD dwFlags = 0, LPREBARBANDINFO prbbi = NULL)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBands_AddAdornments(m_hWnd, ModuleHelper::GetModuleInstance(), dwFlags, prbbi);
+ }
+
+ BOOL AddBands(UINT uBandCount, LPREBARBANDINFO prbbi)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBands_AddBands(m_hWnd, ModuleHelper::GetModuleInstance(), uBandCount, prbbi);
+ }
+
+ BOOL Show(BOOL bShow = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::CommandBands_Show(m_hWnd, bShow);
+ }
+};
+
+typedef CCECommandBandsCtrlT<ATL::CWindow> CCECommandBandsCtrl;
+
+#endif // _WIN32_WCE
+
+}; // namespace WTL
+
+#endif // __ATLCTRLS_H__
diff --git a/plugins/XSoundNotify/src/wtl/include/atldlgs.h b/plugins/XSoundNotify/src/wtl/include/atldlgs.h new file mode 100644 index 0000000000..421694e50b --- /dev/null +++ b/plugins/XSoundNotify/src/wtl/include/atldlgs.h @@ -0,0 +1,6386 @@ +// Windows Template Library - WTL version 8.1
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//
+// This file is a part of the Windows Template Library.
+// The use and distribution terms for this software are covered by the
+// Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
+// which can be found in the file CPL.TXT at the root of this distribution.
+// By using this software in any fashion, you are agreeing to be bound by
+// the terms of this license. You must not remove this notice, or
+// any other, from this software.
+
+#ifndef __ATLDLGS_H__
+#define __ATLDLGS_H__
+
+#pragma once
+
+#ifndef __ATLAPP_H__
+ #error atldlgs.h requires atlapp.h to be included first
+#endif
+
+#ifndef __ATLWIN_H__
+ #error atldlgs.h requires atlwin.h to be included first
+#endif
+
+#include <commdlg.h>
+#include <shlobj.h>
+
+#if (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
+ #include <shobjidl.h>
+#endif // (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Classes in this file:
+//
+// CFileDialogImpl<T>
+// CFileDialog
+// CFileDialogEx
+// CMultiFileDialogImpl<T>
+// CMultiFileDialog
+// CShellFileDialogImpl<T>
+// CShellFileOpenDialogImpl<T>
+// CShellFileOpenDialog
+// CShellFileSaveDialogImpl<T>
+// CShellFileSaveDialog
+// CFolderDialogImpl<T>
+// CFolderDialog
+// CFontDialogImpl<T>
+// CFontDialog
+// CRichEditFontDialogImpl<T>
+// CRichEditFontDialog
+// CColorDialogImpl<T>
+// CColorDialog
+// CPrintDialogImpl<T>
+// CPrintDialog
+// CPrintDialogExImpl<T>
+// CPrintDialogEx
+// CPageSetupDialogImpl<T>
+// CPageSetupDialog
+// CFindReplaceDialogImpl<T>
+// CFindReplaceDialog
+//
+// CDialogBaseUnits
+// CMemDlgTemplate
+// CIndirectDialogImpl<T, TDlgTemplate, TBase>
+//
+// CPropertySheetWindow
+// CPropertySheetImpl<T, TBase>
+// CPropertySheet
+// CPropertyPageWindow
+// CPropertyPageImpl<T, TBase>
+// CPropertyPage<t_wDlgTemplateID>
+// CAxPropertyPageImpl<T, TBase>
+// CAxPropertyPage<t_wDlgTemplateID>
+//
+// CWizard97SheetWindow
+// CWizard97SheetImpl<T, TBase>
+// CWizard97Sheet
+// CWizard97PageWindow
+// CWizard97PageImpl<T, TBase>
+// CWizard97ExteriorPageImpl<T, TBase>
+// CWizard97InteriorPageImpl<T, TBase>
+//
+// CAeroWizardFrameWindow
+// CAeroWizardFrameImpl<T, TBase>
+// CAeroWizardFrame
+// CAeroWizardPageWindow
+// CAeroWizardPageImpl<T, TBase>
+// CAeroWizardPage<t_wDlgTemplateID>
+// CAeroWizardAxPageImpl<T, TBase>
+// CAeroWizardAxPage<t_wDlgTemplateID>
+//
+// CTaskDialogConfig
+// CTaskDialogImpl<T>
+// CTaskDialog
+//
+// Global functions:
+// AtlTaskDialog()
+
+
+namespace WTL
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// CFileDialogImpl - used for File Open or File Save As
+
+// compatibility with the old (vc6.0) headers
+#if (_WIN32_WINNT >= 0x0500) && !defined(OPENFILENAME_SIZE_VERSION_400)
+ #ifndef CDSIZEOF_STRUCT
+ #define CDSIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
+ #endif
+ #define OPENFILENAME_SIZE_VERSION_400A CDSIZEOF_STRUCT(OPENFILENAMEA,lpTemplateName)
+ #define OPENFILENAME_SIZE_VERSION_400W CDSIZEOF_STRUCT(OPENFILENAMEW,lpTemplateName)
+ #ifdef UNICODE
+ #define OPENFILENAME_SIZE_VERSION_400 OPENFILENAME_SIZE_VERSION_400W
+ #else
+ #define OPENFILENAME_SIZE_VERSION_400 OPENFILENAME_SIZE_VERSION_400A
+ #endif // !UNICODE
+#endif // (_WIN32_WINNT >= 0x0500) && !defined(OPENFILENAME_SIZE_VERSION_400)
+
+#if !defined(_WIN32_WCE) && !defined(CDN_INCLUDEITEM)
+ #define CDN_INCLUDEITEM (CDN_FIRST - 0x0007)
+#endif
+
+template <class T>
+class ATL_NO_VTABLE CFileDialogImpl : public ATL::CDialogImplBase
+{
+public:
+#if defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
+ OPENFILENAMEEX m_ofn;
+#else
+ OPENFILENAME m_ofn;
+#endif
+ BOOL m_bOpenFileDialog; // TRUE for file open, FALSE for file save
+ TCHAR m_szFileTitle[_MAX_FNAME]; // contains file title after return
+ TCHAR m_szFileName[_MAX_PATH]; // contains full path name after return
+
+ CFileDialogImpl(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
+ LPCTSTR lpszDefExt = NULL,
+ LPCTSTR lpszFileName = NULL,
+ DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ LPCTSTR lpszFilter = NULL,
+ HWND hWndParent = NULL)
+ {
+ memset(&m_ofn, 0, sizeof(m_ofn)); // initialize structure to 0/NULL
+ m_szFileName[0] = _T('\0');
+ m_szFileTitle[0] = _T('\0');
+
+ m_bOpenFileDialog = bOpenFileDialog;
+
+#if defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
+ m_ofn.lStructSize = bOpenFileDialog ? sizeof(m_ofn) : sizeof(OPENFILENAME);
+#else
+ m_ofn.lStructSize = sizeof(m_ofn);
+#endif
+
+#if (_WIN32_WINNT >= 0x0500)
+ // adjust struct size if running on older version of Windows
+ if(AtlIsOldWindows())
+ {
+ ATLASSERT(sizeof(m_ofn) > OPENFILENAME_SIZE_VERSION_400); // must be
+ m_ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
+ }
+#endif // (_WIN32_WINNT >= 0x0500)
+ m_ofn.lpstrFile = m_szFileName;
+ m_ofn.nMaxFile = _MAX_PATH;
+ m_ofn.lpstrDefExt = lpszDefExt;
+ m_ofn.lpstrFileTitle = (LPTSTR)m_szFileTitle;
+ m_ofn.nMaxFileTitle = _MAX_FNAME;
+#ifndef _WIN32_WCE
+ m_ofn.Flags = dwFlags | OFN_EXPLORER | OFN_ENABLEHOOK | OFN_ENABLESIZING;
+#else // CE specific
+ m_ofn.Flags = dwFlags | OFN_EXPLORER | OFN_ENABLEHOOK;
+#endif // !_WIN32_WCE
+ m_ofn.lpstrFilter = lpszFilter;
+ m_ofn.hInstance = ModuleHelper::GetResourceInstance();
+ m_ofn.lpfnHook = (LPOFNHOOKPROC)T::StartDialogProc;
+ m_ofn.hwndOwner = hWndParent;
+
+ // setup initial file name
+ if(lpszFileName != NULL)
+ SecureHelper::strncpy_x(m_szFileName, _countof(m_szFileName), lpszFileName, _TRUNCATE);
+ }
+
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ ATLASSERT((m_ofn.Flags & OFN_ENABLEHOOK) != 0);
+ ATLASSERT(m_ofn.lpfnHook != NULL); // can still be a user hook
+
+ ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
+
+ if(m_ofn.hwndOwner == NULL) // set only if not specified before
+ m_ofn.hwndOwner = hWndParent;
+
+ ATLASSERT(m_hWnd == NULL);
+ ModuleHelper::AddCreateWndData(&m_thunk.cd, (ATL::CDialogImplBase*)this);
+
+ BOOL bRet;
+ if(m_bOpenFileDialog)
+#if defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
+ bRet = ::GetOpenFileNameEx(&m_ofn);
+ else
+ bRet = ::GetSaveFileName((LPOPENFILENAME)&m_ofn);
+#else
+ bRet = ::GetOpenFileName(&m_ofn);
+ else
+ bRet = ::GetSaveFileName(&m_ofn);
+#endif
+
+ m_hWnd = NULL;
+
+ return bRet ? IDOK : IDCANCEL;
+ }
+
+// Attributes
+ ATL::CWindow GetFileDialogWindow() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ATL::CWindow(GetParent());
+ }
+
+ int GetFilePath(LPTSTR lpstrFilePath, int nLength) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
+
+ return (int)GetFileDialogWindow().SendMessage(CDM_GETFILEPATH, nLength, (LPARAM)lpstrFilePath);
+ }
+
+ int GetFolderIDList(LPVOID lpBuff, int nLength) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
+
+ return (int)GetFileDialogWindow().SendMessage(CDM_GETFOLDERIDLIST, nLength, (LPARAM)lpBuff);
+ }
+
+ int GetFolderPath(LPTSTR lpstrFolderPath, int nLength) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
+
+ return (int)GetFileDialogWindow().SendMessage(CDM_GETFOLDERPATH, nLength, (LPARAM)lpstrFolderPath);
+ }
+
+ int GetSpec(LPTSTR lpstrSpec, int nLength) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
+
+ return (int)GetFileDialogWindow().SendMessage(CDM_GETSPEC, nLength, (LPARAM)lpstrSpec);
+ }
+
+ void SetControlText(int nCtrlID, LPCTSTR lpstrText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
+
+ GetFileDialogWindow().SendMessage(CDM_SETCONTROLTEXT, nCtrlID, (LPARAM)lpstrText);
+ }
+
+ void SetDefExt(LPCTSTR lpstrExt)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
+
+ GetFileDialogWindow().SendMessage(CDM_SETDEFEXT, 0, (LPARAM)lpstrExt);
+ }
+
+ BOOL GetReadOnlyPref() const // return TRUE if readonly checked
+ {
+ return ((m_ofn.Flags & OFN_READONLY) != 0) ? TRUE : FALSE;
+ }
+
+// Operations
+ void HideControl(int nCtrlID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((m_ofn.Flags & OFN_EXPLORER) != 0);
+
+ GetFileDialogWindow().SendMessage(CDM_HIDECONTROL, nCtrlID);
+ }
+
+// Special override for common dialogs
+ BOOL EndDialog(INT_PTR /*nRetCode*/ = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ GetFileDialogWindow().SendMessage(WM_COMMAND, MAKEWPARAM(IDCANCEL, 0));
+ return TRUE;
+ }
+
+// Message map and handlers
+ BEGIN_MSG_MAP(CFileDialogImpl)
+ NOTIFY_CODE_HANDLER(CDN_FILEOK, _OnFileOK)
+ NOTIFY_CODE_HANDLER(CDN_FOLDERCHANGE, _OnFolderChange)
+ NOTIFY_CODE_HANDLER(CDN_HELP, _OnHelp)
+ NOTIFY_CODE_HANDLER(CDN_INITDONE, _OnInitDone)
+ NOTIFY_CODE_HANDLER(CDN_SELCHANGE, _OnSelChange)
+ NOTIFY_CODE_HANDLER(CDN_SHAREVIOLATION, _OnShareViolation)
+ NOTIFY_CODE_HANDLER(CDN_TYPECHANGE, _OnTypeChange)
+#ifndef _WIN32_WCE
+ NOTIFY_CODE_HANDLER(CDN_INCLUDEITEM, _OnIncludeItem)
+#endif // !_WIN32_WCE
+ END_MSG_MAP()
+
+ LRESULT _OnFileOK(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ T* pT = static_cast<T*>(this);
+ return !pT->OnFileOK((LPOFNOTIFY)pnmh);
+ }
+
+ LRESULT _OnFolderChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ T* pT = static_cast<T*>(this);
+ pT->OnFolderChange((LPOFNOTIFY)pnmh);
+ return 0;
+ }
+
+ LRESULT _OnHelp(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ T* pT = static_cast<T*>(this);
+ pT->OnHelp((LPOFNOTIFY)pnmh);
+ return 0;
+ }
+
+ LRESULT _OnInitDone(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ T* pT = static_cast<T*>(this);
+ pT->OnInitDone((LPOFNOTIFY)pnmh);
+ return 0;
+ }
+
+ LRESULT _OnSelChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ T* pT = static_cast<T*>(this);
+ pT->OnSelChange((LPOFNOTIFY)pnmh);
+ return 0;
+ }
+
+ LRESULT _OnShareViolation(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ T* pT = static_cast<T*>(this);
+ return pT->OnShareViolation((LPOFNOTIFY)pnmh);
+ }
+
+ LRESULT _OnTypeChange(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ T* pT = static_cast<T*>(this);
+ pT->OnTypeChange((LPOFNOTIFY)pnmh);
+ return 0;
+ }
+
+#ifndef _WIN32_WCE
+ LRESULT _OnIncludeItem(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ T* pT = static_cast<T*>(this);
+ return pT->OnIncludeItem((LPOFNOTIFYEX)pnmh);
+ }
+#endif // !_WIN32_WCE
+
+// Overrideables
+ BOOL OnFileOK(LPOFNOTIFY /*lpon*/)
+ {
+ return TRUE;
+ }
+
+ void OnFolderChange(LPOFNOTIFY /*lpon*/)
+ {
+ }
+
+ void OnHelp(LPOFNOTIFY /*lpon*/)
+ {
+ }
+
+ void OnInitDone(LPOFNOTIFY /*lpon*/)
+ {
+ }
+
+ void OnSelChange(LPOFNOTIFY /*lpon*/)
+ {
+ }
+
+ int OnShareViolation(LPOFNOTIFY /*lpon*/)
+ {
+ return 0;
+ }
+
+ void OnTypeChange(LPOFNOTIFY /*lpon*/)
+ {
+ }
+
+#ifndef _WIN32_WCE
+ BOOL OnIncludeItem(LPOFNOTIFYEX /*lponex*/)
+ {
+ return TRUE; // include item
+ }
+#endif // !_WIN32_WCE
+};
+
+class CFileDialog : public CFileDialogImpl<CFileDialog>
+{
+public:
+ CFileDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
+ LPCTSTR lpszDefExt = NULL,
+ LPCTSTR lpszFileName = NULL,
+ DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ LPCTSTR lpszFilter = NULL,
+ HWND hWndParent = NULL)
+ : CFileDialogImpl<CFileDialog>(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent)
+ { }
+
+ // override base class map and references to handlers
+ DECLARE_EMPTY_MSG_MAP()
+};
+
+#if defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
+class CFileDialogEx : public CFileDialogImpl<CFileDialogEx>
+{
+public:
+ CFileDialogEx( // Supports only FileOpen
+ LPCTSTR lpszDefExt = NULL,
+ LPCTSTR lpszFileName = NULL,
+ DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ OFN_EXFLAG ExFlags = OFN_EXFLAG_THUMBNAILVIEW,
+ OFN_SORTORDER dwSortOrder = OFN_SORTORDER_AUTO,
+ LPCTSTR lpszFilter = NULL,
+ HWND hWndParent = NULL)
+ : CFileDialogImpl<CFileDialogEx>(TRUE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent)
+ {
+ m_ofn.ExFlags = ExFlags;
+ m_ofn.dwSortOrder = dwSortOrder;
+ }
+
+ // override base class map and references to handlers
+ DECLARE_EMPTY_MSG_MAP()
+};
+#endif // defined(__AYGSHELL_H__) && (_WIN32_WCE >= 0x0501)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Multi File Dialog - Multi-select File Open dialog
+
+#ifndef _WIN32_WCE
+
+// The class dynamically resizes the buffer as the file selection changes
+// (as described in Knowledge Base article 131462). It also expands selected
+// shortcut files to take into account the full path of the target file.
+// Note that this doesn't work on Win9x for the old style dialogs, as well as
+// on NT for non-Unicode builds.
+
+#ifndef _WTL_FIXED_OFN_BUFFER_LENGTH
+ #define _WTL_FIXED_OFN_BUFFER_LENGTH 0x10000
+#endif
+
+template <class T>
+class ATL_NO_VTABLE CMultiFileDialogImpl : public CFileDialogImpl< T >
+{
+public:
+ mutable LPCTSTR m_pNextFile;
+#ifndef _UNICODE
+ bool m_bIsNT;
+#endif
+
+ CMultiFileDialogImpl(
+ LPCTSTR lpszDefExt = NULL,
+ LPCTSTR lpszFileName = NULL,
+ DWORD dwFlags = OFN_HIDEREADONLY,
+ LPCTSTR lpszFilter = NULL,
+ HWND hWndParent = NULL)
+ : CFileDialogImpl<T>(TRUE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent),
+ m_pNextFile(NULL)
+ {
+ m_ofn.Flags |= OFN_ALLOWMULTISELECT; // Force multiple selection mode
+
+#ifndef _UNICODE
+ OSVERSIONINFO ovi = { sizeof(ovi) };
+ ::GetVersionEx(&ovi);
+ m_bIsNT = (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT);
+ if (m_bIsNT)
+ {
+ // On NT platforms, GetOpenFileNameA thunks to GetOpenFileNameW and there
+ // is absolutely nothing we can do except to start off with a large buffer.
+ ATLVERIFY(ResizeFilenameBuffer(_WTL_FIXED_OFN_BUFFER_LENGTH));
+ }
+#endif
+ }
+
+ ~CMultiFileDialogImpl()
+ {
+ if (m_ofn.lpstrFile != m_szFileName) // Free the buffer if we allocated it
+ delete[] m_ofn.lpstrFile;
+ }
+
+// Operations
+ // Get the directory that the files were chosen from.
+ // The function returns the number of characters copied, not including the terminating zero.
+ // If the buffer is NULL, the function returns the required size, in characters, including the terminating zero.
+ // If the function fails, the return value is zero.
+ int GetDirectory(LPTSTR pBuffer, int nBufLen) const
+ {
+ if (m_ofn.lpstrFile == NULL)
+ return 0;
+
+ LPCTSTR pStr = m_ofn.lpstrFile;
+ int nLength = lstrlen(pStr);
+ if (pStr[nLength + 1] == 0)
+ {
+ // The OFN buffer contains a single item so extract its path.
+ LPCTSTR pSep = MinCrtHelper::_strrchr(pStr, _T('\\'));
+ if (pSep != NULL)
+ nLength = (int)(DWORD_PTR)(pSep - pStr);
+ }
+
+ int nRet = 0;
+ if (pBuffer == NULL) // If the buffer is NULL, return the required length
+ {
+ nRet = nLength + 1;
+ }
+ else if (nBufLen > nLength)
+ {
+ SecureHelper::strncpy_x(pBuffer, nBufLen, pStr, nLength);
+ nRet = nLength;
+ }
+
+ return nRet;
+ }
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ bool GetDirectory(_CSTRING_NS::CString& strDir) const
+ {
+ bool bRet = false;
+
+ int nLength = GetDirectory(NULL, 0);
+ if (nLength > 0)
+ {
+ bRet = (GetDirectory(strDir.GetBuffer(nLength), nLength) > 0);
+ strDir.ReleaseBuffer(nLength - 1);
+ }
+
+ return bRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ // Get the first filename as a pointer into the buffer.
+ LPCTSTR GetFirstFileName() const
+ {
+ if (m_ofn.lpstrFile == NULL)
+ return NULL;
+
+ m_pNextFile = NULL; // Reset internal buffer pointer
+
+ LPCTSTR pStr = m_ofn.lpstrFile;
+ int nLength = lstrlen(pStr);
+ if (pStr[nLength + 1] != 0)
+ {
+ // Multiple items were selected. The first string is the directory,
+ // so skip forwards to the second string.
+ pStr += nLength + 1;
+
+ // Set up m_pNext so it points to the second item (or null).
+ m_pNextFile = pStr;
+ GetNextFileName();
+ }
+ else
+ {
+ // A single item was selected. Skip forward past the path.
+ LPCTSTR pSep = MinCrtHelper::_strrchr(pStr, _T('\\'));
+ if (pSep != NULL)
+ pStr = pSep + 1;
+ }
+
+ return pStr;
+ }
+
+ // Get the next filename as a pointer into the buffer.
+ LPCTSTR GetNextFileName() const
+ {
+ if (m_pNextFile == NULL)
+ return NULL;
+
+ LPCTSTR pStr = m_pNextFile;
+ // Set "m_pNextFile" to point to the next file name, or null if we
+ // have reached the last file in the list.
+ int nLength = lstrlen(pStr);
+ m_pNextFile = (pStr[nLength + 1] != 0) ? &pStr[nLength + 1] : NULL;
+
+ return pStr;
+ }
+
+ // Get the first filename as a full path.
+ // The function returns the number of characters copied, not including the terminating zero.
+ // If the buffer is NULL, the function returns the required size, in characters, including the terminating zero.
+ // If the function fails, the return value is zero.
+ int GetFirstPathName(LPTSTR pBuffer, int nBufLen) const
+ {
+ LPCTSTR pStr = GetFirstFileName();
+ int nLengthDir = GetDirectory(NULL, 0);
+ if((pStr == NULL) || (nLengthDir == 0))
+ return 0;
+
+ // Figure out the required length.
+ int nLengthTotal = nLengthDir + lstrlen(pStr);
+
+ int nRet = 0;
+ if(pBuffer == NULL) // If the buffer is NULL, return the required length
+ {
+ nRet = nLengthTotal + 1;
+ }
+ else if (nBufLen > nLengthTotal) // If the buffer is big enough, go ahead and construct the path
+ {
+ GetDirectory(pBuffer, nBufLen);
+ SecureHelper::strcat_x(pBuffer, nBufLen, _T("\\"));
+ SecureHelper::strcat_x(pBuffer, nBufLen, pStr);
+ nRet = nLengthTotal;
+ }
+
+ return nRet;
+ }
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ bool GetFirstPathName(_CSTRING_NS::CString& strPath) const
+ {
+ bool bRet = false;
+
+ int nLength = GetFirstPathName(NULL, 0);
+ if (nLength > 0)
+ {
+ bRet = (GetFirstPathName(strPath.GetBuffer(nLength), nLength) > 0);
+ strPath.ReleaseBuffer(nLength - 1);
+ }
+
+ return bRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ // Get the next filename as a full path.
+ // The function returns the number of characters copied, not including the terminating zero.
+ // If the buffer is NULL, the function returns the required size, in characters, including the terminating zero.
+ // If the function fails, the return value is zero.
+ // The internal position marker is moved forward only if the function succeeds and the buffer was large enough.
+ int GetNextPathName(LPTSTR pBuffer, int nBufLen) const
+ {
+ if (m_pNextFile == NULL)
+ return 0;
+
+ int nRet = 0;
+ LPCTSTR pStr = m_pNextFile;
+ // Does the filename contain a backslash?
+ if (MinCrtHelper::_strrchr(pStr, _T('\\')) != NULL)
+ {
+ // Yes, so we'll assume it's a full path.
+ int nLength = lstrlen(pStr);
+
+ if (pBuffer == NULL) // If the buffer is NULL, return the required length
+ {
+ nRet = nLength + 1;
+ }
+ else if (nBufLen > nLength) // The buffer is big enough, so go ahead and copy the filename
+ {
+ SecureHelper::strcpy_x(pBuffer, nBufLen, GetNextFileName());
+ nRet = nBufLen;
+ }
+ }
+ else
+ {
+ // The filename is relative, so construct the full path.
+ int nLengthDir = GetDirectory(NULL, 0);
+ if (nLengthDir > 0)
+ {
+ // Calculate the required space.
+ int nLengthTotal = nLengthDir + lstrlen(pStr);
+
+ if(pBuffer == NULL) // If the buffer is NULL, return the required length
+ {
+ nRet = nLengthTotal + 1;
+ }
+ else if (nBufLen > nLengthTotal) // If the buffer is big enough, go ahead and construct the path
+ {
+ GetDirectory(pBuffer, nBufLen);
+ SecureHelper::strcat_x(pBuffer, nBufLen, _T("\\"));
+ SecureHelper::strcat_x(pBuffer, nBufLen, GetNextFileName());
+ nRet = nLengthTotal;
+ }
+ }
+ }
+
+ return nRet;
+ }
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ bool GetNextPathName(_CSTRING_NS::CString& strPath) const
+ {
+ bool bRet = false;
+
+ int nLength = GetNextPathName(NULL, 0);
+ if (nLength > 0)
+ {
+ bRet = (GetNextPathName(strPath.GetBuffer(nLength), nLength) > 0);
+ strPath.ReleaseBuffer(nLength - 1);
+ }
+
+ return bRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+// Implementation
+ bool ResizeFilenameBuffer(DWORD dwLength)
+ {
+ if (dwLength > m_ofn.nMaxFile)
+ {
+ // Free the old buffer.
+ if (m_ofn.lpstrFile != m_szFileName)
+ {
+ delete[] m_ofn.lpstrFile;
+ m_ofn.lpstrFile = NULL;
+ m_ofn.nMaxFile = 0;
+ }
+
+ // Allocate the new buffer.
+ LPTSTR lpstrBuff = NULL;
+ ATLTRY(lpstrBuff = new TCHAR[dwLength]);
+ if (lpstrBuff != NULL)
+ {
+ m_ofn.lpstrFile = lpstrBuff;
+ m_ofn.lpstrFile[0] = 0;
+ m_ofn.nMaxFile = dwLength;
+ }
+ }
+
+ return (m_ofn.lpstrFile != NULL);
+ }
+
+ void OnSelChange(LPOFNOTIFY /*lpon*/)
+ {
+#ifndef _UNICODE
+ // There is no point resizing the buffer in ANSI builds running on NT.
+ if (m_bIsNT)
+ return;
+#endif
+
+ // Get the buffer length required to hold the spec.
+ int nLength = GetSpec(NULL, 0);
+ if (nLength <= 1)
+ return; // no files are selected, presumably
+
+ // Add room for the directory, and an extra terminating zero.
+ nLength += GetFolderPath(NULL, 0) + 1;
+
+ if (!ResizeFilenameBuffer(nLength))
+ {
+ ATLASSERT(FALSE);
+ return;
+ }
+
+ // If we are not following links then our work is done.
+ if ((m_ofn.Flags & OFN_NODEREFERENCELINKS) != 0)
+ return;
+
+ // Get the file spec, which is the text in the edit control.
+ if (GetSpec(m_ofn.lpstrFile, m_ofn.nMaxFile) <= 0)
+ return;
+
+ // Get the ID-list of the current folder.
+ int nBytes = GetFolderIDList(NULL, 0);
+ CTempBuffer<ITEMIDLIST> idlist;
+ idlist.AllocateBytes(nBytes);
+ if ((nBytes <= 0) || (GetFolderIDList(idlist, nBytes) <= 0))
+ return;
+
+ // First bind to the desktop folder, then to the current folder.
+ ATL::CComPtr<IShellFolder> pDesktop, pFolder;
+ if (FAILED(::SHGetDesktopFolder(&pDesktop)))
+ return;
+ if (FAILED(pDesktop->BindToObject(idlist, NULL, IID_IShellFolder, (void**)&pFolder)))
+ return;
+
+ // Work through the file spec, looking for quoted filenames. If we find a shortcut file, then
+ // we need to add enough extra buffer space to hold its target path.
+ DWORD nExtraChars = 0;
+ bool bInsideQuotes = false;
+ LPCTSTR pAnchor = m_ofn.lpstrFile;
+ LPCTSTR pChar = m_ofn.lpstrFile;
+ for ( ; *pChar; ++pChar)
+ {
+ // Look for quotation marks.
+ if (*pChar == _T('\"'))
+ {
+ // We are either entering or leaving a passage of quoted text.
+ bInsideQuotes = !bInsideQuotes;
+
+ // Is it an opening or closing quote?
+ if (bInsideQuotes)
+ {
+ // We found an opening quote, so set "pAnchor" to the following character.
+ pAnchor = pChar + 1;
+ }
+ else // closing quote
+ {
+ // Each quoted entity should be shorter than MAX_PATH.
+ if (pChar - pAnchor >= MAX_PATH)
+ return;
+
+ // Get the ID-list and attributes of the file.
+ USES_CONVERSION;
+ int nFileNameLength = (int)(DWORD_PTR)(pChar - pAnchor);
+ TCHAR szFileName[MAX_PATH];
+ SecureHelper::strncpy_x(szFileName, MAX_PATH, pAnchor, nFileNameLength);
+ LPITEMIDLIST pidl = NULL;
+ DWORD dwAttrib = SFGAO_LINK;
+ if (SUCCEEDED(pFolder->ParseDisplayName(NULL, NULL, T2W(szFileName), NULL, &pidl, &dwAttrib)))
+ {
+ // Is it a shortcut file?
+ if (dwAttrib & SFGAO_LINK)
+ {
+ // Bind to its IShellLink interface.
+ ATL::CComPtr<IShellLink> pLink;
+ if (SUCCEEDED(pFolder->BindToObject(pidl, NULL, IID_IShellLink, (void**)&pLink)))
+ {
+ // Get the shortcut's target path.
+ TCHAR szPath[MAX_PATH];
+ if (SUCCEEDED(pLink->GetPath(szPath, MAX_PATH, NULL, 0)))
+ {
+ // If the target path is longer than the shortcut name, then add on the number
+ // of extra characters that are required.
+ int nNewLength = lstrlen(szPath);
+ if (nNewLength > nFileNameLength)
+ nExtraChars += nNewLength - nFileNameLength;
+ }
+ }
+ }
+
+ // Free the ID-list returned by ParseDisplayName.
+ ::CoTaskMemFree(pidl);
+ }
+ }
+ }
+ }
+
+ // If we need more space for shortcut targets, then reallocate.
+ if (nExtraChars > 0)
+ ATLVERIFY(ResizeFilenameBuffer(m_ofn.nMaxFile + nExtraChars));
+ }
+};
+
+class CMultiFileDialog : public CMultiFileDialogImpl<CMultiFileDialog>
+{
+public:
+ CMultiFileDialog(
+ LPCTSTR lpszDefExt = NULL,
+ LPCTSTR lpszFileName = NULL,
+ DWORD dwFlags = OFN_HIDEREADONLY,
+ LPCTSTR lpszFilter = NULL,
+ HWND hWndParent = NULL)
+ : CMultiFileDialogImpl<CMultiFileDialog>(lpszDefExt, lpszFileName, dwFlags, lpszFilter, hWndParent)
+ { }
+
+ BEGIN_MSG_MAP(CMultiFileDialog)
+ CHAIN_MSG_MAP(CMultiFileDialogImpl<CMultiFileDialog>)
+ END_MSG_MAP()
+};
+
+#endif // !_WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Shell File Dialog - new Shell File Open and Save dialogs in Vista
+
+// Note: Use GetPtr() to access dialog interface methods.
+// Example:
+// CShellFileOpenDialog dlg;
+// dlg.GetPtr()->SetTitle(L"MyFileOpenDialog");
+
+#if (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
+
+///////////////////////////////////////////////////////////////////////////////
+// CShellFileDialogImpl - base class for CShellFileOpenDialogImpl and CShellFileSaveDialogImpl
+
+template <class T>
+class ATL_NO_VTABLE CShellFileDialogImpl : public IFileDialogEvents
+{
+public:
+// Operations
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ INT_PTR nRet = -1;
+
+ T* pT = static_cast<T*>(this);
+ if(pT->m_spFileDlg == NULL)
+ {
+ ATLASSERT(FALSE);
+ return nRet;
+ }
+
+ DWORD dwCookie = 0;
+ pT->_Advise(dwCookie);
+
+ HRESULT hRet = pT->m_spFileDlg->Show(hWndParent);
+ if(SUCCEEDED(hRet))
+ nRet = IDOK;
+ else if(hRet == HRESULT_FROM_WIN32(ERROR_CANCELLED))
+ nRet = IDCANCEL;
+ else
+ ATLASSERT(FALSE); // error
+
+ pT->_Unadvise(dwCookie);
+
+ return nRet;
+ }
+
+ bool IsNull() const
+ {
+ const T* pT = static_cast<const T*>(this);
+ return (pT->m_spFileDlg == NULL);
+ }
+
+// Operations - get file path after dialog returns
+ HRESULT GetFilePath(LPWSTR lpstrFilePath, int cchLength)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg != NULL);
+
+ ATL::CComPtr<IShellItem> spItem;
+ HRESULT hRet = pT->m_spFileDlg->GetResult(&spItem);
+
+ if(SUCCEEDED(hRet))
+ hRet = GetFileNameFromShellItem(spItem, SIGDN_FILESYSPATH, lpstrFilePath, cchLength);
+
+ return hRet;
+ }
+
+ HRESULT GetFileTitle(LPWSTR lpstrFileTitle, int cchLength)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg != NULL);
+
+ ATL::CComPtr<IShellItem> spItem;
+ HRESULT hRet = pT->m_spFileDlg->GetResult(&spItem);
+
+ if(SUCCEEDED(hRet))
+ hRet = GetFileNameFromShellItem(spItem, SIGDN_NORMALDISPLAY, lpstrFileTitle, cchLength);
+
+ return hRet;
+ }
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ HRESULT GetFilePath(_CSTRING_NS::CString& strFilePath)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg != NULL);
+
+ ATL::CComPtr<IShellItem> spItem;
+ HRESULT hRet = pT->m_spFileDlg->GetResult(&spItem);
+
+ if(SUCCEEDED(hRet))
+ hRet = GetFileNameFromShellItem(spItem, SIGDN_FILESYSPATH, strFilePath);
+
+ return hRet;
+ }
+
+ HRESULT GetFileTitle(_CSTRING_NS::CString& strFileTitle)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg != NULL);
+
+ ATL::CComPtr<IShellItem> spItem;
+ HRESULT hRet = pT->m_spFileDlg->GetResult(&spItem);
+
+ if(SUCCEEDED(hRet))
+ hRet = GetFileNameFromShellItem(spItem, SIGDN_NORMALDISPLAY, strFileTitle);
+
+ return hRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+// Helpers for IShellItem
+ static HRESULT GetFileNameFromShellItem(IShellItem* pShellItem, SIGDN type, LPWSTR lpstr, int cchLength)
+ {
+ ATLASSERT(pShellItem != NULL);
+
+ LPWSTR lpstrName = NULL;
+ HRESULT hRet = pShellItem->GetDisplayName(type, &lpstrName);
+
+ if(SUCCEEDED(hRet))
+ {
+ if(lstrlenW(lpstrName) < cchLength)
+ {
+ SecureHelper::strcpyW_x(lpstr, cchLength, lpstrName);
+ }
+ else
+ {
+ ATLASSERT(FALSE);
+ hRet = DISP_E_BUFFERTOOSMALL;
+ }
+
+ ::CoTaskMemFree(lpstrName);
+ }
+
+ return hRet;
+ }
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ static HRESULT GetFileNameFromShellItem(IShellItem* pShellItem, SIGDN type, _CSTRING_NS::CString& str)
+ {
+ ATLASSERT(pShellItem != NULL);
+
+ LPWSTR lpstrName = NULL;
+ HRESULT hRet = pShellItem->GetDisplayName(type, &lpstrName);
+
+ if(SUCCEEDED(hRet))
+ {
+ str = lpstrName;
+ ::CoTaskMemFree(lpstrName);
+ }
+
+ return hRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+// Implementation
+ void _Advise(DWORD& dwCookie)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg != NULL);
+ HRESULT hRet = pT->m_spFileDlg->Advise((IFileDialogEvents*)this, &dwCookie);
+ ATLVERIFY(SUCCEEDED(hRet));
+ }
+
+ void _Unadvise(DWORD dwCookie)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg != NULL);
+ HRESULT hRet = pT->m_spFileDlg->Unadvise(dwCookie);
+ ATLVERIFY(SUCCEEDED(hRet));
+ }
+
+ void _Init(LPCWSTR lpszFileName, DWORD dwOptions, LPCWSTR lpszDefExt, const COMDLG_FILTERSPEC* arrFilterSpec, UINT uFilterSpecCount)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg != NULL);
+
+ HRESULT hRet = E_FAIL;
+
+ if(lpszFileName != NULL)
+ {
+ hRet = pT->m_spFileDlg->SetFileName(lpszFileName);
+ ATLASSERT(SUCCEEDED(hRet));
+ }
+
+ hRet = pT->m_spFileDlg->SetOptions(dwOptions);
+ ATLASSERT(SUCCEEDED(hRet));
+
+ if(lpszDefExt != NULL)
+ {
+ hRet = pT->m_spFileDlg->SetDefaultExtension(lpszDefExt);
+ ATLASSERT(SUCCEEDED(hRet));
+ }
+
+ if(arrFilterSpec != NULL && uFilterSpecCount != 0U)
+ {
+ hRet = pT->m_spFileDlg->SetFileTypes(uFilterSpecCount, arrFilterSpec);
+ ATLASSERT(SUCCEEDED(hRet));
+ }
+ }
+
+// Implementation - IUnknown interface
+ STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject)
+ {
+ if(ppvObject == NULL)
+ return E_POINTER;
+
+ T* pT = static_cast<T*>(this);
+ if(IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IFileDialogEvents))
+ {
+ *ppvObject = (IFileDialogEvents*)pT;
+ // AddRef() not needed
+ return S_OK;
+ }
+
+ return E_NOINTERFACE;
+ }
+
+ virtual ULONG STDMETHODCALLTYPE AddRef()
+ {
+ return 1;
+ }
+
+ virtual ULONG STDMETHODCALLTYPE Release()
+ {
+ return 1;
+ }
+
+// Implementation - IFileDialogEvents interface
+ virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnFileOk(IFileDialog* pfd)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
+ pfd; // avoid level 4 warning
+ return pT->OnFileOk();
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnFolderChanging(IFileDialog* pfd, IShellItem* psiFolder)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
+ pfd; // avoid level 4 warning
+ return pT->OnFolderChanging(psiFolder);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnFolderChange(IFileDialog* pfd)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
+ pfd; // avoid level 4 warning
+ return pT->OnFolderChange();
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnSelectionChange(IFileDialog* pfd)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
+ pfd; // avoid level 4 warning
+ return pT->OnSelectionChange();
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnShareViolation(IFileDialog* pfd, IShellItem* psi, FDE_SHAREVIOLATION_RESPONSE* pResponse)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
+ pfd; // avoid level 4 warning
+ return pT->OnShareViolation(psi, pResponse);
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnTypeChange(IFileDialog* pfd)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
+ pfd; // avoid level 4 warning
+ return pT->OnTypeChange();
+ }
+
+ virtual HRESULT STDMETHODCALLTYPE IFileDialogEvents::OnOverwrite(IFileDialog* pfd, IShellItem* psi, FDE_OVERWRITE_RESPONSE* pResponse)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_spFileDlg.IsEqualObject(pfd));
+ pfd; // avoid level 4 warning
+ return pT->OnOverwrite(psi, pResponse);
+ }
+
+// Overrideables - Event handlers
+ HRESULT OnFileOk()
+ {
+ return E_NOTIMPL;
+ }
+
+ HRESULT OnFolderChanging(IShellItem* /*psiFolder*/)
+ {
+ return E_NOTIMPL;
+ }
+
+ HRESULT OnFolderChange()
+ {
+ return E_NOTIMPL;
+ }
+
+ HRESULT OnSelectionChange()
+ {
+ return E_NOTIMPL;
+ }
+
+ HRESULT OnShareViolation(IShellItem* /*psi*/, FDE_SHAREVIOLATION_RESPONSE* /*pResponse*/)
+ {
+ return E_NOTIMPL;
+ }
+
+ HRESULT OnTypeChange()
+ {
+ return E_NOTIMPL;
+ }
+
+ HRESULT OnOverwrite(IShellItem* /*psi*/, FDE_OVERWRITE_RESPONSE* /*pResponse*/)
+ {
+ return E_NOTIMPL;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CShellFileOpenDialogImpl - implements new Shell File Open dialog
+
+template <class T>
+class ATL_NO_VTABLE CShellFileOpenDialogImpl : public CShellFileDialogImpl< T >
+{
+public:
+ ATL::CComPtr<IFileOpenDialog> m_spFileDlg;
+
+ CShellFileOpenDialogImpl(LPCWSTR lpszFileName = NULL,
+ DWORD dwOptions = FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST,
+ LPCWSTR lpszDefExt = NULL,
+ const COMDLG_FILTERSPEC* arrFilterSpec = NULL,
+ UINT uFilterSpecCount = 0U)
+ {
+ HRESULT hRet = m_spFileDlg.CoCreateInstance(CLSID_FileOpenDialog);
+
+ if(SUCCEEDED(hRet))
+ _Init(lpszFileName, dwOptions, lpszDefExt, arrFilterSpec, uFilterSpecCount);
+ }
+
+ IFileOpenDialog* GetPtr()
+ {
+ return m_spFileDlg;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CShellFileOpenDialog - new Shell File Open dialog without events
+
+class CShellFileOpenDialog : public CShellFileOpenDialogImpl<CShellFileOpenDialog>
+{
+public:
+ CShellFileOpenDialog(LPCWSTR lpszFileName = NULL,
+ DWORD dwOptions = FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_FILEMUSTEXIST,
+ LPCWSTR lpszDefExt = NULL,
+ const COMDLG_FILTERSPEC* arrFilterSpec = NULL,
+ UINT uFilterSpecCount = 0U) : CShellFileOpenDialogImpl<CShellFileOpenDialog>(lpszFileName, dwOptions, lpszDefExt, arrFilterSpec, uFilterSpecCount)
+ { }
+
+// Implementation (remove _Advise/_Unadvise code using template magic)
+ void _Advise(DWORD& /*dwCookie*/)
+ { }
+
+ void _Unadvise(DWORD /*dwCookie*/)
+ { }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CShellFileSaveDialogImpl - implements new Shell File Save dialog
+
+template <class T>
+class ATL_NO_VTABLE CShellFileSaveDialogImpl : public CShellFileDialogImpl< T >
+{
+public:
+ ATL::CComPtr<IFileSaveDialog> m_spFileDlg;
+
+ CShellFileSaveDialogImpl(LPCWSTR lpszFileName = NULL,
+ DWORD dwOptions = FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_OVERWRITEPROMPT,
+ LPCWSTR lpszDefExt = NULL,
+ const COMDLG_FILTERSPEC* arrFilterSpec = NULL,
+ UINT uFilterSpecCount = 0U)
+ {
+ HRESULT hRet = m_spFileDlg.CoCreateInstance(CLSID_FileSaveDialog);
+
+ if(SUCCEEDED(hRet))
+ _Init(lpszFileName, dwOptions, lpszDefExt, arrFilterSpec, uFilterSpecCount);
+ }
+
+ IFileSaveDialog* GetPtr()
+ {
+ return m_spFileDlg;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CShellFileSaveDialog - new Shell File Save dialog without events
+
+class CShellFileSaveDialog : public CShellFileSaveDialogImpl<CShellFileSaveDialog>
+{
+public:
+ CShellFileSaveDialog(LPCWSTR lpszFileName = NULL,
+ DWORD dwOptions = FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST | FOS_OVERWRITEPROMPT,
+ LPCWSTR lpszDefExt = NULL,
+ const COMDLG_FILTERSPEC* arrFilterSpec = NULL,
+ UINT uFilterSpecCount = 0U) : CShellFileSaveDialogImpl<CShellFileSaveDialog>(lpszFileName, dwOptions, lpszDefExt, arrFilterSpec, uFilterSpecCount)
+ { }
+
+// Implementation (remove _Advise/_Unadvise code using template magic)
+ void _Advise(DWORD& /*dwCookie*/)
+ { }
+
+ void _Unadvise(DWORD /*dwCookie*/)
+ { }
+};
+
+#endif // (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CFolderDialogImpl - used for browsing for a folder
+
+#ifndef _WIN32_WCE
+
+template <class T>
+class ATL_NO_VTABLE CFolderDialogImpl
+{
+public:
+ BROWSEINFO m_bi;
+ LPCTSTR m_lpstrInitialFolder;
+ LPCITEMIDLIST m_pidlInitialSelection;
+ bool m_bExpandInitialSelection;
+ TCHAR m_szFolderDisplayName[MAX_PATH];
+ TCHAR m_szFolderPath[MAX_PATH];
+ LPITEMIDLIST m_pidlSelected;
+ HWND m_hWnd; // used only in the callback function
+
+// Constructor
+ CFolderDialogImpl(HWND hWndParent = NULL, LPCTSTR lpstrTitle = NULL, UINT uFlags = BIF_RETURNONLYFSDIRS) :
+ m_lpstrInitialFolder(NULL), m_pidlInitialSelection(NULL), m_bExpandInitialSelection(false), m_pidlSelected(NULL), m_hWnd(NULL)
+ {
+ memset(&m_bi, 0, sizeof(m_bi)); // initialize structure to 0/NULL
+
+ m_bi.hwndOwner = hWndParent;
+ m_bi.pidlRoot = NULL;
+ m_bi.pszDisplayName = m_szFolderDisplayName;
+ m_bi.lpszTitle = lpstrTitle;
+ m_bi.ulFlags = uFlags;
+ m_bi.lpfn = BrowseCallbackProc;
+ m_bi.lParam = (LPARAM)static_cast<T*>(this);
+
+ m_szFolderPath[0] = 0;
+ m_szFolderDisplayName[0] = 0;
+ }
+
+ ~CFolderDialogImpl()
+ {
+ ::CoTaskMemFree(m_pidlSelected);
+ }
+
+// Operations
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ if(m_bi.hwndOwner == NULL) // set only if not specified before
+ m_bi.hwndOwner = hWndParent;
+
+ // Clear out any previous results
+ m_szFolderPath[0] = 0;
+ m_szFolderDisplayName[0] = 0;
+ ::CoTaskMemFree(m_pidlSelected);
+
+ INT_PTR nRet = IDCANCEL;
+ m_pidlSelected = ::SHBrowseForFolder(&m_bi);
+
+ if(m_pidlSelected != NULL)
+ {
+ nRet = IDOK;
+
+ // If BIF_RETURNONLYFSDIRS is set, we try to get the filesystem path.
+ // Otherwise, the caller must handle the ID-list directly.
+ if((m_bi.ulFlags & BIF_RETURNONLYFSDIRS) != 0)
+ {
+ if(::SHGetPathFromIDList(m_pidlSelected, m_szFolderPath) == FALSE)
+ nRet = IDCANCEL;
+ }
+ }
+
+ return nRet;
+ }
+
+ // Methods to call before DoModal
+ void SetInitialFolder(LPCTSTR lpstrInitialFolder, bool bExpand = true)
+ {
+ // lpstrInitialFolder may be a file if BIF_BROWSEINCLUDEFILES is specified
+ m_lpstrInitialFolder = lpstrInitialFolder;
+ m_bExpandInitialSelection = bExpand;
+ }
+
+ void SetInitialSelection(LPCITEMIDLIST pidl, bool bExpand = true)
+ {
+ m_pidlInitialSelection = pidl;
+ m_bExpandInitialSelection = bExpand;
+ }
+
+ // Methods to call after DoModal
+ LPITEMIDLIST GetSelectedItem(bool bDetach = false)
+ {
+ LPITEMIDLIST pidl = m_pidlSelected;
+ if(bDetach)
+ m_pidlSelected = NULL;
+
+ return pidl;
+ }
+
+ LPCTSTR GetFolderPath() const
+ {
+ return m_szFolderPath;
+ }
+
+ LPCTSTR GetFolderDisplayName() const
+ {
+ return m_szFolderDisplayName;
+ }
+
+ int GetFolderImageIndex() const
+ {
+ return m_bi.iImage;
+ }
+
+// Callback function and overrideables
+ static int CALLBACK BrowseCallbackProc(HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
+ {
+#ifndef BFFM_VALIDATEFAILED
+ #ifdef UNICODE
+ const int BFFM_VALIDATEFAILED = 4;
+ #else
+ const int BFFM_VALIDATEFAILED = 3;
+ #endif
+#endif // !BFFM_VALIDATEFAILED
+#ifndef BFFM_IUNKNOWN
+ const int BFFM_IUNKNOWN = 5;
+#endif // !BFFM_IUNKNOWN
+#ifndef BIF_NEWDIALOGSTYLE
+ const UINT BIF_NEWDIALOGSTYLE = 0x0040;
+#endif // !BIF_NEWDIALOGSTYLE
+
+ int nRet = 0;
+ T* pT = (T*)lpData;
+ bool bClear = false;
+ if(pT->m_hWnd == NULL)
+ {
+ pT->m_hWnd = hWnd;
+ bClear = true;
+ }
+ else
+ {
+ ATLASSERT(pT->m_hWnd == hWnd);
+ }
+
+ switch(uMsg)
+ {
+ case BFFM_INITIALIZED:
+ // Set initial selection
+ // Note that m_pidlInitialSelection, if set, takes precedence over m_lpstrInitialFolder
+ if(pT->m_pidlInitialSelection != NULL)
+ pT->SetSelection(pT->m_pidlInitialSelection);
+ else if(pT->m_lpstrInitialFolder != NULL)
+ pT->SetSelection(pT->m_lpstrInitialFolder);
+
+ // Expand initial selection if appropriate
+ if(pT->m_bExpandInitialSelection && ((pT->m_bi.ulFlags & BIF_NEWDIALOGSTYLE) != 0))
+ {
+ if(pT->m_pidlInitialSelection != NULL)
+ pT->SetExpanded(pT->m_pidlInitialSelection);
+ else if(pT->m_lpstrInitialFolder != NULL)
+ pT->SetExpanded(pT->m_lpstrInitialFolder);
+ }
+ pT->OnInitialized();
+ break;
+ case BFFM_SELCHANGED:
+ pT->OnSelChanged((LPITEMIDLIST)lParam);
+ break;
+ case BFFM_VALIDATEFAILED:
+ nRet = pT->OnValidateFailed((LPCTSTR)lParam);
+ break;
+ case BFFM_IUNKNOWN:
+ pT->OnIUnknown((IUnknown*)lParam);
+ break;
+ default:
+ ATLTRACE2(atlTraceUI, 0, _T("Unknown message received in CFolderDialogImpl::BrowseCallbackProc\n"));
+ break;
+ }
+
+ if(bClear)
+ pT->m_hWnd = NULL;
+ return nRet;
+ }
+
+ void OnInitialized()
+ {
+ }
+
+ void OnSelChanged(LPITEMIDLIST /*pItemIDList*/)
+ {
+ }
+
+ int OnValidateFailed(LPCTSTR /*lpstrFolderPath*/)
+ {
+ return 1; // 1=continue, 0=EndDialog
+ }
+
+ void OnIUnknown(IUnknown* /*pUnknown*/)
+ {
+ }
+
+ // Commands - valid to call only from handlers
+ void EnableOK(BOOL bEnable)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, BFFM_ENABLEOK, 0, bEnable);
+ }
+
+ void SetSelection(LPCITEMIDLIST pItemIDList)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, BFFM_SETSELECTION, FALSE, (LPARAM)pItemIDList);
+ }
+
+ void SetSelection(LPCTSTR lpstrFolderPath)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, BFFM_SETSELECTION, TRUE, (LPARAM)lpstrFolderPath);
+ }
+
+ void SetStatusText(LPCTSTR lpstrText)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)lpstrText);
+ }
+
+ void SetOKText(LPCTSTR lpstrOKText)
+ {
+#ifndef BFFM_SETOKTEXT
+ const UINT BFFM_SETOKTEXT = WM_USER + 105;
+#endif
+ ATLASSERT(m_hWnd != NULL);
+ USES_CONVERSION;
+ LPCWSTR lpstr = T2CW(lpstrOKText);
+ ::SendMessage(m_hWnd, BFFM_SETOKTEXT, 0, (LPARAM)lpstr);
+ }
+
+ void SetExpanded(LPCITEMIDLIST pItemIDList)
+ {
+#ifndef BFFM_SETEXPANDED
+ const UINT BFFM_SETEXPANDED = WM_USER + 106;
+#endif
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, BFFM_SETEXPANDED, FALSE, (LPARAM)pItemIDList);
+ }
+
+ void SetExpanded(LPCTSTR lpstrFolderPath)
+ {
+#ifndef BFFM_SETEXPANDED
+ const UINT BFFM_SETEXPANDED = WM_USER + 106;
+#endif
+ ATLASSERT(m_hWnd != NULL);
+ USES_CONVERSION;
+ LPCWSTR lpstr = T2CW(lpstrFolderPath);
+ ::SendMessage(m_hWnd, BFFM_SETEXPANDED, TRUE, (LPARAM)lpstr);
+ }
+};
+
+class CFolderDialog : public CFolderDialogImpl<CFolderDialog>
+{
+public:
+ CFolderDialog(HWND hWndParent = NULL, LPCTSTR lpstrTitle = NULL, UINT uFlags = BIF_RETURNONLYFSDIRS)
+ : CFolderDialogImpl<CFolderDialog>(hWndParent, lpstrTitle, uFlags)
+ { }
+};
+
+#endif // !_WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CCommonDialogImplBase - base class for common dialog classes
+
+class ATL_NO_VTABLE CCommonDialogImplBase : public ATL::CWindowImplBase
+{
+public:
+ static UINT_PTR APIENTRY HookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+ {
+ if(uMsg != WM_INITDIALOG)
+ return 0;
+ CCommonDialogImplBase* pT = (CCommonDialogImplBase*)ModuleHelper::ExtractCreateWndData();
+ ATLASSERT(pT != NULL);
+ ATLASSERT(pT->m_hWnd == NULL);
+ ATLASSERT(::IsWindow(hWnd));
+ // subclass dialog's window
+ if(!pT->SubclassWindow(hWnd))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("Subclassing a common dialog failed\n"));
+ return 0;
+ }
+ // check message map for WM_INITDIALOG handler
+ LRESULT lRes = 0;
+ if(pT->ProcessWindowMessage(pT->m_hWnd, uMsg, wParam, lParam, lRes, 0) == FALSE)
+ return 0;
+ return lRes;
+ }
+
+// Special override for common dialogs
+ BOOL EndDialog(INT_PTR /*nRetCode*/ = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ SendMessage(WM_COMMAND, MAKEWPARAM(IDABORT, 0));
+ return TRUE;
+ }
+
+// Implementation - try to override these, to prevent errors
+ HWND Create(HWND, ATL::_U_RECT, LPCTSTR, DWORD, DWORD, ATL::_U_MENUorID, ATOM, LPVOID)
+ {
+ ATLASSERT(FALSE); // should not be called
+ return NULL;
+ }
+
+ static LRESULT CALLBACK StartWindowProc(HWND /*hWnd*/, UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
+ {
+ ATLASSERT(FALSE); // should not be called
+ return 0;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CFontDialogImpl - font selection dialog
+
+#ifndef _WIN32_WCE
+
+template <class T>
+class ATL_NO_VTABLE CFontDialogImpl : public CCommonDialogImplBase
+{
+public:
+ enum { _cchStyleName = 64 };
+
+ CHOOSEFONT m_cf;
+ TCHAR m_szStyleName[_cchStyleName]; // contains style name after return
+ LOGFONT m_lf; // default LOGFONT to store the info
+
+// Constructors
+ CFontDialogImpl(LPLOGFONT lplfInitial = NULL,
+ DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS,
+ HDC hDCPrinter = NULL,
+ HWND hWndParent = NULL)
+ {
+ memset(&m_cf, 0, sizeof(m_cf));
+ memset(&m_lf, 0, sizeof(m_lf));
+ memset(&m_szStyleName, 0, sizeof(m_szStyleName));
+
+ m_cf.lStructSize = sizeof(m_cf);
+ m_cf.hwndOwner = hWndParent;
+ m_cf.rgbColors = RGB(0, 0, 0);
+ m_cf.lpszStyle = (LPTSTR)&m_szStyleName;
+ m_cf.Flags = dwFlags | CF_ENABLEHOOK;
+ m_cf.lpfnHook = (LPCFHOOKPROC)T::HookProc;
+
+ if(lplfInitial != NULL)
+ {
+ m_cf.lpLogFont = lplfInitial;
+ m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
+ m_lf = *lplfInitial;
+ }
+ else
+ {
+ m_cf.lpLogFont = &m_lf;
+ }
+
+ if(hDCPrinter != NULL)
+ {
+ m_cf.hDC = hDCPrinter;
+ m_cf.Flags |= CF_PRINTERFONTS;
+ }
+ }
+
+// Operations
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ ATLASSERT((m_cf.Flags & CF_ENABLEHOOK) != 0);
+ ATLASSERT(m_cf.lpfnHook != NULL); // can still be a user hook
+
+ if(m_cf.hwndOwner == NULL) // set only if not specified before
+ m_cf.hwndOwner = hWndParent;
+
+ ATLASSERT(m_hWnd == NULL);
+ ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
+
+ BOOL bRet = ::ChooseFont(&m_cf);
+
+ m_hWnd = NULL;
+
+ if(bRet) // copy logical font from user's initialization buffer (if needed)
+ SecureHelper::memcpy_x(&m_lf, sizeof(m_lf), m_cf.lpLogFont, sizeof(m_lf));
+
+ return bRet ? IDOK : IDCANCEL;
+ }
+
+ // works only when the dialog is dislayed or after
+ void GetCurrentFont(LPLOGFONT lplf) const
+ {
+ ATLASSERT(lplf != NULL);
+
+ if(m_hWnd != NULL)
+ ::SendMessage(m_hWnd, WM_CHOOSEFONT_GETLOGFONT, 0, (LPARAM)lplf);
+ else
+ *lplf = m_lf;
+ }
+
+ // works only when the dialog is dislayed or before
+#ifndef _WIN32_WCE
+ void SetLogFont(LPLOGFONT lplf)
+ {
+ ATLASSERT(lplf != NULL);
+#ifndef WM_CHOOSEFONT_SETLOGFONT
+ const UINT WM_CHOOSEFONT_SETLOGFONT = (WM_USER + 101);
+#endif
+ if(m_hWnd != NULL)
+ {
+ ::SendMessage(m_hWnd, WM_CHOOSEFONT_SETLOGFONT, 0, (LPARAM)lplf);
+ }
+ else
+ {
+ m_lf = *lplf;
+ m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
+ }
+ }
+
+ void SetFlags(DWORD dwFlags)
+ {
+#ifndef WM_CHOOSEFONT_SETFLAGS
+ const UINT WM_CHOOSEFONT_SETFLAGS = (WM_USER + 102);
+#endif
+ if(m_hWnd != NULL)
+ {
+ CHOOSEFONT cf = { sizeof(CHOOSEFONT) };
+ cf.Flags = dwFlags;
+ ::SendMessage(m_hWnd, WM_CHOOSEFONT_SETFLAGS, 0, (LPARAM)&cf);
+ }
+ else
+ {
+ m_cf.Flags = dwFlags;
+ }
+ }
+#endif // !_WIN32_WCE
+
+ // Helpers for parsing information after successful return
+ LPCTSTR GetFaceName() const // return the face name of the font
+ {
+ return (LPCTSTR)m_cf.lpLogFont->lfFaceName;
+ }
+
+ LPCTSTR GetStyleName() const // return the style name of the font
+ {
+ return m_cf.lpszStyle;
+ }
+
+ int GetSize() const // return the pt size of the font
+ {
+ return m_cf.iPointSize;
+ }
+
+ COLORREF GetColor() const // return the color of the font
+ {
+ return m_cf.rgbColors;
+ }
+
+ int GetWeight() const // return the chosen font weight
+ {
+ return (int)m_cf.lpLogFont->lfWeight;
+ }
+
+ BOOL IsStrikeOut() const // return TRUE if strikeout
+ {
+ return (m_cf.lpLogFont->lfStrikeOut) ? TRUE : FALSE;
+ }
+
+ BOOL IsUnderline() const // return TRUE if underline
+ {
+ return (m_cf.lpLogFont->lfUnderline) ? TRUE : FALSE;
+ }
+
+ BOOL IsBold() const // return TRUE if bold font
+ {
+ return (m_cf.lpLogFont->lfWeight == FW_BOLD) ? TRUE : FALSE;
+ }
+
+ BOOL IsItalic() const // return TRUE if italic font
+ {
+ return m_cf.lpLogFont->lfItalic ? TRUE : FALSE;
+ }
+};
+
+class CFontDialog : public CFontDialogImpl<CFontDialog>
+{
+public:
+ CFontDialog(LPLOGFONT lplfInitial = NULL,
+ DWORD dwFlags = CF_EFFECTS | CF_SCREENFONTS,
+ HDC hDCPrinter = NULL,
+ HWND hWndParent = NULL)
+ : CFontDialogImpl<CFontDialog>(lplfInitial, dwFlags, hDCPrinter, hWndParent)
+ { }
+
+ DECLARE_EMPTY_MSG_MAP()
+};
+
+#endif // _WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CRichEditFontDialogImpl - font selection for the Rich Edit ctrl
+
+#if defined(_RICHEDIT_) && !defined(_WIN32_WCE)
+
+template <class T>
+class ATL_NO_VTABLE CRichEditFontDialogImpl : public CFontDialogImpl< T >
+{
+public:
+ CRichEditFontDialogImpl(const CHARFORMAT& charformat,
+ DWORD dwFlags = CF_SCREENFONTS,
+ HDC hDCPrinter = NULL,
+ HWND hWndParent = NULL)
+ : CFontDialogImpl< T >(NULL, dwFlags, hDCPrinter, hWndParent)
+ {
+ m_cf.Flags |= CF_INITTOLOGFONTSTRUCT;
+ m_cf.Flags |= FillInLogFont(charformat);
+ m_cf.lpLogFont = &m_lf;
+
+ if((charformat.dwMask & CFM_COLOR) != 0)
+ m_cf.rgbColors = charformat.crTextColor;
+ }
+
+ void GetCharFormat(CHARFORMAT& cf) const
+ {
+ USES_CONVERSION;
+ cf.dwEffects = 0;
+ cf.dwMask = 0;
+ if((m_cf.Flags & CF_NOSTYLESEL) == 0)
+ {
+ cf.dwMask |= CFM_BOLD | CFM_ITALIC;
+ cf.dwEffects |= IsBold() ? CFE_BOLD : 0;
+ cf.dwEffects |= IsItalic() ? CFE_ITALIC : 0;
+ }
+ if((m_cf.Flags & CF_NOSIZESEL) == 0)
+ {
+ cf.dwMask |= CFM_SIZE;
+ // GetSize() returns in tenths of points so mulitply by 2 to get twips
+ cf.yHeight = GetSize() * 2;
+ }
+
+ if((m_cf.Flags & CF_NOFACESEL) == 0)
+ {
+ cf.dwMask |= CFM_FACE;
+ cf.bPitchAndFamily = m_cf.lpLogFont->lfPitchAndFamily;
+#if (_RICHEDIT_VER >= 0x0200)
+ SecureHelper::strcpy_x(cf.szFaceName, _countof(cf.szFaceName), GetFaceName());
+#else // !(_RICHEDIT_VER >= 0x0200)
+ SecureHelper::strcpyA_x(cf.szFaceName, _countof(cf.szFaceName), T2A((LPTSTR)(LPCTSTR)GetFaceName()));
+#endif // !(_RICHEDIT_VER >= 0x0200)
+ }
+
+ if((m_cf.Flags & CF_EFFECTS) != 0)
+ {
+ cf.dwMask |= CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR;
+ cf.dwEffects |= IsUnderline() ? CFE_UNDERLINE : 0;
+ cf.dwEffects |= IsStrikeOut() ? CFE_STRIKEOUT : 0;
+ cf.crTextColor = GetColor();
+ }
+ if((m_cf.Flags & CF_NOSCRIPTSEL) == 0)
+ {
+ cf.bCharSet = m_cf.lpLogFont->lfCharSet;
+ cf.dwMask |= CFM_CHARSET;
+ }
+ cf.yOffset = 0;
+ }
+
+ DWORD FillInLogFont(const CHARFORMAT& cf)
+ {
+ USES_CONVERSION;
+ DWORD dwFlags = 0;
+ if((cf.dwMask & CFM_SIZE) != 0)
+ {
+ HDC hDC = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
+ LONG yPerInch = ::GetDeviceCaps(hDC, LOGPIXELSY);
+ m_lf.lfHeight = -(int)((cf.yHeight * yPerInch) / 1440);
+ }
+ else
+ m_lf.lfHeight = 0;
+
+ m_lf.lfWidth = 0;
+ m_lf.lfEscapement = 0;
+ m_lf.lfOrientation = 0;
+
+ if((cf.dwMask & (CFM_ITALIC | CFM_BOLD)) == (CFM_ITALIC | CFM_BOLD))
+ {
+ m_lf.lfWeight = ((cf.dwEffects & CFE_BOLD) != 0) ? FW_BOLD : FW_NORMAL;
+ m_lf.lfItalic = (BYTE)(((cf.dwEffects & CFE_ITALIC) != 0) ? TRUE : FALSE);
+ }
+ else
+ {
+ dwFlags |= CF_NOSTYLESEL;
+ m_lf.lfWeight = FW_DONTCARE;
+ m_lf.lfItalic = FALSE;
+ }
+
+ if((cf.dwMask & (CFM_UNDERLINE | CFM_STRIKEOUT | CFM_COLOR)) == (CFM_UNDERLINE|CFM_STRIKEOUT|CFM_COLOR))
+ {
+ dwFlags |= CF_EFFECTS;
+ m_lf.lfUnderline = (BYTE)(((cf.dwEffects & CFE_UNDERLINE) != 0) ? TRUE : FALSE);
+ m_lf.lfStrikeOut = (BYTE)(((cf.dwEffects & CFE_STRIKEOUT) != 0) ? TRUE : FALSE);
+ }
+ else
+ {
+ m_lf.lfUnderline = (BYTE)FALSE;
+ m_lf.lfStrikeOut = (BYTE)FALSE;
+ }
+
+ if((cf.dwMask & CFM_CHARSET) != 0)
+ m_lf.lfCharSet = cf.bCharSet;
+ else
+ dwFlags |= CF_NOSCRIPTSEL;
+ m_lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
+ m_lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
+ m_lf.lfQuality = DEFAULT_QUALITY;
+ if((cf.dwMask & CFM_FACE) != 0)
+ {
+ m_lf.lfPitchAndFamily = cf.bPitchAndFamily;
+#if (_RICHEDIT_VER >= 0x0200)
+ SecureHelper::strcpy_x(m_lf.lfFaceName, _countof(m_lf.lfFaceName), cf.szFaceName);
+#else // !(_RICHEDIT_VER >= 0x0200)
+ SecureHelper::strcpy_x(m_lf.lfFaceName, _countof(m_lf.lfFaceName), A2T((LPSTR)cf.szFaceName));
+#endif // !(_RICHEDIT_VER >= 0x0200)
+ }
+ else
+ {
+ m_lf.lfPitchAndFamily = DEFAULT_PITCH|FF_DONTCARE;
+ m_lf.lfFaceName[0] = (TCHAR)0;
+ }
+ return dwFlags;
+ }
+};
+
+class CRichEditFontDialog : public CRichEditFontDialogImpl<CRichEditFontDialog>
+{
+public:
+ CRichEditFontDialog(const CHARFORMAT& charformat,
+ DWORD dwFlags = CF_SCREENFONTS,
+ HDC hDCPrinter = NULL,
+ HWND hWndParent = NULL)
+ : CRichEditFontDialogImpl<CRichEditFontDialog>(charformat, dwFlags, hDCPrinter, hWndParent)
+ { }
+
+ DECLARE_EMPTY_MSG_MAP()
+};
+
+#endif // defined(_RICHEDIT_) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CColorDialogImpl - color selection
+
+#if !defined(_WIN32_WCE) || ((_WIN32_WCE > 420) && !(defined(WIN32_PLATFORM_WFSP) && (_WIN32_WCE > 0x0500)))
+
+#ifdef _WIN32_WCE
+ #pragma comment(lib, "commdlg.lib")
+
+ #ifndef SETRGBSTRING
+ #define SETRGBSTRING _T("commdlg_SetRGBColor")
+ #endif
+
+ #ifndef COLOROKSTRING
+ #define COLOROKSTRING _T("commdlg_ColorOK")
+ #endif
+#endif
+
+template <class T>
+class ATL_NO_VTABLE CColorDialogImpl : public CCommonDialogImplBase
+{
+public:
+ CHOOSECOLOR m_cc;
+
+// Constructor
+ CColorDialogImpl(COLORREF clrInit = 0, DWORD dwFlags = 0, HWND hWndParent = NULL)
+ {
+ memset(&m_cc, 0, sizeof(m_cc));
+
+ m_cc.lStructSize = sizeof(m_cc);
+ m_cc.lpCustColors = GetCustomColors();
+ m_cc.hwndOwner = hWndParent;
+ m_cc.Flags = dwFlags | CC_ENABLEHOOK;
+ m_cc.lpfnHook = (LPCCHOOKPROC)T::HookProc;
+
+ if(clrInit != 0)
+ {
+ m_cc.rgbResult = clrInit;
+ m_cc.Flags |= CC_RGBINIT;
+ }
+ }
+
+// Operations
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ ATLASSERT((m_cc.Flags & CC_ENABLEHOOK) != 0);
+ ATLASSERT(m_cc.lpfnHook != NULL); // can still be a user hook
+
+ if(m_cc.hwndOwner == NULL) // set only if not specified before
+ m_cc.hwndOwner = hWndParent;
+
+ ATLASSERT(m_hWnd == NULL);
+ ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
+
+ BOOL bRet = ::ChooseColor(&m_cc);
+
+ m_hWnd = NULL;
+
+ return bRet ? IDOK : IDCANCEL;
+ }
+
+ // Set the current color while dialog is displayed
+ void SetCurrentColor(COLORREF clr)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ SendMessage(_GetSetRGBMessage(), 0, (LPARAM)clr);
+ }
+
+ // Get the selected color after DoModal returns, or in OnColorOK
+ COLORREF GetColor() const
+ {
+ return m_cc.rgbResult;
+ }
+
+// Special override for the color dialog
+ static UINT_PTR APIENTRY HookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+ {
+ if(uMsg != WM_INITDIALOG && uMsg != _GetColorOKMessage())
+ return 0;
+
+ LPCHOOSECOLOR lpCC = (LPCHOOSECOLOR)lParam;
+ CCommonDialogImplBase* pT = NULL;
+
+ if(uMsg == WM_INITDIALOG)
+ {
+ pT = (CCommonDialogImplBase*)ModuleHelper::ExtractCreateWndData();
+ lpCC->lCustData = (LPARAM)pT;
+ ATLASSERT(pT != NULL);
+ ATLASSERT(pT->m_hWnd == NULL);
+ ATLASSERT(::IsWindow(hWnd));
+ // subclass dialog's window
+ if(!pT->SubclassWindow(hWnd))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("Subclassing a Color common dialog failed\n"));
+ return 0;
+ }
+ }
+ else if(uMsg == _GetColorOKMessage())
+ {
+ pT = (CCommonDialogImplBase*)lpCC->lCustData;
+ ATLASSERT(pT != NULL);
+ ATLASSERT(::IsWindow(pT->m_hWnd));
+ }
+
+ // pass to the message map
+ LRESULT lRes;
+ if(pT->ProcessWindowMessage(pT->m_hWnd, uMsg, wParam, lParam, lRes, 0) == FALSE)
+ return 0;
+ return lRes;
+ }
+
+// Helpers
+ static COLORREF* GetCustomColors()
+ {
+ static COLORREF rgbCustomColors[16] =
+ {
+ RGB(255, 255, 255), RGB(255, 255, 255),
+ RGB(255, 255, 255), RGB(255, 255, 255),
+ RGB(255, 255, 255), RGB(255, 255, 255),
+ RGB(255, 255, 255), RGB(255, 255, 255),
+ RGB(255, 255, 255), RGB(255, 255, 255),
+ RGB(255, 255, 255), RGB(255, 255, 255),
+ RGB(255, 255, 255), RGB(255, 255, 255),
+ RGB(255, 255, 255), RGB(255, 255, 255),
+ };
+
+ return rgbCustomColors;
+ }
+
+ static UINT _GetSetRGBMessage()
+ {
+ static UINT uSetRGBMessage = 0;
+ if(uSetRGBMessage == 0)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CColorDialogImpl::_GetSetRGBMessage.\n"));
+ ATLASSERT(FALSE);
+ return 0;
+ }
+
+ if(uSetRGBMessage == 0)
+ uSetRGBMessage = ::RegisterWindowMessage(SETRGBSTRING);
+
+ lock.Unlock();
+ }
+ ATLASSERT(uSetRGBMessage != 0);
+ return uSetRGBMessage;
+ }
+
+ static UINT _GetColorOKMessage()
+ {
+ static UINT uColorOKMessage = 0;
+ if(uColorOKMessage == 0)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CColorDialogImpl::_GetColorOKMessage.\n"));
+ ATLASSERT(FALSE);
+ return 0;
+ }
+
+ if(uColorOKMessage == 0)
+ uColorOKMessage = ::RegisterWindowMessage(COLOROKSTRING);
+
+ lock.Unlock();
+ }
+ ATLASSERT(uColorOKMessage != 0);
+ return uColorOKMessage;
+ }
+
+// Message map and handlers
+ BEGIN_MSG_MAP(CColorDialogImpl)
+ MESSAGE_HANDLER(_GetColorOKMessage(), _OnColorOK)
+ END_MSG_MAP()
+
+ LRESULT _OnColorOK(UINT, WPARAM, LPARAM, BOOL&)
+ {
+ T* pT = static_cast<T*>(this);
+ return pT->OnColorOK();
+ }
+
+// Overrideable
+ BOOL OnColorOK() // validate color
+ {
+ return FALSE;
+ }
+};
+
+class CColorDialog : public CColorDialogImpl<CColorDialog>
+{
+public:
+ CColorDialog(COLORREF clrInit = 0, DWORD dwFlags = 0, HWND hWndParent = NULL)
+ : CColorDialogImpl<CColorDialog>(clrInit, dwFlags, hWndParent)
+ { }
+
+ // override base class map and references to handlers
+ DECLARE_EMPTY_MSG_MAP()
+};
+
+#endif // !defined(_WIN32_WCE) || ((_WIN32_WCE > 420) && !(defined(WIN32_PLATFORM_WFSP) && (_WIN32_WCE > 0x0500)))
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CPrintDialogImpl - used for Print... and PrintSetup...
+
+#ifndef _WIN32_WCE
+
+// global helper
+static HDC _AtlCreateDC(HGLOBAL hDevNames, HGLOBAL hDevMode)
+{
+ if(hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDevNames = (LPDEVNAMES)::GlobalLock(hDevNames);
+ LPDEVMODE lpDevMode = (hDevMode != NULL) ? (LPDEVMODE)::GlobalLock(hDevMode) : NULL;
+
+ if(lpDevNames == NULL)
+ return NULL;
+
+ HDC hDC = ::CreateDC((LPCTSTR)lpDevNames + lpDevNames->wDriverOffset,
+ (LPCTSTR)lpDevNames + lpDevNames->wDeviceOffset,
+ (LPCTSTR)lpDevNames + lpDevNames->wOutputOffset,
+ lpDevMode);
+
+ ::GlobalUnlock(hDevNames);
+ if(hDevMode != NULL)
+ ::GlobalUnlock(hDevMode);
+ return hDC;
+}
+
+template <class T>
+class ATL_NO_VTABLE CPrintDialogImpl : public CCommonDialogImplBase
+{
+public:
+ // print dialog parameter block (note this is a reference)
+ PRINTDLG& m_pd;
+
+// Constructors
+ CPrintDialogImpl(BOOL bPrintSetupOnly = FALSE, // TRUE for Print Setup, FALSE for Print Dialog
+ DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION,
+ HWND hWndParent = NULL)
+ : m_pd(m_pdActual)
+ {
+ memset(&m_pdActual, 0, sizeof(m_pdActual));
+
+ m_pd.lStructSize = sizeof(m_pdActual);
+ m_pd.hwndOwner = hWndParent;
+ m_pd.Flags = (dwFlags | PD_ENABLEPRINTHOOK | PD_ENABLESETUPHOOK);
+ m_pd.lpfnPrintHook = (LPPRINTHOOKPROC)T::HookProc;
+ m_pd.lpfnSetupHook = (LPSETUPHOOKPROC)T::HookProc;
+
+ if(bPrintSetupOnly)
+ m_pd.Flags |= PD_PRINTSETUP;
+ else
+ m_pd.Flags |= PD_RETURNDC;
+
+ m_pd.Flags &= ~PD_RETURNIC; // do not support information context
+ }
+
+// Operations
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ ATLASSERT((m_pd.Flags & PD_ENABLEPRINTHOOK) != 0);
+ ATLASSERT((m_pd.Flags & PD_ENABLESETUPHOOK) != 0);
+ ATLASSERT(m_pd.lpfnPrintHook != NULL); // can still be a user hook
+ ATLASSERT(m_pd.lpfnSetupHook != NULL); // can still be a user hook
+ ATLASSERT((m_pd.Flags & PD_RETURNDEFAULT) == 0); // use GetDefaults for this
+
+ if(m_pd.hwndOwner == NULL) // set only if not specified before
+ m_pd.hwndOwner = hWndParent;
+
+ ATLASSERT(m_hWnd == NULL);
+ ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
+
+ BOOL bRet = ::PrintDlg(&m_pd);
+
+ m_hWnd = NULL;
+
+ return bRet ? IDOK : IDCANCEL;
+ }
+
+ // GetDefaults will not display a dialog but will get device defaults
+ BOOL GetDefaults()
+ {
+ m_pd.Flags |= PD_RETURNDEFAULT;
+ ATLASSERT(m_pd.hDevMode == NULL); // must be NULL
+ ATLASSERT(m_pd.hDevNames == NULL); // must be NULL
+
+ return ::PrintDlg(&m_pd);
+ }
+
+ // Helpers for parsing information after successful return num. copies requested
+ int GetCopies() const
+ {
+ if((m_pd.Flags & PD_USEDEVMODECOPIES) != 0)
+ {
+ LPDEVMODE lpDevMode = GetDevMode();
+ return (lpDevMode != NULL) ? lpDevMode->dmCopies : -1;
+ }
+
+ return m_pd.nCopies;
+ }
+
+ BOOL PrintCollate() const // TRUE if collate checked
+ {
+ return ((m_pd.Flags & PD_COLLATE) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL PrintSelection() const // TRUE if printing selection
+ {
+ return ((m_pd.Flags & PD_SELECTION) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL PrintAll() const // TRUE if printing all pages
+ {
+ return (!PrintRange() && !PrintSelection()) ? TRUE : FALSE;
+ }
+
+ BOOL PrintRange() const // TRUE if printing page range
+ {
+ return ((m_pd.Flags & PD_PAGENUMS) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL PrintToFile() const // TRUE if printing to a file
+ {
+ return ((m_pd.Flags & PD_PRINTTOFILE) != 0) ? TRUE : FALSE;
+ }
+
+ int GetFromPage() const // starting page if valid
+ {
+ return PrintRange() ? m_pd.nFromPage : -1;
+ }
+
+ int GetToPage() const // ending page if valid
+ {
+ return PrintRange() ? m_pd.nToPage : -1;
+ }
+
+ LPDEVMODE GetDevMode() const // return DEVMODE
+ {
+ if(m_pd.hDevMode == NULL)
+ return NULL;
+
+ return (LPDEVMODE)::GlobalLock(m_pd.hDevMode);
+ }
+
+ LPCTSTR GetDriverName() const // return driver name
+ {
+ if(m_pd.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pd.hDevNames);
+ if(lpDev == NULL)
+ return NULL;
+
+ return (LPCTSTR)lpDev + lpDev->wDriverOffset;
+ }
+
+ LPCTSTR GetDeviceName() const // return device name
+ {
+ if(m_pd.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pd.hDevNames);
+ if(lpDev == NULL)
+ return NULL;
+
+ return (LPCTSTR)lpDev + lpDev->wDeviceOffset;
+ }
+
+ LPCTSTR GetPortName() const // return output port name
+ {
+ if(m_pd.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pd.hDevNames);
+ if(lpDev == NULL)
+ return NULL;
+
+ return (LPCTSTR)lpDev + lpDev->wOutputOffset;
+ }
+
+ HDC GetPrinterDC() const // return HDC (caller must delete)
+ {
+ ATLASSERT((m_pd.Flags & PD_RETURNDC) != 0);
+ return m_pd.hDC;
+ }
+
+ // This helper creates a DC based on the DEVNAMES and DEVMODE structures.
+ // This DC is returned, but also stored in m_pd.hDC as though it had been
+ // returned by CommDlg. It is assumed that any previously obtained DC
+ // has been/will be deleted by the user. This may be
+ // used without ever invoking the print/print setup dialogs.
+ HDC CreatePrinterDC()
+ {
+ m_pd.hDC = _AtlCreateDC(m_pd.hDevNames, m_pd.hDevMode);
+ return m_pd.hDC;
+ }
+
+// Implementation
+ PRINTDLG m_pdActual; // the Print/Print Setup need to share this
+
+ // The following handle the case of print setup... from the print dialog
+ CPrintDialogImpl(PRINTDLG& pdInit) : m_pd(pdInit)
+ { }
+
+ BEGIN_MSG_MAP(CPrintDialogImpl)
+#ifdef psh1
+ COMMAND_ID_HANDLER(psh1, OnPrintSetup) // print setup button when print is displayed
+#else // !psh1
+ COMMAND_ID_HANDLER(0x0400, OnPrintSetup) // value from dlgs.h
+#endif // !psh1
+ END_MSG_MAP()
+
+ LRESULT OnPrintSetup(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& /*bHandled*/)
+ {
+ T dlgSetup(m_pd);
+ ModuleHelper::AddCreateWndData(&dlgSetup.m_thunk.cd, (CCommonDialogImplBase*)&dlgSetup);
+ return DefWindowProc(WM_COMMAND, MAKEWPARAM(wID, wNotifyCode), (LPARAM)hWndCtl);
+ }
+};
+
+class CPrintDialog : public CPrintDialogImpl<CPrintDialog>
+{
+public:
+ CPrintDialog(BOOL bPrintSetupOnly = FALSE,
+ DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION,
+ HWND hWndParent = NULL)
+ : CPrintDialogImpl<CPrintDialog>(bPrintSetupOnly, dwFlags, hWndParent)
+ { }
+
+ CPrintDialog(PRINTDLG& pdInit) : CPrintDialogImpl<CPrintDialog>(pdInit)
+ { }
+};
+
+#endif // _WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CPrintDialogExImpl - new print dialog for Windows 2000
+
+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+
+}; // namespace WTL
+
+#include <atlcom.h>
+
+extern "C" const __declspec(selectany) IID IID_IPrintDialogCallback = {0x5852a2c3, 0x6530, 0x11d1, {0xb6, 0xa3, 0x0, 0x0, 0xf8, 0x75, 0x7b, 0xf9}};
+extern "C" const __declspec(selectany) IID IID_IPrintDialogServices = {0x509aaeda, 0x5639, 0x11d1, {0xb6, 0xa1, 0x0, 0x0, 0xf8, 0x75, 0x7b, 0xf9}};
+
+namespace WTL
+{
+
+template <class T>
+class ATL_NO_VTABLE CPrintDialogExImpl :
+ public ATL::CWindow,
+ public ATL::CMessageMap,
+ public IPrintDialogCallback,
+ public ATL::IObjectWithSiteImpl< T >
+{
+public:
+ PRINTDLGEX m_pdex;
+
+// Constructor
+ CPrintDialogExImpl(DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION | PD_NOCURRENTPAGE,
+ HWND hWndParent = NULL)
+ {
+ memset(&m_pdex, 0, sizeof(m_pdex));
+
+ m_pdex.lStructSize = sizeof(PRINTDLGEX);
+ m_pdex.hwndOwner = hWndParent;
+ m_pdex.Flags = dwFlags;
+ m_pdex.nStartPage = START_PAGE_GENERAL;
+ // callback object will be set in DoModal
+
+ m_pdex.Flags &= ~PD_RETURNIC; // do not support information context
+ }
+
+// Operations
+ HRESULT DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ ATLASSERT(m_hWnd == NULL);
+ ATLASSERT((m_pdex.Flags & PD_RETURNDEFAULT) == 0); // use GetDefaults for this
+
+ if(m_pdex.hwndOwner == NULL) // set only if not specified before
+ m_pdex.hwndOwner = hWndParent;
+
+ T* pT = static_cast<T*>(this);
+ m_pdex.lpCallback = (IUnknown*)(IPrintDialogCallback*)pT;
+
+ HRESULT hResult = ::PrintDlgEx(&m_pdex);
+
+ m_hWnd = NULL;
+
+ return hResult;
+ }
+
+ BOOL EndDialog(INT_PTR /*nRetCode*/ = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ SendMessage(WM_COMMAND, MAKEWPARAM(IDABORT, 0));
+ return TRUE;
+ }
+
+ // GetDefaults will not display a dialog but will get device defaults
+ HRESULT GetDefaults()
+ {
+ m_pdex.Flags |= PD_RETURNDEFAULT;
+ ATLASSERT(m_pdex.hDevMode == NULL); // must be NULL
+ ATLASSERT(m_pdex.hDevNames == NULL); // must be NULL
+
+ return ::PrintDlgEx(&m_pdex);
+ }
+
+ // Helpers for parsing information after successful return num. copies requested
+ int GetCopies() const
+ {
+ if((m_pdex.Flags & PD_USEDEVMODECOPIES) != 0)
+ {
+ LPDEVMODE lpDevMode = GetDevMode();
+ return (lpDevMode != NULL) ? lpDevMode->dmCopies : -1;
+ }
+
+ return m_pdex.nCopies;
+ }
+
+ BOOL PrintCollate() const // TRUE if collate checked
+ {
+ return ((m_pdex.Flags & PD_COLLATE) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL PrintSelection() const // TRUE if printing selection
+ {
+ return ((m_pdex.Flags & PD_SELECTION) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL PrintAll() const // TRUE if printing all pages
+ {
+ return (!PrintRange() && !PrintSelection()) ? TRUE : FALSE;
+ }
+
+ BOOL PrintRange() const // TRUE if printing page range
+ {
+ return ((m_pdex.Flags & PD_PAGENUMS) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL PrintToFile() const // TRUE if printing to a file
+ {
+ return ((m_pdex.Flags & PD_PRINTTOFILE) != 0) ? TRUE : FALSE;
+ }
+
+ LPDEVMODE GetDevMode() const // return DEVMODE
+ {
+ if(m_pdex.hDevMode == NULL)
+ return NULL;
+
+ return (LPDEVMODE)::GlobalLock(m_pdex.hDevMode);
+ }
+
+ LPCTSTR GetDriverName() const // return driver name
+ {
+ if(m_pdex.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pdex.hDevNames);
+ if(lpDev == NULL)
+ return NULL;
+
+ return (LPCTSTR)lpDev + lpDev->wDriverOffset;
+ }
+
+ LPCTSTR GetDeviceName() const // return device name
+ {
+ if(m_pdex.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pdex.hDevNames);
+ if(lpDev == NULL)
+ return NULL;
+
+ return (LPCTSTR)lpDev + lpDev->wDeviceOffset;
+ }
+
+ LPCTSTR GetPortName() const // return output port name
+ {
+ if(m_pdex.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_pdex.hDevNames);
+ if(lpDev == NULL)
+ return NULL;
+
+ return (LPCTSTR)lpDev + lpDev->wOutputOffset;
+ }
+
+ HDC GetPrinterDC() const // return HDC (caller must delete)
+ {
+ ATLASSERT((m_pdex.Flags & PD_RETURNDC) != 0);
+ return m_pdex.hDC;
+ }
+
+ // This helper creates a DC based on the DEVNAMES and DEVMODE structures.
+ // This DC is returned, but also stored in m_pdex.hDC as though it had been
+ // returned by CommDlg. It is assumed that any previously obtained DC
+ // has been/will be deleted by the user. This may be
+ // used without ever invoking the print/print setup dialogs.
+ HDC CreatePrinterDC()
+ {
+ m_pdex.hDC = _AtlCreateDC(m_pdex.hDevNames, m_pdex.hDevMode);
+ return m_pdex.hDC;
+ }
+
+// Implementation - interfaces
+
+// IUnknown
+ STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject)
+ {
+ if(ppvObject == NULL)
+ return E_POINTER;
+
+ T* pT = static_cast<T*>(this);
+ if(IsEqualGUID(riid, IID_IUnknown) || IsEqualGUID(riid, IID_IPrintDialogCallback))
+ {
+ *ppvObject = (IPrintDialogCallback*)pT;
+ // AddRef() not needed
+ return S_OK;
+ }
+ else if(IsEqualGUID(riid, IID_IObjectWithSite))
+ {
+ *ppvObject = (IObjectWithSite*)pT;
+ // AddRef() not needed
+ return S_OK;
+ }
+
+ return E_NOINTERFACE;
+ }
+
+ virtual ULONG STDMETHODCALLTYPE AddRef()
+ {
+ return 1;
+ }
+
+ virtual ULONG STDMETHODCALLTYPE Release()
+ {
+ return 1;
+ }
+
+// IPrintDialogCallback
+ STDMETHOD(InitDone)()
+ {
+ return S_FALSE;
+ }
+
+ STDMETHOD(SelectionChange)()
+ {
+ return S_FALSE;
+ }
+
+ STDMETHOD(HandleMessage)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
+ {
+ // set up m_hWnd the first time
+ if(m_hWnd == NULL)
+ Attach(hWnd);
+
+ // call message map
+ HRESULT hRet = ProcessWindowMessage(hWnd, uMsg, wParam, lParam, *plResult, 0) ? S_OK : S_FALSE;
+ if(hRet == S_OK && uMsg == WM_NOTIFY) // return in DWLP_MSGRESULT
+ ::SetWindowLongPtr(GetParent(), DWLP_MSGRESULT, (LONG_PTR)*plResult);
+
+ if(uMsg == WM_INITDIALOG && hRet == S_OK && (BOOL)*plResult != FALSE)
+ hRet = S_FALSE;
+
+ return hRet;
+ }
+};
+
+class CPrintDialogEx : public CPrintDialogExImpl<CPrintDialogEx>
+{
+public:
+ CPrintDialogEx(
+ DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_NOSELECTION | PD_NOCURRENTPAGE,
+ HWND hWndParent = NULL)
+ : CPrintDialogExImpl<CPrintDialogEx>(dwFlags, hWndParent)
+ { }
+
+ DECLARE_EMPTY_MSG_MAP()
+};
+
+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CPageSetupDialogImpl - Page Setup dialog
+
+#ifndef _WIN32_WCE
+
+template <class T>
+class ATL_NO_VTABLE CPageSetupDialogImpl : public CCommonDialogImplBase
+{
+public:
+ PAGESETUPDLG m_psd;
+ ATL::CWndProcThunk m_thunkPaint;
+
+// Constructors
+ CPageSetupDialogImpl(DWORD dwFlags = PSD_MARGINS | PSD_INWININIINTLMEASURE, HWND hWndParent = NULL)
+ {
+ memset(&m_psd, 0, sizeof(m_psd));
+
+ m_psd.lStructSize = sizeof(m_psd);
+ m_psd.hwndOwner = hWndParent;
+ m_psd.Flags = (dwFlags | PSD_ENABLEPAGESETUPHOOK | PSD_ENABLEPAGEPAINTHOOK);
+ m_psd.lpfnPageSetupHook = (LPPAGESETUPHOOK)T::HookProc;
+ m_thunkPaint.Init((WNDPROC)T::PaintHookProc, this);
+#if (_ATL_VER >= 0x0700)
+ m_psd.lpfnPagePaintHook = (LPPAGEPAINTHOOK)m_thunkPaint.GetWNDPROC();
+#else
+ m_psd.lpfnPagePaintHook = (LPPAGEPAINTHOOK)&(m_thunkPaint.thunk);
+#endif
+ }
+
+ DECLARE_EMPTY_MSG_MAP()
+
+// Attributes
+ LPDEVMODE GetDevMode() const // return DEVMODE
+ {
+ if(m_psd.hDevMode == NULL)
+ return NULL;
+
+ return (LPDEVMODE)::GlobalLock(m_psd.hDevMode);
+ }
+
+ LPCTSTR GetDriverName() const // return driver name
+ {
+ if(m_psd.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_psd.hDevNames);
+ return (LPCTSTR)lpDev + lpDev->wDriverOffset;
+ }
+
+ LPCTSTR GetDeviceName() const // return device name
+ {
+ if(m_psd.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_psd.hDevNames);
+ return (LPCTSTR)lpDev + lpDev->wDeviceOffset;
+ }
+
+ LPCTSTR GetPortName() const // return output port name
+ {
+ if(m_psd.hDevNames == NULL)
+ return NULL;
+
+ LPDEVNAMES lpDev = (LPDEVNAMES)::GlobalLock(m_psd.hDevNames);
+ return (LPCTSTR)lpDev + lpDev->wOutputOffset;
+ }
+
+ HDC CreatePrinterDC()
+ {
+ return _AtlCreateDC(m_psd.hDevNames, m_psd.hDevMode);
+ }
+
+ SIZE GetPaperSize() const
+ {
+ SIZE size;
+ size.cx = m_psd.ptPaperSize.x;
+ size.cy = m_psd.ptPaperSize.y;
+ return size;
+ }
+
+ void GetMargins(LPRECT lpRectMargins, LPRECT lpRectMinMargins) const
+ {
+ if(lpRectMargins != NULL)
+ *lpRectMargins = m_psd.rtMargin;
+ if(lpRectMinMargins != NULL)
+ *lpRectMinMargins = m_psd.rtMinMargin;
+ }
+
+// Operations
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ ATLASSERT((m_psd.Flags & PSD_ENABLEPAGESETUPHOOK) != 0);
+ ATLASSERT((m_psd.Flags & PSD_ENABLEPAGEPAINTHOOK) != 0);
+ ATLASSERT(m_psd.lpfnPageSetupHook != NULL); // can still be a user hook
+ ATLASSERT(m_psd.lpfnPagePaintHook != NULL); // can still be a user hook
+
+ if(m_psd.hwndOwner == NULL) // set only if not specified before
+ m_psd.hwndOwner = hWndParent;
+
+ ATLASSERT(m_hWnd == NULL);
+ ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
+
+ BOOL bRet = ::PageSetupDlg(&m_psd);
+
+ m_hWnd = NULL;
+
+ return bRet ? IDOK : IDCANCEL;
+ }
+
+// Implementation
+ static UINT_PTR CALLBACK PaintHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+ {
+ T* pT = (T*)hWnd;
+ UINT_PTR uRet = 0;
+ switch(uMsg)
+ {
+ case WM_PSD_PAGESETUPDLG:
+ uRet = pT->PreDrawPage(LOWORD(wParam), HIWORD(wParam), (LPPAGESETUPDLG)lParam);
+ break;
+ case WM_PSD_FULLPAGERECT:
+ case WM_PSD_MINMARGINRECT:
+ case WM_PSD_MARGINRECT:
+ case WM_PSD_GREEKTEXTRECT:
+ case WM_PSD_ENVSTAMPRECT:
+ case WM_PSD_YAFULLPAGERECT:
+ uRet = pT->OnDrawPage(uMsg, (HDC)wParam, (LPRECT)lParam);
+ break;
+ default:
+ ATLTRACE2(atlTraceUI, 0, _T("CPageSetupDialogImpl::PaintHookProc - unknown message received\n"));
+ break;
+ }
+ return uRet;
+ }
+
+// Overridables
+ UINT_PTR PreDrawPage(WORD /*wPaper*/, WORD /*wFlags*/, LPPAGESETUPDLG /*pPSD*/)
+ {
+ // return 1 to prevent any more drawing
+ return 0;
+ }
+
+ UINT_PTR OnDrawPage(UINT /*uMsg*/, HDC /*hDC*/, LPRECT /*lpRect*/)
+ {
+ return 0; // do the default
+ }
+};
+
+class CPageSetupDialog : public CPageSetupDialogImpl<CPageSetupDialog>
+{
+public:
+ CPageSetupDialog(DWORD dwFlags = PSD_MARGINS | PSD_INWININIINTLMEASURE, HWND hWndParent = NULL)
+ : CPageSetupDialogImpl<CPageSetupDialog>(dwFlags, hWndParent)
+ { }
+
+ // override PaintHookProc and references to handlers
+ static UINT_PTR CALLBACK PaintHookProc(HWND, UINT, WPARAM, LPARAM)
+ {
+ return 0;
+ }
+};
+
+#endif // _WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CFindReplaceDialogImpl - Find/FindReplace modeless dialogs
+
+#ifndef _WIN32_WCE
+
+template <class T>
+class ATL_NO_VTABLE CFindReplaceDialogImpl : public CCommonDialogImplBase
+{
+public:
+ enum { _cchFindReplaceBuffer = 128 };
+
+ FINDREPLACE m_fr;
+ TCHAR m_szFindWhat[_cchFindReplaceBuffer];
+ TCHAR m_szReplaceWith[_cchFindReplaceBuffer];
+
+// Constructors
+ CFindReplaceDialogImpl()
+ {
+ memset(&m_fr, 0, sizeof(m_fr));
+ m_szFindWhat[0] = _T('\0');
+ m_szReplaceWith[0] = _T('\0');
+
+ m_fr.lStructSize = sizeof(m_fr);
+ m_fr.Flags = FR_ENABLEHOOK;
+ m_fr.lpfnHook = (LPFRHOOKPROC)T::HookProc;
+ m_fr.lpstrFindWhat = (LPTSTR)m_szFindWhat;
+ m_fr.wFindWhatLen = _cchFindReplaceBuffer;
+ m_fr.lpstrReplaceWith = (LPTSTR)m_szReplaceWith;
+ m_fr.wReplaceWithLen = _cchFindReplaceBuffer;
+ }
+
+ // Note: You must allocate the object on the heap.
+ // If you do not, you must override OnFinalMessage()
+ virtual void OnFinalMessage(HWND /*hWnd*/)
+ {
+ delete this;
+ }
+
+ HWND Create(BOOL bFindDialogOnly, // TRUE for Find, FALSE for FindReplace
+ LPCTSTR lpszFindWhat,
+ LPCTSTR lpszReplaceWith = NULL,
+ DWORD dwFlags = FR_DOWN,
+ HWND hWndParent = NULL)
+ {
+ ATLASSERT((m_fr.Flags & FR_ENABLEHOOK) != 0);
+ ATLASSERT(m_fr.lpfnHook != NULL);
+
+ m_fr.Flags |= dwFlags;
+
+ if(hWndParent == NULL)
+ m_fr.hwndOwner = ::GetActiveWindow();
+ else
+ m_fr.hwndOwner = hWndParent;
+ ATLASSERT(m_fr.hwndOwner != NULL); // must have an owner for modeless dialog
+
+ if(lpszFindWhat != NULL)
+ SecureHelper::strncpy_x(m_szFindWhat, _countof(m_szFindWhat), lpszFindWhat, _TRUNCATE);
+
+ if(lpszReplaceWith != NULL)
+ SecureHelper::strncpy_x(m_szReplaceWith, _countof(m_szReplaceWith), lpszReplaceWith, _TRUNCATE);
+
+ ATLASSERT(m_hWnd == NULL);
+ ModuleHelper::AddCreateWndData(&m_thunk.cd, (CCommonDialogImplBase*)this);
+
+ HWND hWnd = NULL;
+ if(bFindDialogOnly)
+ hWnd = ::FindText(&m_fr);
+ else
+ hWnd = ::ReplaceText(&m_fr);
+
+ ATLASSERT(m_hWnd == hWnd);
+ return hWnd;
+ }
+
+ static const UINT GetFindReplaceMsg()
+ {
+ static const UINT nMsgFindReplace = ::RegisterWindowMessage(FINDMSGSTRING);
+ return nMsgFindReplace;
+ }
+ // call while handling FINDMSGSTRING registered message
+ // to retreive the object
+ static T* PASCAL GetNotifier(LPARAM lParam)
+ {
+ ATLASSERT(lParam != NULL);
+ T* pDlg = (T*)(lParam - offsetof(T, m_fr));
+ return pDlg;
+ }
+
+// Operations
+ // Helpers for parsing information after successful return
+ LPCTSTR GetFindString() const // get find string
+ {
+ return (LPCTSTR)m_fr.lpstrFindWhat;
+ }
+
+ LPCTSTR GetReplaceString() const // get replacement string
+ {
+ return (LPCTSTR)m_fr.lpstrReplaceWith;
+ }
+
+ BOOL SearchDown() const // TRUE if search down, FALSE is up
+ {
+ return ((m_fr.Flags & FR_DOWN) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL FindNext() const // TRUE if command is find next
+ {
+ return ((m_fr.Flags & FR_FINDNEXT) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL MatchCase() const // TRUE if matching case
+ {
+ return ((m_fr.Flags & FR_MATCHCASE) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL MatchWholeWord() const // TRUE if matching whole words only
+ {
+ return ((m_fr.Flags & FR_WHOLEWORD) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL ReplaceCurrent() const // TRUE if replacing current string
+ {
+ return ((m_fr. Flags & FR_REPLACE) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL ReplaceAll() const // TRUE if replacing all occurrences
+ {
+ return ((m_fr.Flags & FR_REPLACEALL) != 0) ? TRUE : FALSE;
+ }
+
+ BOOL IsTerminating() const // TRUE if terminating dialog
+ {
+ return ((m_fr.Flags & FR_DIALOGTERM) != 0) ? TRUE : FALSE ;
+ }
+};
+
+class CFindReplaceDialog : public CFindReplaceDialogImpl<CFindReplaceDialog>
+{
+public:
+ DECLARE_EMPTY_MSG_MAP()
+};
+
+#endif // !_WIN32_WCE
+
+
+/////////////////////////////////////////////////////////////////////////
+// CDialogBaseUnits - Dialog Units helper
+//
+
+class CDialogBaseUnits
+{
+public:
+ SIZE m_sizeUnits;
+
+// Constructors
+ CDialogBaseUnits()
+ {
+ // The base units of the out-dated System Font
+ LONG nDlgBaseUnits = ::GetDialogBaseUnits();
+ m_sizeUnits.cx = LOWORD(nDlgBaseUnits);
+ m_sizeUnits.cy = HIWORD(nDlgBaseUnits);
+ }
+
+ CDialogBaseUnits(HWND hWnd)
+ {
+ if(!InitDialogBaseUnits(hWnd)) {
+ LONG nDlgBaseUnits = ::GetDialogBaseUnits();
+ m_sizeUnits.cx = LOWORD(nDlgBaseUnits);
+ m_sizeUnits.cy = HIWORD(nDlgBaseUnits);
+ }
+ }
+
+ CDialogBaseUnits(HFONT hFont, HWND hWnd = NULL)
+ {
+ if(!InitDialogBaseUnits(hFont, hWnd)) {
+ LONG nDlgBaseUnits = ::GetDialogBaseUnits();
+ m_sizeUnits.cx = LOWORD(nDlgBaseUnits);
+ m_sizeUnits.cy = HIWORD(nDlgBaseUnits);
+ }
+ }
+
+ CDialogBaseUnits(LOGFONT lf, HWND hWnd = NULL)
+ {
+ if(!InitDialogBaseUnits(lf, hWnd)) {
+ LONG nDlgBaseUnits = ::GetDialogBaseUnits();
+ m_sizeUnits.cx = LOWORD(nDlgBaseUnits);
+ m_sizeUnits.cy = HIWORD(nDlgBaseUnits);
+ }
+ }
+
+// Operations
+ BOOL InitDialogBaseUnits(HWND hWnd)
+ {
+ ATLASSERT(::IsWindow(hWnd));
+ RECT rc = { 0, 0, 4, 8 };
+ if(!::MapDialogRect(hWnd, &rc)) return FALSE;
+ m_sizeUnits.cx = rc.right;
+ m_sizeUnits.cy = rc.bottom;
+ return TRUE;
+ }
+
+ BOOL InitDialogBaseUnits(LOGFONT lf, HWND hWnd = NULL)
+ {
+ CFont font;
+ font.CreateFontIndirect(&lf);
+ if(font.IsNull()) return FALSE;
+ return InitDialogBaseUnits(font, hWnd);
+ }
+
+ BOOL InitDialogBaseUnits(HFONT hFont, HWND hWnd = NULL)
+ {
+ ATLASSERT(hFont != NULL);
+ CWindowDC dc = hWnd;
+ TEXTMETRIC tmText = { 0 };
+ SIZE sizeText = { 0 };
+ HFONT hFontOld = dc.SelectFont(hFont);
+ dc.GetTextMetrics(&tmText);
+ m_sizeUnits.cy = tmText.tmHeight + tmText.tmExternalLeading;
+ dc.GetTextExtent(_T("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"), 52, &sizeText);
+ m_sizeUnits.cx = (sizeText.cx + 26) / 52;
+ dc.SelectFont(hFontOld);
+ return TRUE;
+ }
+
+ SIZE GetDialogBaseUnits() const
+ {
+ return m_sizeUnits;
+ }
+
+ INT MapDialogPixelsX(INT x) const
+ {
+ return ::MulDiv(x, 4, m_sizeUnits.cx); // Pixels X to DLU
+ }
+
+ INT MapDialogPixelsY(INT y) const
+ {
+ return ::MulDiv(y, 8, m_sizeUnits.cy); // Pixels Y to DLU
+ }
+
+ POINT MapDialogPixels(POINT pt) const
+ {
+ POINT out = { MapDialogPixelsX(pt.x), MapDialogPixelsY(pt.y) };
+ return out;
+ }
+
+ SIZE MapDialogPixels(SIZE input) const
+ {
+ SIZE out = { MapDialogPixelsX(input.cx), MapDialogPixelsY(input.cy) };
+ return out;
+ }
+
+ RECT MapDialogPixels(RECT input) const
+ {
+ RECT out = { MapDialogPixelsX(input.left), MapDialogPixelsY(input.top), MapDialogPixelsX(input.right), MapDialogPixelsY(input.bottom) };
+ return out;
+ }
+
+ INT MapDialogUnitsX(INT x) const
+ {
+ return ::MulDiv(x, m_sizeUnits.cx, 4); // DLU to Pixels X
+ }
+
+ INT MapDialogUnitsY(INT y) const
+ {
+ return ::MulDiv(y, m_sizeUnits.cx, 8); // DLU to Pixels Y
+ }
+
+ POINT MapDialogUnits(POINT pt) const
+ {
+ POINT out = { MapDialogUnitsX(pt.x), MapDialogUnitsY(pt.y) };
+ return out;
+ }
+
+ SIZE MapDialogUnits(SIZE input) const
+ {
+ SIZE out = { MapDialogUnitsX(input.cx), MapDialogUnitsY(input.cy) };
+ return out;
+ }
+
+ RECT MapDialogUnits(RECT input) const
+ {
+ RECT out = { MapDialogUnitsX(input.left), MapDialogUnitsY(input.top), MapDialogUnitsX(input.right), MapDialogUnitsY(input.bottom) };
+ return out;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CMemDlgTemplate - in-memory dialog template - DLGTEMPLATE or DLGTEMPLATEEX
+
+#if (_ATL_VER >= 0x800)
+ typedef ATL::_DialogSplitHelper::DLGTEMPLATEEX DLGTEMPLATEEX;
+ typedef ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX DLGITEMTEMPLATEEX;
+#else // (_ATL_VER >= 0x800)
+ typedef ATL::_DialogSizeHelper::_ATL_DLGTEMPLATEEX DLGTEMPLATEEX;
+ #pragma pack(push, 4)
+ struct DLGITEMTEMPLATEEX
+ {
+ DWORD helpID;
+ DWORD exStyle;
+ DWORD style;
+ short x;
+ short y;
+ short cx;
+ short cy;
+ DWORD id;
+ };
+ #pragma pack(pop)
+#endif // (_ATL_VER >= 0x800)
+
+
+class CMemDlgTemplate
+{
+public:
+ enum StdCtrlType
+ {
+ CTRL_BUTTON = 0x0080,
+ CTRL_EDIT = 0x0081,
+ CTRL_STATIC = 0x0082,
+ CTRL_LISTBOX = 0x0083,
+ CTRL_SCROLLBAR = 0x0084,
+ CTRL_COMBOBOX = 0x0085
+ };
+
+ CMemDlgTemplate() : m_hData(NULL), m_pData(NULL), m_pPtr(NULL), m_cAllocated(0)
+ { }
+
+ ~CMemDlgTemplate()
+ {
+ Reset();
+ }
+
+ bool IsValid() const
+ {
+ return (m_pData != NULL);
+ }
+
+ bool IsTemplateEx() const
+ {
+ return (IsValid() && ((DLGTEMPLATEEX*)m_pData)->signature == 0xFFFF);
+ }
+
+ LPDLGTEMPLATE GetTemplatePtr()
+ {
+ return reinterpret_cast<LPDLGTEMPLATE>(m_pData);
+ }
+
+ DLGTEMPLATEEX* GetTemplateExPtr()
+ {
+ return reinterpret_cast<DLGTEMPLATEEX*>(m_pData);
+ }
+
+ void Reset()
+ {
+ if (IsValid()) {
+#ifndef UNDER_CE
+ ::GlobalUnlock(m_pData);
+#endif
+ ATLVERIFY(::GlobalFree(m_hData) == NULL);
+ }
+
+ m_hData = NULL;
+ m_pData = NULL;
+ m_pPtr = NULL;
+ m_cAllocated = 0;
+ }
+
+ void Create(bool bDlgEx, LPCTSTR lpszCaption, RECT rc, DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ LPCTSTR lpstrFontName = NULL, WORD wFontSize = 0, WORD wWeight = 0, BYTE bItalic = 0, BYTE bCharset = 0, DWORD dwHelpID = 0,
+ ATL::_U_STRINGorID ClassName = 0U, ATL::_U_STRINGorID Menu = 0U)
+ {
+ Create(bDlgEx, lpszCaption, (short) rc.left, (short) rc.top, (short) (rc.right - rc.left), (short) (rc.bottom - rc.top), dwStyle, dwExStyle,
+ lpstrFontName, wFontSize, wWeight, bItalic, bCharset, dwHelpID, ClassName.m_lpstr, Menu.m_lpstr);
+ }
+
+ void Create(bool bDlgEx, LPCTSTR lpszCaption, short nX, short nY, short nWidth, short nHeight, DWORD dwStyle = 0, DWORD dwExStyle = 0,
+ LPCTSTR lpstrFontName = NULL, WORD wFontSize = 0, WORD wWeight = 0, BYTE bItalic = 0, BYTE bCharset = 0, DWORD dwHelpID = 0,
+ ATL::_U_STRINGorID ClassName = 0U, ATL::_U_STRINGorID Menu = 0U)
+ {
+ // Should have DS_SETFONT style to set the dialog font name and size
+ if (lpstrFontName != NULL)
+ {
+ dwStyle |= DS_SETFONT;
+ }
+ else
+ {
+ dwStyle &= ~DS_SETFONT;
+ }
+
+ if (bDlgEx)
+ {
+ DLGTEMPLATEEX dlg = {1, 0xFFFF, dwHelpID, dwExStyle, dwStyle, 0, nX, nY, nWidth, nHeight};
+ AddData(&dlg, sizeof(dlg));
+ }
+ else
+ {
+ DLGTEMPLATE dlg = {dwStyle, dwExStyle, 0, nX, nY, nWidth, nHeight};
+ AddData(&dlg, sizeof(dlg));
+ }
+
+#ifndef _WIN32_WCE
+ if (Menu.m_lpstr == NULL)
+ {
+ WORD menuData = 0;
+ AddData(&menuData, sizeof(WORD));
+ }
+ else if (IS_INTRESOURCE(Menu.m_lpstr))
+ {
+ WORD menuData[] = {0xFFFF, (WORD)Menu.m_lpstr};
+ AddData(menuData, sizeof(menuData));
+ }
+ else
+ {
+ AddString(Menu.m_lpstr);
+ }
+#else // _WIN32_WCE
+ // Windows CE doesn't support the addition of menus to a dialog box
+ ATLASSERT(Menu.m_lpstr == NULL);
+ Menu.m_lpstr; // avoid level 4 warning
+ WORD menuData = 0;
+ AddData(&menuData, sizeof(WORD));
+#endif // _WIN32_WCE
+
+ if (ClassName.m_lpstr == NULL)
+ {
+ WORD classData = 0;
+ AddData(&classData, sizeof(WORD));
+ }
+ else if (IS_INTRESOURCE(ClassName.m_lpstr))
+ {
+ WORD classData[] = {0xFFFF, (WORD)ClassName.m_lpstr};
+ AddData(classData, sizeof(classData));
+ }
+ else
+ {
+ AddString(ClassName.m_lpstr);
+ }
+
+ // Set dialog caption
+ AddString(lpszCaption);
+
+ if (lpstrFontName != NULL)
+ {
+ AddData(&wFontSize, sizeof(wFontSize));
+
+ if (bDlgEx)
+ {
+ AddData(&wWeight, sizeof(wWeight));
+ AddData(&bItalic, sizeof(bItalic));
+ AddData(&bCharset, sizeof(bCharset));
+ }
+
+ AddString(lpstrFontName);
+ }
+ }
+
+ void AddControl(ATL::_U_STRINGorID ClassName, WORD wId, RECT rc, DWORD dwStyle, DWORD dwExStyle,
+ ATL::_U_STRINGorID Text, const WORD* pCreationData = NULL, WORD nCreationData = 0, DWORD dwHelpID = 0)
+ {
+ AddControl(ClassName.m_lpstr, wId, (short) rc.left, (short) rc.top, (short) (rc.right - rc.left), (short) (rc.bottom - rc.top), dwStyle, dwExStyle,
+ Text.m_lpstr, pCreationData, nCreationData, dwHelpID);
+ }
+
+ void AddControl(ATL::_U_STRINGorID ClassName, WORD wId, short nX, short nY, short nWidth, short nHeight, DWORD dwStyle, DWORD dwExStyle,
+ ATL::_U_STRINGorID Text, const WORD* pCreationData = NULL, WORD nCreationData = 0, DWORD dwHelpID = 0)
+ {
+ ATLASSERT(IsValid());
+
+ // DWORD align data
+ m_pPtr = (LPBYTE)(DWORD_PTR)((DWORD)(DWORD_PTR)(m_pPtr + 3) & (~3));
+
+ if (IsTemplateEx())
+ {
+ DLGTEMPLATEEX* dlg = (DLGTEMPLATEEX*)m_pData;
+ dlg->cDlgItems++;
+
+ DLGITEMTEMPLATEEX item = {dwHelpID, ATL::CControlWinTraits::GetWndExStyle(0) | dwExStyle, ATL::CControlWinTraits::GetWndStyle(0) | dwStyle, nX, nY, nWidth, nHeight, wId};
+ AddData(&item, sizeof(item));
+ }
+ else
+ {
+ LPDLGTEMPLATE dlg = (LPDLGTEMPLATE)m_pData;
+ dlg->cdit++;
+
+ DLGITEMTEMPLATE item = {ATL::CControlWinTraits::GetWndStyle(0) | dwStyle, ATL::CControlWinTraits::GetWndExStyle(0) | dwExStyle, nX, nY, nWidth, nHeight, wId};
+ AddData(&item, sizeof(item));
+ }
+
+ ATLASSERT(ClassName.m_lpstr != NULL);
+ if (IS_INTRESOURCE(ClassName.m_lpstr))
+ {
+ WORD wData[] = {0xFFFF, (WORD)ClassName.m_lpstr};
+ AddData(wData, sizeof(wData));
+ }
+ else
+ {
+ AddString(ClassName.m_lpstr);
+ }
+
+ if (Text.m_lpstr == NULL)
+ {
+ WORD classData = 0;
+ AddData(&classData, sizeof(WORD));
+ }
+ else if (IS_INTRESOURCE(Text.m_lpstr))
+ {
+ WORD wData[] = {0xFFFF, (WORD)Text.m_lpstr};
+ AddData(wData, sizeof(wData));
+ }
+ else
+ {
+ AddString(Text.m_lpstr);
+ }
+
+ AddData(&nCreationData, sizeof(nCreationData));
+
+ if ((nCreationData != 0))
+ {
+ ATLASSERT(pCreationData != NULL);
+ AddData(pCreationData, nCreationData * sizeof(WORD));
+ }
+ }
+
+ void AddStdControl(StdCtrlType CtrlType, WORD wId, short nX, short nY, short nWidth, short nHeight,
+ DWORD dwStyle, DWORD dwExStyle, ATL::_U_STRINGorID Text, const WORD* pCreationData = NULL, WORD nCreationData = 0, DWORD dwHelpID = 0)
+ {
+ AddControl(CtrlType, wId, nX, nY, nWidth, nHeight, dwStyle, dwExStyle, Text, pCreationData, nCreationData, dwHelpID);
+ }
+
+ void AddData(LPCVOID pData, size_t nData)
+ {
+ ATLASSERT(pData != NULL);
+
+ const SIZE_T ALLOCATION_INCREMENT = 1024;
+
+ if (m_pData == NULL)
+ {
+ m_cAllocated = ((nData / ALLOCATION_INCREMENT) + 1) * ALLOCATION_INCREMENT;
+ m_hData = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, m_cAllocated);
+ ATLASSERT(m_hData != NULL);
+#ifndef UNDER_CE
+ m_pPtr = m_pData = static_cast<LPBYTE>(::GlobalLock(m_hData));
+#else
+ m_pPtr = m_pData = static_cast<LPBYTE>(m_hData);
+#endif
+ ATLASSERT(m_pData != NULL);
+ }
+ else if (((m_pPtr - m_pData) + nData) > m_cAllocated)
+ {
+ SIZE_T ptrPos = (m_pPtr - m_pData);
+ m_cAllocated += ((nData / ALLOCATION_INCREMENT) + 1) * ALLOCATION_INCREMENT;
+#ifndef UNDER_CE
+ ::GlobalUnlock(m_pData);
+#endif
+ m_hData = ::GlobalReAlloc(m_hData, m_cAllocated, GMEM_MOVEABLE | GMEM_ZEROINIT);
+ ATLASSERT(m_hData != NULL);
+#ifndef UNDER_CE
+ m_pData = static_cast<LPBYTE>(::GlobalLock(m_hData));
+#else
+ m_pData = static_cast<LPBYTE>(m_hData);
+#endif
+ ATLASSERT(m_pData != NULL);
+ m_pPtr = m_pData + ptrPos;
+ }
+
+ SecureHelper::memcpy_x(m_pPtr, m_cAllocated - (m_pPtr - m_pData), pData, nData);
+
+ m_pPtr += nData;
+ }
+
+ void AddString(LPCTSTR lpszStr)
+ {
+ if (lpszStr == NULL)
+ {
+ WCHAR szEmpty = 0;
+ AddData(&szEmpty, sizeof(szEmpty));
+ }
+ else
+ {
+ USES_CONVERSION;
+ LPCWSTR lpstr = T2CW(lpszStr);
+ int nSize = lstrlenW(lpstr) + 1;
+ AddData(lpstr, nSize * sizeof(WCHAR));
+ }
+ }
+
+ HANDLE m_hData;
+ LPBYTE m_pData;
+ LPBYTE m_pPtr;
+ SIZE_T m_cAllocated;
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Dialog and control macros for indirect dialogs
+
+// for DLGTEMPLATE
+#define BEGIN_DIALOG(x, y, width, height) \
+ void DoInitTemplate() \
+ { \
+ bool bExTemplate = false; \
+ short nX = x, nY = y, nWidth = width, nHeight = height; \
+ LPCTSTR szCaption = NULL; \
+ DWORD dwStyle = WS_POPUP | WS_BORDER | WS_SYSMENU; \
+ DWORD dwExStyle = 0; \
+ LPCTSTR szFontName = NULL; \
+ WORD wFontSize = 0; \
+ WORD wWeight = 0; \
+ BYTE bItalic = 0; \
+ BYTE bCharset = 0; \
+ DWORD dwHelpID = 0; \
+ ATL::_U_STRINGorID Menu = 0U; \
+ ATL::_U_STRINGorID ClassName = 0U;
+
+// for DLGTEMPLATEEX
+#define BEGIN_DIALOG_EX(x, y, width, height, helpID) \
+ void DoInitTemplate() \
+ { \
+ bool bExTemplate = true; \
+ short nX = x, nY = y, nWidth = width, nHeight = height; \
+ LPCTSTR szCaption = NULL; \
+ DWORD dwStyle = WS_POPUP | WS_BORDER | WS_SYSMENU; \
+ DWORD dwExStyle = 0; \
+ LPCTSTR szFontName = NULL; \
+ WORD wFontSize = 0; \
+ WORD wWeight = 0; \
+ BYTE bItalic = 0; \
+ BYTE bCharset = 0; \
+ DWORD dwHelpID = helpID; \
+ ATL::_U_STRINGorID Menu = 0U; \
+ ATL::_U_STRINGorID ClassName = 0U;
+
+#define END_DIALOG() \
+ m_Template.Create(bExTemplate, szCaption, nX, nY, nWidth, nHeight, dwStyle, dwExStyle, szFontName, wFontSize, wWeight, bItalic, bCharset, dwHelpID, ClassName, Menu); \
+ };
+
+#define DIALOG_CAPTION(caption) \
+ szCaption = caption;
+#define DIALOG_STYLE(style) \
+ dwStyle = style;
+#define DIALOG_EXSTYLE(exStyle) \
+ dwExStyle = exStyle;
+#define DIALOG_FONT(pointSize, typeFace) \
+ wFontSize = pointSize; \
+ szFontName = typeFace;
+#define DIALOG_FONT_EX(pointsize, typeface, weight, italic, charset) \
+ ATLASSERT(bExTemplate); \
+ wFontSize = pointsize; \
+ szFontName = typeface; \
+ wWeight = weight; \
+ bItalic = italic; \
+ bCharset = charset;
+#define DIALOG_MENU(menuName) \
+ Menu = menuName;
+#define DIALOG_CLASS(className) \
+ ClassName = className;
+
+#define BEGIN_CONTROLS_MAP() \
+ void DoInitControls() \
+ {
+
+#define END_CONTROLS_MAP() \
+ };
+
+
+#define CONTROL_LTEXT(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_STATIC, (WORD)id, x, y, width, height, style | SS_LEFT | WS_GROUP, exStyle, text, NULL, 0);
+#define CONTROL_CTEXT(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_STATIC, (WORD)id, x, y, width, height, style | SS_CENTER | WS_GROUP, exStyle, text, NULL, 0);
+#define CONTROL_RTEXT(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_STATIC, (WORD)id, x, y, width, height, style | SS_RIGHT | WS_GROUP, exStyle, text, NULL, 0);
+#define CONTROL_PUSHBUTTON(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_PUSHBUTTON | WS_TABSTOP, exStyle, text, NULL, 0);
+#define CONTROL_DEFPUSHBUTTON(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_DEFPUSHBUTTON | WS_TABSTOP, exStyle, text, NULL, 0);
+#ifndef _WIN32_WCE
+#define CONTROL_PUSHBOX(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_PUSHBOX | WS_TABSTOP, exStyle, text, NULL, 0);
+#endif // !_WIN32_WCE
+#define CONTROL_STATE3(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_3STATE | WS_TABSTOP, exStyle, text, NULL, 0);
+#define CONTROL_AUTO3STATE(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_AUTO3STATE | WS_TABSTOP, exStyle, text, NULL, 0);
+#define CONTROL_CHECKBOX(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_CHECKBOX | WS_TABSTOP, exStyle, text, NULL, 0);
+#define CONTROL_AUTOCHECKBOX(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_AUTOCHECKBOX | WS_TABSTOP, exStyle, text, NULL, 0);
+#define CONTROL_RADIOBUTTON(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_RADIOBUTTON | WS_TABSTOP, exStyle, text, NULL, 0);
+#define CONTROL_AUTORADIOBUTTON(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_AUTORADIOBUTTON | WS_TABSTOP, exStyle, text, NULL, 0);
+#define CONTROL_COMBOBOX(id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_COMBOBOX, (WORD)id, x, y, width, height, style | CBS_DROPDOWN | WS_TABSTOP, exStyle, (LPCTSTR)NULL, NULL, 0);
+#define CONTROL_EDITTEXT(id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_EDIT, (WORD)id, x, y, width, height, style | ES_LEFT | WS_BORDER | WS_TABSTOP, exStyle, (LPCTSTR)NULL, NULL, 0);
+#define CONTROL_GROUPBOX(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_BUTTON, (WORD)id, x, y, width, height, style | BS_GROUPBOX, exStyle, text, NULL, 0);
+#define CONTROL_LISTBOX(id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_LISTBOX, (WORD)id, x, y, width, height, style | LBS_NOTIFY | WS_BORDER, exStyle, (LPCTSTR)NULL, NULL, 0);
+#define CONTROL_SCROLLBAR(id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_SCROLLBAR, (WORD)id, x, y, width, height, style | SBS_HORZ, exStyle, (LPCTSTR)NULL, NULL, 0);
+#define CONTROL_ICON(text, id, x, y, width, height, style, exStyle) \
+ m_Template.AddStdControl(WTL::CMemDlgTemplate::CTRL_STATIC, (WORD)id, x, y, width, height, style | SS_ICON, exStyle, text, NULL, 0);
+#define CONTROL_CONTROL(text, id, className, style, x, y, width, height, exStyle) \
+ m_Template.AddControl(className, (WORD)id, x, y, width, height, style, exStyle, text, NULL, 0);
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CIndirectDialogImpl - dialogs with template in memory
+
+template <class T, class TDlgTemplate = CMemDlgTemplate, class TBase = ATL::CDialogImpl<T, ATL::CWindow> >
+class ATL_NO_VTABLE CIndirectDialogImpl : public TBase
+{
+public:
+ enum { IDD = 0 }; // no dialog template resource
+
+ TDlgTemplate m_Template;
+
+ void CreateTemplate()
+ {
+ T* pT = static_cast<T*>(this);
+ pT->DoInitTemplate();
+ pT->DoInitControls();
+ }
+
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow(), LPARAM dwInitParam = NULL)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_hWnd == NULL);
+
+ if (!m_Template.IsValid())
+ CreateTemplate();
+
+#if (_ATL_VER >= 0x0800)
+ // Allocate the thunk structure here, where we can fail gracefully.
+ BOOL result = m_thunk.Init(NULL, NULL);
+ if (result == FALSE)
+ {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return -1;
+ }
+#endif // (_ATL_VER >= 0x0800)
+
+ ModuleHelper::AddCreateWndData(&m_thunk.cd, pT);
+
+#ifdef _DEBUG
+ m_bModal = true;
+#endif // _DEBUG
+
+ return ::DialogBoxIndirectParam(ModuleHelper::GetResourceInstance(), m_Template.GetTemplatePtr(), hWndParent, (DLGPROC)T::StartDialogProc, dwInitParam);
+ }
+
+ HWND Create(HWND hWndParent, LPARAM dwInitParam = NULL)
+ {
+ T* pT = static_cast<T*>(this);
+ ATLASSERT(pT->m_hWnd == NULL);
+
+ if (!m_Template.IsValid())
+ CreateTemplate();
+
+#if (_ATL_VER >= 0x0800)
+ // Allocate the thunk structure here, where we can fail gracefully.
+ BOOL result = m_thunk.Init(NULL, NULL);
+ if (result == FALSE)
+ {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return NULL;
+ }
+#endif // (_ATL_VER >= 0x0800)
+
+ ModuleHelper::AddCreateWndData(&m_thunk.cd, pT);
+
+#ifdef _DEBUG
+ m_bModal = false;
+#endif // _DEBUG
+
+ HWND hWnd = ::CreateDialogIndirectParam(ModuleHelper::GetResourceInstance(), (LPCDLGTEMPLATE)m_Template.GetTemplatePtr(), hWndParent, (DLGPROC)T::StartDialogProc, dwInitParam);
+ ATLASSERT(m_hWnd == hWnd);
+
+ return hWnd;
+ }
+
+ // for CComControl
+ HWND Create(HWND hWndParent, RECT&, LPARAM dwInitParam = NULL)
+ {
+ return Create(hWndParent, dwInitParam);
+ }
+
+ void DoInitTemplate()
+ {
+ ATLASSERT(FALSE); // MUST be defined in derived class
+ }
+
+ void DoInitControls()
+ {
+ ATLASSERT(FALSE); // MUST be defined in derived class
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// CPropertySheetWindow - client side for a property sheet
+
+class CPropertySheetWindow : public ATL::CWindow
+{
+public:
+// Constructors
+ CPropertySheetWindow(HWND hWnd = NULL) : ATL::CWindow(hWnd)
+ { }
+
+ CPropertySheetWindow& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Attributes
+ int GetPageCount() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HWND hWndTabCtrl = GetTabControl();
+ ATLASSERT(hWndTabCtrl != NULL);
+ return (int)::SendMessage(hWndTabCtrl, TCM_GETITEMCOUNT, 0, 0L);
+ }
+
+ HWND GetActivePage() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HWND)::SendMessage(m_hWnd, PSM_GETCURRENTPAGEHWND, 0, 0L);
+ }
+
+ int GetActiveIndex() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ HWND hWndTabCtrl = GetTabControl();
+ ATLASSERT(hWndTabCtrl != NULL);
+ return (int)::SendMessage(hWndTabCtrl, TCM_GETCURSEL, 0, 0L);
+ }
+
+ BOOL SetActivePage(int nPageIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, PSM_SETCURSEL, nPageIndex, 0L);
+ }
+
+ BOOL SetActivePage(HPROPSHEETPAGE hPage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hPage != NULL);
+ return (BOOL)::SendMessage(m_hWnd, PSM_SETCURSEL, 0, (LPARAM)hPage);
+ }
+
+ BOOL SetActivePageByID(int nPageID)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, PSM_SETCURSELID, 0, nPageID);
+ }
+
+ void SetTitle(LPCTSTR lpszText, UINT nStyle = 0)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT((nStyle & ~PSH_PROPTITLE) == 0); // only PSH_PROPTITLE is valid
+ ATLASSERT(lpszText != NULL);
+ ::SendMessage(m_hWnd, PSM_SETTITLE, nStyle, (LPARAM)lpszText);
+ }
+
+ HWND GetTabControl() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HWND)::SendMessage(m_hWnd, PSM_GETTABCONTROL, 0, 0L);
+ }
+
+ void SetFinishText(LPCTSTR lpszText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_SETFINISHTEXT, 0, (LPARAM)lpszText);
+ }
+
+ void SetWizardButtons(DWORD dwFlags)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::PostMessage(m_hWnd, PSM_SETWIZBUTTONS, 0, dwFlags);
+ }
+
+// Operations
+ BOOL AddPage(HPROPSHEETPAGE hPage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hPage != NULL);
+ return (BOOL)::SendMessage(m_hWnd, PSM_ADDPAGE, 0, (LPARAM)hPage);
+ }
+
+ BOOL AddPage(LPCPROPSHEETPAGE pPage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(pPage != NULL);
+ HPROPSHEETPAGE hPage = ::CreatePropertySheetPage(pPage);
+ if(hPage == NULL)
+ return FALSE;
+ return (BOOL)::SendMessage(m_hWnd, PSM_ADDPAGE, 0, (LPARAM)hPage);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL InsertPage(int nNewPageIndex, HPROPSHEETPAGE hPage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hPage != NULL);
+ return (BOOL)::SendMessage(m_hWnd, PSM_INSERTPAGE, nNewPageIndex, (LPARAM)hPage);
+ }
+
+ BOOL InsertPage(int nNewPageIndex, LPCPROPSHEETPAGE pPage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(pPage != NULL);
+ HPROPSHEETPAGE hPage = ::CreatePropertySheetPage(pPage);
+ if(hPage == NULL)
+ return FALSE;
+ return (BOOL)::SendMessage(m_hWnd, PSM_INSERTPAGE, nNewPageIndex, (LPARAM)hPage);
+ }
+
+ BOOL InsertPage(HPROPSHEETPAGE hPageInsertAfter, HPROPSHEETPAGE hPage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hPage != NULL);
+ return (BOOL)::SendMessage(m_hWnd, PSM_INSERTPAGE, (WPARAM)hPageInsertAfter, (LPARAM)hPage);
+ }
+
+ BOOL InsertPage(HPROPSHEETPAGE hPageInsertAfter, LPCPROPSHEETPAGE pPage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(pPage != NULL);
+ HPROPSHEETPAGE hPage = ::CreatePropertySheetPage(pPage);
+ if(hPage == NULL)
+ return FALSE;
+ return (BOOL)::SendMessage(m_hWnd, PSM_INSERTPAGE, (WPARAM)hPageInsertAfter, (LPARAM)hPage);
+ }
+#endif // !_WIN32_WCE
+
+ void RemovePage(int nPageIndex)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_REMOVEPAGE, nPageIndex, 0L);
+ }
+
+ void RemovePage(HPROPSHEETPAGE hPage)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(hPage != NULL);
+ ::SendMessage(m_hWnd, PSM_REMOVEPAGE, 0, (LPARAM)hPage);
+ }
+
+ BOOL PressButton(int nButton)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, PSM_PRESSBUTTON, nButton, 0L);
+ }
+
+ BOOL Apply()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, PSM_APPLY, 0, 0L);
+ }
+
+ void CancelToClose()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_CANCELTOCLOSE, 0, 0L);
+ }
+
+ void SetModified(HWND hWndPage, BOOL bChanged = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(::IsWindow(hWndPage));
+ UINT uMsg = bChanged ? PSM_CHANGED : PSM_UNCHANGED;
+ ::SendMessage(m_hWnd, uMsg, (WPARAM)hWndPage, 0L);
+ }
+
+ LRESULT QuerySiblings(WPARAM wParam, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return ::SendMessage(m_hWnd, PSM_QUERYSIBLINGS, wParam, lParam);
+ }
+
+ void RebootSystem()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_REBOOTSYSTEM, 0, 0L);
+ }
+
+ void RestartWindows()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_RESTARTWINDOWS, 0, 0L);
+ }
+
+ BOOL IsDialogMessage(LPMSG lpMsg)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, PSM_ISDIALOGMESSAGE, 0, (LPARAM)lpMsg);
+ }
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ int HwndToIndex(HWND hWnd) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PSM_HWNDTOINDEX, (WPARAM)hWnd, 0L);
+ }
+
+ HWND IndexToHwnd(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HWND)::SendMessage(m_hWnd, PSM_INDEXTOHWND, nIndex, 0L);
+ }
+
+ int PageToIndex(HPROPSHEETPAGE hPage) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PSM_PAGETOINDEX, 0, (LPARAM)hPage);
+ }
+
+ HPROPSHEETPAGE IndexToPage(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HPROPSHEETPAGE)::SendMessage(m_hWnd, PSM_INDEXTOPAGE, nIndex, 0L);
+ }
+
+ int IdToIndex(int nID) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PSM_IDTOINDEX, 0, nID);
+ }
+
+ int IndexToId(int nIndex) const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PSM_INDEXTOID, nIndex, 0L);
+ }
+
+ int GetResult() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (int)::SendMessage(m_hWnd, PSM_GETRESULT, 0, 0L);
+ }
+
+ BOOL RecalcPageSizes()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (BOOL)::SendMessage(m_hWnd, PSM_RECALCPAGESIZES, 0, 0L);
+ }
+
+ void SetHeaderTitle(int nIndex, LPCTSTR lpstrHeaderTitle)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_SETHEADERTITLE, nIndex, (LPARAM)lpstrHeaderTitle);
+ }
+
+ void SetHeaderSubTitle(int nIndex, LPCTSTR lpstrHeaderSubTitle)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_SETHEADERSUBTITLE, nIndex, (LPARAM)lpstrHeaderSubTitle);
+ }
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+// Implementation - override to prevent usage
+ HWND Create(LPCTSTR, HWND, ATL::_U_RECT = NULL, LPCTSTR = NULL, DWORD = 0, DWORD = 0, ATL::_U_MENUorID = 0U, LPVOID = NULL)
+ {
+ ATLASSERT(FALSE);
+ return NULL;
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// CPropertySheetImpl - implements a property sheet
+
+template <class T, class TBase = CPropertySheetWindow>
+class ATL_NO_VTABLE CPropertySheetImpl : public ATL::CWindowImplBaseT< TBase >
+{
+public:
+ PROPSHEETHEADER m_psh;
+ ATL::CSimpleArray<HPROPSHEETPAGE> m_arrPages;
+
+#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC specific
+ #ifndef PROPSHEET_LINK_SIZE
+ #define PROPSHEET_LINK_SIZE 128
+ #endif // PROPSHEET_LINK_SIZE
+ TCHAR m_szLink[PROPSHEET_LINK_SIZE];
+ static LPCTSTR m_pszTitle;
+ static LPCTSTR m_pszLink;
+#endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
+
+// Construction/Destruction
+ CPropertySheetImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL, UINT uStartPage = 0, HWND hWndParent = NULL)
+ {
+ memset(&m_psh, 0, sizeof(PROPSHEETHEADER));
+ m_psh.dwSize = sizeof(PROPSHEETHEADER);
+ m_psh.dwFlags = PSH_USECALLBACK;
+ m_psh.hInstance = ModuleHelper::GetResourceInstance();
+ m_psh.phpage = NULL; // will be set later
+ m_psh.nPages = 0; // will be set later
+ m_psh.pszCaption = title.m_lpstr;
+ m_psh.nStartPage = uStartPage;
+ m_psh.hwndParent = hWndParent; // if NULL, will be set in DoModal/Create
+ m_psh.pfnCallback = T::PropSheetCallback;
+
+#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC specific
+ m_psh.dwFlags |= PSH_MAXIMIZE;
+ m_szLink[0] = 0;
+#endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
+ }
+
+ ~CPropertySheetImpl()
+ {
+ if(m_arrPages.GetSize() > 0) // sheet never created, destroy all pages
+ {
+ for(int i = 0; i < m_arrPages.GetSize(); i++)
+ ::DestroyPropertySheetPage((HPROPSHEETPAGE)m_arrPages[i]);
+ }
+ }
+
+// Callback function and overrideables
+ static int CALLBACK PropSheetCallback(HWND hWnd, UINT uMsg, LPARAM lParam)
+ {
+ lParam; // avoid level 4 warning
+ int nRet = 0;
+
+ if(uMsg == PSCB_INITIALIZED)
+ {
+ ATLASSERT(hWnd != NULL);
+ T* pT = (T*)ModuleHelper::ExtractCreateWndData();
+ // subclass the sheet window
+ pT->SubclassWindow(hWnd);
+ // remove page handles array
+ pT->_CleanUpPages();
+
+#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC specific
+ m_pszTitle = pT->m_psh.pszCaption;
+ if(*pT->m_szLink != 0)
+ m_pszLink = pT->m_szLink;
+#endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC specific
+
+ pT->OnSheetInitialized();
+ }
+#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC specific uMsg
+ else
+ {
+ switch(uMsg)
+ {
+ case PSCB_GETVERSION :
+ nRet = COMCTL32_VERSION;
+ break;
+ case PSCB_GETTITLE :
+ if(m_pszTitle != NULL)
+ {
+ lstrcpy((LPTSTR)lParam, m_pszTitle);
+ m_pszTitle = NULL;
+ }
+ break;
+ case PSCB_GETLINKTEXT:
+ if(m_pszLink != NULL)
+ {
+ lstrcpy((LPTSTR)lParam, m_pszLink);
+ m_pszLink = NULL;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+#endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
+
+ return nRet;
+ }
+
+ void OnSheetInitialized()
+ {
+ }
+
+// Create method
+ HWND Create(HWND hWndParent = NULL)
+ {
+ ATLASSERT(m_hWnd == NULL);
+
+ m_psh.dwFlags |= PSH_MODELESS;
+ if(m_psh.hwndParent == NULL)
+ m_psh.hwndParent = hWndParent;
+ m_psh.phpage = (HPROPSHEETPAGE*)m_arrPages.GetData();
+ m_psh.nPages = m_arrPages.GetSize();
+
+ T* pT = static_cast<T*>(this);
+ ModuleHelper::AddCreateWndData(&pT->m_thunk.cd, pT);
+
+ HWND hWnd = (HWND)::PropertySheet(&m_psh);
+ _CleanUpPages(); // ensure clean-up, required if call failed
+
+ ATLASSERT(m_hWnd == hWnd);
+
+ return hWnd;
+ }
+
+ INT_PTR DoModal(HWND hWndParent = ::GetActiveWindow())
+ {
+ ATLASSERT(m_hWnd == NULL);
+
+ m_psh.dwFlags &= ~PSH_MODELESS;
+ if(m_psh.hwndParent == NULL)
+ m_psh.hwndParent = hWndParent;
+ m_psh.phpage = (HPROPSHEETPAGE*)m_arrPages.GetData();
+ m_psh.nPages = m_arrPages.GetSize();
+
+ T* pT = static_cast<T*>(this);
+ ModuleHelper::AddCreateWndData(&pT->m_thunk.cd, pT);
+
+ INT_PTR nRet = ::PropertySheet(&m_psh);
+ _CleanUpPages(); // ensure clean-up, required if call failed
+
+ return nRet;
+ }
+
+ // implementation helper - clean up pages array
+ void _CleanUpPages()
+ {
+ m_psh.nPages = 0;
+ m_psh.phpage = NULL;
+ m_arrPages.RemoveAll();
+ }
+
+// Attributes (extended overrides of client class methods)
+// These now can be called before the sheet is created
+// Note: Calling these after the sheet is created gives unpredictable results
+ int GetPageCount() const
+ {
+ if(m_hWnd == NULL) // not created yet
+ return m_arrPages.GetSize();
+ return TBase::GetPageCount();
+ }
+
+ int GetActiveIndex() const
+ {
+ if(m_hWnd == NULL) // not created yet
+ return m_psh.nStartPage;
+ return TBase::GetActiveIndex();
+ }
+
+ HPROPSHEETPAGE GetPage(int nPageIndex) const
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+ return (HPROPSHEETPAGE)m_arrPages[nPageIndex];
+ }
+
+ int GetPageIndex(HPROPSHEETPAGE hPage) const
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+ return m_arrPages.Find((HPROPSHEETPAGE&)hPage);
+ }
+
+ BOOL SetActivePage(int nPageIndex)
+ {
+ if(m_hWnd == NULL) // not created yet
+ {
+ ATLASSERT(nPageIndex >= 0 && nPageIndex < m_arrPages.GetSize());
+ m_psh.nStartPage = nPageIndex;
+ return TRUE;
+ }
+ return TBase::SetActivePage(nPageIndex);
+ }
+
+ BOOL SetActivePage(HPROPSHEETPAGE hPage)
+ {
+ ATLASSERT(hPage != NULL);
+ if (m_hWnd == NULL) // not created yet
+ {
+ int nPageIndex = GetPageIndex(hPage);
+ if(nPageIndex == -1)
+ return FALSE;
+
+ return SetActivePage(nPageIndex);
+ }
+ return TBase::SetActivePage(hPage);
+
+ }
+
+ void SetTitle(LPCTSTR lpszText, UINT nStyle = 0)
+ {
+ ATLASSERT((nStyle & ~PSH_PROPTITLE) == 0); // only PSH_PROPTITLE is valid
+ ATLASSERT(lpszText != NULL);
+
+ if(m_hWnd == NULL)
+ {
+ // set internal state
+ m_psh.pszCaption = lpszText; // must exist until sheet is created
+ m_psh.dwFlags &= ~PSH_PROPTITLE;
+ m_psh.dwFlags |= nStyle;
+ }
+ else
+ {
+ // set external state
+ TBase::SetTitle(lpszText, nStyle);
+ }
+ }
+
+#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC specific Link field
+ void SetLinkText(LPCTSTR lpszText)
+ {
+ ATLASSERT(lpszText != NULL);
+ ATLASSERT(lstrlen(lpszText) < PROPSHEET_LINK_SIZE);
+ lstrcpy(m_szLink, lpszText);
+ }
+#endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
+
+ void SetWizardMode()
+ {
+ m_psh.dwFlags |= PSH_WIZARD;
+ }
+
+ void EnableHelp()
+ {
+ m_psh.dwFlags |= PSH_HASHELP;
+ }
+
+// Operations
+ BOOL AddPage(HPROPSHEETPAGE hPage)
+ {
+ ATLASSERT(hPage != NULL);
+ BOOL bRet = FALSE;
+ if(m_hWnd != NULL)
+ bRet = TBase::AddPage(hPage);
+ else // sheet not created yet, use internal data
+ bRet = m_arrPages.Add((HPROPSHEETPAGE&)hPage);
+ return bRet;
+ }
+
+ BOOL AddPage(LPCPROPSHEETPAGE pPage)
+ {
+ ATLASSERT(pPage != NULL);
+ HPROPSHEETPAGE hPage = ::CreatePropertySheetPage(pPage);
+ if(hPage == NULL)
+ return FALSE;
+ BOOL bRet = AddPage(hPage);
+ if(!bRet)
+ ::DestroyPropertySheetPage(hPage);
+ return bRet;
+ }
+
+ BOOL RemovePage(HPROPSHEETPAGE hPage)
+ {
+ ATLASSERT(hPage != NULL);
+ if (m_hWnd == NULL) // not created yet
+ {
+ int nPage = GetPageIndex(hPage);
+ if(nPage == -1)
+ return FALSE;
+ return RemovePage(nPage);
+ }
+ TBase::RemovePage(hPage);
+ return TRUE;
+
+ }
+
+ BOOL RemovePage(int nPageIndex)
+ {
+ BOOL bRet = TRUE;
+ if(m_hWnd != NULL)
+ TBase::RemovePage(nPageIndex);
+ else // sheet not created yet, use internal data
+ bRet = m_arrPages.RemoveAt(nPageIndex);
+ return bRet;
+ }
+
+#if (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+ void SetHeader(LPCTSTR szbmHeader)
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+
+ m_psh.dwFlags &= ~PSH_WIZARD;
+ m_psh.dwFlags |= (PSH_HEADER | PSH_WIZARD97);
+ m_psh.pszbmHeader = szbmHeader;
+ }
+
+ void SetHeader(HBITMAP hbmHeader)
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+
+ m_psh.dwFlags &= ~PSH_WIZARD;
+ m_psh.dwFlags |= (PSH_HEADER | PSH_USEHBMHEADER | PSH_WIZARD97);
+ m_psh.hbmHeader = hbmHeader;
+ }
+
+ void SetWatermark(LPCTSTR szbmWatermark, HPALETTE hplWatermark = NULL)
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+
+ m_psh.dwFlags &= ~PSH_WIZARD;
+ m_psh.dwFlags |= PSH_WATERMARK | PSH_WIZARD97;
+ m_psh.pszbmWatermark = szbmWatermark;
+
+ if (hplWatermark != NULL)
+ {
+ m_psh.dwFlags |= PSH_USEHPLWATERMARK;
+ m_psh.hplWatermark = hplWatermark;
+ }
+ }
+
+ void SetWatermark(HBITMAP hbmWatermark, HPALETTE hplWatermark = NULL)
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+
+ m_psh.dwFlags &= ~PSH_WIZARD;
+ m_psh.dwFlags |= (PSH_WATERMARK | PSH_USEHBMWATERMARK | PSH_WIZARD97);
+ m_psh.hbmWatermark = hbmWatermark;
+
+ if (hplWatermark != NULL)
+ {
+ m_psh.dwFlags |= PSH_USEHPLWATERMARK;
+ m_psh.hplWatermark = hplWatermark;
+ }
+ }
+
+ void StretchWatermark(bool bStretchWatermark)
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+ if (bStretchWatermark)
+ m_psh.dwFlags |= PSH_STRETCHWATERMARK;
+ else
+ m_psh.dwFlags &= ~PSH_STRETCHWATERMARK;
+ }
+#endif // (_WIN32_IE >= 0x0400) && !defined(_WIN32_WCE)
+
+// Message map and handlers
+ BEGIN_MSG_MAP(CPropertySheetImpl)
+ MESSAGE_HANDLER(WM_COMMAND, OnCommand)
+ MESSAGE_HANDLER(WM_SYSCOMMAND, OnSysCommand)
+ END_MSG_MAP()
+
+ LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
+ {
+ LRESULT lRet = DefWindowProc(uMsg, wParam, lParam);
+ if(HIWORD(wParam) == BN_CLICKED && (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) &&
+ ((m_psh.dwFlags & PSH_MODELESS) != 0) && (GetActivePage() == NULL))
+ DestroyWindow();
+ return lRet;
+ }
+
+ LRESULT OnSysCommand(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled)
+ {
+ if(((m_psh.dwFlags & PSH_MODELESS) == PSH_MODELESS) && ((wParam & 0xFFF0) == SC_CLOSE))
+ SendMessage(WM_CLOSE);
+ else
+ bHandled = FALSE;
+ return 0;
+ }
+};
+
+#if defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__) // PPC static pointers
+template < class T, class TBase >
+LPCWSTR CPropertySheetImpl<T,TBase>::m_pszTitle = NULL;
+template < class T, class TBase>
+LPCWSTR CPropertySheetImpl<T,TBase>::m_pszLink = NULL;
+#endif // defined(_AYGSHELL_H_) || defined(__AYGSHELL_H__)
+
+// for non-customized sheets
+class CPropertySheet : public CPropertySheetImpl<CPropertySheet>
+{
+public:
+ CPropertySheet(ATL::_U_STRINGorID title = (LPCTSTR)NULL, UINT uStartPage = 0, HWND hWndParent = NULL)
+ : CPropertySheetImpl<CPropertySheet>(title, uStartPage, hWndParent)
+ { }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CPropertyPageWindow - client side for a property page
+
+class CPropertyPageWindow : public ATL::CWindow
+{
+public:
+// Constructors
+ CPropertyPageWindow(HWND hWnd = NULL) : ATL::CWindow(hWnd)
+ { }
+
+ CPropertyPageWindow& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Attributes
+ CPropertySheetWindow GetPropertySheet() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CPropertySheetWindow(GetParent());
+ }
+
+// Operations
+ BOOL Apply()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ return GetPropertySheet().Apply();
+ }
+
+ void CancelToClose()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetPropertySheet().CancelToClose();
+ }
+
+ void SetModified(BOOL bChanged = TRUE)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetPropertySheet().SetModified(m_hWnd, bChanged);
+ }
+
+ LRESULT QuerySiblings(WPARAM wParam, LPARAM lParam)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ return GetPropertySheet().QuerySiblings(wParam, lParam);
+ }
+
+ void RebootSystem()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetPropertySheet().RebootSystem();
+ }
+
+ void RestartWindows()
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetPropertySheet().RestartWindows();
+ }
+
+ void SetWizardButtons(DWORD dwFlags)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetPropertySheet().SetWizardButtons(dwFlags);
+ }
+
+// Implementation - overrides to prevent usage
+ HWND Create(LPCTSTR, HWND, ATL::_U_RECT = NULL, LPCTSTR = NULL, DWORD = 0, DWORD = 0, ATL::_U_MENUorID = 0U, LPVOID = NULL)
+ {
+ ATLASSERT(FALSE);
+ return NULL;
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// CPropertyPageImpl - implements a property page
+
+template <class T, class TBase = CPropertyPageWindow>
+class ATL_NO_VTABLE CPropertyPageImpl : public ATL::CDialogImplBaseT< TBase >
+{
+public:
+ PROPSHEETPAGE m_psp;
+
+ operator PROPSHEETPAGE*() { return &m_psp; }
+
+// Construction
+ CPropertyPageImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL)
+ {
+ // initialize PROPSHEETPAGE struct
+ memset(&m_psp, 0, sizeof(PROPSHEETPAGE));
+ m_psp.dwSize = sizeof(PROPSHEETPAGE);
+ m_psp.dwFlags = PSP_USECALLBACK;
+ m_psp.hInstance = ModuleHelper::GetResourceInstance();
+ T* pT = static_cast<T*>(this);
+ m_psp.pszTemplate = MAKEINTRESOURCE(pT->IDD);
+ m_psp.pfnDlgProc = (DLGPROC)T::StartDialogProc;
+ m_psp.pfnCallback = T::PropPageCallback;
+ m_psp.lParam = (LPARAM)pT;
+
+ if(title.m_lpstr != NULL)
+ SetTitle(title);
+ }
+
+// Callback function and overrideables
+ static UINT CALLBACK PropPageCallback(HWND hWnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
+ {
+ hWnd; // avoid level 4 warning
+ ATLASSERT(hWnd == NULL);
+ T* pT = (T*)ppsp->lParam;
+ UINT uRet = 0;
+
+ switch(uMsg)
+ {
+ case PSPCB_CREATE:
+ {
+ ATL::CDialogImplBaseT< TBase >* pPage = (ATL::CDialogImplBaseT< TBase >*)pT;
+ ModuleHelper::AddCreateWndData(&pPage->m_thunk.cd, pPage);
+ uRet = pT->OnPageCreate() ? 1 : 0;
+ }
+ break;
+#if (_WIN32_IE >= 0x0500)
+ case PSPCB_ADDREF:
+ pT->OnPageAddRef();
+ break;
+#endif // (_WIN32_IE >= 0x0500)
+ case PSPCB_RELEASE:
+ pT->OnPageRelease();
+ break;
+ default:
+ break;
+ }
+
+ return uRet;
+ }
+
+ bool OnPageCreate()
+ {
+ return true; // true - allow page to be created, false - prevent creation
+ }
+
+#if (_WIN32_IE >= 0x0500)
+ void OnPageAddRef()
+ {
+ }
+#endif // (_WIN32_IE >= 0x0500)
+
+ void OnPageRelease()
+ {
+ }
+
+// Create method
+ HPROPSHEETPAGE Create()
+ {
+ return ::CreatePropertySheetPage(&m_psp);
+ }
+
+// Attributes
+ void SetTitle(ATL::_U_STRINGorID title)
+ {
+ m_psp.pszTitle = title.m_lpstr;
+ m_psp.dwFlags |= PSP_USETITLE;
+ }
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+ void SetHeaderTitle(LPCTSTR lpstrHeaderTitle)
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+ m_psp.dwFlags |= PSP_USEHEADERTITLE;
+ m_psp.pszHeaderTitle = lpstrHeaderTitle;
+ }
+
+ void SetHeaderSubTitle(LPCTSTR lpstrHeaderSubTitle)
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+ m_psp.dwFlags |= PSP_USEHEADERSUBTITLE;
+ m_psp.pszHeaderSubTitle = lpstrHeaderSubTitle;
+ }
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+// Operations
+ void EnableHelp()
+ {
+ m_psp.dwFlags |= PSP_HASHELP;
+ }
+
+// Message map and handlers
+ BEGIN_MSG_MAP(CPropertyPageImpl)
+ MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
+ END_MSG_MAP()
+
+ // NOTE: Define _WTL_NEW_PAGE_NOTIFY_HANDLERS to use new notification
+ // handlers that return direct values without any restrictions
+ LRESULT OnNotify(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
+ {
+#ifndef _WIN32_WCE
+ // This notification is sometimes received on Windows CE after the window is already destroyed
+ ATLASSERT(::IsWindow(m_hWnd));
+#endif
+ NMHDR* pNMHDR = (NMHDR*)lParam;
+
+ // don't handle messages not from the page/sheet itself
+ if(pNMHDR->hwndFrom != m_hWnd && pNMHDR->hwndFrom != ::GetParent(m_hWnd))
+ {
+ bHandled = FALSE;
+ return 1;
+ }
+#ifdef _WIN32_WCE
+ ATLASSERT(::IsWindow(m_hWnd));
+#endif
+
+ T* pT = static_cast<T*>(this);
+ LRESULT lResult = 0;
+ switch(pNMHDR->code)
+ {
+#ifdef _WTL_NEW_PAGE_NOTIFY_HANDLERS
+ case PSN_SETACTIVE:
+ lResult = pT->OnSetActive();
+ break;
+ case PSN_KILLACTIVE:
+ lResult = pT->OnKillActive();
+ break;
+ case PSN_APPLY:
+ lResult = pT->OnApply();
+ break;
+ case PSN_RESET:
+ pT->OnReset();
+ break;
+ case PSN_QUERYCANCEL:
+ lResult = pT->OnQueryCancel();
+ break;
+ case PSN_WIZNEXT:
+ lResult = pT->OnWizardNext();
+ break;
+ case PSN_WIZBACK:
+ lResult = pT->OnWizardBack();
+ break;
+ case PSN_WIZFINISH:
+ lResult = pT->OnWizardFinish();
+ break;
+ case PSN_HELP:
+ pT->OnHelp();
+ break;
+#ifndef _WIN32_WCE
+#if (_WIN32_IE >= 0x0400)
+ case PSN_GETOBJECT:
+ if(!pT->OnGetObject((LPNMOBJECTNOTIFY)lParam))
+ bHandled = FALSE;
+ break;
+#endif // (_WIN32_IE >= 0x0400)
+#if (_WIN32_IE >= 0x0500)
+ case PSN_TRANSLATEACCELERATOR:
+ {
+ LPPSHNOTIFY lpPSHNotify = (LPPSHNOTIFY)lParam;
+ lResult = pT->OnTranslateAccelerator((LPMSG)lpPSHNotify->lParam);
+ }
+ break;
+ case PSN_QUERYINITIALFOCUS:
+ {
+ LPPSHNOTIFY lpPSHNotify = (LPPSHNOTIFY)lParam;
+ lResult = (LRESULT)pT->OnQueryInitialFocus((HWND)lpPSHNotify->lParam);
+ }
+ break;
+#endif // (_WIN32_IE >= 0x0500)
+#endif // !_WIN32_WCE
+
+#else // !_WTL_NEW_PAGE_NOTIFY_HANDLERS
+ case PSN_SETACTIVE:
+ lResult = pT->OnSetActive() ? 0 : -1;
+ break;
+ case PSN_KILLACTIVE:
+ lResult = !pT->OnKillActive();
+ break;
+ case PSN_APPLY:
+ lResult = pT->OnApply() ? PSNRET_NOERROR : PSNRET_INVALID_NOCHANGEPAGE;
+ break;
+ case PSN_RESET:
+ pT->OnReset();
+ break;
+ case PSN_QUERYCANCEL:
+ lResult = !pT->OnQueryCancel();
+ break;
+ case PSN_WIZNEXT:
+ lResult = pT->OnWizardNext();
+ break;
+ case PSN_WIZBACK:
+ lResult = pT->OnWizardBack();
+ break;
+ case PSN_WIZFINISH:
+ lResult = !pT->OnWizardFinish();
+ break;
+ case PSN_HELP:
+ pT->OnHelp();
+ break;
+#ifndef _WIN32_WCE
+#if (_WIN32_IE >= 0x0400)
+ case PSN_GETOBJECT:
+ if(!pT->OnGetObject((LPNMOBJECTNOTIFY)lParam))
+ bHandled = FALSE;
+ break;
+#endif // (_WIN32_IE >= 0x0400)
+#if (_WIN32_IE >= 0x0500)
+ case PSN_TRANSLATEACCELERATOR:
+ {
+ LPPSHNOTIFY lpPSHNotify = (LPPSHNOTIFY)lParam;
+ lResult = pT->OnTranslateAccelerator((LPMSG)lpPSHNotify->lParam) ? PSNRET_MESSAGEHANDLED : PSNRET_NOERROR;
+ }
+ break;
+ case PSN_QUERYINITIALFOCUS:
+ {
+ LPPSHNOTIFY lpPSHNotify = (LPPSHNOTIFY)lParam;
+ lResult = (LRESULT)pT->OnQueryInitialFocus((HWND)lpPSHNotify->lParam);
+ }
+ break;
+#endif // (_WIN32_IE >= 0x0500)
+#endif // !_WIN32_WCE
+
+#endif // !_WTL_NEW_PAGE_NOTIFY_HANDLERS
+ default:
+ bHandled = FALSE; // not handled
+ }
+
+ return lResult;
+ }
+
+// Overridables
+ // NOTE: Define _WTL_NEW_PAGE_NOTIFY_HANDLERS to use new notification
+ // handlers that return direct values without any restrictions
+#ifdef _WTL_NEW_PAGE_NOTIFY_HANDLERS
+ int OnSetActive()
+ {
+ // 0 = allow activate
+ // -1 = go back that was active
+ // page ID = jump to page
+ return 0;
+ }
+
+ BOOL OnKillActive()
+ {
+ // FALSE = allow deactivate
+ // TRUE = prevent deactivation
+ return FALSE;
+ }
+
+ int OnApply()
+ {
+ // PSNRET_NOERROR = apply OK
+ // PSNRET_INVALID = apply not OK, return to this page
+ // PSNRET_INVALID_NOCHANGEPAGE = apply not OK, don't change focus
+ return PSNRET_NOERROR;
+ }
+
+ void OnReset()
+ {
+ }
+
+ BOOL OnQueryCancel()
+ {
+ // FALSE = allow cancel
+ // TRUE = prevent cancel
+ return FALSE;
+ }
+
+ int OnWizardBack()
+ {
+ // 0 = goto previous page
+ // -1 = prevent page change
+ // >0 = jump to page by dlg ID
+ return 0;
+ }
+
+ int OnWizardNext()
+ {
+ // 0 = goto next page
+ // -1 = prevent page change
+ // >0 = jump to page by dlg ID
+ return 0;
+ }
+
+ INT_PTR OnWizardFinish()
+ {
+ // FALSE = allow finish
+ // TRUE = prevent finish
+ // HWND = prevent finish and set focus to HWND (CommCtrl 5.80 only)
+ return FALSE;
+ }
+
+ void OnHelp()
+ {
+ }
+
+#ifndef _WIN32_WCE
+#if (_WIN32_IE >= 0x0400)
+ BOOL OnGetObject(LPNMOBJECTNOTIFY /*lpObjectNotify*/)
+ {
+ return FALSE; // not processed
+ }
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0500)
+ int OnTranslateAccelerator(LPMSG /*lpMsg*/)
+ {
+ // PSNRET_NOERROR - message not handled
+ // PSNRET_MESSAGEHANDLED - message handled
+ return PSNRET_NOERROR;
+ }
+
+ HWND OnQueryInitialFocus(HWND /*hWndFocus*/)
+ {
+ // NULL = set focus to default control
+ // HWND = set focus to HWND
+ return NULL;
+ }
+#endif // (_WIN32_IE >= 0x0500)
+#endif // !_WIN32_WCE
+
+#else // !_WTL_NEW_PAGE_NOTIFY_HANDLERS
+ BOOL OnSetActive()
+ {
+ return TRUE;
+ }
+
+ BOOL OnKillActive()
+ {
+ return TRUE;
+ }
+
+ BOOL OnApply()
+ {
+ return TRUE;
+ }
+
+ void OnReset()
+ {
+ }
+
+ BOOL OnQueryCancel()
+ {
+ return TRUE; // ok to cancel
+ }
+
+ int OnWizardBack()
+ {
+ // 0 = goto previous page
+ // -1 = prevent page change
+ // >0 = jump to page by dlg ID
+ return 0;
+ }
+
+ int OnWizardNext()
+ {
+ // 0 = goto next page
+ // -1 = prevent page change
+ // >0 = jump to page by dlg ID
+ return 0;
+ }
+
+ BOOL OnWizardFinish()
+ {
+ return TRUE;
+ }
+
+ void OnHelp()
+ {
+ }
+
+#ifndef _WIN32_WCE
+#if (_WIN32_IE >= 0x0400)
+ BOOL OnGetObject(LPNMOBJECTNOTIFY /*lpObjectNotify*/)
+ {
+ return FALSE; // not processed
+ }
+#endif // (_WIN32_IE >= 0x0400)
+
+#if (_WIN32_IE >= 0x0500)
+ BOOL OnTranslateAccelerator(LPMSG /*lpMsg*/)
+ {
+ return FALSE; // not translated
+ }
+
+ HWND OnQueryInitialFocus(HWND /*hWndFocus*/)
+ {
+ return NULL; // default
+ }
+#endif // (_WIN32_IE >= 0x0500)
+#endif // !_WIN32_WCE
+
+#endif // !_WTL_NEW_PAGE_NOTIFY_HANDLERS
+};
+
+// for non-customized pages
+template <WORD t_wDlgTemplateID>
+class CPropertyPage : public CPropertyPageImpl<CPropertyPage<t_wDlgTemplateID> >
+{
+public:
+ enum { IDD = t_wDlgTemplateID };
+
+ CPropertyPage(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : CPropertyPageImpl<CPropertyPage>(title)
+ { }
+
+ DECLARE_EMPTY_MSG_MAP()
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// CAxPropertyPageImpl - property page that hosts ActiveX controls
+
+#ifndef _ATL_NO_HOSTING
+
+// Note: You must #include <atlhost.h> to use these classes
+
+template <class T, class TBase = CPropertyPageWindow>
+class ATL_NO_VTABLE CAxPropertyPageImpl : public CPropertyPageImpl< T, TBase >
+{
+public:
+// Data members
+ HGLOBAL m_hInitData;
+ HGLOBAL m_hDlgRes;
+ HGLOBAL m_hDlgResSplit;
+
+// Constructor/destructor
+ CAxPropertyPageImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL) :
+ CPropertyPageImpl< T, TBase >(title),
+ m_hInitData(NULL), m_hDlgRes(NULL), m_hDlgResSplit(NULL)
+ {
+ T* pT = static_cast<T*>(this);
+ pT; // avoid level 4 warning
+
+ // initialize ActiveX hosting and modify dialog template
+ ATL::AtlAxWinInit();
+
+ HINSTANCE hInstance = ModuleHelper::GetResourceInstance();
+ LPCTSTR lpTemplateName = MAKEINTRESOURCE(pT->IDD);
+ HRSRC hDlg = ::FindResource(hInstance, lpTemplateName, (LPTSTR)RT_DIALOG);
+ if(hDlg != NULL)
+ {
+ HRSRC hDlgInit = ::FindResource(hInstance, lpTemplateName, (LPTSTR)_ATL_RT_DLGINIT);
+
+ BYTE* pInitData = NULL;
+ if(hDlgInit != NULL)
+ {
+ m_hInitData = ::LoadResource(hInstance, hDlgInit);
+ pInitData = (BYTE*)::LockResource(m_hInitData);
+ }
+
+ m_hDlgRes = ::LoadResource(hInstance, hDlg);
+ DLGTEMPLATE* pDlg = (DLGTEMPLATE*)::LockResource(m_hDlgRes);
+ LPCDLGTEMPLATE lpDialogTemplate = ATL::_DialogSplitHelper::SplitDialogTemplate(pDlg, pInitData);
+ if(lpDialogTemplate != pDlg)
+ m_hDlgResSplit = GlobalHandle(lpDialogTemplate);
+
+ // set up property page to use in-memory dialog template
+ if(lpDialogTemplate != NULL)
+ {
+ m_psp.dwFlags |= PSP_DLGINDIRECT;
+ m_psp.pResource = lpDialogTemplate;
+ }
+ else
+ {
+ ATLASSERT(FALSE && _T("CAxPropertyPageImpl - ActiveX initializtion failed!"));
+ }
+ }
+ else
+ {
+ ATLASSERT(FALSE && _T("CAxPropertyPageImpl - Cannot find dialog template!"));
+ }
+ }
+
+ ~CAxPropertyPageImpl()
+ {
+ if(m_hInitData != NULL)
+ {
+ UnlockResource(m_hInitData);
+ FreeResource(m_hInitData);
+ }
+ if(m_hDlgRes != NULL)
+ {
+ UnlockResource(m_hDlgRes);
+ FreeResource(m_hDlgRes);
+ }
+ if(m_hDlgResSplit != NULL)
+ {
+ ::GlobalFree(m_hDlgResSplit);
+ }
+ }
+
+// Methods
+ // call this one to handle keyboard message for ActiveX controls
+ BOOL PreTranslateMessage(LPMSG pMsg)
+ {
+ if ((pMsg->message < WM_KEYFIRST || pMsg->message > WM_KEYLAST) &&
+ (pMsg->message < WM_MOUSEFIRST || pMsg->message > WM_MOUSELAST))
+ return FALSE;
+ // find a direct child of the dialog from the window that has focus
+ HWND hWndCtl = ::GetFocus();
+ if (IsChild(hWndCtl) && ::GetParent(hWndCtl) != m_hWnd)
+ {
+ do
+ {
+ hWndCtl = ::GetParent(hWndCtl);
+ }
+ while (::GetParent(hWndCtl) != m_hWnd);
+ }
+ // give controls a chance to translate this message
+ return (BOOL)::SendMessage(hWndCtl, WM_FORWARDMSG, 0, (LPARAM)pMsg);
+ }
+
+// Overridables
+#if (_WIN32_IE >= 0x0500)
+ // new default implementation for ActiveX hosting pages
+#ifdef _WTL_NEW_PAGE_NOTIFY_HANDLERS
+ int OnTranslateAccelerator(LPMSG lpMsg)
+ {
+ T* pT = static_cast<T*>(this);
+ return (pT->PreTranslateMessage(lpMsg) != FALSE) ? PSNRET_MESSAGEHANDLED : PSNRET_NOERROR;
+ }
+#else // !_WTL_NEW_PAGE_NOTIFY_HANDLERS
+ BOOL OnTranslateAccelerator(LPMSG lpMsg)
+ {
+ T* pT = static_cast<T*>(this);
+ return pT->PreTranslateMessage(lpMsg);
+ }
+#endif // !_WTL_NEW_PAGE_NOTIFY_HANDLERS
+#endif // (_WIN32_IE >= 0x0500)
+
+// Support for new stuff in ATL7
+#if (_ATL_VER >= 0x0700)
+ int GetIDD()
+ {
+ return( static_cast<T*>(this)->IDD );
+ }
+
+ virtual DLGPROC GetDialogProc()
+ {
+ return DialogProc;
+ }
+
+ static INT_PTR CALLBACK DialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+ {
+ CAxPropertyPageImpl< T, TBase >* pThis = (CAxPropertyPageImpl< T, TBase >*)hWnd;
+ if (uMsg == WM_INITDIALOG)
+ {
+ HRESULT hr;
+ if (FAILED(hr = pThis->CreateActiveXControls(pThis->GetIDD())))
+ {
+ ATLASSERT(FALSE);
+ return FALSE;
+ }
+ }
+ return CPropertyPageImpl< T, TBase >::DialogProc(hWnd, uMsg, wParam, lParam);
+ }
+
+// ActiveX controls creation
+ virtual HRESULT CreateActiveXControls(UINT nID)
+ {
+ // Load dialog template and InitData
+ HRSRC hDlgInit = ::FindResource(ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(nID), (LPTSTR)_ATL_RT_DLGINIT);
+ BYTE* pInitData = NULL;
+ HGLOBAL hData = NULL;
+ HRESULT hr = S_OK;
+ if (hDlgInit != NULL)
+ {
+ hData = ::LoadResource(ATL::_AtlBaseModule.GetResourceInstance(), hDlgInit);
+ if (hData != NULL)
+ pInitData = (BYTE*) ::LockResource(hData);
+ }
+
+ HRSRC hDlg = ::FindResource(ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(nID), (LPTSTR)RT_DIALOG);
+ if (hDlg != NULL)
+ {
+ HGLOBAL hResource = ::LoadResource(ATL::_AtlBaseModule.GetResourceInstance(), hDlg);
+ DLGTEMPLATE* pDlg = NULL;
+ if (hResource != NULL)
+ {
+ pDlg = (DLGTEMPLATE*) ::LockResource(hResource);
+ if (pDlg != NULL)
+ {
+ // Get first control on the template
+ BOOL bDialogEx = ATL::_DialogSplitHelper::IsDialogEx(pDlg);
+ WORD nItems = ATL::_DialogSplitHelper::DlgTemplateItemCount(pDlg);
+
+ // Get first control on the dialog
+ DLGITEMTEMPLATE* pItem = ATL::_DialogSplitHelper::FindFirstDlgItem(pDlg);
+ HWND hWndPrev = GetWindow(GW_CHILD);
+
+ // Create all ActiveX cotnrols in the dialog template and place them in the correct tab order (z-order)
+ for (WORD nItem = 0; nItem < nItems; nItem++)
+ {
+ DWORD wID = bDialogEx ? ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->id : pItem->id;
+ if (ATL::_DialogSplitHelper::IsActiveXControl(pItem, bDialogEx))
+ {
+ BYTE* pData = NULL;
+ DWORD dwLen = ATL::_DialogSplitHelper::FindCreateData(wID, pInitData, &pData);
+ ATL::CComPtr<IStream> spStream;
+ if (dwLen != 0)
+ {
+ HGLOBAL h = GlobalAlloc(GHND, dwLen);
+ if (h != NULL)
+ {
+ BYTE* pBytes = (BYTE*) GlobalLock(h);
+ BYTE* pSource = pData;
+ SecureHelper::memcpy_x(pBytes, dwLen, pSource, dwLen);
+ GlobalUnlock(h);
+ CreateStreamOnHGlobal(h, TRUE, &spStream);
+ }
+ else
+ {
+ hr = E_OUTOFMEMORY;
+ break;
+ }
+ }
+
+ ATL::CComBSTR bstrLicKey;
+ hr = ATL::_DialogSplitHelper::ParseInitData(spStream, &bstrLicKey.m_str);
+ if (SUCCEEDED(hr))
+ {
+ ATL::CAxWindow2 wnd;
+ // Get control caption.
+ LPWSTR pszClassName =
+ bDialogEx ?
+ (LPWSTR)(((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem) + 1) :
+ (LPWSTR)(pItem + 1);
+ // Get control rect.
+ RECT rect;
+ rect.left =
+ bDialogEx ?
+ ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->x :
+ pItem->x;
+ rect.top =
+ bDialogEx ?
+ ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->y :
+ pItem->y;
+ rect.right = rect.left +
+ (bDialogEx ?
+ ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->cx :
+ pItem->cx);
+ rect.bottom = rect.top +
+ (bDialogEx ?
+ ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->cy :
+ pItem->cy);
+
+ // Convert from dialog units to screen units
+ MapDialogRect(&rect);
+
+ // Create AxWindow with a NULL caption.
+ wnd.Create(m_hWnd,
+ &rect,
+ NULL,
+ (bDialogEx ?
+ ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->style :
+ pItem->style) | WS_TABSTOP,
+ bDialogEx ?
+ ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->exStyle :
+ 0,
+ bDialogEx ?
+ ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->id :
+ pItem->id,
+ NULL);
+
+ if (wnd != NULL)
+ {
+#ifndef _WIN32_WCE
+ // Set the Help ID
+ if (bDialogEx && ((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->helpID != 0)
+ wnd.SetWindowContextHelpId(((ATL::_DialogSplitHelper::DLGITEMTEMPLATEEX*)pItem)->helpID);
+#endif // !_WIN32_WCE
+ // Try to create the ActiveX control.
+ hr = wnd.CreateControlLic(pszClassName, spStream, NULL, bstrLicKey);
+ if (FAILED(hr))
+ break;
+ // Set the correct tab position.
+ if (nItem == 0)
+ hWndPrev = HWND_TOP;
+ wnd.SetWindowPos(hWndPrev, 0,0,0,0,SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
+ hWndPrev = wnd;
+ }
+ else
+ {
+ hr = ATL::AtlHresultFromLastError();
+ }
+ }
+ }
+ else
+ {
+ if (nItem != 0)
+ hWndPrev = ::GetWindow(hWndPrev, GW_HWNDNEXT);
+ }
+ pItem = ATL::_DialogSplitHelper::FindNextDlgItem(pItem, bDialogEx);
+ }
+ }
+ else
+ hr = ATL::AtlHresultFromLastError();
+ }
+ else
+ hr = ATL::AtlHresultFromLastError();
+ }
+ return hr;
+ }
+
+// Event handling support
+ HRESULT AdviseSinkMap(bool bAdvise)
+ {
+ if(!bAdvise && m_hWnd == NULL)
+ {
+ // window is gone, controls are already unadvised
+ ATLTRACE2(atlTraceUI, 0, _T("CAxPropertyPageImpl::AdviseSinkMap called after the window was destroyed\n"));
+ return S_OK;
+ }
+ HRESULT hRet = E_NOTIMPL;
+ __if_exists(T::_GetSinkMapFinder)
+ {
+ T* pT = static_cast<T*>(this);
+ hRet = AtlAdviseSinkMap(pT, bAdvise);
+ }
+ return hRet;
+ }
+
+// Message map and handlers
+ typedef CPropertyPageImpl< T, TBase> _baseClass;
+ BEGIN_MSG_MAP(CAxPropertyPageImpl)
+ MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
+ MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
+ CHAIN_MSG_MAP(_baseClass)
+ END_MSG_MAP()
+
+ LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
+ {
+ // initialize controls in dialog with DLGINIT resource section
+ ExecuteDlgInit(static_cast<T*>(this)->IDD);
+ AdviseSinkMap(true);
+ bHandled = FALSE;
+ return 1;
+ }
+
+ LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
+ {
+ AdviseSinkMap(false);
+ bHandled = FALSE;
+ return 1;
+ }
+#endif // (_ATL_VER >= 0x0700)
+};
+
+// for non-customized pages
+template <WORD t_wDlgTemplateID>
+class CAxPropertyPage : public CAxPropertyPageImpl<CAxPropertyPage<t_wDlgTemplateID> >
+{
+public:
+ enum { IDD = t_wDlgTemplateID };
+
+ CAxPropertyPage(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : CAxPropertyPageImpl<CAxPropertyPage>(title)
+ { }
+
+#if (_WIN32_IE >= 0x0500) || (_ATL_VER >= 0x0700)
+ // not empty so we handle accelerators/create controls
+ BEGIN_MSG_MAP(CAxPropertyPage)
+ CHAIN_MSG_MAP(CAxPropertyPageImpl<CAxPropertyPage<t_wDlgTemplateID> >)
+ END_MSG_MAP()
+#else // !((_WIN32_IE >= 0x0500) || (_ATL_VER >= 0x0700))
+ DECLARE_EMPTY_MSG_MAP()
+#endif // !((_WIN32_IE >= 0x0500) || (_ATL_VER >= 0x0700))
+};
+
+#endif // _ATL_NO_HOSTING
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Wizard97 Support
+
+#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+// Sample wizard dialog resources:
+//
+// IDD_WIZ97_INTERIOR_BLANK DIALOG 0, 0, 317, 143
+// STYLE DS_SETFONT | WS_CHILD | WS_DISABLED | WS_CAPTION
+// CAPTION "Wizard97 Property Page - Interior"
+// FONT 8, "MS Shell Dlg"
+// BEGIN
+// END
+//
+// IDD_WIZ97_EXTERIOR_BLANK DIALOGEX 0, 0, 317, 193
+// STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_DISABLED | WS_CAPTION
+// CAPTION "Wizard97 Property Page - Welcome/Complete"
+// FONT 8, "MS Shell Dlg", 0, 0, 0x0
+// BEGIN
+// LTEXT "Welcome to the X Wizard",IDC_WIZ97_EXTERIOR_TITLE,115,8,
+// 195,24
+// LTEXT "Wizard Explanation\r\n(The height of the static text should be in multiples of 8 dlus)",
+// IDC_STATIC,115,40,195,16
+// LTEXT "h",IDC_WIZ97_BULLET1,118,64,8,8
+// LTEXT "List Item 1 (the h is turned into a bullet)",IDC_STATIC,
+// 127,63,122,8
+// LTEXT "h",IDC_WIZ97_BULLET2,118,79,8,8
+// LTEXT "List Item 2. Keep 7 dlus between paragraphs",IDC_STATIC,
+// 127,78,33,8
+// CONTROL "&Do not show this Welcome page again",
+// IDC_WIZ97_WELCOME_NOTAGAIN,"Button",BS_AUTOCHECKBOX |
+// WS_TABSTOP,115,169,138,10
+// END
+//
+// GUIDELINES DESIGNINFO
+// BEGIN
+// IDD_WIZ97_INTERIOR_BLANK, DIALOG
+// BEGIN
+// LEFTMARGIN, 7
+// RIGHTMARGIN, 310
+// VERTGUIDE, 21
+// VERTGUIDE, 31
+// VERTGUIDE, 286
+// VERTGUIDE, 296
+// TOPMARGIN, 7
+// BOTTOMMARGIN, 136
+// HORZGUIDE, 8
+// END
+//
+// IDD_WIZ97_EXTERIOR_BLANK, DIALOG
+// BEGIN
+// RIGHTMARGIN, 310
+// VERTGUIDE, 115
+// VERTGUIDE, 118
+// VERTGUIDE, 127
+// TOPMARGIN, 7
+// BOTTOMMARGIN, 186
+// HORZGUIDE, 8
+// HORZGUIDE, 32
+// HORZGUIDE, 40
+// HORZGUIDE, 169
+// END
+// END
+
+///////////////////////////////////////////////////////////////////////////////
+// CWizard97SheetWindow - client side for a Wizard 97 style wizard sheet
+
+class CWizard97SheetWindow : public CPropertySheetWindow
+{
+public:
+// Constructors
+ CWizard97SheetWindow(HWND hWnd = NULL) : CPropertySheetWindow(hWnd)
+ { }
+
+ CWizard97SheetWindow& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Operations
+ HFONT GetExteriorPageTitleFont(void)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HFONT)::SendMessage(m_hWnd, GetMessage_GetExteriorPageTitleFont(), 0, 0L);
+ }
+
+ HFONT GetBulletFont(void)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return (HFONT)::SendMessage(m_hWnd, GetMessage_GetBulletFont(), 0, 0L);
+ }
+
+// Helpers
+ static UINT GetMessage_GetExteriorPageTitleFont()
+ {
+ static UINT uGetExteriorPageTitleFont = 0;
+ if(uGetExteriorPageTitleFont == 0)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CWizard97SheetWindow::GetMessage_GetExteriorPageTitleFont().\n"));
+ ATLASSERT(FALSE);
+ return 0;
+ }
+
+ if(uGetExteriorPageTitleFont == 0)
+ uGetExteriorPageTitleFont = ::RegisterWindowMessage(_T("GetExteriorPageTitleFont_531AF056-B8BE-4c4c-B786-AC608DF0DF12"));
+
+ lock.Unlock();
+ }
+ ATLASSERT(uGetExteriorPageTitleFont != 0);
+ return uGetExteriorPageTitleFont;
+ }
+
+ static UINT GetMessage_GetBulletFont()
+ {
+ static UINT uGetBulletFont = 0;
+ if(uGetBulletFont == 0)
+ {
+ CStaticDataInitCriticalSectionLock lock;
+ if(FAILED(lock.Lock()))
+ {
+ ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CWizard97SheetWindow::GetMessage_GetBulletFont().\n"));
+ ATLASSERT(FALSE);
+ return 0;
+ }
+
+ if(uGetBulletFont == 0)
+ uGetBulletFont = ::RegisterWindowMessage(_T("GetBulletFont_AD347D08-8F65-45ef-982E-6352E8218AD5"));
+
+ lock.Unlock();
+ }
+ ATLASSERT(uGetBulletFont != 0);
+ return uGetBulletFont;
+ }
+
+// Implementation - override to prevent usage
+ HWND Create(LPCTSTR, HWND, ATL::_U_RECT = NULL, LPCTSTR = NULL, DWORD = 0, DWORD = 0, ATL::_U_MENUorID = 0U, LPVOID = NULL)
+ {
+ ATLASSERT(FALSE);
+ return NULL;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CWizard97SheetImpl - implements a Wizard 97 style wizard sheet
+
+template <class T, class TBase = CWizard97SheetWindow>
+class ATL_NO_VTABLE CWizard97SheetImpl : public CPropertySheetImpl< T, TBase >
+{
+protected:
+// Typedefs
+ typedef CWizard97SheetImpl< T, TBase > thisClass;
+ typedef CPropertySheetImpl< T, TBase > baseClass;
+
+// Member variables
+ CFont m_fontExteriorPageTitle; // Welcome and Completion page title font
+ CFont m_fontBullet; // Bullet font (used on static text 'h' to produce a small bullet)
+ bool m_bReceivedFirstSizeMessage;
+
+public:
+ CWizard97SheetImpl(ATL::_U_STRINGorID title, ATL::_U_STRINGorID headerBitmap, ATL::_U_STRINGorID watermarkBitmap, UINT uStartPage = 0, HWND hWndParent = NULL) :
+ baseClass(title, uStartPage, hWndParent),
+ m_bReceivedFirstSizeMessage(false)
+ {
+ m_psh.dwFlags &= ~(PSH_NOCONTEXTHELP);
+ m_psh.dwFlags &= ~(PSH_WIZARD | PSH_WIZARD_LITE);
+
+ m_psh.dwFlags |= (PSH_HASHELP | PSH_WIZARDCONTEXTHELP);
+ m_psh.dwFlags |= PSH_WIZARD97;
+
+ baseClass::SetHeader(headerBitmap.m_lpstr);
+ baseClass::SetWatermark(watermarkBitmap.m_lpstr);
+ }
+
+// Overrides from base class
+ void OnSheetInitialized()
+ {
+ T* pT = static_cast<T*>(this);
+ pT->_InitializeFonts();
+
+ // We'd like to center the wizard here, but its too early.
+ // Instead, we'll do CenterWindow upon our first WM_SIZE message
+ }
+
+// Initialization
+ void _InitializeFonts()
+ {
+ // Setup the Title and Bullet Font
+ // (Property pages can send the "get external page title font" and "get bullet font" messages)
+ // The derived class needs to do the actual SetFont for the dialog items)
+
+ CFontHandle fontThisDialog = this->GetFont();
+ CClientDC dcScreen(NULL);
+
+ LOGFONT titleLogFont = {0};
+ LOGFONT bulletLogFont = {0};
+ fontThisDialog.GetLogFont(&titleLogFont);
+ fontThisDialog.GetLogFont(&bulletLogFont);
+
+ // The Wizard 97 Spec recommends to do the Title Font
+ // as Verdana Bold, 12pt.
+ titleLogFont.lfCharSet = DEFAULT_CHARSET;
+ titleLogFont.lfWeight = FW_BOLD;
+ SecureHelper::strcpy_x(titleLogFont.lfFaceName, _countof(titleLogFont.lfFaceName), _T("Verdana Bold"));
+ INT titleFontPointSize = 12;
+ titleLogFont.lfHeight = -::MulDiv(titleFontPointSize, dcScreen.GetDeviceCaps(LOGPIXELSY), 72);
+ m_fontExteriorPageTitle.CreateFontIndirect(&titleLogFont);
+
+ // The Wizard 97 Spec recommends to do Bullets by having
+ // static text of "h" in the Marlett font.
+ bulletLogFont.lfCharSet = DEFAULT_CHARSET;
+ bulletLogFont.lfWeight = FW_NORMAL;
+ SecureHelper::strcpy_x(bulletLogFont.lfFaceName, _countof(bulletLogFont.lfFaceName), _T("Marlett"));
+ INT bulletFontSize = 8;
+ bulletLogFont.lfHeight = -::MulDiv(bulletFontSize, dcScreen.GetDeviceCaps(LOGPIXELSY), 72);
+ m_fontBullet.CreateFontIndirect(&bulletLogFont);
+ }
+
+// Message Handling
+ BEGIN_MSG_MAP(thisClass)
+ MESSAGE_HANDLER(CWizard97SheetWindow::GetMessage_GetExteriorPageTitleFont(), OnGetExteriorPageTitleFont)
+ MESSAGE_HANDLER(CWizard97SheetWindow::GetMessage_GetBulletFont(), OnGetBulletFont)
+ MESSAGE_HANDLER(WM_SIZE, OnSize)
+ CHAIN_MSG_MAP(baseClass)
+ END_MSG_MAP()
+
+ LRESULT OnGetExteriorPageTitleFont(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
+ {
+ return (LRESULT)(HFONT)m_fontExteriorPageTitle;
+ }
+
+ LRESULT OnGetBulletFont(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
+ {
+ return (LRESULT)(HFONT)m_fontBullet;
+ }
+
+ LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
+ {
+ if(!m_bReceivedFirstSizeMessage)
+ {
+ m_bReceivedFirstSizeMessage = true;
+ this->CenterWindow();
+ }
+
+ bHandled = FALSE;
+ return 0;
+ }
+};
+
+// for non-customized sheets
+class CWizard97Sheet : public CWizard97SheetImpl<CWizard97Sheet>
+{
+protected:
+// Typedefs
+ typedef CWizard97Sheet thisClass;
+ typedef CWizard97SheetImpl<CWizard97Sheet> baseClass;
+
+public:
+ CWizard97Sheet(ATL::_U_STRINGorID title, ATL::_U_STRINGorID headerBitmap, ATL::_U_STRINGorID watermarkBitmap, UINT uStartPage = 0, HWND hWndParent = NULL) :
+ baseClass(title, headerBitmap, watermarkBitmap, uStartPage, hWndParent)
+ { }
+
+ BEGIN_MSG_MAP(thisClass)
+ CHAIN_MSG_MAP(baseClass)
+ END_MSG_MAP()
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CWizard97PageWindow - client side for a Wizard 97 style wizard page
+
+#define WIZARD97_EXTERIOR_CXDLG 317
+#define WIZARD97_EXTERIOR_CYDLG 193
+
+#define WIZARD97_INTERIOR_CXDLG 317
+#define WIZARD97_INTERIOR_CYDLG 143
+
+class CWizard97PageWindow : public CPropertyPageWindow
+{
+public:
+// Constructors
+ CWizard97PageWindow(HWND hWnd = NULL) : CPropertyPageWindow(hWnd)
+ { }
+
+ CWizard97PageWindow& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Attributes
+ CWizard97SheetWindow GetPropertySheet() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return CWizard97SheetWindow(GetParent());
+ }
+
+// Operations
+ HFONT GetExteriorPageTitleFont(void)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return GetPropertySheet().GetExteriorPageTitleFont();
+ }
+
+ HFONT GetBulletFont(void)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ return GetPropertySheet().GetBulletFont();
+ }
+
+// Implementation - overrides to prevent usage
+ HWND Create(LPCTSTR, HWND, ATL::_U_RECT = NULL, LPCTSTR = NULL, DWORD = 0, DWORD = 0, ATL::_U_MENUorID = 0U, LPVOID = NULL)
+ {
+ ATLASSERT(FALSE);
+ return NULL;
+ }
+
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CWizard97PageImpl - implements a Wizard 97 style wizard page
+
+template <class T, class TBase = CWizard97PageWindow>
+class ATL_NO_VTABLE CWizard97PageImpl : public CPropertyPageImpl< T, TBase >
+{
+protected:
+// Typedefs
+ typedef CWizard97PageImpl< T, TBase > thisClass;
+ typedef CPropertyPageImpl< T, TBase > baseClass;
+
+public:
+ CWizard97PageImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : baseClass(title)
+ { }
+
+// Message Handling
+ BEGIN_MSG_MAP(thisClass)
+ CHAIN_MSG_MAP(baseClass)
+ END_MSG_MAP()
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CWizard97ExteriorPageImpl - implements a Wizard 97 style exterior wizard page
+
+template <class T, class TBase = CWizard97PageWindow>
+class ATL_NO_VTABLE CWizard97ExteriorPageImpl : public CPropertyPageImpl< T, TBase >
+{
+protected:
+// Typedefs
+ typedef CWizard97ExteriorPageImpl< T, TBase > thisClass;
+ typedef CPropertyPageImpl< T, TBase > baseClass;
+
+public:
+// Constructors
+ CWizard97ExteriorPageImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : baseClass(title)
+ {
+ m_psp.dwFlags |= PSP_HASHELP;
+ m_psp.dwFlags |= PSP_HIDEHEADER;
+ }
+
+// Message Handling
+ BEGIN_MSG_MAP(thisClass)
+ CHAIN_MSG_MAP(baseClass)
+ END_MSG_MAP()
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CWizard97InteriorPageImpl - implements a Wizard 97 style interior wizard page
+
+template <class T, class TBase = CWizard97PageWindow>
+class ATL_NO_VTABLE CWizard97InteriorPageImpl : public CPropertyPageImpl< T, TBase >
+{
+protected:
+// Typedefs
+ typedef CWizard97InteriorPageImpl< T, TBase > thisClass;
+ typedef CPropertyPageImpl< T, TBase > baseClass;
+
+public:
+// Constructors
+ CWizard97InteriorPageImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : baseClass(title)
+ {
+ m_psp.dwFlags |= PSP_HASHELP;
+ m_psp.dwFlags &= ~PSP_HIDEHEADER;
+ m_psp.dwFlags |= PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
+
+ // Be sure to have the derived class define this in the constructor.
+ // We'll default it to something obvious in case its forgotten.
+ baseClass::SetHeaderTitle(_T("Call SetHeaderTitle in Derived Class"));
+ baseClass::SetHeaderSubTitle(_T("Call SetHeaderSubTitle in the constructor of the Derived Class."));
+ }
+
+// Message Handling
+ BEGIN_MSG_MAP(thisClass)
+ CHAIN_MSG_MAP(baseClass)
+ END_MSG_MAP()
+};
+
+#endif // (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Aero Wizard support
+
+#if (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
+
+///////////////////////////////////////////////////////////////////////////////
+// CAeroWizardFrameWindow - client side for an Aero Wizard frame window
+
+class CAeroWizardFrameWindow : public CPropertySheetWindow
+{
+public:
+// Constructors
+ CAeroWizardFrameWindow(HWND hWnd = NULL) : CPropertySheetWindow(hWnd)
+ { }
+
+ CAeroWizardFrameWindow& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Operations - new, Aero Wizard only
+ void SetNextText(LPCWSTR lpszText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_SETNEXTTEXT, 0, (LPARAM)lpszText);
+ }
+
+ void ShowWizardButtons(DWORD dwButtons, DWORD dwStates)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::PostMessage(m_hWnd, PSM_SHOWWIZBUTTONS, (WPARAM)dwStates, (LPARAM)dwButtons);
+ }
+
+ void EnableWizardButtons(DWORD dwButtons, DWORD dwStates)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::PostMessage(m_hWnd, PSM_ENABLEWIZBUTTONS, (WPARAM)dwStates, (LPARAM)dwButtons);
+ }
+
+ void SetButtonText(DWORD dwButton, LPCWSTR lpszText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::SendMessage(m_hWnd, PSM_SETBUTTONTEXT, (WPARAM)dwButton, (LPARAM)lpszText);
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAeroWizardFrameImpl - implements an Aero Wizard frame
+
+template <class T, class TBase = CAeroWizardFrameWindow>
+class ATL_NO_VTABLE CAeroWizardFrameImpl : public CPropertySheetImpl<T, TBase >
+{
+public:
+// Constructor
+ CAeroWizardFrameImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL, UINT uStartPage = 0, HWND hWndParent = NULL) :
+ CPropertySheetImpl<T, TBase >(title, uStartPage, hWndParent)
+ {
+ m_psh.dwFlags |= PSH_WIZARD | PSH_AEROWIZARD;
+ }
+
+// Operations
+ void EnableResizing()
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+ m_psh.dwFlags |= PSH_RESIZABLE;
+ }
+
+ void UseHeaderBitmap()
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+ m_psh.dwFlags |= PSH_HEADERBITMAP;
+ }
+
+ void SetNoMargin()
+ {
+ ATLASSERT(m_hWnd == NULL); // can't do this after it's created
+ m_psh.dwFlags |= PSH_NOMARGIN;
+ }
+
+// Override to prevent use
+ HWND Create(HWND /*hWndParent*/ = NULL)
+ {
+ ATLASSERT(FALSE); // not supported for Aero Wizard
+ return NULL;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAeroWizardFrame - for non-customized frames
+
+class CAeroWizardFrame : public CAeroWizardFrameImpl<CAeroWizardFrame>
+{
+public:
+ CAeroWizardFrame(ATL::_U_STRINGorID title = (LPCTSTR)NULL, UINT uStartPage = 0, HWND hWndParent = NULL)
+ : CAeroWizardFrameImpl<CAeroWizardFrame>(title, uStartPage, hWndParent)
+ { }
+
+ BEGIN_MSG_MAP(CAeroWizardFrame)
+ MESSAGE_HANDLER(WM_COMMAND, CAeroWizardFrameImpl<CAeroWizardFrame>::OnCommand)
+ END_MSG_MAP()
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAeroWizardPageWindow - client side for an Aero Wizard page
+
+class CAeroWizardPageWindow : public CPropertyPageWindow
+{
+public:
+// Constructors
+ CAeroWizardPageWindow(HWND hWnd = NULL) : CPropertyPageWindow(hWnd)
+ { }
+
+ CAeroWizardPageWindow& operator =(HWND hWnd)
+ {
+ m_hWnd = hWnd;
+ return *this;
+ }
+
+// Attributes
+ CAeroWizardFrameWindow GetAeroWizardFrame() const
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ // This is not really top-level frame window, but it processes all frame messages
+ return CAeroWizardFrameWindow(GetParent());
+ }
+
+// Operations - new, Aero Wizard only
+ void SetNextText(LPCWSTR lpszText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetAeroWizardFrame().SetNextText(lpszText);
+ }
+
+ void ShowWizardButtons(DWORD dwButtons, DWORD dwStates)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetAeroWizardFrame().ShowWizardButtons(dwButtons, dwStates);
+ }
+
+ void EnableWizardButtons(DWORD dwButtons, DWORD dwStates)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetAeroWizardFrame().EnableWizardButtons(dwButtons, dwStates);
+ }
+
+ void SetButtonText(DWORD dwButton, LPCWSTR lpszText)
+ {
+ ATLASSERT(::IsWindow(m_hWnd));
+ ATLASSERT(GetParent() != NULL);
+ GetAeroWizardFrame().SetButtonText(dwButton, lpszText);
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAeroWizardPageImpl - implements an Aero Wizard page
+
+template <class T, class TBase = CAeroWizardPageWindow>
+class ATL_NO_VTABLE CAeroWizardPageImpl : public CPropertyPageImpl<T, TBase >
+{
+public:
+ CAeroWizardPageImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : CPropertyPageImpl<T, TBase >(title)
+ { }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAeroWizardPage - for non-customized pages
+
+template <WORD t_wDlgTemplateID>
+class CAeroWizardPage : public CAeroWizardPageImpl<CAeroWizardPage<t_wDlgTemplateID> >
+{
+public:
+ enum { IDD = t_wDlgTemplateID };
+
+ CAeroWizardPage(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : CAeroWizardPageImpl<CAeroWizardPage>(title)
+ { }
+
+ DECLARE_EMPTY_MSG_MAP()
+};
+
+
+#ifndef _ATL_NO_HOSTING
+
+// Note: You must #include <atlhost.h> to use these classes
+
+///////////////////////////////////////////////////////////////////////////////
+// CAeroWizardAxPageImpl - Aero Wizard page that hosts ActiveX controls
+
+template <class T, class TBase = CAeroWizardPageWindow>
+class ATL_NO_VTABLE CAeroWizardAxPageImpl : public CAxPropertyPageImpl< T, TBase >
+{
+public:
+ CAeroWizardAxPageImpl(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : CAxPropertyPageImpl< T, TBase >(title)
+ { }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAeroWizardAxPage - for non-customized pages
+
+template <WORD t_wDlgTemplateID>
+class CAeroWizardAxPage : public CAeroWizardAxPageImpl<CAeroWizardAxPage<t_wDlgTemplateID> >
+{
+public:
+ enum { IDD = t_wDlgTemplateID };
+
+ CAeroWizardAxPage(ATL::_U_STRINGorID title = (LPCTSTR)NULL) : CAeroWizardAxPageImpl<CAeroWizardAxPage>(title)
+ { }
+
+#if (_WIN32_IE >= 0x0500) || (_ATL_VER >= 0x0700)
+ // not empty so we handle accelerators/create controls
+ BEGIN_MSG_MAP(CAeroWizardAxPage)
+ CHAIN_MSG_MAP(CAeroWizardAxPageImpl<CAeroWizardAxPage<t_wDlgTemplateID> >)
+ END_MSG_MAP()
+#else // !((_WIN32_IE >= 0x0500) || (_ATL_VER >= 0x0700))
+ DECLARE_EMPTY_MSG_MAP()
+#endif // !((_WIN32_IE >= 0x0500) || (_ATL_VER >= 0x0700))
+};
+
+#endif // _ATL_NO_HOSTING
+
+#endif // (_WIN32_WINNT >= 0x0600) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// TaskDialog support
+
+#if ((_WIN32_WINNT >= 0x0600) || defined(_WTL_TASKDIALOG)) && !defined(_WIN32_WCE)
+
+///////////////////////////////////////////////////////////////////////////////
+// AtlTaskDialog - support for TaskDialog() function
+
+inline int AtlTaskDialog(HWND hWndParent,
+ ATL::_U_STRINGorID WindowTitle, ATL::_U_STRINGorID MainInstructionText, ATL::_U_STRINGorID ContentText,
+ TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons = 0U, ATL::_U_STRINGorID Icon = (LPCTSTR)NULL)
+{
+ int nRet = -1;
+
+#ifdef _WTL_TASKDIALOG_DIRECT
+ USES_CONVERSION;
+ HRESULT hRet = ::TaskDialog(hWndParent, ModuleHelper::GetResourceInstance(),
+ IS_INTRESOURCE(WindowTitle.m_lpstr) ? (LPCWSTR) WindowTitle.m_lpstr : T2CW(WindowTitle.m_lpstr),
+ IS_INTRESOURCE(MainInstructionText.m_lpstr) ? (LPCWSTR) MainInstructionText.m_lpstr : T2CW(MainInstructionText.m_lpstr),
+ IS_INTRESOURCE(ContentText.m_lpstr) ? (LPCWSTR) ContentText.m_lpstr : T2CW(ContentText.m_lpstr),
+ dwCommonButtons,
+ IS_INTRESOURCE(Icon.m_lpstr) ? (LPCWSTR) Icon.m_lpstr : T2CW(Icon.m_lpstr),
+ &nRet);
+ ATLVERIFY(SUCCEEDED(hRet));
+#else
+ // This allows apps to run on older versions of Windows
+ typedef HRESULT (STDAPICALLTYPE *PFN_TaskDialog)(HWND hwndParent, HINSTANCE hInstance, PCWSTR pszWindowTitle, PCWSTR pszMainInstruction, PCWSTR pszContent, TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons, PCWSTR pszIcon, int* pnButton);
+
+ HMODULE m_hCommCtrlDLL = ::LoadLibrary(_T("comctl32.dll"));
+ if(m_hCommCtrlDLL != NULL)
+ {
+ PFN_TaskDialog pfnTaskDialog = (PFN_TaskDialog)::GetProcAddress(m_hCommCtrlDLL, "TaskDialog");
+ if(pfnTaskDialog != NULL)
+ {
+ USES_CONVERSION;
+ HRESULT hRet = pfnTaskDialog(hWndParent, ModuleHelper::GetResourceInstance(),
+ IS_INTRESOURCE(WindowTitle.m_lpstr) ? (LPCWSTR) WindowTitle.m_lpstr : T2CW(WindowTitle.m_lpstr),
+ IS_INTRESOURCE(MainInstructionText.m_lpstr) ? (LPCWSTR) MainInstructionText.m_lpstr : T2CW(MainInstructionText.m_lpstr),
+ IS_INTRESOURCE(ContentText.m_lpstr) ? (LPCWSTR) ContentText.m_lpstr : T2CW(ContentText.m_lpstr),
+ dwCommonButtons,
+ IS_INTRESOURCE(Icon.m_lpstr) ? (LPCWSTR) Icon.m_lpstr : T2CW(Icon.m_lpstr),
+ &nRet);
+ ATLVERIFY(SUCCEEDED(hRet));
+ }
+
+ ::FreeLibrary(m_hCommCtrlDLL);
+ }
+#endif
+
+ return nRet;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CTaskDialogConfig - TASKDIALOGCONFIG wrapper
+
+class CTaskDialogConfig : public TASKDIALOGCONFIG
+{
+public:
+// Constructor
+ CTaskDialogConfig()
+ {
+ Init();
+ }
+
+ void Init()
+ {
+ memset(this, 0, sizeof(TASKDIALOGCONFIG)); // initialize structure to 0/NULL
+ this->cbSize = sizeof(TASKDIALOGCONFIG);
+ this->hInstance = ModuleHelper::GetResourceInstance();
+ }
+
+// Operations - setting values
+ // common buttons
+ void SetCommonButtons(TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons)
+ {
+ this->dwCommonButtons = dwCommonButtons;
+ }
+
+ // window title text
+ void SetWindowTitle(UINT nID)
+ {
+ this->pszWindowTitle = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetWindowTitle(LPCWSTR lpstrWindowTitle)
+ {
+ this->pszWindowTitle = lpstrWindowTitle;
+ }
+
+ // main icon
+ void SetMainIcon(HICON hIcon)
+ {
+ this->dwFlags |= TDF_USE_HICON_MAIN;
+ this->hMainIcon = hIcon;
+ }
+
+ void SetMainIcon(UINT nID)
+ {
+ this->dwFlags &= ~TDF_USE_HICON_MAIN;
+ this->pszMainIcon = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetMainIcon(LPCWSTR lpstrMainIcon)
+ {
+ this->dwFlags &= ~TDF_USE_HICON_MAIN;
+ this->pszMainIcon = lpstrMainIcon;
+ }
+
+ // main instruction text
+ void SetMainInstructionText(UINT nID)
+ {
+ this->pszMainInstruction = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetMainInstructionText(LPCWSTR lpstrMainInstruction)
+ {
+ this->pszMainInstruction = lpstrMainInstruction;
+ }
+
+ // content text
+ void SetContentText(UINT nID)
+ {
+ this->pszContent = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetContentText(LPCWSTR lpstrContent)
+ {
+ this->pszContent = lpstrContent;
+ }
+
+ // buttons
+ void SetButtons(const TASKDIALOG_BUTTON* pButtons, UINT cButtons, int nDefaultButton = 0)
+ {
+ this->pButtons = pButtons;
+ this->cButtons = cButtons;
+ if(nDefaultButton != 0)
+ this->nDefaultButton = nDefaultButton;
+ }
+
+ void SetDefaultButton(int nDefaultButton)
+ {
+ this->nDefaultButton = nDefaultButton;
+ }
+
+ // radio buttons
+ void SetRadioButtons(const TASKDIALOG_BUTTON* pRadioButtons, UINT cRadioButtons, int nDefaultRadioButton = 0)
+ {
+ this->pRadioButtons = pRadioButtons;
+ this->cRadioButtons = cRadioButtons;
+ if(nDefaultRadioButton != 0)
+ this->nDefaultRadioButton = nDefaultRadioButton;
+ }
+
+ void SetDefaultRadioButton(int nDefaultRadioButton)
+ {
+ this->nDefaultRadioButton = nDefaultRadioButton;
+ }
+
+ // verification text
+ void SetVerificationText(UINT nID)
+ {
+ this->pszVerificationText = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetVerificationText(LPCWSTR lpstrVerificationText)
+ {
+ this->pszVerificationText = lpstrVerificationText;
+ }
+
+ // expanded information text
+ void SetExpandedInformationText(UINT nID)
+ {
+ this->pszExpandedInformation = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetExpandedInformationText(LPCWSTR lpstrExpandedInformation)
+ {
+ this->pszExpandedInformation = lpstrExpandedInformation;
+ }
+
+ // expanded control text
+ void SetExpandedControlText(UINT nID)
+ {
+ this->pszExpandedControlText = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetExpandedControlText(LPCWSTR lpstrExpandedControlText)
+ {
+ this->pszExpandedControlText = lpstrExpandedControlText;
+ }
+
+ // collapsed control text
+ void SetCollapsedControlText(UINT nID)
+ {
+ this->pszCollapsedControlText = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetCollapsedControlText(LPCWSTR lpstrCollapsedControlText)
+ {
+ this->pszCollapsedControlText = lpstrCollapsedControlText;
+ }
+
+ // footer icon
+ void SetFooterIcon(HICON hIcon)
+ {
+ this->dwFlags |= TDF_USE_HICON_FOOTER;
+ this->hFooterIcon = hIcon;
+ }
+
+ void SetFooterIcon(UINT nID)
+ {
+ this->dwFlags &= ~TDF_USE_HICON_FOOTER;
+ this->pszFooterIcon = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetFooterIcon(LPCWSTR lpstrFooterIcon)
+ {
+ this->dwFlags &= ~TDF_USE_HICON_FOOTER;
+ this->pszFooterIcon = lpstrFooterIcon;
+ }
+
+ // footer text
+ void SetFooterText(UINT nID)
+ {
+ this->pszFooter = MAKEINTRESOURCEW(nID);
+ }
+
+ void SetFooterText(LPCWSTR lpstrFooterText)
+ {
+ this->pszFooter = lpstrFooterText;
+ }
+
+ // width (in DLUs)
+ void SetWidth(UINT cxWidth)
+ {
+ this->cxWidth = cxWidth;
+ }
+
+ // modify flags
+ void ModifyFlags(DWORD dwRemove, DWORD dwAdd)
+ {
+ this->dwFlags = (this->dwFlags & ~dwRemove) | dwAdd;
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CTaskDialogImpl - implements a Task Dialog
+
+template <class T>
+class ATL_NO_VTABLE CTaskDialogImpl
+{
+public:
+ CTaskDialogConfig m_tdc;
+ HWND m_hWnd; // used only in callback functions
+
+// Constructor
+ CTaskDialogImpl(HWND hWndParent = NULL) : m_hWnd(NULL)
+ {
+ m_tdc.hwndParent = hWndParent;
+ m_tdc.pfCallback = T::TaskDialogCallback;
+ m_tdc.lpCallbackData = (LONG_PTR)static_cast<T*>(this);
+ }
+
+// Operations
+ HRESULT DoModal(HWND hWndParent = ::GetActiveWindow(), int* pnButton = NULL, int* pnRadioButton = NULL, BOOL* pfVerificationFlagChecked = NULL)
+ {
+ if(m_tdc.hwndParent == NULL)
+ m_tdc.hwndParent = hWndParent;
+
+#ifdef _WTL_TASKDIALOG_DIRECT
+ return ::TaskDialogIndirect(&m_tdc, pnButton, pnRadioButton, pfVerificationFlagChecked);
+#else
+
+ // This allows apps to run on older versions of Windows
+ typedef HRESULT (STDAPICALLTYPE *PFN_TaskDialogIndirect)(const TASKDIALOGCONFIG* pTaskConfig, int* pnButton, int* pnRadioButton, BOOL* pfVerificationFlagChecked);
+
+ HRESULT hRet = E_UNEXPECTED;
+ HMODULE m_hCommCtrlDLL = ::LoadLibrary(_T("comctl32.dll"));
+ if(m_hCommCtrlDLL != NULL)
+ {
+ PFN_TaskDialogIndirect pfnTaskDialogIndirect = (PFN_TaskDialogIndirect)::GetProcAddress(m_hCommCtrlDLL, "TaskDialogIndirect");
+ if(pfnTaskDialogIndirect != NULL)
+ hRet = pfnTaskDialogIndirect(&m_tdc, pnButton, pnRadioButton, pfVerificationFlagChecked);
+
+ ::FreeLibrary(m_hCommCtrlDLL);
+ }
+
+ return hRet;
+#endif
+ }
+
+// Operations - setting values of TASKDIALOGCONFIG
+ // common buttons
+ void SetCommonButtons(TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons)
+ { m_tdc.SetCommonButtons(dwCommonButtons); }
+ // window title text
+ void SetWindowTitle(UINT nID)
+ { m_tdc.SetWindowTitle(nID); }
+ void SetWindowTitle(LPCWSTR lpstrWindowTitle)
+ { m_tdc.SetWindowTitle(lpstrWindowTitle); }
+ // main icon
+ void SetMainIcon(HICON hIcon)
+ { m_tdc.SetMainIcon(hIcon); }
+ void SetMainIcon(UINT nID)
+ { m_tdc.SetMainIcon(nID); }
+ void SetMainIcon(LPCWSTR lpstrMainIcon)
+ { m_tdc.SetMainIcon(lpstrMainIcon); }
+ // main instruction text
+ void SetMainInstructionText(UINT nID)
+ { m_tdc.SetMainInstructionText(nID); }
+ void SetMainInstructionText(LPCWSTR lpstrMainInstruction)
+ { m_tdc.SetMainInstructionText(lpstrMainInstruction); }
+ // content text
+ void SetContentText(UINT nID)
+ { m_tdc.SetContentText(nID); }
+ void SetContentText(LPCWSTR lpstrContent)
+ { m_tdc.SetContentText(lpstrContent); }
+ // buttons
+ void SetButtons(const TASKDIALOG_BUTTON* pButtons, UINT cButtons, int nDefaultButton = 0)
+ { m_tdc.SetButtons(pButtons, cButtons, nDefaultButton); }
+ void SetDefaultButton(int nDefaultButton)
+ { m_tdc.SetDefaultButton(nDefaultButton); }
+ // radio buttons
+ void SetRadioButtons(const TASKDIALOG_BUTTON* pRadioButtons, UINT cRadioButtons, int nDefaultRadioButton = 0)
+ { m_tdc.SetRadioButtons(pRadioButtons, cRadioButtons, nDefaultRadioButton); }
+ void SetDefaultRadioButton(int nDefaultRadioButton)
+ { m_tdc.SetDefaultRadioButton(nDefaultRadioButton); }
+ // verification text
+ void SetVerificationText(UINT nID)
+ { m_tdc.SetVerificationText(nID); }
+ void SetVerificationText(LPCWSTR lpstrVerificationText)
+ { m_tdc.SetVerificationText(lpstrVerificationText); }
+ // expanded information text
+ void SetExpandedInformationText(UINT nID)
+ { m_tdc.SetExpandedInformationText(nID); }
+ void SetExpandedInformationText(LPCWSTR lpstrExpandedInformation)
+ { m_tdc.SetExpandedInformationText(lpstrExpandedInformation); }
+ // expanded control text
+ void SetExpandedControlText(UINT nID)
+ { m_tdc.SetExpandedControlText(nID); }
+ void SetExpandedControlText(LPCWSTR lpstrExpandedControlText)
+ { m_tdc.SetExpandedControlText(lpstrExpandedControlText); }
+ // collapsed control text
+ void SetCollapsedControlText(UINT nID)
+ { m_tdc.SetCollapsedControlText(nID); }
+ void SetCollapsedControlText(LPCWSTR lpstrCollapsedControlText)
+ { m_tdc.SetCollapsedControlText(lpstrCollapsedControlText); }
+ // footer icon
+ void SetFooterIcon(HICON hIcon)
+ { m_tdc.SetFooterIcon(hIcon); }
+ void SetFooterIcon(UINT nID)
+ { m_tdc.SetFooterIcon(nID); }
+ void SetFooterIcon(LPCWSTR lpstrFooterIcon)
+ { m_tdc.SetFooterIcon(lpstrFooterIcon); }
+ // footer text
+ void SetFooterText(UINT nID)
+ { m_tdc.SetFooterText(nID); }
+ void SetFooterText(LPCWSTR lpstrFooterText)
+ { m_tdc.SetFooterText(lpstrFooterText); }
+ // width (in DLUs)
+ void SetWidth(UINT cxWidth)
+ { m_tdc.SetWidth(cxWidth); }
+ // modify flags
+ void ModifyFlags(DWORD dwRemove, DWORD dwAdd)
+ { m_tdc.ModifyFlags(dwRemove, dwAdd); }
+
+// Implementation
+ static HRESULT CALLBACK TaskDialogCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LONG_PTR lpRefData)
+ {
+ T* pT = (T*)lpRefData;
+ ATLASSERT(pT->m_hWnd == NULL || pT->m_hWnd == hWnd);
+
+ BOOL bRet = FALSE;
+ switch(uMsg)
+ {
+ case TDN_DIALOG_CONSTRUCTED:
+ pT->m_hWnd = hWnd;
+ pT->OnDialogConstructed();
+ break;
+ case TDN_CREATED:
+ pT->OnCreated();
+ break;
+ case TDN_BUTTON_CLICKED:
+ bRet = pT->OnButtonClicked((int)wParam);
+ break;
+ case TDN_RADIO_BUTTON_CLICKED:
+ pT->OnRadioButtonClicked((int)wParam);
+ break;
+ case TDN_HYPERLINK_CLICKED:
+ pT->OnHyperlinkClicked((LPCWSTR)lParam);
+ break;
+ case TDN_EXPANDO_BUTTON_CLICKED:
+ pT->OnExpandoButtonClicked((wParam != 0));
+ break;
+ case TDN_VERIFICATION_CLICKED:
+ pT->OnVerificationClicked((wParam != 0));
+ break;
+ case TDN_HELP:
+ pT->OnHelp();
+ break;
+ case TDN_TIMER:
+ bRet = pT->OnTimer((DWORD)wParam);
+ break;
+ case TDN_NAVIGATED:
+ pT->OnNavigated();
+ break;
+ case TDN_DESTROYED:
+ pT->OnDestroyed();
+ pT->m_hWnd = NULL;
+ break;
+ default:
+ ATLTRACE2(atlTraceUI, 0, _T("Unknown notification received in CTaskDialogImpl::TaskDialogCallback\n"));
+ break;
+ }
+
+ return (HRESULT)bRet;
+ }
+
+// Overrideables - notification handlers
+ void OnDialogConstructed()
+ {
+ }
+
+ void OnCreated()
+ {
+ }
+
+ BOOL OnButtonClicked(int /*nButton*/)
+ {
+ return FALSE; // don't prevent dialog to close
+ }
+
+ void OnRadioButtonClicked(int /*nRadioButton*/)
+ {
+ }
+
+ void OnHyperlinkClicked(LPCWSTR /*pszHREF*/)
+ {
+ }
+
+ void OnExpandoButtonClicked(bool /*bExpanded*/)
+ {
+ }
+
+ void OnVerificationClicked(bool /*bChecked*/)
+ {
+ }
+
+ void OnHelp()
+ {
+ }
+
+ BOOL OnTimer(DWORD /*dwTickCount*/)
+ {
+ return FALSE; // don't reset counter
+ }
+
+ void OnNavigated()
+ {
+ }
+
+ void OnDestroyed()
+ {
+ }
+
+// Commands - valid to call only from handlers
+ void NavigatePage(TASKDIALOGCONFIG& tdc)
+ {
+ ATLASSERT(m_hWnd != NULL);
+
+ tdc.cbSize = sizeof(TASKDIALOGCONFIG);
+ if(tdc.hwndParent == NULL)
+ tdc.hwndParent = m_tdc.hwndParent;
+ tdc.pfCallback = m_tdc.pfCallback;
+ tdc.lpCallbackData = m_tdc.lpCallbackData;
+ (TASKDIALOGCONFIG)m_tdc = tdc;
+
+ ::SendMessage(m_hWnd, TDM_NAVIGATE_PAGE, 0, (LPARAM)&tdc);
+ }
+
+ // modify TASKDIALOGCONFIG values, then call this to update task dialog
+ void NavigatePage()
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_NAVIGATE_PAGE, 0, (LPARAM)&m_tdc);
+ }
+
+ void ClickButton(int nButton)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_CLICK_BUTTON, nButton, 0L);
+ }
+
+ void SetMarqueeProgressBar(BOOL bMarquee)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_SET_MARQUEE_PROGRESS_BAR, bMarquee, 0L);
+ }
+
+ BOOL SetProgressBarState(int nNewState)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ return (BOOL)::SendMessage(m_hWnd, TDM_SET_PROGRESS_BAR_STATE, nNewState, 0L);
+ }
+
+ DWORD SetProgressBarRange(int nMinRange, int nMaxRange)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ return (DWORD)::SendMessage(m_hWnd, TDM_SET_PROGRESS_BAR_RANGE, 0, MAKELPARAM(nMinRange, nMaxRange));
+ }
+
+ int SetProgressBarPos(int nNewPos)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ return (int)::SendMessage(m_hWnd, TDM_SET_PROGRESS_BAR_POS, nNewPos, 0L);
+ }
+
+ BOOL SetProgressBarMarquee(BOOL bMarquee, UINT uSpeed)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ return (BOOL)::SendMessage(m_hWnd, TDM_SET_PROGRESS_BAR_MARQUEE, bMarquee, uSpeed);
+ }
+
+ void SetElementText(TASKDIALOG_ELEMENTS element, LPCWSTR lpstrText)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_SET_ELEMENT_TEXT, element, (LPARAM)lpstrText);
+ }
+
+ void ClickRadioButton(int nRadioButton)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_CLICK_RADIO_BUTTON, nRadioButton, 0L);
+ }
+
+ void EnableButton(int nButton, BOOL bEnable)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_ENABLE_BUTTON, nButton, bEnable);
+ }
+
+ void EnableRadioButton(int nButton, BOOL bEnable)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_ENABLE_RADIO_BUTTON, nButton, bEnable);
+ }
+
+ void ClickVerification(BOOL bCheck, BOOL bFocus)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_CLICK_VERIFICATION, bCheck, bFocus);
+ }
+
+ void UpdateElementText(TASKDIALOG_ELEMENTS element, LPCWSTR lpstrText)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_UPDATE_ELEMENT_TEXT, element, (LPARAM)lpstrText);
+ }
+
+ void SetButtonElevationRequiredState(int nButton, BOOL bElevation)
+ {
+ ATLASSERT(m_hWnd != NULL);
+ ::SendMessage(m_hWnd, TDM_SET_BUTTON_ELEVATION_REQUIRED_STATE, nButton, bElevation);
+ }
+
+ void UpdateIcon(TASKDIALOG_ICON_ELEMENTS element, HICON hIcon)
+ {
+ ATLASSERT(m_hWnd != NULL);
+#ifdef _DEBUG
+ if(element == TDIE_ICON_MAIN)
+ ATLASSERT((m_tdc.dwFlags & TDF_USE_HICON_MAIN) != 0);
+ else if(element == TDIE_ICON_FOOTER)
+ ATLASSERT((m_tdc.dwFlags & TDF_USE_HICON_FOOTER) != 0);
+#endif // _DEBUG
+ ::SendMessage(m_hWnd, TDM_UPDATE_ICON, element, (LPARAM)hIcon);
+ }
+
+ void UpdateIcon(TASKDIALOG_ICON_ELEMENTS element, LPCWSTR lpstrIcon)
+ {
+ ATLASSERT(m_hWnd != NULL);
+#ifdef _DEBUG
+ if(element == TDIE_ICON_MAIN)
+ ATLASSERT((m_tdc.dwFlags & TDF_USE_HICON_MAIN) == 0);
+ else if(element == TDIE_ICON_FOOTER)
+ ATLASSERT((m_tdc.dwFlags & TDF_USE_HICON_FOOTER) == 0);
+#endif // _DEBUG
+ ::SendMessage(m_hWnd, TDM_UPDATE_ICON, element, (LPARAM)lpstrIcon);
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CTaskDialog - for non-customized task dialogs
+
+class CTaskDialog : public CTaskDialogImpl<CTaskDialog>
+{
+public:
+ CTaskDialog(HWND hWndParent = NULL) : CTaskDialogImpl<CTaskDialog>(hWndParent)
+ {
+ m_tdc.pfCallback = NULL;
+ }
+};
+
+#endif // ((_WIN32_WINNT >= 0x0600) || defined(_WTL_TASKDIALOG)) && !defined(_WIN32_WCE)
+
+}; // namespace WTL
+
+#endif // __ATLDLGS_H__
diff --git a/plugins/XSoundNotify/src/wtl/include/atlgdi.h b/plugins/XSoundNotify/src/wtl/include/atlgdi.h new file mode 100644 index 0000000000..1e452c4d9b --- /dev/null +++ b/plugins/XSoundNotify/src/wtl/include/atlgdi.h @@ -0,0 +1,3891 @@ +// Windows Template Library - WTL version 8.1
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//
+// This file is a part of the Windows Template Library.
+// The use and distribution terms for this software are covered by the
+// Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
+// which can be found in the file CPL.TXT at the root of this distribution.
+// By using this software in any fashion, you are agreeing to be bound by
+// the terms of this license. You must not remove this notice, or
+// any other, from this software.
+
+#ifndef __ATLGDI_H__
+#define __ATLGDI_H__
+
+#pragma once
+
+#ifndef __ATLAPP_H__
+ #error atlgdi.h requires atlapp.h to be included first
+#endif
+
+
+// protect template members from windowsx.h macros
+#ifdef _INC_WINDOWSX
+ #undef CopyRgn
+ #undef CreateBrush
+ #undef CreatePen
+ #undef SelectBrush
+ #undef SelectPen
+ #undef SelectFont
+ #undef SelectBitmap
+#endif // _INC_WINDOWSX
+
+// required libraries
+#if !defined(_ATL_NO_MSIMG) && !defined(_WIN32_WCE)
+ #pragma comment(lib, "msimg32.lib")
+#endif // !defined(_ATL_NO_MSIMG) && !defined(_WIN32_WCE)
+#if !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
+ #pragma comment(lib, "opengl32.lib")
+#endif // !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Classes in this file:
+//
+// CPenT<t_bManaged>
+// CBrushT<t_bManaged>
+// CLogFont
+// CFontT<t_bManaged>
+// CBitmapT<t_bManaged>
+// CPaletteT<t_bManaged>
+// CRgnT<t_bManaged>
+// CDCT<t_bManaged>
+// CPaintDC
+// CClientDC
+// CWindowDC
+// CMemoryDC
+// CEnhMetaFileInfo
+// CEnhMetaFileT<t_bManaged>
+// CEnhMetaFileDC
+//
+// Global functions:
+// AtlGetBitmapResourceInfo()
+// AtlGetBitmapResourceBitsPerPixel()
+// AtlIsAlphaBitmapResource()
+// AtlIsDib16()
+// AtlGetDibColorTableSize()
+// AtlGetDibNumColors(),
+// AtlGetDibBitmap()
+// AtlCopyBitmap()
+// AtlCreatePackedDib16()
+// AtlSetClipboardDib16()
+// AtlGetClipboardDib()
+
+
+namespace WTL
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// Bitmap resource helpers to extract bitmap information for a bitmap resource
+
+inline LPBITMAPINFOHEADER AtlGetBitmapResourceInfo(HMODULE hModule, ATL::_U_STRINGorID image)
+{
+ HRSRC hResource = ::FindResource(hModule, image.m_lpstr, RT_BITMAP);
+ ATLASSERT(hResource != NULL);
+ HGLOBAL hGlobal = ::LoadResource(hModule, hResource);
+ ATLASSERT(hGlobal != NULL);
+ LPBITMAPINFOHEADER pBitmapInfoHeader = (LPBITMAPINFOHEADER)::LockResource(hGlobal);
+ ATLASSERT(pBitmapInfoHeader != NULL);
+ return pBitmapInfoHeader;
+}
+
+inline WORD AtlGetBitmapResourceBitsPerPixel(HMODULE hModule, ATL::_U_STRINGorID image)
+{
+ LPBITMAPINFOHEADER pBitmapInfoHeader = AtlGetBitmapResourceInfo(hModule, image);
+ ATLASSERT(pBitmapInfoHeader != NULL);
+ return pBitmapInfoHeader->biBitCount;
+}
+
+inline WORD AtlGetBitmapResourceBitsPerPixel(ATL::_U_STRINGorID image)
+{
+ return AtlGetBitmapResourceBitsPerPixel(ModuleHelper::GetResourceInstance(), image);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// 32-bit (alpha channel) bitmap resource helper
+
+// Note: 32-bit (alpha channel) images work only on Windows XP with Common Controls version 6.
+// If you want your app to work on older version of Windows, load non-alpha images if Common
+// Controls version is less than 6.
+
+inline bool AtlIsAlphaBitmapResource(ATL::_U_STRINGorID image)
+{
+ return (AtlGetBitmapResourceBitsPerPixel(image) == 32);
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CPen
+
+template <bool t_bManaged>
+class CPenT
+{
+public:
+// Data members
+ HPEN m_hPen;
+
+// Constructor/destructor/operators
+ CPenT(HPEN hPen = NULL) : m_hPen(hPen)
+ { }
+
+ ~CPenT()
+ {
+ if(t_bManaged && m_hPen != NULL)
+ DeleteObject();
+ }
+
+ CPenT<t_bManaged>& operator =(HPEN hPen)
+ {
+ Attach(hPen);
+ return *this;
+ }
+
+ void Attach(HPEN hPen)
+ {
+ if(t_bManaged && m_hPen != NULL && m_hPen != hPen)
+ ::DeleteObject(m_hPen);
+ m_hPen = hPen;
+ }
+
+ HPEN Detach()
+ {
+ HPEN hPen = m_hPen;
+ m_hPen = NULL;
+ return hPen;
+ }
+
+ operator HPEN() const { return m_hPen; }
+
+ bool IsNull() const { return (m_hPen == NULL); }
+
+// Create methods
+ HPEN CreatePen(int nPenStyle, int nWidth, COLORREF crColor)
+ {
+ ATLASSERT(m_hPen == NULL);
+ m_hPen = ::CreatePen(nPenStyle, nWidth, crColor);
+ return m_hPen;
+ }
+
+#ifndef _WIN32_WCE
+ HPEN CreatePen(int nPenStyle, int nWidth, const LOGBRUSH* pLogBrush, int nStyleCount = 0, const DWORD* lpStyle = NULL)
+ {
+ ATLASSERT(m_hPen == NULL);
+ m_hPen = ::ExtCreatePen(nPenStyle, nWidth, pLogBrush, nStyleCount, lpStyle);
+ return m_hPen;
+ }
+#endif // !_WIN32_WCE
+
+ HPEN CreatePenIndirect(LPLOGPEN lpLogPen)
+ {
+ ATLASSERT(m_hPen == NULL);
+ m_hPen = ::CreatePenIndirect(lpLogPen);
+ return m_hPen;
+ }
+
+ BOOL DeleteObject()
+ {
+ ATLASSERT(m_hPen != NULL);
+ BOOL bRet = ::DeleteObject(m_hPen);
+ if(bRet)
+ m_hPen = NULL;
+ return bRet;
+ }
+
+// Attributes
+ int GetLogPen(LOGPEN* pLogPen) const
+ {
+ ATLASSERT(m_hPen != NULL);
+ return ::GetObject(m_hPen, sizeof(LOGPEN), pLogPen);
+ }
+
+ bool GetLogPen(LOGPEN& LogPen) const
+ {
+ ATLASSERT(m_hPen != NULL);
+ return (::GetObject(m_hPen, sizeof(LOGPEN), &LogPen) == sizeof(LOGPEN));
+ }
+
+#ifndef _WIN32_WCE
+ int GetExtLogPen(EXTLOGPEN* pLogPen) const
+ {
+ ATLASSERT(m_hPen != NULL);
+ return ::GetObject(m_hPen, sizeof(EXTLOGPEN), pLogPen);
+ }
+
+ bool GetExtLogPen(EXTLOGPEN& ExtLogPen) const
+ {
+ ATLASSERT(m_hPen != NULL);
+ return (::GetObject(m_hPen, sizeof(EXTLOGPEN), &ExtLogPen) == sizeof(EXTLOGPEN));
+ }
+#endif // !_WIN32_WCE
+};
+
+typedef CPenT<false> CPenHandle;
+typedef CPenT<true> CPen;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CBrush
+
+template <bool t_bManaged>
+class CBrushT
+{
+public:
+// Data members
+ HBRUSH m_hBrush;
+
+// Constructor/destructor/operators
+ CBrushT(HBRUSH hBrush = NULL) : m_hBrush(hBrush)
+ { }
+
+ ~CBrushT()
+ {
+ if(t_bManaged && m_hBrush != NULL)
+ DeleteObject();
+ }
+
+ CBrushT<t_bManaged>& operator =(HBRUSH hBrush)
+ {
+ Attach(hBrush);
+ return *this;
+ }
+
+ void Attach(HBRUSH hBrush)
+ {
+ if(t_bManaged && m_hBrush != NULL && m_hBrush != hBrush)
+ ::DeleteObject(m_hBrush);
+ m_hBrush = hBrush;
+ }
+
+ HBRUSH Detach()
+ {
+ HBRUSH hBrush = m_hBrush;
+ m_hBrush = NULL;
+ return hBrush;
+ }
+
+ operator HBRUSH() const { return m_hBrush; }
+
+ bool IsNull() const { return (m_hBrush == NULL); }
+
+// Create methods
+ HBRUSH CreateSolidBrush(COLORREF crColor)
+ {
+ ATLASSERT(m_hBrush == NULL);
+ m_hBrush = ::CreateSolidBrush(crColor);
+ return m_hBrush;
+ }
+
+#ifndef _WIN32_WCE
+ HBRUSH CreateHatchBrush(int nIndex, COLORREF crColor)
+ {
+ ATLASSERT(m_hBrush == NULL);
+ m_hBrush = ::CreateHatchBrush(nIndex, crColor);
+ return m_hBrush;
+ }
+#endif // !_WIN32_WCE
+
+#if !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
+ HBRUSH CreateBrushIndirect(const LOGBRUSH* lpLogBrush)
+ {
+ ATLASSERT(m_hBrush == NULL);
+#ifndef _WIN32_WCE
+ m_hBrush = ::CreateBrushIndirect(lpLogBrush);
+#else // CE specific
+ m_hBrush = ATL::CreateBrushIndirect(lpLogBrush);
+#endif // _WIN32_WCE
+ return m_hBrush;
+ }
+#endif // !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
+
+ HBRUSH CreatePatternBrush(HBITMAP hBitmap)
+ {
+ ATLASSERT(m_hBrush == NULL);
+ m_hBrush = ::CreatePatternBrush(hBitmap);
+ return m_hBrush;
+ }
+
+ HBRUSH CreateDIBPatternBrush(HGLOBAL hPackedDIB, UINT nUsage)
+ {
+ ATLASSERT(hPackedDIB != NULL);
+ const void* lpPackedDIB = GlobalLock(hPackedDIB);
+ ATLASSERT(lpPackedDIB != NULL);
+ m_hBrush = ::CreateDIBPatternBrushPt(lpPackedDIB, nUsage);
+ GlobalUnlock(hPackedDIB);
+ return m_hBrush;
+ }
+
+ HBRUSH CreateDIBPatternBrush(const void* lpPackedDIB, UINT nUsage)
+ {
+ ATLASSERT(m_hBrush == NULL);
+ m_hBrush = ::CreateDIBPatternBrushPt(lpPackedDIB, nUsage);
+ return m_hBrush;
+ }
+
+ HBRUSH CreateSysColorBrush(int nIndex)
+ {
+ ATLASSERT(m_hBrush == NULL);
+ m_hBrush = ::GetSysColorBrush(nIndex);
+ return m_hBrush;
+ }
+
+ BOOL DeleteObject()
+ {
+ ATLASSERT(m_hBrush != NULL);
+ BOOL bRet = ::DeleteObject(m_hBrush);
+ if(bRet)
+ m_hBrush = NULL;
+ return bRet;
+ }
+
+// Attributes
+ int GetLogBrush(LOGBRUSH* pLogBrush) const
+ {
+ ATLASSERT(m_hBrush != NULL);
+ return ::GetObject(m_hBrush, sizeof(LOGBRUSH), pLogBrush);
+ }
+
+ bool GetLogBrush(LOGBRUSH& LogBrush) const
+ {
+ ATLASSERT(m_hBrush != NULL);
+ return (::GetObject(m_hBrush, sizeof(LOGBRUSH), &LogBrush) == sizeof(LOGBRUSH));
+ }
+};
+
+typedef CBrushT<false> CBrushHandle;
+typedef CBrushT<true> CBrush;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CFont
+
+class CLogFont : public LOGFONT
+{
+public:
+ CLogFont()
+ {
+ memset(this, 0, sizeof(LOGFONT));
+ }
+
+ CLogFont(const LOGFONT& lf)
+ {
+ Copy(&lf);
+ }
+
+ CLogFont(HFONT hFont)
+ {
+ ATLASSERT(::GetObjectType(hFont) == OBJ_FONT);
+ ::GetObject(hFont, sizeof(LOGFONT), (LOGFONT*)this);
+ }
+
+ HFONT CreateFontIndirect()
+ {
+ return ::CreateFontIndirect(this);
+ }
+
+ void SetBold()
+ {
+ lfWeight = FW_BOLD;
+ }
+
+ bool IsBold() const
+ {
+ return (lfWeight >= FW_BOLD);
+ }
+
+ void MakeBolder(int iScale = 1)
+ {
+ lfWeight += FW_BOLD * iScale;
+ }
+
+ void MakeLarger(int iScale)
+ {
+ if(lfHeight > 0)
+ lfHeight += iScale;
+ else
+ lfHeight -= iScale;
+ }
+
+ void SetHeight(LONG nPointSize, HDC hDC = NULL)
+ {
+ HDC hDC1 = (hDC != NULL) ? hDC : ::GetDC(NULL);
+ // For MM_TEXT mapping mode
+ lfHeight = -::MulDiv(nPointSize, ::GetDeviceCaps(hDC1, LOGPIXELSY), 72);
+ if(hDC == NULL)
+ ::ReleaseDC(NULL, hDC1);
+ }
+
+ LONG GetHeight(HDC hDC = NULL) const
+ {
+ HDC hDC1 = (hDC != NULL) ? hDC : ::GetDC(NULL);
+ // For MM_TEXT mapping mode
+ LONG nPointSize = ::MulDiv(-lfHeight, 72, ::GetDeviceCaps(hDC1, LOGPIXELSY));
+ if(hDC == NULL)
+ ::ReleaseDC(NULL, hDC1);
+
+ return nPointSize;
+ }
+
+ LONG GetDeciPointHeight(HDC hDC = NULL) const
+ {
+ HDC hDC1 = (hDC != NULL) ? hDC : ::GetDC(NULL);
+#ifndef _WIN32_WCE
+ POINT ptOrg = { 0, 0 };
+ ::DPtoLP(hDC1, &ptOrg, 1);
+ POINT pt = { 0, 0 };
+ pt.y = abs(lfHeight) + ptOrg.y;
+ ::LPtoDP(hDC1, &pt,1);
+ LONG nDeciPoint = ::MulDiv(pt.y, 720, ::GetDeviceCaps(hDC1, LOGPIXELSY)); // 72 points/inch, 10 decipoints/point
+#else // CE specific
+ // DP and LP are always the same on CE
+ LONG nDeciPoint = ::MulDiv(abs(lfHeight), 720, ::GetDeviceCaps(hDC1, LOGPIXELSY)); // 72 points/inch, 10 decipoints/point
+#endif // _WIN32_WCE
+ if(hDC == NULL)
+ ::ReleaseDC(NULL, hDC1);
+
+ return nDeciPoint;
+ }
+
+ void SetHeightFromDeciPoint(LONG nDeciPtHeight, HDC hDC = NULL)
+ {
+ HDC hDC1 = (hDC != NULL) ? hDC : ::GetDC(NULL);
+#ifndef _WIN32_WCE
+ POINT pt = { 0, 0 };
+ pt.y = ::MulDiv(::GetDeviceCaps(hDC1, LOGPIXELSY), nDeciPtHeight, 720); // 72 points/inch, 10 decipoints/point
+ ::DPtoLP(hDC1, &pt, 1);
+ POINT ptOrg = { 0, 0 };
+ ::DPtoLP(hDC1, &ptOrg, 1);
+ lfHeight = -abs(pt.y - ptOrg.y);
+#else // CE specific
+ // DP and LP are always the same on CE
+ lfHeight = -abs(::MulDiv(::GetDeviceCaps(hDC1, LOGPIXELSY), nDeciPtHeight, 720)); // 72 points/inch, 10 decipoints/point
+#endif // _WIN32_WCE
+ if(hDC == NULL)
+ ::ReleaseDC(NULL, hDC1);
+ }
+
+#ifndef _WIN32_WCE
+ void SetCaptionFont()
+ {
+ NONCLIENTMETRICS ncm = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
+ ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0));
+ Copy(&ncm.lfCaptionFont);
+ }
+
+ void SetMenuFont()
+ {
+ NONCLIENTMETRICS ncm = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
+ ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0));
+ Copy(&ncm.lfMenuFont);
+ }
+
+ void SetStatusFont()
+ {
+ NONCLIENTMETRICS ncm = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
+ ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0));
+ Copy(&ncm.lfStatusFont);
+ }
+
+ void SetMessageBoxFont()
+ {
+ NONCLIENTMETRICS ncm = { RunTimeHelper::SizeOf_NONCLIENTMETRICS() };
+ ATLVERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0));
+ Copy(&ncm.lfMessageFont);
+ }
+#endif // !_WIN32_WCE
+
+ void Copy(const LOGFONT* pLogFont)
+ {
+ ATLASSERT(pLogFont != NULL);
+ *(LOGFONT*)this = *pLogFont;
+ }
+
+ CLogFont& operator =(const CLogFont& src)
+ {
+ Copy(&src);
+ return *this;
+ }
+
+ CLogFont& operator =(const LOGFONT& src)
+ {
+ Copy(&src);
+ return *this;
+ }
+
+ CLogFont& operator =(HFONT hFont)
+ {
+ ATLASSERT(::GetObjectType(hFont) == OBJ_FONT);
+ ::GetObject(hFont, sizeof(LOGFONT), (LOGFONT*)this);
+ return *this;
+ }
+
+ bool operator ==(const LOGFONT& logfont) const
+ {
+ return(logfont.lfHeight == lfHeight &&
+ logfont.lfWidth == lfWidth &&
+ logfont.lfEscapement == lfEscapement &&
+ logfont.lfOrientation == lfOrientation &&
+ logfont.lfWeight == lfWeight &&
+ logfont.lfItalic == lfItalic &&
+ logfont.lfUnderline == lfUnderline &&
+ logfont.lfStrikeOut == lfStrikeOut &&
+ logfont.lfCharSet == lfCharSet &&
+ logfont.lfOutPrecision == lfOutPrecision &&
+ logfont.lfClipPrecision == lfClipPrecision &&
+ logfont.lfQuality == lfQuality &&
+ logfont.lfPitchAndFamily == lfPitchAndFamily &&
+ lstrcmp(logfont.lfFaceName, lfFaceName) == 0);
+ }
+};
+
+
+template <bool t_bManaged>
+class CFontT
+{
+public:
+// Data members
+ HFONT m_hFont;
+
+// Constructor/destructor/operators
+ CFontT(HFONT hFont = NULL) : m_hFont(hFont)
+ { }
+
+ ~CFontT()
+ {
+ if(t_bManaged && m_hFont != NULL)
+ DeleteObject();
+ }
+
+ CFontT<t_bManaged>& operator =(HFONT hFont)
+ {
+ Attach(hFont);
+ return *this;
+ }
+
+ void Attach(HFONT hFont)
+ {
+ if(t_bManaged && m_hFont != NULL && m_hFont != hFont)
+ ::DeleteObject(m_hFont);
+ m_hFont = hFont;
+ }
+
+ HFONT Detach()
+ {
+ HFONT hFont = m_hFont;
+ m_hFont = NULL;
+ return hFont;
+ }
+
+ operator HFONT() const { return m_hFont; }
+
+ bool IsNull() const { return (m_hFont == NULL); }
+
+// Create methods
+ HFONT CreateFontIndirect(const LOGFONT* lpLogFont)
+ {
+ ATLASSERT(m_hFont == NULL);
+ m_hFont = ::CreateFontIndirect(lpLogFont);
+ return m_hFont;
+ }
+
+#if !defined(_WIN32_WCE) && (_WIN32_WINNT >= 0x0500)
+ HFONT CreateFontIndirectEx(CONST ENUMLOGFONTEXDV* penumlfex)
+ {
+ ATLASSERT(m_hFont == NULL);
+ m_hFont = ::CreateFontIndirectEx(penumlfex);
+ return m_hFont;
+ }
+#endif // !defined(_WIN32_WCE) && (_WIN32_WINNT >= 0x0500)
+
+#if !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
+ HFONT CreateFont(int nHeight, int nWidth, int nEscapement,
+ int nOrientation, int nWeight, BYTE bItalic, BYTE bUnderline,
+ BYTE cStrikeOut, BYTE nCharSet, BYTE nOutPrecision,
+ BYTE nClipPrecision, BYTE nQuality, BYTE nPitchAndFamily,
+ LPCTSTR lpszFacename)
+ {
+ ATLASSERT(m_hFont == NULL);
+#ifndef _WIN32_WCE
+ m_hFont = ::CreateFont(nHeight, nWidth, nEscapement,
+ nOrientation, nWeight, bItalic, bUnderline, cStrikeOut,
+ nCharSet, nOutPrecision, nClipPrecision, nQuality,
+ nPitchAndFamily, lpszFacename);
+#else // CE specific
+ m_hFont = ATL::CreateFont(nHeight, nWidth, nEscapement,
+ nOrientation, nWeight, bItalic, bUnderline, cStrikeOut,
+ nCharSet, nOutPrecision, nClipPrecision, nQuality,
+ nPitchAndFamily, lpszFacename);
+#endif // _WIN32_WCE
+ return m_hFont;
+ }
+#endif // !defined(_WIN32_WCE) || (_ATL_VER >= 0x0800)
+
+ HFONT CreatePointFont(int nPointSize, LPCTSTR lpszFaceName, HDC hDC = NULL, bool bBold = false, bool bItalic = false)
+ {
+ LOGFONT logFont = { 0 };
+ logFont.lfCharSet = DEFAULT_CHARSET;
+ logFont.lfHeight = nPointSize;
+ SecureHelper::strncpy_x(logFont.lfFaceName, _countof(logFont.lfFaceName), lpszFaceName, _TRUNCATE);
+
+ if(bBold)
+ logFont.lfWeight = FW_BOLD;
+ if(bItalic)
+ logFont.lfItalic = (BYTE)TRUE;
+
+ return CreatePointFontIndirect(&logFont, hDC);
+ }
+
+ HFONT CreatePointFontIndirect(const LOGFONT* lpLogFont, HDC hDC = NULL)
+ {
+ HDC hDC1 = (hDC != NULL) ? hDC : ::GetDC(NULL);
+
+ // convert nPointSize to logical units based on hDC
+ LOGFONT logFont = *lpLogFont;
+#ifndef _WIN32_WCE
+ POINT pt = { 0, 0 };
+ pt.y = ::MulDiv(::GetDeviceCaps(hDC1, LOGPIXELSY), logFont.lfHeight, 720); // 72 points/inch, 10 decipoints/point
+ ::DPtoLP(hDC1, &pt, 1);
+ POINT ptOrg = { 0, 0 };
+ ::DPtoLP(hDC1, &ptOrg, 1);
+ logFont.lfHeight = -abs(pt.y - ptOrg.y);
+#else // CE specific
+ // DP and LP are always the same on CE
+ logFont.lfHeight = -abs(::MulDiv(::GetDeviceCaps(hDC1, LOGPIXELSY), logFont.lfHeight, 720)); // 72 points/inch, 10 decipoints/point
+#endif // _WIN32_WCE
+
+ if(hDC == NULL)
+ ::ReleaseDC(NULL, hDC1);
+
+ return CreateFontIndirect(&logFont);
+ }
+
+ BOOL DeleteObject()
+ {
+ ATLASSERT(m_hFont != NULL);
+ BOOL bRet = ::DeleteObject(m_hFont);
+ if(bRet)
+ m_hFont = NULL;
+ return bRet;
+ }
+
+// Attributes
+ int GetLogFont(LOGFONT* pLogFont) const
+ {
+ ATLASSERT(m_hFont != NULL);
+ return ::GetObject(m_hFont, sizeof(LOGFONT), pLogFont);
+ }
+
+ bool GetLogFont(LOGFONT& LogFont) const
+ {
+ ATLASSERT(m_hFont != NULL);
+ return (::GetObject(m_hFont, sizeof(LOGFONT), &LogFont) == sizeof(LOGFONT));
+ }
+};
+
+typedef CFontT<false> CFontHandle;
+typedef CFontT<true> CFont;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CBitmap
+
+template <bool t_bManaged>
+class CBitmapT
+{
+public:
+// Data members
+ HBITMAP m_hBitmap;
+
+// Constructor/destructor/operators
+ CBitmapT(HBITMAP hBitmap = NULL) : m_hBitmap(hBitmap)
+ { }
+
+ ~CBitmapT()
+ {
+ if(t_bManaged && m_hBitmap != NULL)
+ DeleteObject();
+ }
+
+ CBitmapT<t_bManaged>& operator =(HBITMAP hBitmap)
+ {
+ Attach(hBitmap);
+ return *this;
+ }
+
+ void Attach(HBITMAP hBitmap)
+ {
+ if(t_bManaged && m_hBitmap != NULL&& m_hBitmap != hBitmap)
+ ::DeleteObject(m_hBitmap);
+ m_hBitmap = hBitmap;
+ }
+
+ HBITMAP Detach()
+ {
+ HBITMAP hBitmap = m_hBitmap;
+ m_hBitmap = NULL;
+ return hBitmap;
+ }
+
+ operator HBITMAP() const { return m_hBitmap; }
+
+ bool IsNull() const { return (m_hBitmap == NULL); }
+
+// Create and load methods
+ HBITMAP LoadBitmap(ATL::_U_STRINGorID bitmap)
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap.m_lpstr);
+ return m_hBitmap;
+ }
+
+ HBITMAP LoadOEMBitmap(UINT nIDBitmap) // for OBM_/OCR_/OIC_
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::LoadBitmap(NULL, MAKEINTRESOURCE(nIDBitmap));
+ return m_hBitmap;
+ }
+
+#ifndef _WIN32_WCE
+ HBITMAP LoadMappedBitmap(UINT nIDBitmap, UINT nFlags = 0, LPCOLORMAP lpColorMap = NULL, int nMapSize = 0)
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::CreateMappedBitmap(ModuleHelper::GetResourceInstance(), nIDBitmap, (WORD)nFlags, lpColorMap, nMapSize);
+ return m_hBitmap;
+ }
+#endif // !_WIN32_WCE
+
+ HBITMAP CreateBitmap(int nWidth, int nHeight, UINT nPlanes, UINT nBitsPerPixel, const void* lpBits)
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::CreateBitmap(nWidth, nHeight, nPlanes, nBitsPerPixel, lpBits);
+ return m_hBitmap;
+ }
+
+#ifndef _WIN32_WCE
+ HBITMAP CreateBitmapIndirect(LPBITMAP lpBitmap)
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::CreateBitmapIndirect(lpBitmap);
+ return m_hBitmap;
+ }
+#endif // !_WIN32_WCE
+
+ HBITMAP CreateCompatibleBitmap(HDC hDC, int nWidth, int nHeight)
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::CreateCompatibleBitmap(hDC, nWidth, nHeight);
+ return m_hBitmap;
+ }
+
+#ifndef _WIN32_WCE
+ HBITMAP CreateDiscardableBitmap(HDC hDC, int nWidth, int nHeight)
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::CreateDiscardableBitmap(hDC, nWidth, nHeight);
+ return m_hBitmap;
+ }
+#endif // !_WIN32_WCE
+
+ BOOL DeleteObject()
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ BOOL bRet = ::DeleteObject(m_hBitmap);
+ if(bRet)
+ m_hBitmap = NULL;
+ return bRet;
+ }
+
+// Attributes
+ int GetBitmap(BITMAP* pBitMap) const
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ return ::GetObject(m_hBitmap, sizeof(BITMAP), pBitMap);
+ }
+
+ bool GetBitmap(BITMAP& bm) const
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ return (::GetObject(m_hBitmap, sizeof(BITMAP), &bm) == sizeof(BITMAP));
+ }
+
+ bool GetSize(SIZE& size) const
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ BITMAP bm = { 0 };
+ if(!GetBitmap(&bm))
+ return false;
+ size.cx = bm.bmWidth;
+ size.cy = bm.bmHeight;
+ return true;
+ }
+
+#ifndef _WIN32_WCE
+ DWORD GetBitmapBits(DWORD dwCount, LPVOID lpBits) const
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ return ::GetBitmapBits(m_hBitmap, dwCount, lpBits);
+ }
+#endif // !_WIN32_WCE
+
+#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
+ DWORD SetBitmapBits(DWORD dwCount, const void* lpBits)
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ return ::SetBitmapBits(m_hBitmap, dwCount, lpBits);
+ }
+#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
+
+#ifndef _WIN32_WCE
+ BOOL GetBitmapDimension(LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ return ::GetBitmapDimensionEx(m_hBitmap, lpSize);
+ }
+
+ BOOL SetBitmapDimension(int nWidth, int nHeight, LPSIZE lpSize = NULL)
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ return ::SetBitmapDimensionEx(m_hBitmap, nWidth, nHeight, lpSize);
+ }
+
+// DIB support
+ HBITMAP CreateDIBitmap(HDC hDC, CONST BITMAPINFOHEADER* lpbmih, DWORD dwInit, CONST VOID* lpbInit, CONST BITMAPINFO* lpbmi, UINT uColorUse)
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::CreateDIBitmap(hDC, lpbmih, dwInit, lpbInit, lpbmi, uColorUse);
+ return m_hBitmap;
+ }
+#endif // !_WIN32_WCE
+
+ HBITMAP CreateDIBSection(HDC hDC, CONST BITMAPINFO* lpbmi, UINT uColorUse, VOID** ppvBits, HANDLE hSection, DWORD dwOffset)
+ {
+ ATLASSERT(m_hBitmap == NULL);
+ m_hBitmap = ::CreateDIBSection(hDC, lpbmi, uColorUse, ppvBits, hSection, dwOffset);
+ return m_hBitmap;
+ }
+
+#ifndef _WIN32_WCE
+ int GetDIBits(HDC hDC, UINT uStartScan, UINT cScanLines, LPVOID lpvBits, LPBITMAPINFO lpbmi, UINT uColorUse) const
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ return ::GetDIBits(hDC, m_hBitmap, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
+ }
+
+ int SetDIBits(HDC hDC, UINT uStartScan, UINT cScanLines, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse)
+ {
+ ATLASSERT(m_hBitmap != NULL);
+ return ::SetDIBits(hDC, m_hBitmap, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
+ }
+#endif // !_WIN32_WCE
+};
+
+typedef CBitmapT<false> CBitmapHandle;
+typedef CBitmapT<true> CBitmap;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CPalette
+
+template <bool t_bManaged>
+class CPaletteT
+{
+public:
+// Data members
+ HPALETTE m_hPalette;
+
+// Constructor/destructor/operators
+ CPaletteT(HPALETTE hPalette = NULL) : m_hPalette(hPalette)
+ { }
+
+ ~CPaletteT()
+ {
+ if(t_bManaged && m_hPalette != NULL)
+ DeleteObject();
+ }
+
+ CPaletteT<t_bManaged>& operator =(HPALETTE hPalette)
+ {
+ Attach(hPalette);
+ return *this;
+ }
+
+ void Attach(HPALETTE hPalette)
+ {
+ if(t_bManaged && m_hPalette != NULL && m_hPalette != hPalette)
+ ::DeleteObject(m_hPalette);
+ m_hPalette = hPalette;
+ }
+
+ HPALETTE Detach()
+ {
+ HPALETTE hPalette = m_hPalette;
+ m_hPalette = NULL;
+ return hPalette;
+ }
+
+ operator HPALETTE() const { return m_hPalette; }
+
+ bool IsNull() const { return (m_hPalette == NULL); }
+
+// Create methods
+ HPALETTE CreatePalette(LPLOGPALETTE lpLogPalette)
+ {
+ ATLASSERT(m_hPalette == NULL);
+ m_hPalette = ::CreatePalette(lpLogPalette);
+ return m_hPalette;
+ }
+
+#ifndef _WIN32_WCE
+ HPALETTE CreateHalftonePalette(HDC hDC)
+ {
+ ATLASSERT(m_hPalette == NULL);
+ ATLASSERT(hDC != NULL);
+ m_hPalette = ::CreateHalftonePalette(hDC);
+ return m_hPalette;
+ }
+#endif // !_WIN32_WCE
+
+ BOOL DeleteObject()
+ {
+ ATLASSERT(m_hPalette != NULL);
+ BOOL bRet = ::DeleteObject(m_hPalette);
+ if(bRet)
+ m_hPalette = NULL;
+ return bRet;
+ }
+
+// Attributes
+ int GetEntryCount() const
+ {
+ ATLASSERT(m_hPalette != NULL);
+ WORD nEntries = 0;
+ ::GetObject(m_hPalette, sizeof(WORD), &nEntries);
+ return (int)nEntries;
+ }
+
+ UINT GetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors) const
+ {
+ ATLASSERT(m_hPalette != NULL);
+ return ::GetPaletteEntries(m_hPalette, nStartIndex, nNumEntries, lpPaletteColors);
+ }
+
+ UINT SetPaletteEntries(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors)
+ {
+ ATLASSERT(m_hPalette != NULL);
+ return ::SetPaletteEntries(m_hPalette, nStartIndex, nNumEntries, lpPaletteColors);
+ }
+
+// Operations
+#ifndef _WIN32_WCE
+ void AnimatePalette(UINT nStartIndex, UINT nNumEntries, LPPALETTEENTRY lpPaletteColors)
+ {
+ ATLASSERT(m_hPalette != NULL);
+ ::AnimatePalette(m_hPalette, nStartIndex, nNumEntries, lpPaletteColors);
+ }
+
+ BOOL ResizePalette(UINT nNumEntries)
+ {
+ ATLASSERT(m_hPalette != NULL);
+ return ::ResizePalette(m_hPalette, nNumEntries);
+ }
+#endif // !_WIN32_WCE
+
+ UINT GetNearestPaletteIndex(COLORREF crColor) const
+ {
+ ATLASSERT(m_hPalette != NULL);
+ return ::GetNearestPaletteIndex(m_hPalette, crColor);
+ }
+};
+
+typedef CPaletteT<false> CPaletteHandle;
+typedef CPaletteT<true> CPalette;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CRgn
+
+template <bool t_bManaged>
+class CRgnT
+{
+public:
+// Data members
+ HRGN m_hRgn;
+
+// Constructor/destructor/operators
+ CRgnT(HRGN hRgn = NULL) : m_hRgn(hRgn)
+ { }
+
+ ~CRgnT()
+ {
+ if(t_bManaged && m_hRgn != NULL)
+ DeleteObject();
+ }
+
+ CRgnT<t_bManaged>& operator =(HRGN hRgn)
+ {
+ Attach(hRgn);
+ return *this;
+ }
+
+ void Attach(HRGN hRgn)
+ {
+ if(t_bManaged && m_hRgn != NULL && m_hRgn != hRgn)
+ ::DeleteObject(m_hRgn);
+ m_hRgn = hRgn;
+ }
+
+ HRGN Detach()
+ {
+ HRGN hRgn = m_hRgn;
+ m_hRgn = NULL;
+ return hRgn;
+ }
+
+ operator HRGN() const { return m_hRgn; }
+
+ bool IsNull() const { return (m_hRgn == NULL); }
+
+// Create methods
+ HRGN CreateRectRgn(int x1, int y1, int x2, int y2)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ m_hRgn = ::CreateRectRgn(x1, y1, x2, y2);
+ return m_hRgn;
+ }
+
+ HRGN CreateRectRgnIndirect(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ m_hRgn = ::CreateRectRgnIndirect(lpRect);
+ return m_hRgn;
+ }
+
+#ifndef _WIN32_WCE
+ HRGN CreateEllipticRgn(int x1, int y1, int x2, int y2)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ m_hRgn = ::CreateEllipticRgn(x1, y1, x2, y2);
+ return m_hRgn;
+ }
+
+ HRGN CreateEllipticRgnIndirect(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ m_hRgn = ::CreateEllipticRgnIndirect(lpRect);
+ return m_hRgn;
+ }
+
+ HRGN CreatePolygonRgn(LPPOINT lpPoints, int nCount, int nMode)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ m_hRgn = ::CreatePolygonRgn(lpPoints, nCount, nMode);
+ return m_hRgn;
+ }
+
+ HRGN CreatePolyPolygonRgn(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount, int nPolyFillMode)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ m_hRgn = ::CreatePolyPolygonRgn(lpPoints, lpPolyCounts, nCount, nPolyFillMode);
+ return m_hRgn;
+ }
+
+ HRGN CreateRoundRectRgn(int x1, int y1, int x2, int y2, int x3, int y3)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ m_hRgn = ::CreateRoundRectRgn(x1, y1, x2, y2, x3, y3);
+ return m_hRgn;
+ }
+
+ HRGN CreateFromPath(HDC hDC)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ ATLASSERT(hDC != NULL);
+ m_hRgn = ::PathToRegion(hDC);
+ return m_hRgn;
+ }
+
+ HRGN CreateFromData(const XFORM* lpXForm, int nCount, const RGNDATA* pRgnData)
+ {
+ ATLASSERT(m_hRgn == NULL);
+ m_hRgn = ::ExtCreateRegion(lpXForm, nCount, pRgnData);
+ return m_hRgn;
+ }
+#endif // !_WIN32_WCE
+
+ BOOL DeleteObject()
+ {
+ ATLASSERT(m_hRgn != NULL);
+ BOOL bRet = ::DeleteObject(m_hRgn);
+ if(bRet)
+ m_hRgn = NULL;
+ return bRet;
+ }
+
+// Operations
+ void SetRectRgn(int x1, int y1, int x2, int y2)
+ {
+ ATLASSERT(m_hRgn != NULL);
+ ::SetRectRgn(m_hRgn, x1, y1, x2, y2);
+ }
+
+ void SetRectRgn(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hRgn != NULL);
+ ::SetRectRgn(m_hRgn, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
+ }
+
+ int CombineRgn(HRGN hRgnSrc1, HRGN hRgnSrc2, int nCombineMode)
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::CombineRgn(m_hRgn, hRgnSrc1, hRgnSrc2, nCombineMode);
+ }
+
+ int CombineRgn(HRGN hRgnSrc, int nCombineMode)
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::CombineRgn(m_hRgn, m_hRgn, hRgnSrc, nCombineMode);
+ }
+
+ int CopyRgn(HRGN hRgnSrc)
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::CombineRgn(m_hRgn, hRgnSrc, NULL, RGN_COPY);
+ }
+
+ BOOL EqualRgn(HRGN hRgn) const
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::EqualRgn(m_hRgn, hRgn);
+ }
+
+ int OffsetRgn(int x, int y)
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::OffsetRgn(m_hRgn, x, y);
+ }
+
+ int OffsetRgn(POINT point)
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::OffsetRgn(m_hRgn, point.x, point.y);
+ }
+
+ int GetRgnBox(LPRECT lpRect) const
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::GetRgnBox(m_hRgn, lpRect);
+ }
+
+ BOOL PtInRegion(int x, int y) const
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::PtInRegion(m_hRgn, x, y);
+ }
+
+ BOOL PtInRegion(POINT point) const
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::PtInRegion(m_hRgn, point.x, point.y);
+ }
+
+ BOOL RectInRegion(LPCRECT lpRect) const
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return ::RectInRegion(m_hRgn, lpRect);
+ }
+
+ int GetRegionData(LPRGNDATA lpRgnData, int nDataSize) const
+ {
+ ATLASSERT(m_hRgn != NULL);
+ return (int)::GetRegionData(m_hRgn, nDataSize, lpRgnData);
+ }
+};
+
+typedef CRgnT<false> CRgnHandle;
+typedef CRgnT<true> CRgn;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CDC - The device context class
+
+template <bool t_bManaged>
+class CDCT
+{
+public:
+// Data members
+ HDC m_hDC;
+
+// Constructor/destructor/operators
+ CDCT(HDC hDC = NULL) : m_hDC(hDC)
+ {
+ }
+
+ ~CDCT()
+ {
+ if(t_bManaged && m_hDC != NULL)
+ ::DeleteDC(Detach());
+ }
+
+ CDCT<t_bManaged>& operator =(HDC hDC)
+ {
+ Attach(hDC);
+ return *this;
+ }
+
+ void Attach(HDC hDC)
+ {
+ if(t_bManaged && m_hDC != NULL && m_hDC != hDC)
+ ::DeleteDC(m_hDC);
+ m_hDC = hDC;
+ }
+
+ HDC Detach()
+ {
+ HDC hDC = m_hDC;
+ m_hDC = NULL;
+ return hDC;
+ }
+
+ operator HDC() const { return m_hDC; }
+
+ bool IsNull() const { return (m_hDC == NULL); }
+
+// Operations
+#ifndef _WIN32_WCE
+ HWND WindowFromDC() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::WindowFromDC(m_hDC);
+ }
+#endif // !_WIN32_WCE
+
+ CPenHandle GetCurrentPen() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return CPenHandle((HPEN)::GetCurrentObject(m_hDC, OBJ_PEN));
+ }
+
+ CBrushHandle GetCurrentBrush() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return CBrushHandle((HBRUSH)::GetCurrentObject(m_hDC, OBJ_BRUSH));
+ }
+
+ CPaletteHandle GetCurrentPalette() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return CPaletteHandle((HPALETTE)::GetCurrentObject(m_hDC, OBJ_PAL));
+ }
+
+ CFontHandle GetCurrentFont() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return CFontHandle((HFONT)::GetCurrentObject(m_hDC, OBJ_FONT));
+ }
+
+ CBitmapHandle GetCurrentBitmap() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return CBitmapHandle((HBITMAP)::GetCurrentObject(m_hDC, OBJ_BITMAP));
+ }
+
+ HDC CreateDC(LPCTSTR lpszDriverName, LPCTSTR lpszDeviceName, LPCTSTR lpszOutput, const DEVMODE* lpInitData)
+ {
+ ATLASSERT(m_hDC == NULL);
+ m_hDC = ::CreateDC(lpszDriverName, lpszDeviceName, lpszOutput, lpInitData);
+ return m_hDC;
+ }
+
+ HDC CreateCompatibleDC(HDC hDC = NULL)
+ {
+ ATLASSERT(m_hDC == NULL);
+ m_hDC = ::CreateCompatibleDC(hDC);
+ return m_hDC;
+ }
+
+ BOOL DeleteDC()
+ {
+ if(m_hDC == NULL)
+ return FALSE;
+ BOOL bRet = ::DeleteDC(m_hDC);
+ if(bRet)
+ m_hDC = NULL;
+ return bRet;
+ }
+
+// Device-Context Functions
+ int SaveDC()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SaveDC(m_hDC);
+ }
+
+ BOOL RestoreDC(int nSavedDC)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::RestoreDC(m_hDC, nSavedDC);
+ }
+
+ int GetDeviceCaps(int nIndex) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetDeviceCaps(m_hDC, nIndex);
+ }
+
+#ifndef _WIN32_WCE
+ UINT SetBoundsRect(LPCRECT lpRectBounds, UINT flags)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetBoundsRect(m_hDC, lpRectBounds, flags);
+ }
+
+ UINT GetBoundsRect(LPRECT lpRectBounds, UINT flags) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetBoundsRect(m_hDC, lpRectBounds, flags);
+ }
+
+ BOOL ResetDC(const DEVMODE* lpDevMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ResetDC(m_hDC, lpDevMode) != NULL;
+ }
+
+// Drawing-Tool Functions
+ BOOL GetBrushOrg(LPPOINT lpPoint) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetBrushOrgEx(m_hDC, lpPoint);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL SetBrushOrg(int x, int y, LPPOINT lpPoint = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetBrushOrgEx(m_hDC, x, y, lpPoint);
+ }
+
+ BOOL SetBrushOrg(POINT point, LPPOINT lpPointRet = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetBrushOrgEx(m_hDC, point.x, point.y, lpPointRet);
+ }
+
+#ifndef _WIN32_WCE
+ int EnumObjects(int nObjectType, int (CALLBACK* lpfn)(LPVOID, LPARAM), LPARAM lpData)
+ {
+ ATLASSERT(m_hDC != NULL);
+#ifdef STRICT
+ return ::EnumObjects(m_hDC, nObjectType, (GOBJENUMPROC)lpfn, lpData);
+#else
+ return ::EnumObjects(m_hDC, nObjectType, (GOBJENUMPROC)lpfn, (LPVOID)lpData);
+#endif
+ }
+#endif // !_WIN32_WCE
+
+// Type-safe selection helpers
+ HPEN SelectPen(HPEN hPen)
+ {
+ ATLASSERT(m_hDC != NULL);
+#ifndef _WIN32_WCE
+ ATLASSERT(hPen == NULL || ::GetObjectType(hPen) == OBJ_PEN || ::GetObjectType(hPen) == OBJ_EXTPEN);
+#else // CE specific
+ ATLASSERT(hPen == NULL || ::GetObjectType(hPen) == OBJ_PEN);
+#endif // _WIN32_WCE
+ return (HPEN)::SelectObject(m_hDC, hPen);
+ }
+
+ HBRUSH SelectBrush(HBRUSH hBrush)
+ {
+ ATLASSERT(m_hDC != NULL);
+ ATLASSERT(hBrush == NULL || ::GetObjectType(hBrush) == OBJ_BRUSH);
+ return (HBRUSH)::SelectObject(m_hDC, hBrush);
+ }
+
+ HFONT SelectFont(HFONT hFont)
+ {
+ ATLASSERT(m_hDC != NULL);
+ ATLASSERT(hFont == NULL || ::GetObjectType(hFont) == OBJ_FONT);
+ return (HFONT)::SelectObject(m_hDC, hFont);
+ }
+
+ HBITMAP SelectBitmap(HBITMAP hBitmap)
+ {
+ ATLASSERT(m_hDC != NULL);
+ ATLASSERT(hBitmap == NULL || ::GetObjectType(hBitmap) == OBJ_BITMAP);
+ return (HBITMAP)::SelectObject(m_hDC, hBitmap);
+ }
+
+ int SelectRgn(HRGN hRgn) // special return for regions
+ {
+ ATLASSERT(m_hDC != NULL);
+ ATLASSERT(hRgn == NULL || ::GetObjectType(hRgn) == OBJ_REGION);
+ return PtrToInt(::SelectObject(m_hDC, hRgn));
+ }
+
+// Type-safe selection helpers for stock objects
+ HPEN SelectStockPen(int nPen)
+ {
+ ATLASSERT(m_hDC != NULL);
+#if (_WIN32_WINNT >= 0x0500)
+ ATLASSERT(nPen == WHITE_PEN || nPen == BLACK_PEN || nPen == NULL_PEN || nPen == DC_PEN);
+#else
+ ATLASSERT(nPen == WHITE_PEN || nPen == BLACK_PEN || nPen == NULL_PEN);
+#endif // !(_WIN32_WINNT >= 0x0500)
+ return SelectPen((HPEN)::GetStockObject(nPen));
+ }
+
+ HBRUSH SelectStockBrush(int nBrush)
+ {
+#if (_WIN32_WINNT >= 0x0500)
+ ATLASSERT((nBrush >= WHITE_BRUSH && nBrush <= HOLLOW_BRUSH) || nBrush == DC_BRUSH);
+#else
+ ATLASSERT(nBrush >= WHITE_BRUSH && nBrush <= HOLLOW_BRUSH);
+#endif // !(_WIN32_WINNT >= 0x0500)
+ return SelectBrush((HBRUSH)::GetStockObject(nBrush));
+ }
+
+ HFONT SelectStockFont(int nFont)
+ {
+#ifndef _WIN32_WCE
+ ATLASSERT((nFont >= OEM_FIXED_FONT && nFont <= SYSTEM_FIXED_FONT) || nFont == DEFAULT_GUI_FONT);
+#else // CE specific
+ ATLASSERT(nFont == SYSTEM_FONT);
+#endif // _WIN32_WCE
+ return SelectFont((HFONT)::GetStockObject(nFont));
+ }
+
+ HPALETTE SelectStockPalette(int nPalette, BOOL bForceBackground)
+ {
+ ATLASSERT(nPalette == DEFAULT_PALETTE); // the only one supported
+ return SelectPalette((HPALETTE)::GetStockObject(nPalette), bForceBackground);
+ }
+
+// Color and Color Palette Functions
+ COLORREF GetNearestColor(COLORREF crColor) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetNearestColor(m_hDC, crColor);
+ }
+
+ HPALETTE SelectPalette(HPALETTE hPalette, BOOL bForceBackground)
+ {
+ ATLASSERT(m_hDC != NULL);
+
+ return ::SelectPalette(m_hDC, hPalette, bForceBackground);
+ }
+
+ UINT RealizePalette()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::RealizePalette(m_hDC);
+ }
+
+#ifndef _WIN32_WCE
+ void UpdateColors()
+ {
+ ATLASSERT(m_hDC != NULL);
+ ::UpdateColors(m_hDC);
+ }
+#endif // !_WIN32_WCE
+
+// Drawing-Attribute Functions
+ COLORREF GetBkColor() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetBkColor(m_hDC);
+ }
+
+ int GetBkMode() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetBkMode(m_hDC);
+ }
+
+#ifndef _WIN32_WCE
+ int GetPolyFillMode() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetPolyFillMode(m_hDC);
+ }
+
+ int GetROP2() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetROP2(m_hDC);
+ }
+
+ int GetStretchBltMode() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetStretchBltMode(m_hDC);
+ }
+#endif // !_WIN32_WCE
+
+ COLORREF GetTextColor() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextColor(m_hDC);
+ }
+
+ COLORREF SetBkColor(COLORREF crColor)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetBkColor(m_hDC, crColor);
+ }
+
+ int SetBkMode(int nBkMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetBkMode(m_hDC, nBkMode);
+ }
+
+#ifndef _WIN32_WCE
+ int SetPolyFillMode(int nPolyFillMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetPolyFillMode(m_hDC, nPolyFillMode);
+ }
+#endif // !_WIN32_WCE
+
+ int SetROP2(int nDrawMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetROP2(m_hDC, nDrawMode);
+ }
+
+#ifndef _WIN32_WCE
+ int SetStretchBltMode(int nStretchMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetStretchBltMode(m_hDC, nStretchMode);
+ }
+#endif // !_WIN32_WCE
+
+ COLORREF SetTextColor(COLORREF crColor)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetTextColor(m_hDC, crColor);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL GetColorAdjustment(LPCOLORADJUSTMENT lpColorAdjust) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetColorAdjustment(m_hDC, lpColorAdjust);
+ }
+
+ BOOL SetColorAdjustment(const COLORADJUSTMENT* lpColorAdjust)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetColorAdjustment(m_hDC, lpColorAdjust);
+ }
+
+// Mapping Functions
+ int GetMapMode() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetMapMode(m_hDC);
+ }
+
+ BOOL GetViewportOrg(LPPOINT lpPoint) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetViewportOrgEx(m_hDC, lpPoint);
+ }
+
+ int SetMapMode(int nMapMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetMapMode(m_hDC, nMapMode);
+ }
+#endif // !_WIN32_WCE
+
+ // Viewport Origin
+ BOOL SetViewportOrg(int x, int y, LPPOINT lpPoint = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetViewportOrgEx(m_hDC, x, y, lpPoint);
+ }
+
+ BOOL SetViewportOrg(POINT point, LPPOINT lpPointRet = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return SetViewportOrg(point.x, point.y, lpPointRet);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL OffsetViewportOrg(int nWidth, int nHeight, LPPOINT lpPoint = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::OffsetViewportOrgEx(m_hDC, nWidth, nHeight, lpPoint);
+ }
+
+ // Viewport Extent
+ BOOL GetViewportExt(LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetViewportExtEx(m_hDC, lpSize);
+ }
+
+ BOOL SetViewportExt(int x, int y, LPSIZE lpSize = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetViewportExtEx(m_hDC, x, y, lpSize);
+ }
+
+ BOOL SetViewportExt(SIZE size, LPSIZE lpSizeRet = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return SetViewportExt(size.cx, size.cy, lpSizeRet);
+ }
+
+ BOOL ScaleViewportExt(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ScaleViewportExtEx(m_hDC, xNum, xDenom, yNum, yDenom, lpSize);
+ }
+#endif // !_WIN32_WCE
+
+ // Window Origin
+#ifndef _WIN32_WCE
+ BOOL GetWindowOrg(LPPOINT lpPoint) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetWindowOrgEx(m_hDC, lpPoint);
+ }
+
+ BOOL SetWindowOrg(int x, int y, LPPOINT lpPoint = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetWindowOrgEx(m_hDC, x, y, lpPoint);
+ }
+
+ BOOL SetWindowOrg(POINT point, LPPOINT lpPointRet = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return SetWindowOrg(point.x, point.y, lpPointRet);
+ }
+
+ BOOL OffsetWindowOrg(int nWidth, int nHeight, LPPOINT lpPoint = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::OffsetWindowOrgEx(m_hDC, nWidth, nHeight, lpPoint);
+ }
+
+ // Window extent
+ BOOL GetWindowExt(LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetWindowExtEx(m_hDC, lpSize);
+ }
+
+ BOOL SetWindowExt(int x, int y, LPSIZE lpSize = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetWindowExtEx(m_hDC, x, y, lpSize);
+ }
+
+ BOOL SetWindowExt(SIZE size, LPSIZE lpSizeRet = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return SetWindowExt(size.cx, size.cy, lpSizeRet);
+ }
+
+ BOOL ScaleWindowExt(int xNum, int xDenom, int yNum, int yDenom, LPSIZE lpSize = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ScaleWindowExtEx(m_hDC, xNum, xDenom, yNum, yDenom, lpSize);
+ }
+
+// Coordinate Functions
+ BOOL DPtoLP(LPPOINT lpPoints, int nCount = 1) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DPtoLP(m_hDC, lpPoints, nCount);
+ }
+
+ BOOL DPtoLP(LPRECT lpRect) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DPtoLP(m_hDC, (LPPOINT)lpRect, 2);
+ }
+
+ BOOL DPtoLP(LPSIZE lpSize) const
+ {
+ SIZE sizeWinExt = { 0, 0 };
+ if(!GetWindowExt(&sizeWinExt))
+ return FALSE;
+ SIZE sizeVpExt = { 0, 0 };
+ if(!GetViewportExt(&sizeVpExt))
+ return FALSE;
+ lpSize->cx = ::MulDiv(lpSize->cx, abs(sizeWinExt.cx), abs(sizeVpExt.cx));
+ lpSize->cy = ::MulDiv(lpSize->cy, abs(sizeWinExt.cy), abs(sizeVpExt.cy));
+ return TRUE;
+ }
+
+ BOOL LPtoDP(LPPOINT lpPoints, int nCount = 1) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::LPtoDP(m_hDC, lpPoints, nCount);
+ }
+
+ BOOL LPtoDP(LPRECT lpRect) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::LPtoDP(m_hDC, (LPPOINT)lpRect, 2);
+ }
+
+ BOOL LPtoDP(LPSIZE lpSize) const
+ {
+ SIZE sizeWinExt = { 0, 0 };
+ if(!GetWindowExt(&sizeWinExt))
+ return FALSE;
+ SIZE sizeVpExt = { 0, 0 };
+ if(!GetViewportExt(&sizeVpExt))
+ return FALSE;
+ lpSize->cx = ::MulDiv(lpSize->cx, abs(sizeVpExt.cx), abs(sizeWinExt.cx));
+ lpSize->cy = ::MulDiv(lpSize->cy, abs(sizeVpExt.cy), abs(sizeWinExt.cy));
+ return TRUE;
+ }
+
+// Special Coordinate Functions (useful for dealing with metafiles and OLE)
+ #define HIMETRIC_INCH 2540 // HIMETRIC units per inch
+
+ void DPtoHIMETRIC(LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ int nMapMode;
+ if((nMapMode = GetMapMode()) < MM_ISOTROPIC && nMapMode != MM_TEXT)
+ {
+ // when using a constrained map mode, map against physical inch
+ ((CDCHandle*)this)->SetMapMode(MM_HIMETRIC);
+ DPtoLP(lpSize);
+ ((CDCHandle*)this)->SetMapMode(nMapMode);
+ }
+ else
+ {
+ // map against logical inch for non-constrained mapping modes
+ int cxPerInch = GetDeviceCaps(LOGPIXELSX);
+ int cyPerInch = GetDeviceCaps(LOGPIXELSY);
+ ATLASSERT(cxPerInch != 0 && cyPerInch != 0);
+ lpSize->cx = ::MulDiv(lpSize->cx, HIMETRIC_INCH, cxPerInch);
+ lpSize->cy = ::MulDiv(lpSize->cy, HIMETRIC_INCH, cyPerInch);
+ }
+ }
+
+ void HIMETRICtoDP(LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ int nMapMode;
+ if((nMapMode = GetMapMode()) < MM_ISOTROPIC && nMapMode != MM_TEXT)
+ {
+ // when using a constrained map mode, map against physical inch
+ ((CDCHandle*)this)->SetMapMode(MM_HIMETRIC);
+ LPtoDP(lpSize);
+ ((CDCHandle*)this)->SetMapMode(nMapMode);
+ }
+ else
+ {
+ // map against logical inch for non-constrained mapping modes
+ int cxPerInch = GetDeviceCaps(LOGPIXELSX);
+ int cyPerInch = GetDeviceCaps(LOGPIXELSY);
+ ATLASSERT(cxPerInch != 0 && cyPerInch != 0);
+ lpSize->cx = ::MulDiv(lpSize->cx, cxPerInch, HIMETRIC_INCH);
+ lpSize->cy = ::MulDiv(lpSize->cy, cyPerInch, HIMETRIC_INCH);
+ }
+ }
+
+ void LPtoHIMETRIC(LPSIZE lpSize) const
+ {
+ LPtoDP(lpSize);
+ DPtoHIMETRIC(lpSize);
+ }
+
+ void HIMETRICtoLP(LPSIZE lpSize) const
+ {
+ HIMETRICtoDP(lpSize);
+ DPtoLP(lpSize);
+ }
+#endif // !_WIN32_WCE
+
+// Region Functions
+ BOOL FillRgn(HRGN hRgn, HBRUSH hBrush)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::FillRgn(m_hDC, hRgn, hBrush);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL FrameRgn(HRGN hRgn, HBRUSH hBrush, int nWidth, int nHeight)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::FrameRgn(m_hDC, hRgn, hBrush, nWidth, nHeight);
+ }
+
+ BOOL InvertRgn(HRGN hRgn)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::InvertRgn(m_hDC, hRgn);
+ }
+
+ BOOL PaintRgn(HRGN hRgn)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PaintRgn(m_hDC, hRgn);
+ }
+#endif // !_WIN32_WCE
+
+// Clipping Functions
+ int GetClipBox(LPRECT lpRect) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetClipBox(m_hDC, lpRect);
+ }
+
+ int GetClipRgn(CRgn& region) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ if(region.IsNull())
+ region.CreateRectRgn(0, 0, 0, 0);
+
+ int nRet = ::GetClipRgn(m_hDC, region);
+ if(nRet != 1)
+ region.DeleteObject();
+
+ return nRet;
+ }
+
+#ifndef _WIN32_WCE
+ BOOL PtVisible(int x, int y) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PtVisible(m_hDC, x, y);
+ }
+
+ BOOL PtVisible(POINT point) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PtVisible(m_hDC, point.x, point.y);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL RectVisible(LPCRECT lpRect) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::RectVisible(m_hDC, lpRect);
+ }
+
+ int SelectClipRgn(HRGN hRgn)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SelectClipRgn(m_hDC, (HRGN)hRgn);
+ }
+
+ int ExcludeClipRect(int x1, int y1, int x2, int y2)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ExcludeClipRect(m_hDC, x1, y1, x2, y2);
+ }
+
+ int ExcludeClipRect(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ExcludeClipRect(m_hDC, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
+ }
+
+#ifndef _WIN32_WCE
+ int ExcludeUpdateRgn(HWND hWnd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ExcludeUpdateRgn(m_hDC, hWnd);
+ }
+#endif // !_WIN32_WCE
+
+ int IntersectClipRect(int x1, int y1, int x2, int y2)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::IntersectClipRect(m_hDC, x1, y1, x2, y2);
+ }
+
+ int IntersectClipRect(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::IntersectClipRect(m_hDC, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
+ }
+
+#ifndef _WIN32_WCE
+ int OffsetClipRgn(int x, int y)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::OffsetClipRgn(m_hDC, x, y);
+ }
+
+ int OffsetClipRgn(SIZE size)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::OffsetClipRgn(m_hDC, size.cx, size.cy);
+ }
+
+ int SelectClipRgn(HRGN hRgn, int nMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ExtSelectClipRgn(m_hDC, hRgn, nMode);
+ }
+#endif // !_WIN32_WCE
+
+// Line-Output Functions
+#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
+ BOOL GetCurrentPosition(LPPOINT lpPoint) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetCurrentPositionEx(m_hDC, lpPoint);
+ }
+
+ BOOL MoveTo(int x, int y, LPPOINT lpPoint = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::MoveToEx(m_hDC, x, y, lpPoint);
+ }
+
+ BOOL MoveTo(POINT point, LPPOINT lpPointRet = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return MoveTo(point.x, point.y, lpPointRet);
+ }
+
+ BOOL LineTo(int x, int y)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::LineTo(m_hDC, x, y);
+ }
+
+ BOOL LineTo(POINT point)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return LineTo(point.x, point.y);
+ }
+#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
+
+#ifndef _WIN32_WCE
+ BOOL Arc(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Arc(m_hDC, x1, y1, x2, y2, x3, y3, x4, y4);
+ }
+
+ BOOL Arc(LPCRECT lpRect, POINT ptStart, POINT ptEnd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Arc(m_hDC, lpRect->left, lpRect->top,
+ lpRect->right, lpRect->bottom, ptStart.x, ptStart.y,
+ ptEnd.x, ptEnd.y);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL Polyline(LPPOINT lpPoints, int nCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Polyline(m_hDC, lpPoints, nCount);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL AngleArc(int x, int y, int nRadius, float fStartAngle, float fSweepAngle)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::AngleArc(m_hDC, x, y, nRadius, fStartAngle, fSweepAngle);
+ }
+
+ BOOL ArcTo(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ArcTo(m_hDC, x1, y1, x2, y2, x3, y3, x4, y4);
+ }
+
+ BOOL ArcTo(LPCRECT lpRect, POINT ptStart, POINT ptEnd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ArcTo(lpRect->left, lpRect->top, lpRect->right,
+ lpRect->bottom, ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
+ }
+
+ int GetArcDirection() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetArcDirection(m_hDC);
+ }
+
+ int SetArcDirection(int nArcDirection)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetArcDirection(m_hDC, nArcDirection);
+ }
+
+ BOOL PolyDraw(const POINT* lpPoints, const BYTE* lpTypes, int nCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PolyDraw(m_hDC, lpPoints, lpTypes, nCount);
+ }
+
+ BOOL PolylineTo(const POINT* lpPoints, int nCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PolylineTo(m_hDC, lpPoints, nCount);
+ }
+
+ BOOL PolyPolyline(const POINT* lpPoints,
+ const DWORD* lpPolyPoints, int nCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PolyPolyline(m_hDC, lpPoints, lpPolyPoints, nCount);
+ }
+
+ BOOL PolyBezier(const POINT* lpPoints, int nCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PolyBezier(m_hDC, lpPoints, nCount);
+ }
+
+ BOOL PolyBezierTo(const POINT* lpPoints, int nCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PolyBezierTo(m_hDC, lpPoints, nCount);
+ }
+#endif // !_WIN32_WCE
+
+// Simple Drawing Functions
+ BOOL FillRect(LPCRECT lpRect, HBRUSH hBrush)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::FillRect(m_hDC, lpRect, hBrush);
+ }
+
+ BOOL FillRect(LPCRECT lpRect, int nColorIndex)
+ {
+ ATLASSERT(m_hDC != NULL);
+#ifndef _WIN32_WCE
+ return ::FillRect(m_hDC, lpRect, (HBRUSH)LongToPtr(nColorIndex + 1));
+#else // CE specific
+ return ::FillRect(m_hDC, lpRect, ::GetSysColorBrush(nColorIndex));
+#endif // _WIN32_WCE
+ }
+
+#ifndef _WIN32_WCE
+ BOOL FrameRect(LPCRECT lpRect, HBRUSH hBrush)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::FrameRect(m_hDC, lpRect, hBrush);
+ }
+#endif // !_WIN32_WCE
+
+#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
+ BOOL InvertRect(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::InvertRect(m_hDC, lpRect);
+ }
+#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
+
+ BOOL DrawIcon(int x, int y, HICON hIcon)
+ {
+ ATLASSERT(m_hDC != NULL);
+#ifndef _WIN32_WCE
+ return ::DrawIcon(m_hDC, x, y, hIcon);
+#else // CE specific
+ return ::DrawIconEx(m_hDC, x, y, hIcon, 0, 0, 0, NULL, DI_NORMAL);
+#endif // _WIN32_WCE
+ }
+
+ BOOL DrawIcon(POINT point, HICON hIcon)
+ {
+ ATLASSERT(m_hDC != NULL);
+#ifndef _WIN32_WCE
+ return ::DrawIcon(m_hDC, point.x, point.y, hIcon);
+#else // CE specific
+ return ::DrawIconEx(m_hDC, point.x, point.y, hIcon, 0, 0, 0, NULL, DI_NORMAL);
+#endif // _WIN32_WCE
+ }
+
+ BOOL DrawIconEx(int x, int y, HICON hIcon, int cxWidth, int cyWidth, UINT uStepIfAniCur = 0, HBRUSH hbrFlickerFreeDraw = NULL, UINT uFlags = DI_NORMAL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawIconEx(m_hDC, x, y, hIcon, cxWidth, cyWidth, uStepIfAniCur, hbrFlickerFreeDraw, uFlags);
+ }
+
+ BOOL DrawIconEx(POINT point, HICON hIcon, SIZE size, UINT uStepIfAniCur = 0, HBRUSH hbrFlickerFreeDraw = NULL, UINT uFlags = DI_NORMAL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawIconEx(m_hDC, point.x, point.y, hIcon, size.cx, size.cy, uStepIfAniCur, hbrFlickerFreeDraw, uFlags);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL DrawState(POINT pt, SIZE size, HBITMAP hBitmap, UINT nFlags, HBRUSH hBrush = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawState(m_hDC, hBrush, NULL, (LPARAM)hBitmap, 0, pt.x, pt.y, size.cx, size.cy, nFlags | DST_BITMAP);
+ }
+
+ BOOL DrawState(POINT pt, SIZE size, HICON hIcon, UINT nFlags, HBRUSH hBrush = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawState(m_hDC, hBrush, NULL, (LPARAM)hIcon, 0, pt.x, pt.y, size.cx, size.cy, nFlags | DST_ICON);
+ }
+
+ BOOL DrawState(POINT pt, SIZE size, LPCTSTR lpszText, UINT nFlags, BOOL bPrefixText = TRUE, int nTextLen = 0, HBRUSH hBrush = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawState(m_hDC, hBrush, NULL, (LPARAM)lpszText, (WPARAM)nTextLen, pt.x, pt.y, size.cx, size.cy, nFlags | (bPrefixText ? DST_PREFIXTEXT : DST_TEXT));
+ }
+
+ BOOL DrawState(POINT pt, SIZE size, DRAWSTATEPROC lpDrawProc, LPARAM lData, UINT nFlags, HBRUSH hBrush = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawState(m_hDC, hBrush, lpDrawProc, lData, 0, pt.x, pt.y, size.cx, size.cy, nFlags | DST_COMPLEX);
+ }
+#endif // !_WIN32_WCE
+
+// Ellipse and Polygon Functions
+#ifndef _WIN32_WCE
+ BOOL Chord(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Chord(m_hDC, x1, y1, x2, y2, x3, y3, x4, y4);
+ }
+
+ BOOL Chord(LPCRECT lpRect, POINT ptStart, POINT ptEnd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Chord(m_hDC, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom, ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
+ }
+#endif // !_WIN32_WCE
+
+ void DrawFocusRect(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hDC != NULL);
+ ::DrawFocusRect(m_hDC, lpRect);
+ }
+
+ BOOL Ellipse(int x1, int y1, int x2, int y2)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Ellipse(m_hDC, x1, y1, x2, y2);
+ }
+
+ BOOL Ellipse(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Ellipse(m_hDC, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL Pie(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Pie(m_hDC, x1, y1, x2, y2, x3, y3, x4, y4);
+ }
+
+ BOOL Pie(LPCRECT lpRect, POINT ptStart, POINT ptEnd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Pie(m_hDC, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom, ptStart.x, ptStart.y, ptEnd.x, ptEnd.y);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL Polygon(LPPOINT lpPoints, int nCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Polygon(m_hDC, lpPoints, nCount);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL PolyPolygon(LPPOINT lpPoints, LPINT lpPolyCounts, int nCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PolyPolygon(m_hDC, lpPoints, lpPolyCounts, nCount);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL Rectangle(int x1, int y1, int x2, int y2)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Rectangle(m_hDC, x1, y1, x2, y2);
+ }
+
+ BOOL Rectangle(LPCRECT lpRect)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Rectangle(m_hDC, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom);
+ }
+
+ BOOL RoundRect(int x1, int y1, int x2, int y2, int x3, int y3)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::RoundRect(m_hDC, x1, y1, x2, y2, x3, y3);
+ }
+
+ BOOL RoundRect(LPCRECT lpRect, POINT point)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::RoundRect(m_hDC, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom, point.x, point.y);
+ }
+
+// Bitmap Functions
+ BOOL PatBlt(int x, int y, int nWidth, int nHeight, DWORD dwRop)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PatBlt(m_hDC, x, y, nWidth, nHeight, dwRop);
+ }
+
+ BOOL BitBlt(int x, int y, int nWidth, int nHeight, HDC hSrcDC,
+ int xSrc, int ySrc, DWORD dwRop)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::BitBlt(m_hDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, dwRop);
+ }
+
+ BOOL StretchBlt(int x, int y, int nWidth, int nHeight, HDC hSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::StretchBlt(m_hDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, nSrcWidth, nSrcHeight, dwRop);
+ }
+
+ COLORREF GetPixel(int x, int y) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetPixel(m_hDC, x, y);
+ }
+
+ COLORREF GetPixel(POINT point) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetPixel(m_hDC, point.x, point.y);
+ }
+
+ COLORREF SetPixel(int x, int y, COLORREF crColor)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetPixel(m_hDC, x, y, crColor);
+ }
+
+ COLORREF SetPixel(POINT point, COLORREF crColor)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetPixel(m_hDC, point.x, point.y, crColor);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL FloodFill(int x, int y, COLORREF crColor)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::FloodFill(m_hDC, x, y, crColor);
+ }
+
+ BOOL ExtFloodFill(int x, int y, COLORREF crColor, UINT nFillType)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ExtFloodFill(m_hDC, x, y, crColor, nFillType);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL MaskBlt(int x, int y, int nWidth, int nHeight, HDC hSrcDC, int xSrc, int ySrc, HBITMAP hMaskBitmap, int xMask, int yMask, DWORD dwRop)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::MaskBlt(m_hDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, hMaskBitmap, xMask, yMask, dwRop);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL PlgBlt(LPPOINT lpPoint, HDC hSrcDC, int xSrc, int ySrc, int nWidth, int nHeight, HBITMAP hMaskBitmap, int xMask, int yMask)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PlgBlt(m_hDC, lpPoint, hSrcDC, xSrc, ySrc, nWidth, nHeight, hMaskBitmap, xMask, yMask);
+ }
+
+ BOOL SetPixelV(int x, int y, COLORREF crColor)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetPixelV(m_hDC, x, y, crColor);
+ }
+
+ BOOL SetPixelV(POINT point, COLORREF crColor)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetPixelV(m_hDC, point.x, point.y, crColor);
+ }
+#endif // !_WIN32_WCE
+
+#if !defined(_ATL_NO_MSIMG) || defined(_WIN32_WCE)
+#ifndef _WIN32_WCE
+ BOOL TransparentBlt(int x, int y, int nWidth, int nHeight, HDC hSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, UINT crTransparent)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::TransparentBlt(m_hDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, nSrcWidth, nSrcHeight, crTransparent);
+ }
+#else // CE specific
+ BOOL TransparentImage(int x, int y, int nWidth, int nHeight, HDC hSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, UINT crTransparent)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::TransparentImage(m_hDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, nSrcWidth, nSrcHeight, crTransparent);
+ }
+#endif // _WIN32_WCE
+
+#if (!defined(_WIN32_WCE) || (_WIN32_WCE >= 420))
+ BOOL GradientFill(const PTRIVERTEX pVertices, DWORD nVertices, void* pMeshElements, DWORD nMeshElements, DWORD dwMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GradientFill(m_hDC, pVertices, nVertices, pMeshElements, nMeshElements, dwMode);
+ }
+
+ BOOL GradientFillRect(RECT& rect, COLORREF clr1, COLORREF clr2, bool bHorizontal)
+ {
+ ATLASSERT(m_hDC != NULL);
+
+ TRIVERTEX arrTvx[2] = { { 0 }, { 0 } };
+
+ arrTvx[0].x = rect.left;
+ arrTvx[0].y = rect.top;
+ arrTvx[0].Red = MAKEWORD(0, GetRValue(clr1));
+ arrTvx[0].Green = MAKEWORD(0, GetGValue(clr1));
+ arrTvx[0].Blue = MAKEWORD(0, GetBValue(clr1));
+ arrTvx[0].Alpha = 0;
+
+ arrTvx[1].x = rect.right;
+ arrTvx[1].y = rect.bottom;
+ arrTvx[1].Red = MAKEWORD(0, GetRValue(clr2));
+ arrTvx[1].Green = MAKEWORD(0, GetGValue(clr2));
+ arrTvx[1].Blue = MAKEWORD(0, GetBValue(clr2));
+ arrTvx[1].Alpha = 0;
+
+ GRADIENT_RECT gr = { 0, 1 };
+
+ return ::GradientFill(m_hDC, arrTvx, 2, &gr, 1, bHorizontal ? GRADIENT_FILL_RECT_H : GRADIENT_FILL_RECT_V);
+ }
+#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 420)
+
+#if !defined(_WIN32_WCE) || (_WIN32_WCE > 0x500)
+ BOOL AlphaBlend(int x, int y, int nWidth, int nHeight, HDC hSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, BLENDFUNCTION bf)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::AlphaBlend(m_hDC, x, y, nWidth, nHeight, hSrcDC, xSrc, ySrc, nSrcWidth, nSrcHeight, bf);
+ }
+#endif // !defined(_WIN32_WCE) || (_WIN32_WCE > 0x500)
+#endif // !defined(_ATL_NO_MSIMG) || defined(_WIN32_WCE)
+
+// Extra bitmap functions
+ // Helper function for painting a disabled toolbar or menu bitmap
+ // This function can take either an HBITMAP (for SS) or a DC with
+ // the bitmap already painted (for cmdbar)
+ BOOL DitherBlt(int x, int y, int nWidth, int nHeight, HDC hSrcDC, HBITMAP hBitmap, int xSrc, int ySrc,
+ HBRUSH hBrushBackground = ::GetSysColorBrush(COLOR_3DFACE),
+ HBRUSH hBrush3DEffect = ::GetSysColorBrush(COLOR_3DHILIGHT),
+ HBRUSH hBrushDisabledImage = ::GetSysColorBrush(COLOR_3DSHADOW))
+ {
+ ATLASSERT(m_hDC != NULL || hBitmap != NULL);
+ ATLASSERT(nWidth > 0 && nHeight > 0);
+
+ // Create a generic DC for all BitBlts
+ CDCHandle dc = (hSrcDC != NULL) ? hSrcDC : ::CreateCompatibleDC(m_hDC);
+ ATLASSERT(dc.m_hDC != NULL);
+ if(dc.m_hDC == NULL)
+ return FALSE;
+
+ // Create a DC for the monochrome DIB section
+ CDC dcBW = ::CreateCompatibleDC(m_hDC);
+ ATLASSERT(dcBW.m_hDC != NULL);
+ if(dcBW.m_hDC == NULL)
+ {
+ if(hSrcDC == NULL)
+ dc.DeleteDC();
+ return FALSE;
+ }
+
+ // Create the monochrome DIB section with a black and white palette
+ struct RGBBWBITMAPINFO
+ {
+ BITMAPINFOHEADER bmiHeader;
+ RGBQUAD bmiColors[2];
+ };
+
+ RGBBWBITMAPINFO rgbBWBitmapInfo =
+ {
+ { sizeof(BITMAPINFOHEADER), nWidth, nHeight, 1, 1, BI_RGB, 0, 0, 0, 0, 0 },
+ { { 0x00, 0x00, 0x00, 0x00 }, { 0xFF, 0xFF, 0xFF, 0x00 } }
+ };
+
+ VOID* pbitsBW;
+ CBitmap bmpBW = ::CreateDIBSection(dcBW, (LPBITMAPINFO)&rgbBWBitmapInfo, DIB_RGB_COLORS, &pbitsBW, NULL, 0);
+ ATLASSERT(bmpBW.m_hBitmap != NULL);
+ if(bmpBW.m_hBitmap == NULL)
+ {
+ if(hSrcDC == NULL)
+ dc.DeleteDC();
+ return FALSE;
+ }
+
+ // Attach the monochrome DIB section and the bitmap to the DCs
+ HBITMAP hbmOldBW = dcBW.SelectBitmap(bmpBW);
+ HBITMAP hbmOldDC = NULL;
+ if(hBitmap != NULL)
+ hbmOldDC = dc.SelectBitmap(hBitmap);
+
+ // Block: Dark gray removal: we want (128, 128, 128) pixels to become black and not white
+ {
+ CDC dcTemp1 = ::CreateCompatibleDC(m_hDC);
+ CDC dcTemp2 = ::CreateCompatibleDC(m_hDC);
+ CBitmap bmpTemp1;
+ bmpTemp1.CreateCompatibleBitmap(dc, nWidth, nHeight);
+ CBitmap bmpTemp2;
+ bmpTemp2.CreateBitmap(nWidth, nHeight, 1, 1, NULL);
+ HBITMAP hOldBmp1 = dcTemp1.SelectBitmap(bmpTemp1);
+ HBITMAP hOldBmp2 = dcTemp2.SelectBitmap(bmpTemp2);
+ // Let's copy our image, it will be altered
+ dcTemp1.BitBlt(0, 0, nWidth, nHeight, dc, xSrc, ySrc, SRCCOPY);
+
+ // All dark gray pixels will become white, the others black
+ dcTemp1.SetBkColor(RGB(128, 128, 128));
+ dcTemp2.BitBlt(0, 0, nWidth, nHeight, dcTemp1, 0, 0, SRCCOPY);
+ // Do an XOR to set to black these white pixels
+ dcTemp1.BitBlt(0, 0, nWidth, nHeight, dcTemp2, 0, 0, SRCINVERT);
+
+ // BitBlt the bitmap into the monochrome DIB section
+ // The DIB section will do a true monochrome conversion
+ // The magenta background being closer to white will become white
+ dcBW.BitBlt(0, 0, nWidth, nHeight, dcTemp1, 0, 0, SRCCOPY);
+
+ // Cleanup
+ dcTemp1.SelectBitmap(hOldBmp1);
+ dcTemp2.SelectBitmap(hOldBmp2);
+ }
+
+ // Paint the destination rectangle using hBrushBackground
+ if(hBrushBackground != NULL)
+ {
+ RECT rc = { x, y, x + nWidth, y + nHeight };
+ FillRect(&rc, hBrushBackground);
+ }
+
+ // BitBlt the black bits in the monochrome bitmap into hBrush3DEffect color in the destination DC
+ // The magic ROP comes from the Charles Petzold's book
+ HBRUSH hOldBrush = SelectBrush(hBrush3DEffect);
+ BitBlt(x + 1, y + 1, nWidth, nHeight, dcBW, 0, 0, 0xB8074A);
+
+ // BitBlt the black bits in the monochrome bitmap into hBrushDisabledImage color in the destination DC
+ SelectBrush(hBrushDisabledImage);
+ BitBlt(x, y, nWidth, nHeight, dcBW, 0, 0, 0xB8074A);
+
+ SelectBrush(hOldBrush);
+ dcBW.SelectBitmap(hbmOldBW);
+ dc.SelectBitmap(hbmOldDC);
+
+ if(hSrcDC == NULL)
+ dc.DeleteDC();
+
+ return TRUE;
+ }
+
+// Text Functions
+#ifndef _WIN32_WCE
+ BOOL TextOut(int x, int y, LPCTSTR lpszString, int nCount = -1)
+ {
+ ATLASSERT(m_hDC != NULL);
+ if(nCount == -1)
+ nCount = lstrlen(lpszString);
+ return ::TextOut(m_hDC, x, y, lpszString, nCount);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL ExtTextOut(int x, int y, UINT nOptions, LPCRECT lpRect, LPCTSTR lpszString, UINT nCount = -1, LPINT lpDxWidths = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ if(nCount == -1)
+ nCount = lstrlen(lpszString);
+ return ::ExtTextOut(m_hDC, x, y, nOptions, lpRect, lpszString, nCount, lpDxWidths);
+ }
+
+#ifndef _WIN32_WCE
+ SIZE TabbedTextOut(int x, int y, LPCTSTR lpszString, int nCount = -1, int nTabPositions = 0, LPINT lpnTabStopPositions = NULL, int nTabOrigin = 0)
+ {
+ ATLASSERT(m_hDC != NULL);
+ if(nCount == -1)
+ nCount = lstrlen(lpszString);
+ LONG lRes = ::TabbedTextOut(m_hDC, x, y, lpszString, nCount, nTabPositions, lpnTabStopPositions, nTabOrigin);
+ SIZE size = { GET_X_LPARAM(lRes), GET_Y_LPARAM(lRes) };
+ return size;
+ }
+#endif // !_WIN32_WCE
+
+ int DrawText(LPCTSTR lpstrText, int cchText, LPRECT lpRect, UINT uFormat)
+ {
+ ATLASSERT(m_hDC != NULL);
+#ifndef _WIN32_WCE
+ ATLASSERT((uFormat & DT_MODIFYSTRING) == 0);
+#endif // !_WIN32_WCE
+ return ::DrawText(m_hDC, lpstrText, cchText, lpRect, uFormat);
+ }
+
+ int DrawText(LPTSTR lpstrText, int cchText, LPRECT lpRect, UINT uFormat)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawText(m_hDC, lpstrText, cchText, lpRect, uFormat);
+ }
+
+#ifndef _WIN32_WCE
+ int DrawTextEx(LPTSTR lpstrText, int cchText, LPRECT lpRect, UINT uFormat, LPDRAWTEXTPARAMS lpDTParams = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawTextEx(m_hDC, lpstrText, cchText, lpRect, uFormat, lpDTParams);
+ }
+#endif // !_WIN32_WCE
+
+#if (_WIN32_WINNT >= 0x0501)
+ int DrawShadowText(LPCWSTR lpstrText, int cchText, LPRECT lpRect, DWORD dwFlags, COLORREF clrText, COLORREF clrShadow, int xOffset, int yOffset)
+ {
+ ATLASSERT(m_hDC != NULL);
+ // This function is present only if comctl32.dll version 6 is loaded;
+ // we use LoadLibrary/GetProcAddress to allow apps compiled with
+ // _WIN32_WINNT >= 0x0501 to run on older Windows/CommCtrl
+ int nRet = 0;
+ HMODULE hCommCtrlDLL = ::LoadLibrary(_T("comctl32.dll"));
+ ATLASSERT(hCommCtrlDLL != NULL);
+ if(hCommCtrlDLL != NULL)
+ {
+ typedef int (WINAPI *PFN_DrawShadowText)(HDC hDC, LPCWSTR lpstrText, UINT cchText, LPRECT lpRect, DWORD dwFlags, COLORREF clrText, COLORREF clrShadow, int xOffset, int yOffset);
+ PFN_DrawShadowText pfnDrawShadowText = (PFN_DrawShadowText)::GetProcAddress(hCommCtrlDLL, "DrawShadowText");
+ ATLASSERT(pfnDrawShadowText != NULL); // this function requires CommCtrl6
+ if(pfnDrawShadowText != NULL)
+ nRet = pfnDrawShadowText(m_hDC, lpstrText, cchText, lpRect, dwFlags, clrText, clrShadow, xOffset, yOffset);
+ ::FreeLibrary(hCommCtrlDLL);
+ }
+ return nRet;
+ }
+#endif // (_WIN32_WINNT >= 0x0501)
+
+ BOOL GetTextExtent(LPCTSTR lpszString, int nCount, LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ if(nCount == -1)
+ nCount = lstrlen(lpszString);
+ return ::GetTextExtentPoint32(m_hDC, lpszString, nCount, lpSize);
+ }
+
+ BOOL GetTextExtentExPoint(LPCTSTR lpszString, int cchString, LPSIZE lpSize, int nMaxExtent, LPINT lpnFit = NULL, LPINT alpDx = NULL)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextExtentExPoint(m_hDC, lpszString, cchString, nMaxExtent, lpnFit, alpDx, lpSize);
+ }
+
+#ifndef _WIN32_WCE
+ DWORD GetTabbedTextExtent(LPCTSTR lpszString, int nCount = -1, int nTabPositions = 0, LPINT lpnTabStopPositions = NULL) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ if(nCount == -1)
+ nCount = lstrlen(lpszString);
+ return ::GetTabbedTextExtent(m_hDC, lpszString, nCount, nTabPositions, lpnTabStopPositions);
+ }
+
+ BOOL GrayString(HBRUSH hBrush, BOOL (CALLBACK* lpfnOutput)(HDC, LPARAM, int), LPARAM lpData, int nCount, int x, int y, int nWidth, int nHeight)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GrayString(m_hDC, hBrush, (GRAYSTRINGPROC)lpfnOutput, lpData, nCount, x, y, nWidth, nHeight);
+ }
+#endif // !_WIN32_WCE
+
+#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
+ UINT GetTextAlign() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextAlign(m_hDC);
+ }
+
+ UINT SetTextAlign(UINT nFlags)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetTextAlign(m_hDC, nFlags);
+ }
+#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
+
+ int GetTextFace(LPTSTR lpszFacename, int nCount) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextFace(m_hDC, nCount, lpszFacename);
+ }
+
+ int GetTextFaceLen() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextFace(m_hDC, 0, NULL);
+ }
+
+#ifndef _ATL_NO_COM
+#ifdef _OLEAUTO_H_
+ BOOL GetTextFace(BSTR& bstrFace) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(m_hDC != NULL);
+ ATLASSERT(bstrFace == NULL);
+
+ int nLen = GetTextFaceLen();
+ if(nLen == 0)
+ return FALSE;
+
+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPTSTR lpszText = buff.Allocate(nLen);
+ if(lpszText == NULL)
+ return FALSE;
+
+ if(!GetTextFace(lpszText, nLen))
+ return FALSE;
+
+ bstrFace = ::SysAllocString(T2OLE(lpszText));
+ return (bstrFace != NULL) ? TRUE : FALSE;
+ }
+#endif
+#endif // !_ATL_NO_COM
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ int GetTextFace(_CSTRING_NS::CString& strFace) const
+ {
+ ATLASSERT(m_hDC != NULL);
+
+ int nLen = GetTextFaceLen();
+ if(nLen == 0)
+ return 0;
+
+ LPTSTR lpstr = strFace.GetBufferSetLength(nLen);
+ if(lpstr == NULL)
+ return 0;
+ int nRet = GetTextFace(lpstr, nLen);
+ strFace.ReleaseBuffer();
+ return nRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ BOOL GetTextMetrics(LPTEXTMETRIC lpMetrics) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextMetrics(m_hDC, lpMetrics);
+ }
+
+#ifndef _WIN32_WCE
+ int SetTextJustification(int nBreakExtra, int nBreakCount)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetTextJustification(m_hDC, nBreakExtra, nBreakCount);
+ }
+
+ int GetTextCharacterExtra() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextCharacterExtra(m_hDC);
+ }
+
+ int SetTextCharacterExtra(int nCharExtra)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetTextCharacterExtra(m_hDC, nCharExtra);
+ }
+#endif // !_WIN32_WCE
+
+// Advanced Drawing
+ BOOL DrawEdge(LPRECT lpRect, UINT nEdge, UINT nFlags)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawEdge(m_hDC, lpRect, nEdge, nFlags);
+ }
+
+ BOOL DrawFrameControl(LPRECT lpRect, UINT nType, UINT nState)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawFrameControl(m_hDC, lpRect, nType, nState);
+ }
+
+// Scrolling Functions
+ BOOL ScrollDC(int dx, int dy, LPCRECT lpRectScroll, LPCRECT lpRectClip, HRGN hRgnUpdate, LPRECT lpRectUpdate)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ScrollDC(m_hDC, dx, dy, lpRectScroll, lpRectClip, hRgnUpdate, lpRectUpdate);
+ }
+
+// Font Functions
+#ifndef _WIN32_WCE
+ BOOL GetCharWidth(UINT nFirstChar, UINT nLastChar, LPINT lpBuffer) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetCharWidth(m_hDC, nFirstChar, nLastChar, lpBuffer);
+ }
+
+ // GetCharWidth32 is not supported under Win9x
+ BOOL GetCharWidth32(UINT nFirstChar, UINT nLastChar, LPINT lpBuffer) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetCharWidth32(m_hDC, nFirstChar, nLastChar, lpBuffer);
+ }
+
+ DWORD SetMapperFlags(DWORD dwFlag)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetMapperFlags(m_hDC, dwFlag);
+ }
+
+ BOOL GetAspectRatioFilter(LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetAspectRatioFilterEx(m_hDC, lpSize);
+ }
+
+ BOOL GetCharABCWidths(UINT nFirstChar, UINT nLastChar, LPABC lpabc) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetCharABCWidths(m_hDC, nFirstChar, nLastChar, lpabc);
+ }
+
+ DWORD GetFontData(DWORD dwTable, DWORD dwOffset, LPVOID lpData, DWORD cbData) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetFontData(m_hDC, dwTable, dwOffset, lpData, cbData);
+ }
+
+ int GetKerningPairs(int nPairs, LPKERNINGPAIR lpkrnpair) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetKerningPairs(m_hDC, nPairs, lpkrnpair);
+ }
+
+ UINT GetOutlineTextMetrics(UINT cbData, LPOUTLINETEXTMETRIC lpotm) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetOutlineTextMetrics(m_hDC, cbData, lpotm);
+ }
+
+ DWORD GetGlyphOutline(UINT nChar, UINT nFormat, LPGLYPHMETRICS lpgm, DWORD cbBuffer, LPVOID lpBuffer, const MAT2* lpmat2) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetGlyphOutline(m_hDC, nChar, nFormat, lpgm, cbBuffer, lpBuffer, lpmat2);
+ }
+
+ BOOL GetCharABCWidths(UINT nFirstChar, UINT nLastChar, LPABCFLOAT lpABCF) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetCharABCWidthsFloat(m_hDC, nFirstChar, nLastChar, lpABCF);
+ }
+
+ BOOL GetCharWidth(UINT nFirstChar, UINT nLastChar, float* lpFloatBuffer) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetCharWidthFloat(m_hDC, nFirstChar, nLastChar, lpFloatBuffer);
+ }
+#endif // !_WIN32_WCE
+
+// Printer/Device Escape Functions
+#ifndef _WIN32_WCE
+ int Escape(int nEscape, int nCount, LPCSTR lpszInData, LPVOID lpOutData)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::Escape(m_hDC, nEscape, nCount, lpszInData, lpOutData);
+ }
+#endif // !_WIN32_WCE
+
+ int Escape(int nEscape, int nInputSize, LPCSTR lpszInputData,
+ int nOutputSize, LPSTR lpszOutputData)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ExtEscape(m_hDC, nEscape, nInputSize, lpszInputData, nOutputSize, lpszOutputData);
+ }
+
+#ifndef _WIN32_WCE
+ int DrawEscape(int nEscape, int nInputSize, LPCSTR lpszInputData)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DrawEscape(m_hDC, nEscape, nInputSize, lpszInputData);
+ }
+#endif // !_WIN32_WCE
+
+ // Escape helpers
+#if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 200) && defined(StartDoc))
+ int StartDoc(LPCTSTR lpszDocName) // old Win3.0 version
+ {
+ DOCINFO di = { 0 };
+ di.cbSize = sizeof(DOCINFO);
+ di.lpszDocName = lpszDocName;
+ return StartDoc(&di);
+ }
+
+ int StartDoc(LPDOCINFO lpDocInfo)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::StartDoc(m_hDC, lpDocInfo);
+ }
+
+ int StartPage()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::StartPage(m_hDC);
+ }
+
+ int EndPage()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::EndPage(m_hDC);
+ }
+
+ int SetAbortProc(BOOL (CALLBACK* lpfn)(HDC, int))
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetAbortProc(m_hDC, (ABORTPROC)lpfn);
+ }
+
+ int AbortDoc()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::AbortDoc(m_hDC);
+ }
+
+ int EndDoc()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::EndDoc(m_hDC);
+ }
+#endif // !defined(_WIN32_WCE) || ((_WIN32_WCE >= 200) && defined(StartDoc))
+
+// MetaFile Functions
+#ifndef _WIN32_WCE
+ BOOL PlayMetaFile(HMETAFILE hMF)
+ {
+ ATLASSERT(m_hDC != NULL);
+ if(::GetDeviceCaps(m_hDC, TECHNOLOGY) == DT_METAFILE)
+ {
+ // playing metafile in metafile, just use core windows API
+ return ::PlayMetaFile(m_hDC, hMF);
+ }
+
+ // for special playback, lParam == pDC
+ return ::EnumMetaFile(m_hDC, hMF, EnumMetaFileProc, (LPARAM)this);
+ }
+
+ BOOL PlayMetaFile(HENHMETAFILE hEnhMetaFile, LPCRECT lpBounds)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::PlayEnhMetaFile(m_hDC, hEnhMetaFile, lpBounds);
+ }
+
+ BOOL AddMetaFileComment(UINT nDataSize, const BYTE* pCommentData) // can be used for enhanced metafiles only
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GdiComment(m_hDC, nDataSize, pCommentData);
+ }
+
+ // Special handling for metafile playback
+ static int CALLBACK EnumMetaFileProc(HDC hDC, HANDLETABLE* pHandleTable, METARECORD* pMetaRec, int nHandles, LPARAM lParam)
+ {
+ CDCHandle* pDC = (CDCHandle*)lParam;
+
+ switch (pMetaRec->rdFunction)
+ {
+ case META_SETMAPMODE:
+ pDC->SetMapMode((int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_SETWINDOWEXT:
+ pDC->SetWindowExt((int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_SETWINDOWORG:
+ pDC->SetWindowOrg((int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_SETVIEWPORTEXT:
+ pDC->SetViewportExt((int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_SETVIEWPORTORG:
+ pDC->SetViewportOrg((int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_SCALEWINDOWEXT:
+ pDC->ScaleWindowExt((int)(short)pMetaRec->rdParm[3], (int)(short)pMetaRec->rdParm[2],
+ (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_SCALEVIEWPORTEXT:
+ pDC->ScaleViewportExt((int)(short)pMetaRec->rdParm[3], (int)(short)pMetaRec->rdParm[2],
+ (int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_OFFSETVIEWPORTORG:
+ pDC->OffsetViewportOrg((int)(short)pMetaRec->rdParm[1], (int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_SAVEDC:
+ pDC->SaveDC();
+ break;
+ case META_RESTOREDC:
+ pDC->RestoreDC((int)(short)pMetaRec->rdParm[0]);
+ break;
+ case META_SETBKCOLOR:
+ pDC->SetBkColor(*(UNALIGNED COLORREF*)&pMetaRec->rdParm[0]);
+ break;
+ case META_SETTEXTCOLOR:
+ pDC->SetTextColor(*(UNALIGNED COLORREF*)&pMetaRec->rdParm[0]);
+ break;
+
+ // need to watch out for SelectObject(HFONT), for custom font mapping
+ case META_SELECTOBJECT:
+ {
+ HGDIOBJ hObject = pHandleTable->objectHandle[pMetaRec->rdParm[0]];
+ UINT nObjType = ::GetObjectType(hObject);
+ if(nObjType == 0)
+ {
+ // object type is unknown, determine if it is a font
+ HFONT hStockFont = (HFONT)::GetStockObject(SYSTEM_FONT);
+ HFONT hFontOld = (HFONT)::SelectObject(pDC->m_hDC, hStockFont);
+ HGDIOBJ hObjOld = ::SelectObject(pDC->m_hDC, hObject);
+ if(hObjOld == hStockFont)
+ {
+ // got the stock object back, so must be selecting a font
+ pDC->SelectFont((HFONT)hObject);
+ break; // don't play the default record
+ }
+ else
+ {
+ // didn't get the stock object back, so restore everything
+ ::SelectObject(pDC->m_hDC, hFontOld);
+ ::SelectObject(pDC->m_hDC, hObjOld);
+ }
+ // and fall through to PlayMetaFileRecord...
+ }
+ else if(nObjType == OBJ_FONT)
+ {
+ // play back as CDCHandle::SelectFont(HFONT)
+ pDC->SelectFont((HFONT)hObject);
+ break; // don't play the default record
+ }
+ }
+ // fall through...
+
+ default:
+ ::PlayMetaFileRecord(hDC, pHandleTable, pMetaRec, nHandles);
+ break;
+ }
+
+ return 1;
+ }
+#endif // !_WIN32_WCE
+
+// Path Functions
+#ifndef _WIN32_WCE
+ BOOL AbortPath()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::AbortPath(m_hDC);
+ }
+
+ BOOL BeginPath()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::BeginPath(m_hDC);
+ }
+
+ BOOL CloseFigure()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::CloseFigure(m_hDC);
+ }
+
+ BOOL EndPath()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::EndPath(m_hDC);
+ }
+
+ BOOL FillPath()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::FillPath(m_hDC);
+ }
+
+ BOOL FlattenPath()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::FlattenPath(m_hDC);
+ }
+
+ BOOL StrokeAndFillPath()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::StrokeAndFillPath(m_hDC);
+ }
+
+ BOOL StrokePath()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::StrokePath(m_hDC);
+ }
+
+ BOOL WidenPath()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::WidenPath(m_hDC);
+ }
+
+ BOOL GetMiterLimit(PFLOAT pfMiterLimit) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetMiterLimit(m_hDC, pfMiterLimit);
+ }
+
+ BOOL SetMiterLimit(float fMiterLimit)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetMiterLimit(m_hDC, fMiterLimit, NULL);
+ }
+
+ int GetPath(LPPOINT lpPoints, LPBYTE lpTypes, int nCount) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetPath(m_hDC, lpPoints, lpTypes, nCount);
+ }
+
+ BOOL SelectClipPath(int nMode)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SelectClipPath(m_hDC, nMode);
+ }
+#endif // !_WIN32_WCE
+
+// Misc Helper Functions
+ static CBrushHandle PASCAL GetHalftoneBrush()
+ {
+ HBRUSH halftoneBrush = NULL;
+ WORD grayPattern[8];
+ for(int i = 0; i < 8; i++)
+ grayPattern[i] = (WORD)(0x5555 << (i & 1));
+ HBITMAP grayBitmap = CreateBitmap(8, 8, 1, 1, &grayPattern);
+ if(grayBitmap != NULL)
+ {
+ halftoneBrush = ::CreatePatternBrush(grayBitmap);
+ DeleteObject(grayBitmap);
+ }
+ return CBrushHandle(halftoneBrush);
+ }
+
+ void DrawDragRect(LPCRECT lpRect, SIZE size, LPCRECT lpRectLast, SIZE sizeLast, HBRUSH hBrush = NULL, HBRUSH hBrushLast = NULL)
+ {
+ // first, determine the update region and select it
+ CRgn rgnOutside;
+ rgnOutside.CreateRectRgnIndirect(lpRect);
+ RECT rect = *lpRect;
+ ::InflateRect(&rect, -size.cx, -size.cy);
+ ::IntersectRect(&rect, &rect, lpRect);
+ CRgn rgnInside;
+ rgnInside.CreateRectRgnIndirect(&rect);
+ CRgn rgnNew;
+ rgnNew.CreateRectRgn(0, 0, 0, 0);
+ rgnNew.CombineRgn(rgnOutside, rgnInside, RGN_XOR);
+
+ HBRUSH hBrushOld = NULL;
+ CBrush brushHalftone;
+ if(hBrush == NULL)
+ brushHalftone = hBrush = CDCHandle::GetHalftoneBrush();
+ if(hBrushLast == NULL)
+ hBrushLast = hBrush;
+
+ CRgn rgnLast;
+ CRgn rgnUpdate;
+ if(lpRectLast != NULL)
+ {
+ // find difference between new region and old region
+ rgnLast.CreateRectRgn(0, 0, 0, 0);
+ rgnOutside.SetRectRgn(lpRectLast->left, lpRectLast->top, lpRectLast->right, lpRectLast->bottom);
+ rect = *lpRectLast;
+ ::InflateRect(&rect, -sizeLast.cx, -sizeLast.cy);
+ ::IntersectRect(&rect, &rect, lpRectLast);
+ rgnInside.SetRectRgn(rect.left, rect.top, rect.right, rect.bottom);
+ rgnLast.CombineRgn(rgnOutside, rgnInside, RGN_XOR);
+
+ // only diff them if brushes are the same
+ if(hBrush == hBrushLast)
+ {
+ rgnUpdate.CreateRectRgn(0, 0, 0, 0);
+ rgnUpdate.CombineRgn(rgnLast, rgnNew, RGN_XOR);
+ }
+ }
+ if(hBrush != hBrushLast && lpRectLast != NULL)
+ {
+ // brushes are different -- erase old region first
+ SelectClipRgn(rgnLast);
+ GetClipBox(&rect);
+ hBrushOld = SelectBrush(hBrushLast);
+ PatBlt(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, PATINVERT);
+ SelectBrush(hBrushOld);
+ hBrushOld = NULL;
+ }
+
+ // draw into the update/new region
+ SelectClipRgn(rgnUpdate.IsNull() ? rgnNew : rgnUpdate);
+ GetClipBox(&rect);
+ hBrushOld = SelectBrush(hBrush);
+ PatBlt(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, PATINVERT);
+
+ // cleanup DC
+ if(hBrushOld != NULL)
+ SelectBrush(hBrushOld);
+ SelectClipRgn(NULL);
+ }
+
+ void FillSolidRect(LPCRECT lpRect, COLORREF clr)
+ {
+ ATLASSERT(m_hDC != NULL);
+
+ COLORREF clrOld = ::SetBkColor(m_hDC, clr);
+ ATLASSERT(clrOld != CLR_INVALID);
+ if(clrOld != CLR_INVALID)
+ {
+ ::ExtTextOut(m_hDC, 0, 0, ETO_OPAQUE, lpRect, NULL, 0, NULL);
+ ::SetBkColor(m_hDC, clrOld);
+ }
+ }
+
+ void FillSolidRect(int x, int y, int cx, int cy, COLORREF clr)
+ {
+ ATLASSERT(m_hDC != NULL);
+
+ RECT rect = { x, y, x + cx, y + cy };
+ FillSolidRect(&rect, clr);
+ }
+
+ void Draw3dRect(LPCRECT lpRect, COLORREF clrTopLeft, COLORREF clrBottomRight)
+ {
+ Draw3dRect(lpRect->left, lpRect->top, lpRect->right - lpRect->left,
+ lpRect->bottom - lpRect->top, clrTopLeft, clrBottomRight);
+ }
+
+ void Draw3dRect(int x, int y, int cx, int cy, COLORREF clrTopLeft, COLORREF clrBottomRight)
+ {
+ FillSolidRect(x, y, cx - 1, 1, clrTopLeft);
+ FillSolidRect(x, y, 1, cy - 1, clrTopLeft);
+ FillSolidRect(x + cx, y, -1, cy, clrBottomRight);
+ FillSolidRect(x, y + cy, cx, -1, clrBottomRight);
+ }
+
+// DIB support
+#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
+ int SetDIBitsToDevice(int x, int y, DWORD dwWidth, DWORD dwHeight, int xSrc, int ySrc, UINT uStartScan, UINT cScanLines, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetDIBitsToDevice(m_hDC, x, y, dwWidth, dwHeight, xSrc, ySrc, uStartScan, cScanLines, lpvBits, lpbmi, uColorUse);
+ }
+#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 410)
+
+#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
+ int StretchDIBits(int x, int y, int nWidth, int nHeight, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, CONST VOID* lpvBits, CONST BITMAPINFO* lpbmi, UINT uColorUse, DWORD dwRop)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::StretchDIBits(m_hDC, x, y, nWidth, nHeight, xSrc, ySrc, nSrcWidth, nSrcHeight, lpvBits, lpbmi, uColorUse, dwRop);
+ }
+
+ UINT GetDIBColorTable(UINT uStartIndex, UINT cEntries, RGBQUAD* pColors) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetDIBColorTable(m_hDC, uStartIndex, cEntries, pColors);
+ }
+
+ UINT SetDIBColorTable(UINT uStartIndex, UINT cEntries, CONST RGBQUAD* pColors)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetDIBColorTable(m_hDC, uStartIndex, cEntries, pColors);
+ }
+#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
+
+// OpenGL support
+#if !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
+ int ChoosePixelFormat(CONST PIXELFORMATDESCRIPTOR* ppfd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ChoosePixelFormat(m_hDC, ppfd);
+ }
+
+ int DescribePixelFormat(int iPixelFormat, UINT nBytes, LPPIXELFORMATDESCRIPTOR ppfd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::DescribePixelFormat(m_hDC, iPixelFormat, nBytes, ppfd);
+ }
+
+ int GetPixelFormat() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetPixelFormat(m_hDC);
+ }
+
+ BOOL SetPixelFormat(int iPixelFormat, CONST PIXELFORMATDESCRIPTOR* ppfd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetPixelFormat(m_hDC, iPixelFormat, ppfd);
+ }
+
+ BOOL SwapBuffers()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SwapBuffers(m_hDC);
+ }
+
+ HGLRC wglCreateContext()
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglCreateContext(m_hDC);
+ }
+
+ HGLRC wglCreateLayerContext(int iLayerPlane)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglCreateLayerContext(m_hDC, iLayerPlane);
+ }
+
+ BOOL wglMakeCurrent(HGLRC hglrc)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglMakeCurrent(m_hDC, hglrc);
+ }
+
+ BOOL wglUseFontBitmaps(DWORD dwFirst, DWORD dwCount, DWORD listBase)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglUseFontBitmaps(m_hDC, dwFirst, dwCount, listBase);
+ }
+
+ BOOL wglUseFontOutlines(DWORD dwFirst, DWORD dwCount, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglUseFontOutlines(m_hDC, dwFirst, dwCount, listBase, deviation, extrusion, format, lpgmf);
+ }
+
+ BOOL wglDescribeLayerPlane(int iPixelFormat, int iLayerPlane, UINT nBytes, LPLAYERPLANEDESCRIPTOR plpd)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglDescribeLayerPlane(m_hDC, iPixelFormat, iLayerPlane, nBytes, plpd);
+ }
+
+ int wglSetLayerPaletteEntries(int iLayerPlane, int iStart, int cEntries, CONST COLORREF* pclr)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglSetLayerPaletteEntries(m_hDC, iLayerPlane, iStart, cEntries, pclr);
+ }
+
+ int wglGetLayerPaletteEntries(int iLayerPlane, int iStart, int cEntries, COLORREF* pclr)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglGetLayerPaletteEntries(m_hDC, iLayerPlane, iStart, cEntries, pclr);
+ }
+
+ BOOL wglRealizeLayerPalette(int iLayerPlane, BOOL bRealize)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglRealizeLayerPalette(m_hDC, iLayerPlane, bRealize);
+ }
+
+ BOOL wglSwapLayerBuffers(UINT uPlanes)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::wglSwapLayerBuffers(m_hDC, uPlanes);
+ }
+#endif // !defined(_ATL_NO_OPENGL) && !defined(_WIN32_WCE)
+
+// New for Windows 2000 only
+#if (_WIN32_WINNT >= 0x0500)
+ COLORREF GetDCPenColor() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetDCPenColor(m_hDC);
+ }
+
+ COLORREF SetDCPenColor(COLORREF clr)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetDCPenColor(m_hDC, clr);
+ }
+
+ COLORREF GetDCBrushColor() const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetDCBrushColor(m_hDC);
+ }
+
+ COLORREF SetDCBrushColor(COLORREF clr)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::SetDCBrushColor(m_hDC, clr);
+ }
+
+#ifndef _WIN32_WCE
+ DWORD GetFontUnicodeRanges(LPGLYPHSET lpgs) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetFontUnicodeRanges(m_hDC, lpgs);
+ }
+#endif // !_WIN32_WCE
+
+ DWORD GetGlyphIndices(LPCTSTR lpstr, int cch, LPWORD pgi, DWORD dwFlags) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetGlyphIndices(m_hDC, lpstr, cch, pgi, dwFlags);
+ }
+
+ BOOL GetTextExtentPointI(LPWORD pgiIn, int cgi, LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextExtentPointI(m_hDC, pgiIn, cgi, lpSize);
+ }
+
+ BOOL GetTextExtentExPointI(LPWORD pgiIn, int cgi, int nMaxExtent, LPINT lpnFit, LPINT alpDx, LPSIZE lpSize) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetTextExtentExPointI(m_hDC, pgiIn, cgi, nMaxExtent, lpnFit, alpDx, lpSize);
+ }
+
+ BOOL GetCharWidthI(UINT giFirst, UINT cgi, LPWORD pgi, LPINT lpBuffer) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetCharWidthI(m_hDC, giFirst, cgi, pgi, lpBuffer);
+ }
+
+ BOOL GetCharABCWidthsI(UINT giFirst, UINT cgi, LPWORD pgi, LPABC lpabc) const
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::GetCharABCWidthsI(m_hDC, giFirst, cgi, pgi, lpabc);
+ }
+#endif // (_WIN32_WINNT >= 0x0500)
+
+// New for Windows 2000 and Windows 98
+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+ BOOL ColorCorrectPalette(HPALETTE hPalette, DWORD dwFirstEntry, DWORD dwNumOfEntries)
+ {
+ ATLASSERT(m_hDC != NULL);
+ return ::ColorCorrectPalette(m_hDC, hPalette, dwFirstEntry, dwNumOfEntries);
+ }
+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+};
+
+typedef CDCT<false> CDCHandle;
+typedef CDCT<true> CDC;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CDC Helpers
+
+class CPaintDC : public CDC
+{
+public:
+// Data members
+ HWND m_hWnd;
+ PAINTSTRUCT m_ps;
+
+// Constructor/destructor
+ CPaintDC(HWND hWnd)
+ {
+ ATLASSERT(::IsWindow(hWnd));
+ m_hWnd = hWnd;
+ m_hDC = ::BeginPaint(hWnd, &m_ps);
+ }
+
+ ~CPaintDC()
+ {
+ ATLASSERT(m_hDC != NULL);
+ ATLASSERT(::IsWindow(m_hWnd));
+ ::EndPaint(m_hWnd, &m_ps);
+ Detach();
+ }
+};
+
+class CClientDC : public CDC
+{
+public:
+// Data members
+ HWND m_hWnd;
+
+// Constructor/destructor
+ CClientDC(HWND hWnd)
+ {
+ ATLASSERT(hWnd == NULL || ::IsWindow(hWnd));
+ m_hWnd = hWnd;
+ m_hDC = ::GetDC(hWnd);
+ }
+
+ ~CClientDC()
+ {
+ ATLASSERT(m_hDC != NULL);
+ ::ReleaseDC(m_hWnd, Detach());
+ }
+};
+
+class CWindowDC : public CDC
+{
+public:
+// Data members
+ HWND m_hWnd;
+
+// Constructor/destructor
+ CWindowDC(HWND hWnd)
+ {
+ ATLASSERT(hWnd == NULL || ::IsWindow(hWnd));
+ m_hWnd = hWnd;
+ m_hDC = ::GetWindowDC(hWnd);
+ }
+
+ ~CWindowDC()
+ {
+ ATLASSERT(m_hDC != NULL);
+ ::ReleaseDC(m_hWnd, Detach());
+ }
+};
+
+class CMemoryDC : public CDC
+{
+public:
+// Data members
+ HDC m_hDCOriginal;
+ RECT m_rcPaint;
+ CBitmap m_bmp;
+ HBITMAP m_hBmpOld;
+
+// Constructor/destructor
+ CMemoryDC(HDC hDC, RECT& rcPaint) : m_hDCOriginal(hDC), m_hBmpOld(NULL)
+ {
+ m_rcPaint = rcPaint;
+ CreateCompatibleDC(m_hDCOriginal);
+ ATLASSERT(m_hDC != NULL);
+ m_bmp.CreateCompatibleBitmap(m_hDCOriginal, m_rcPaint.right - m_rcPaint.left, m_rcPaint.bottom - m_rcPaint.top);
+ ATLASSERT(m_bmp.m_hBitmap != NULL);
+ m_hBmpOld = SelectBitmap(m_bmp);
+ SetViewportOrg(-m_rcPaint.left, -m_rcPaint.top);
+ }
+
+ ~CMemoryDC()
+ {
+ ::BitBlt(m_hDCOriginal, m_rcPaint.left, m_rcPaint.top, m_rcPaint.right - m_rcPaint.left, m_rcPaint.bottom - m_rcPaint.top, m_hDC, m_rcPaint.left, m_rcPaint.top, SRCCOPY);
+ SelectBitmap(m_hBmpOld);
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Enhanced metafile support
+
+#ifndef _WIN32_WCE
+
+class CEnhMetaFileInfo
+{
+public:
+// Data members
+ HENHMETAFILE m_hEMF;
+ BYTE* m_pBits;
+ TCHAR* m_pDesc;
+ ENHMETAHEADER m_header;
+ PIXELFORMATDESCRIPTOR m_pfd;
+
+// Constructor/destructor
+ CEnhMetaFileInfo(HENHMETAFILE hEMF) : m_pBits(NULL), m_pDesc(NULL), m_hEMF(hEMF)
+ { }
+
+ ~CEnhMetaFileInfo()
+ {
+ delete [] m_pBits;
+ delete [] m_pDesc;
+ }
+
+// Operations
+ BYTE* GetEnhMetaFileBits()
+ {
+ ATLASSERT(m_hEMF != NULL);
+ UINT nBytes = ::GetEnhMetaFileBits(m_hEMF, 0, NULL);
+ delete [] m_pBits;
+ m_pBits = NULL;
+ ATLTRY(m_pBits = new BYTE[nBytes]);
+ if (m_pBits != NULL)
+ ::GetEnhMetaFileBits(m_hEMF, nBytes, m_pBits);
+ return m_pBits;
+ }
+
+ LPTSTR GetEnhMetaFileDescription()
+ {
+ ATLASSERT(m_hEMF != NULL);
+ UINT nLen = ::GetEnhMetaFileDescription(m_hEMF, 0, NULL);
+ delete [] m_pDesc;
+ m_pDesc = NULL;
+ ATLTRY(m_pDesc = new TCHAR[nLen]);
+ if (m_pDesc != NULL)
+ nLen = ::GetEnhMetaFileDescription(m_hEMF, nLen, m_pDesc);
+ return m_pDesc;
+ }
+
+ ENHMETAHEADER* GetEnhMetaFileHeader()
+ {
+ ATLASSERT(m_hEMF != NULL);
+ memset(&m_header, 0, sizeof(m_header));
+ m_header.iType = EMR_HEADER;
+ m_header.nSize = sizeof(ENHMETAHEADER);
+ UINT n = ::GetEnhMetaFileHeader(m_hEMF, sizeof(ENHMETAHEADER), &m_header);
+ return (n != 0) ? &m_header : NULL;
+ }
+
+ PIXELFORMATDESCRIPTOR* GetEnhMetaFilePixelFormat()
+ {
+ ATLASSERT(m_hEMF != NULL);
+ memset(&m_pfd, 0, sizeof(m_pfd));
+ UINT n = ::GetEnhMetaFilePixelFormat(m_hEMF, sizeof(m_pfd), &m_pfd);
+ return (n != 0) ? &m_pfd : NULL;
+ }
+};
+
+
+template <bool t_bManaged>
+class CEnhMetaFileT
+{
+public:
+// Data members
+ HENHMETAFILE m_hEMF;
+
+// Constructor/destructor
+ CEnhMetaFileT(HENHMETAFILE hEMF = NULL) : m_hEMF(hEMF)
+ {
+ }
+
+ ~CEnhMetaFileT()
+ {
+ if(t_bManaged && m_hEMF != NULL)
+ DeleteObject();
+ }
+
+// Operations
+ CEnhMetaFileT<t_bManaged>& operator =(HENHMETAFILE hEMF)
+ {
+ Attach(hEMF);
+ return *this;
+ }
+
+ void Attach(HENHMETAFILE hEMF)
+ {
+ if(t_bManaged && m_hEMF != NULL && m_hEMF != hEMF)
+ DeleteObject();
+ m_hEMF = hEMF;
+ }
+
+ HENHMETAFILE Detach()
+ {
+ HENHMETAFILE hEMF = m_hEMF;
+ m_hEMF = NULL;
+ return hEMF;
+ }
+
+ operator HENHMETAFILE() const { return m_hEMF; }
+
+ bool IsNull() const { return (m_hEMF == NULL); }
+
+ BOOL DeleteObject()
+ {
+ ATLASSERT(m_hEMF != NULL);
+ BOOL bRet = ::DeleteEnhMetaFile(m_hEMF);
+ m_hEMF = NULL;
+ return bRet;
+ }
+
+ UINT GetEnhMetaFileBits(UINT cbBuffer, LPBYTE lpbBuffer) const
+ {
+ ATLASSERT(m_hEMF != NULL);
+ return ::GetEnhMetaFileBits(m_hEMF, cbBuffer, lpbBuffer);
+ }
+
+ UINT GetEnhMetaFileDescription(UINT cchBuffer, LPTSTR lpszDescription) const
+ {
+ ATLASSERT(m_hEMF != NULL);
+ return ::GetEnhMetaFileDescription(m_hEMF, cchBuffer, lpszDescription);
+ }
+
+ UINT GetEnhMetaFileHeader(LPENHMETAHEADER lpemh) const
+ {
+ ATLASSERT(m_hEMF != NULL);
+ lpemh->iType = EMR_HEADER;
+ lpemh->nSize = sizeof(ENHMETAHEADER);
+ return ::GetEnhMetaFileHeader(m_hEMF, sizeof(ENHMETAHEADER), lpemh);
+ }
+
+ UINT GetEnhMetaFilePaletteEntries(UINT cEntries, LPPALETTEENTRY lppe) const
+ {
+ ATLASSERT(m_hEMF != NULL);
+ return ::GetEnhMetaFilePaletteEntries(m_hEMF, cEntries, lppe);
+ }
+
+ UINT GetEnhMetaFilePixelFormat(DWORD cbBuffer, PIXELFORMATDESCRIPTOR* ppfd) const
+ {
+ ATLASSERT(m_hEMF != NULL);
+ return ::GetEnhMetaFilePixelFormat(m_hEMF, cbBuffer, ppfd);
+ }
+};
+
+typedef CEnhMetaFileT<false> CEnhMetaFileHandle;
+typedef CEnhMetaFileT<true> CEnhMetaFile;
+
+
+class CEnhMetaFileDC : public CDC
+{
+public:
+// Constructor/destructor
+ CEnhMetaFileDC()
+ {
+ }
+
+ CEnhMetaFileDC(HDC hdc, LPCRECT lpRect)
+ {
+ Create(hdc, NULL, lpRect, NULL);
+ ATLASSERT(m_hDC != NULL);
+ }
+
+ CEnhMetaFileDC(HDC hdcRef, LPCTSTR lpFilename, LPCRECT lpRect, LPCTSTR lpDescription)
+ {
+ Create(hdcRef, lpFilename, lpRect, lpDescription);
+ ATLASSERT(m_hDC != NULL);
+ }
+
+ ~CEnhMetaFileDC()
+ {
+ HENHMETAFILE hEMF = Close();
+ if (hEMF != NULL)
+ ::DeleteEnhMetaFile(hEMF);
+ }
+
+// Operations
+ void Create(HDC hdcRef, LPCTSTR lpFilename, LPCRECT lpRect, LPCTSTR lpDescription)
+ {
+ ATLASSERT(m_hDC == NULL);
+ m_hDC = ::CreateEnhMetaFile(hdcRef, lpFilename, lpRect, lpDescription);
+ }
+
+ HENHMETAFILE Close()
+ {
+ HENHMETAFILE hEMF = NULL;
+ if (m_hDC != NULL)
+ {
+ hEMF = ::CloseEnhMetaFile(m_hDC);
+ m_hDC = NULL;
+ }
+ return hEMF;
+ }
+};
+
+#endif // !_WIN32_WCE
+
+
+///////////////////////////////////////////////////////////////////////////////
+// WinCE compatible clipboard CF_DIB format support functions
+
+#ifndef _WTL_NO_DIB16
+
+#define DIBINFO16_BITFIELDS { 31744, 992, 31 }
+
+// DIBINFO16 - To avoid color table problems in WinCE we only create this type of Dib
+struct DIBINFO16 // a BITMAPINFO with 2 additional color bitfields
+{
+ BITMAPINFOHEADER bmiHeader;
+ RGBQUAD bmiColors[3];
+
+ DIBINFO16(SIZE size)
+ {
+ BITMAPINFOHEADER bmih = { sizeof(BITMAPINFOHEADER), size.cx, size.cy,
+ 1, 16, BI_BITFIELDS, 2 * size.cx * size.cy , 0, 0, 3 };
+ DWORD dw[3] = DIBINFO16_BITFIELDS ;
+
+ bmiHeader = bmih;
+ SecureHelper::memcpy_x(bmiColors, sizeof(bmiColors), dw, 3 * sizeof(DWORD));
+ }
+};
+
+
+// AtlxxxDibxxx minimal packed DIB implementation and helpers to copy and paste CF_DIB
+
+inline bool AtlIsDib16(LPBITMAPINFOHEADER pbmih)
+{
+ return (pbmih->biBitCount == 16) && (pbmih->biCompression == BI_BITFIELDS);
+}
+
+inline int AtlGetDibColorTableSize(LPBITMAPINFOHEADER pbmih)
+{
+ switch (pbmih->biBitCount)
+ {
+ case 2:
+ case 4:
+ case 8:
+ return pbmih->biClrUsed ? pbmih->biClrUsed : 1 << pbmih->biBitCount;
+ case 24:
+ break;
+ case 16:
+ case 32:
+ return pbmih->biCompression == BI_BITFIELDS ? 3 : 0;
+ default:
+ ATLASSERT(FALSE); // should never come here
+ }
+
+ return 0;
+}
+
+inline int AtlGetDibNumColors(LPBITMAPINFOHEADER pbmih)
+{
+ switch (pbmih->biBitCount)
+ {
+ case 2:
+ case 4:
+ case 8:
+ if (pbmih->biClrUsed)
+ return pbmih->biClrUsed;
+ else
+ break;
+ case 16:
+ if (pbmih->biCompression == BI_BITFIELDS )
+ return 1 << 15;
+ else
+ break;
+ case 24:
+ break;
+ case 32:
+ if (pbmih->biCompression == BI_BITFIELDS )
+ return 1 << 24;
+ else
+ break;
+ default:
+ ATLASSERT(FALSE);
+ }
+
+ return 1 << pbmih->biBitCount;
+}
+
+inline HBITMAP AtlGetDibBitmap(LPBITMAPINFO pbmi)
+{
+ CDC dc(NULL);
+ void* pBits = NULL;
+
+ LPBYTE pDibBits = (LPBYTE)pbmi + sizeof(BITMAPINFOHEADER) + AtlGetDibColorTableSize(&pbmi->bmiHeader) * sizeof(RGBQUAD);
+ HBITMAP hbm = CreateDIBSection(dc, pbmi, DIB_RGB_COLORS, &pBits, NULL, NULL);
+ if (hbm != NULL)
+ {
+ int cbBits = pbmi->bmiHeader.biWidth * pbmi->bmiHeader.biHeight * pbmi->bmiHeader.biBitCount / 8;
+ SecureHelper::memcpy_x(pBits, cbBits, pDibBits, pbmi->bmiHeader.biSizeImage);
+ }
+
+ return hbm;
+}
+
+inline HBITMAP AtlCopyBitmap(HBITMAP hbm, SIZE sizeDst, bool bAsBitmap = false)
+{
+ CDC hdcSrc = CreateCompatibleDC(NULL);
+ CDC hdcDst = CreateCompatibleDC(NULL);
+
+ CBitmapHandle hbmOld = NULL, hbmOld2 = NULL, bmSrc = hbm;
+
+ CBitmap bmNew = NULL;
+
+ SIZE sizeSrc = { 0 };
+ bmSrc.GetSize(sizeSrc);
+
+ hbmOld = hdcSrc.SelectBitmap(bmSrc);
+
+ if (bAsBitmap)
+ {
+ bmNew.CreateCompatibleBitmap(hdcSrc, sizeDst.cx, sizeDst.cy);
+ }
+ else
+ {
+ DIBINFO16 dib16(sizeDst);
+ LPVOID pBits = NULL;
+ bmNew = CreateDIBSection(hdcDst, (const BITMAPINFO*)&dib16, DIB_RGB_COLORS, &pBits, NULL, NULL);
+ }
+
+ ATLASSERT(!bmNew.IsNull());
+
+ hbmOld2 = hdcDst.SelectBitmap(bmNew);
+ BOOL bOK = FALSE;
+
+ if ((sizeDst.cx == sizeSrc.cx) && (sizeDst.cy == sizeSrc.cy))
+ bOK = hdcDst.BitBlt(0, 0, sizeDst.cx, sizeDst.cy, hdcSrc, 0, 0, SRCCOPY);
+ else
+ bOK = hdcDst.StretchBlt(0, 0, sizeDst.cx, sizeDst.cy, hdcSrc, 0, 0, sizeSrc.cx, sizeSrc.cy, SRCCOPY);
+
+ hdcSrc.SelectBitmap(hbmOld);
+ hdcDst.SelectBitmap(hbmOld2);
+
+ if (bOK == FALSE)
+ bmNew.DeleteObject();
+
+ return bmNew.Detach();
+}
+
+inline HLOCAL AtlCreatePackedDib16(HBITMAP hbm, SIZE size)
+{
+ DIBSECTION ds = { 0 };
+ LPBYTE pDib = NULL;
+ bool bCopied = false;
+
+ bool bOK = GetObject(hbm, sizeof(ds), &ds) == sizeof(ds);
+ if ((bOK == FALSE) || (ds.dsBm.bmBits == NULL) || (AtlIsDib16(&ds.dsBmih) == FALSE) ||
+ (ds.dsBmih.biWidth != size.cx ) || (ds.dsBmih.biHeight != size.cy ))
+ {
+ if ((hbm = AtlCopyBitmap(hbm, size)) != NULL)
+ {
+ bCopied = true;
+ bOK = GetObject(hbm, sizeof(ds), &ds) == sizeof(ds);
+ }
+ else
+ {
+ bOK = FALSE;
+ }
+ }
+
+ if((bOK != FALSE) && (AtlIsDib16(&ds.dsBmih) != FALSE) && (ds.dsBm.bmBits != NULL))
+ {
+ pDib = (LPBYTE)LocalAlloc(LMEM_ZEROINIT, sizeof(DIBINFO16) + ds.dsBmih.biSizeImage);
+ if (pDib != NULL)
+ {
+ SecureHelper::memcpy_x(pDib, sizeof(DIBINFO16) + ds.dsBmih.biSizeImage, &ds.dsBmih, sizeof(DIBINFO16));
+ SecureHelper::memcpy_x(pDib + sizeof(DIBINFO16), ds.dsBmih.biSizeImage, ds.dsBm.bmBits, ds.dsBmih.biSizeImage);
+ }
+ }
+
+ if (bCopied == true)
+ DeleteObject(hbm);
+
+ return (HLOCAL)pDib;
+}
+
+inline bool AtlSetClipboardDib16(HBITMAP hbm, SIZE size, HWND hWnd)
+{
+ ATLASSERT(::IsWindow(hWnd));
+ BOOL bOK = OpenClipboard(hWnd);
+ if (bOK != FALSE)
+ {
+ bOK = EmptyClipboard();
+ if (bOK != FALSE)
+ {
+ HLOCAL hDib = AtlCreatePackedDib16(hbm, size);
+ if (hDib != NULL)
+ {
+ bOK = SetClipboardData(CF_DIB, hDib) != NULL;
+ if (bOK == FALSE)
+ LocalFree(hDib);
+ }
+ else
+ {
+ bOK = FALSE;
+ }
+ }
+ CloseClipboard();
+ }
+
+ return (bOK != FALSE);
+}
+
+inline HBITMAP AtlGetClipboardDib(HWND hWnd)
+{
+ ATLASSERT(::IsWindow(hWnd) != FALSE);
+ HBITMAP hbm = NULL;
+ if (OpenClipboard(hWnd) != FALSE)
+ {
+ LPBITMAPINFO pbmi = (LPBITMAPINFO)GetClipboardData(CF_DIB);
+ if (pbmi != NULL)
+ hbm = AtlGetDibBitmap(pbmi);
+ CloseClipboard();
+ }
+
+ return hbm;
+}
+
+#endif // _WTL_NO_DIB16
+
+}; // namespace WTL
+
+#endif // __ATLGDI_H__
diff --git a/plugins/XSoundNotify/src/wtl/include/atlres.h b/plugins/XSoundNotify/src/wtl/include/atlres.h new file mode 100644 index 0000000000..22fb3e6fdd --- /dev/null +++ b/plugins/XSoundNotify/src/wtl/include/atlres.h @@ -0,0 +1,263 @@ +// Windows Template Library - WTL version 8.1
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//
+// This file is a part of the Windows Template Library.
+// The use and distribution terms for this software are covered by the
+// Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
+// which can be found in the file CPL.TXT at the root of this distribution.
+// By using this software in any fashion, you are agreeing to be bound by
+// the terms of this license. You must not remove this notice, or
+// any other, from this software.
+
+#ifndef __ATLRES_H__
+#define __ATLRES_H__
+
+#pragma once
+
+#if defined(_WIN32_WCE) && !defined(__ATLRESCE_H__)
+ #error Use atlresCE.h instead of atlres.h for Windows CE
+#endif
+
+
+#ifdef RC_INVOKED
+#ifndef _INC_WINDOWS
+
+ #define _INC_WINDOWS
+
+ #ifndef _WIN32_WCE
+ #define VS_VERSION_INFO 1
+
+ #ifdef APSTUDIO_INVOKED
+ #define APSTUDIO_HIDDEN_SYMBOLS // Ignore following symbols
+ #endif // APSTUDIO_INVOKED
+
+ #ifndef WINVER
+ #define WINVER 0x0400 // default to Windows Version 4.0
+ #endif // !WINVER
+
+ #include <winresrc.h>
+
+ // operation messages sent to DLGINIT
+ #define LB_ADDSTRING (WM_USER+1)
+ #define CB_ADDSTRING (WM_USER+3)
+ #endif // !_WIN32_WCE
+
+ #ifdef APSTUDIO_INVOKED
+ #undef APSTUDIO_HIDDEN_SYMBOLS
+ #endif // APSTUDIO_INVOKED
+
+ #ifdef IDC_STATIC
+ #undef IDC_STATIC
+ #endif // IDC_STATIC
+ #define IDC_STATIC (-1)
+
+#endif // !_INC_WINDOWS
+#endif // RC_INVOKED
+
+#ifdef APSTUDIO_INVOKED
+ #define APSTUDIO_HIDDEN_SYMBOLS
+#endif // APSTUDIO_INVOKED
+
+///////////////////////////////////////////////////////////////////////////////
+// ATL resource types
+
+#ifndef RC_INVOKED
+ #define RT_DLGINIT MAKEINTRESOURCE(240)
+ #define RT_TOOLBAR MAKEINTRESOURCE(241)
+#endif // RC_INVOKED
+
+///////////////////////////////////////////////////////////////////////////////
+
+#ifdef APSTUDIO_INVOKED
+ #undef APSTUDIO_HIDDEN_SYMBOLS
+#endif // APSTUDIO_INVOKED
+
+///////////////////////////////////////////////////////////////////////////////
+// Standard window components
+
+#define ID_SEPARATOR 0 // special separator value
+#define ID_DEFAULT_PANE 0 // default status bar pane
+
+#ifndef RC_INVOKED // code only
+// standard control bars (IDW = window ID)
+ #define ATL_IDW_TOOLBAR 0xE800 // main Toolbar for window
+ #define ATL_IDW_STATUS_BAR 0xE801 // Status bar window
+ #define ATL_IDW_COMMAND_BAR 0xE802 // Command bar window
+
+// parts of a frame window
+ #define ATL_IDW_CLIENT 0xE900
+ #define ATL_IDW_PANE_FIRST 0xE900 // first pane (256 max)
+ #define ATL_IDW_PANE_LAST 0xE9FF
+ #define ATL_IDW_HSCROLL_FIRST 0xEA00 // first Horz scrollbar (16 max)
+ #define ATL_IDW_VSCROLL_FIRST 0xEA10 // first Vert scrollbar (16 max)
+
+ #define ATL_IDW_SIZE_BOX 0xEA20 // size box for splitters
+ #define ATL_IDW_PANE_SAVE 0xEA21 // to shift ATL_IDW_PANE_FIRST
+
+// bands for a rebar
+ #define ATL_IDW_BAND_FIRST 0xEB00
+ #define ATL_IDW_BAND_LAST 0xEBFF
+#endif // !RC_INVOKED
+
+///////////////////////////////////////////////////////////////////////////////
+// Standard Commands
+
+// File commands
+#define ID_FILE_NEW 0xE100
+#define ID_FILE_OPEN 0xE101
+#define ID_FILE_CLOSE 0xE102
+#define ID_FILE_SAVE 0xE103
+#define ID_FILE_SAVE_AS 0xE104
+#define ID_FILE_PAGE_SETUP 0xE105
+#define ID_FILE_PRINT_SETUP 0xE106
+#define ID_FILE_PRINT 0xE107
+#define ID_FILE_PRINT_DIRECT 0xE108
+#define ID_FILE_PRINT_PREVIEW 0xE109
+#define ID_FILE_UPDATE 0xE10A
+#define ID_FILE_SAVE_COPY_AS 0xE10B
+#define ID_FILE_SEND_MAIL 0xE10C
+
+#define ID_FILE_MRU_FIRST 0xE110
+#define ID_FILE_MRU_FILE1 0xE110 // range - 16 max
+#define ID_FILE_MRU_FILE2 0xE111
+#define ID_FILE_MRU_FILE3 0xE112
+#define ID_FILE_MRU_FILE4 0xE113
+#define ID_FILE_MRU_FILE5 0xE114
+#define ID_FILE_MRU_FILE6 0xE115
+#define ID_FILE_MRU_FILE7 0xE116
+#define ID_FILE_MRU_FILE8 0xE117
+#define ID_FILE_MRU_FILE9 0xE118
+#define ID_FILE_MRU_FILE10 0xE119
+#define ID_FILE_MRU_FILE11 0xE11A
+#define ID_FILE_MRU_FILE12 0xE11B
+#define ID_FILE_MRU_FILE13 0xE11C
+#define ID_FILE_MRU_FILE14 0xE11D
+#define ID_FILE_MRU_FILE15 0xE11E
+#define ID_FILE_MRU_FILE16 0xE11F
+#define ID_FILE_MRU_LAST 0xE11F
+
+// Edit commands
+#define ID_EDIT_CLEAR 0xE120
+#define ID_EDIT_CLEAR_ALL 0xE121
+#define ID_EDIT_COPY 0xE122
+#define ID_EDIT_CUT 0xE123
+#define ID_EDIT_FIND 0xE124
+#define ID_EDIT_PASTE 0xE125
+#define ID_EDIT_PASTE_LINK 0xE126
+#define ID_EDIT_PASTE_SPECIAL 0xE127
+#define ID_EDIT_REPEAT 0xE128
+#define ID_EDIT_REPLACE 0xE129
+#define ID_EDIT_SELECT_ALL 0xE12A
+#define ID_EDIT_UNDO 0xE12B
+#define ID_EDIT_REDO 0xE12C
+
+// Window commands
+#define ID_WINDOW_NEW 0xE130
+#define ID_WINDOW_ARRANGE 0xE131
+#define ID_WINDOW_CASCADE 0xE132
+#define ID_WINDOW_TILE_HORZ 0xE133
+#define ID_WINDOW_TILE_VERT 0xE134
+#define ID_WINDOW_SPLIT 0xE135
+#ifndef RC_INVOKED // code only
+ #define ATL_IDM_WINDOW_FIRST 0xE130
+ #define ATL_IDM_WINDOW_LAST 0xE13F
+ #define ATL_IDM_FIRST_MDICHILD 0xFF00 // window list starts here
+ #define ATL_IDM_LAST_MDICHILD 0xFFFD
+#endif // !RC_INVOKED
+// TabView
+#define ID_WINDOW_TABFIRST 0xFF00 // = ATL_IDM_FIRST_MDICHILD
+#define ID_WINDOW_TABLAST 0xFFFD
+#define ID_WINDOW_SHOWTABLIST 0xFFFE
+
+// Help and App commands
+#define ID_APP_ABOUT 0xE140
+#define ID_APP_EXIT 0xE141
+#define ID_HELP_INDEX 0xE142
+#define ID_HELP_FINDER 0xE143
+#define ID_HELP_USING 0xE144
+#define ID_CONTEXT_HELP 0xE145 // shift-F1
+// special commands for processing help
+#define ID_HELP 0xE146 // first attempt for F1
+#define ID_DEFAULT_HELP 0xE147 // last attempt
+
+// Misc
+#define ID_NEXT_PANE 0xE150
+#define ID_PREV_PANE 0xE151
+#define ID_PANE_CLOSE 0xE152
+
+// Format
+#define ID_FORMAT_FONT 0xE160
+
+// Scroll
+#define ID_SCROLL_UP 0xE170
+#define ID_SCROLL_DOWN 0xE171
+#define ID_SCROLL_PAGE_UP 0xE172
+#define ID_SCROLL_PAGE_DOWN 0xE173
+#define ID_SCROLL_TOP 0xE174
+#define ID_SCROLL_BOTTOM 0xE175
+#define ID_SCROLL_LEFT 0xE176
+#define ID_SCROLL_RIGHT 0xE177
+#define ID_SCROLL_PAGE_LEFT 0xE178
+#define ID_SCROLL_PAGE_RIGHT 0xE179
+#define ID_SCROLL_ALL_LEFT 0xE17A
+#define ID_SCROLL_ALL_RIGHT 0xE17B
+
+// OLE commands
+#define ID_OLE_INSERT_NEW 0xE200
+#define ID_OLE_EDIT_LINKS 0xE201
+#define ID_OLE_EDIT_CONVERT 0xE202
+#define ID_OLE_EDIT_CHANGE_ICON 0xE203
+#define ID_OLE_EDIT_PROPERTIES 0xE204
+#define ID_OLE_VERB_FIRST 0xE210 // range - 16 max
+#ifndef RC_INVOKED // code only
+ #define ID_OLE_VERB_LAST 0xE21F
+#endif // !RC_INVOKED
+
+// View commands (same number used as IDW used for toolbar and status bar)
+#define ID_VIEW_TOOLBAR 0xE800
+#define ID_VIEW_STATUS_BAR 0xE801
+#define ID_VIEW_REFRESH 0xE803
+#define ID_VIEW_RIBBON 0xE804 // Ribbon
+
+///////////////////////////////////////////////////////////////////////////////
+// Standard control IDs
+
+#ifdef IDC_STATIC
+ #undef IDC_STATIC
+#endif // IDC_STATIC
+#define IDC_STATIC (-1) // all static controls
+
+///////////////////////////////////////////////////////////////////////////////
+// Standard string error/warnings
+
+// idle status bar message
+#define ATL_IDS_IDLEMESSAGE 0xE001
+
+#ifndef RC_INVOKED // code only
+ #define ATL_IDS_SCFIRST 0xEF00
+#endif // !RC_INVOKED
+
+#define ATL_IDS_SCSIZE 0xEF00
+#define ATL_IDS_SCMOVE 0xEF01
+#define ATL_IDS_SCMINIMIZE 0xEF02
+#define ATL_IDS_SCMAXIMIZE 0xEF03
+#define ATL_IDS_SCNEXTWINDOW 0xEF04
+#define ATL_IDS_SCPREVWINDOW 0xEF05
+#define ATL_IDS_SCCLOSE 0xEF06
+#define ATL_IDS_SCRESTORE 0xEF12
+#define ATL_IDS_SCTASKLIST 0xEF13
+
+#define ATL_IDS_MDICHILD 0xEF1F
+#define ATL_IDS_MRU_FILE 0xEFDA
+
+///////////////////////////////////////////////////////////////////////////////
+// Misc. control IDs
+
+// Property Sheet control id's (determined with Spy++)
+#define ID_APPLY_NOW 0x3021
+#define ID_WIZBACK 0x3023
+#define ID_WIZNEXT 0x3024
+#define ID_WIZFINISH 0x3025
+#define ATL_IDC_TAB_CONTROL 0x3020
+
+#endif // __ATLRES_H__
diff --git a/plugins/XSoundNotify/src/wtl/include/atluser.h b/plugins/XSoundNotify/src/wtl/include/atluser.h new file mode 100644 index 0000000000..6cd8205a73 --- /dev/null +++ b/plugins/XSoundNotify/src/wtl/include/atluser.h @@ -0,0 +1,1391 @@ +// Windows Template Library - WTL version 8.1
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//
+// This file is a part of the Windows Template Library.
+// The use and distribution terms for this software are covered by the
+// Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
+// which can be found in the file CPL.TXT at the root of this distribution.
+// By using this software in any fashion, you are agreeing to be bound by
+// the terms of this license. You must not remove this notice, or
+// any other, from this software.
+
+#ifndef __ATLUSER_H__
+#define __ATLUSER_H__
+
+#pragma once
+
+#ifndef __ATLAPP_H__
+ #error atluser.h requires atlapp.h to be included first
+#endif
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Classes in this file:
+//
+// CMenuItemInfo
+// CMenuT<t_bManaged>
+// CAcceleratorT<t_bManaged>
+// CIconT<t_bManaged>
+// CCursorT<t_bManaged>
+// CResource
+//
+// Global functions:
+// AtlMessageBox()
+//
+// AtlLoadAccelerators()
+// AtlLoadMenu()
+// AtlLoadBitmap()
+// AtlLoadSysBitmap()
+// AtlLoadCursor()
+// AtlLoadSysCursor()
+// AtlLoadIcon()
+// AtlLoadSysIcon()
+// AtlLoadBitmapImage()
+// AtlLoadCursorImage()
+// AtlLoadIconImage()
+// AtlLoadSysBitmapImage()
+// AtlLoadSysCursorImage()
+// AtlLoadSysIconImage()
+// AtlLoadString()
+
+
+namespace WTL
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// AtlMessageBox - accepts both memory and resource based strings
+
+inline int AtlMessageBox(HWND hWndOwner, ATL::_U_STRINGorID message, ATL::_U_STRINGorID title = (LPCTSTR)NULL, UINT uType = MB_OK | MB_ICONINFORMATION)
+{
+ ATLASSERT(hWndOwner == NULL || ::IsWindow(hWndOwner));
+
+ LPTSTR lpstrMessage = NULL;
+ if(IS_INTRESOURCE(message.m_lpstr))
+ {
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ ATLTRY(lpstrMessage = new TCHAR[nLen]);
+ if(lpstrMessage == NULL)
+ {
+ ATLASSERT(FALSE);
+ return 0;
+ }
+ int nRes = ::LoadString(ModuleHelper::GetResourceInstance(), LOWORD(message.m_lpstr), lpstrMessage, nLen);
+ if(nRes < nLen - 1)
+ break;
+ delete [] lpstrMessage;
+ lpstrMessage = NULL;
+ }
+
+ message.m_lpstr = lpstrMessage;
+ }
+
+ LPTSTR lpstrTitle = NULL;
+ if(IS_INTRESOURCE(title.m_lpstr) && LOWORD(title.m_lpstr) != 0)
+ {
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ ATLTRY(lpstrTitle = new TCHAR[nLen]);
+ if(lpstrTitle == NULL)
+ {
+ ATLASSERT(FALSE);
+ return 0;
+ }
+ int nRes = ::LoadString(ModuleHelper::GetResourceInstance(), LOWORD(title.m_lpstr), lpstrTitle, nLen);
+ if(nRes < nLen - 1)
+ break;
+ delete [] lpstrTitle;
+ lpstrTitle = NULL;
+ }
+
+ title.m_lpstr = lpstrTitle;
+ }
+
+ int nRet = ::MessageBox(hWndOwner, message.m_lpstr, title.m_lpstr, uType);
+
+ delete [] lpstrMessage;
+ delete [] lpstrTitle;
+
+ return nRet;
+}
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CMenu
+
+#if (WINVER >= 0x0500)
+ #ifndef MII_SIZEOF_STRUCT
+ #define MII_SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
+ #endif
+ #define MENUITEMINFO_SIZE_VERSION_400A MII_SIZEOF_STRUCT(MENUITEMINFOA, cch)
+ #define MENUITEMINFO_SIZE_VERSION_400W MII_SIZEOF_STRUCT(MENUITEMINFOW, cch)
+ #ifdef UNICODE
+ #define MENUITEMINFO_SIZE_VERSION_400 MENUITEMINFO_SIZE_VERSION_400W
+ #else
+ #define MENUITEMINFO_SIZE_VERSION_400 MENUITEMINFO_SIZE_VERSION_400A
+ #endif // !UNICODE
+#endif // (WINVER >= 0x0500)
+
+class CMenuItemInfo : public MENUITEMINFO
+{
+public:
+ CMenuItemInfo()
+ {
+ memset(this, 0, sizeof(MENUITEMINFO));
+ cbSize = sizeof(MENUITEMINFO);
+#if (WINVER >= 0x0500)
+ // adjust struct size if running on older version of Windows
+ if(AtlIsOldWindows())
+ {
+ ATLASSERT(cbSize > MENUITEMINFO_SIZE_VERSION_400); // must be
+ cbSize = MENUITEMINFO_SIZE_VERSION_400;
+ }
+#endif // (WINVER >= 0x0500)
+ }
+};
+
+
+// forward declarations
+template <bool t_bManaged> class CMenuT;
+typedef CMenuT<false> CMenuHandle;
+typedef CMenuT<true> CMenu;
+
+
+template <bool t_bManaged>
+class CMenuT
+{
+public:
+// Data members
+ HMENU m_hMenu;
+
+// Constructor/destructor/operators
+ CMenuT(HMENU hMenu = NULL) : m_hMenu(hMenu)
+ { }
+
+ ~CMenuT()
+ {
+ if(t_bManaged && m_hMenu != NULL)
+ DestroyMenu();
+ }
+
+ CMenuT<t_bManaged>& operator =(HMENU hMenu)
+ {
+ Attach(hMenu);
+ return *this;
+ }
+
+ void Attach(HMENU hMenuNew)
+ {
+ ATLASSERT(::IsMenu(hMenuNew));
+ if(t_bManaged && m_hMenu != NULL && m_hMenu != hMenuNew)
+ ::DestroyMenu(m_hMenu);
+ m_hMenu = hMenuNew;
+ }
+
+ HMENU Detach()
+ {
+ HMENU hMenu = m_hMenu;
+ m_hMenu = NULL;
+ return hMenu;
+ }
+
+ operator HMENU() const { return m_hMenu; }
+
+ bool IsNull() const { return (m_hMenu == NULL); }
+
+ BOOL IsMenu() const
+ {
+ return ::IsMenu(m_hMenu);
+ }
+
+// Create/destroy methods
+ BOOL CreateMenu()
+ {
+ ATLASSERT(m_hMenu == NULL);
+ m_hMenu = ::CreateMenu();
+ return (m_hMenu != NULL) ? TRUE : FALSE;
+ }
+
+ BOOL CreatePopupMenu()
+ {
+ ATLASSERT(m_hMenu == NULL);
+ m_hMenu = ::CreatePopupMenu();
+ return (m_hMenu != NULL) ? TRUE : FALSE;
+ }
+
+ BOOL LoadMenu(ATL::_U_STRINGorID menu)
+ {
+ ATLASSERT(m_hMenu == NULL);
+ m_hMenu = ::LoadMenu(ModuleHelper::GetResourceInstance(), menu.m_lpstr);
+ return (m_hMenu != NULL) ? TRUE : FALSE;
+ }
+
+#ifndef _WIN32_WCE
+ BOOL LoadMenuIndirect(const void* lpMenuTemplate)
+ {
+ ATLASSERT(m_hMenu == NULL);
+ m_hMenu = ::LoadMenuIndirect(lpMenuTemplate);
+ return (m_hMenu != NULL) ? TRUE : FALSE;
+ }
+#endif // !_WIN32_WCE
+
+ BOOL DestroyMenu()
+ {
+ if (m_hMenu == NULL)
+ return FALSE;
+ BOOL bRet = ::DestroyMenu(m_hMenu);
+ if(bRet)
+ m_hMenu = NULL;
+ return bRet;
+ }
+
+// Menu Operations
+ BOOL DeleteMenu(UINT nPosition, UINT nFlags)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::DeleteMenu(m_hMenu, nPosition, nFlags);
+ }
+
+ BOOL TrackPopupMenu(UINT nFlags, int x, int y, HWND hWnd, LPCRECT lpRect = NULL)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+#ifndef _WIN32_WCE
+#if (WINVER >= 0x0500)
+ x = _FixTrackMenuPopupX(x, y);
+#endif // !(WINVER >= 0x0500)
+ return ::TrackPopupMenu(m_hMenu, nFlags, x, y, 0, hWnd, lpRect);
+#else // CE specific
+ lpRect;
+ return ::TrackPopupMenuEx(m_hMenu, nFlags, x, y, hWnd, NULL);
+#endif // _WIN32_WCE
+ }
+
+ BOOL TrackPopupMenuEx(UINT uFlags, int x, int y, HWND hWnd, LPTPMPARAMS lptpm = NULL)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+ x = _FixTrackMenuPopupX(x, y);
+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+ return ::TrackPopupMenuEx(m_hMenu, uFlags, x, y, hWnd, lptpm);
+ }
+
+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+ // helper that fixes popup menu X position when it's off-screen
+ static int _FixTrackMenuPopupX(int x, int y)
+ {
+ POINT pt = { x, y };
+ HMONITOR hMonitor = ::MonitorFromPoint(pt, MONITOR_DEFAULTTONULL);
+ if(hMonitor == NULL)
+ {
+ HMONITOR hMonitorNear = ::MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
+ if(hMonitorNear != NULL)
+ {
+ MONITORINFO mi = { 0 };
+ mi.cbSize = sizeof(MONITORINFO);
+ if(::GetMonitorInfo(hMonitorNear, &mi) != FALSE)
+ {
+ if(x < mi.rcWork.left)
+ x = mi.rcWork.left;
+ else if(x > mi.rcWork.right)
+ x = mi.rcWork.right;
+ }
+ }
+ }
+
+ return x;
+ }
+
+ BOOL GetMenuInfo(LPMENUINFO lpMenuInfo) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuInfo(m_hMenu, lpMenuInfo);
+ }
+
+ BOOL SetMenuInfo(LPCMENUINFO lpMenuInfo)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::SetMenuInfo(m_hMenu, lpMenuInfo);
+ }
+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+
+// Menu Item Operations
+ BOOL AppendMenu(UINT nFlags, UINT_PTR nIDNewItem = 0, LPCTSTR lpszNewItem = NULL)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::AppendMenu(m_hMenu, nFlags, nIDNewItem, lpszNewItem);
+ }
+
+ BOOL AppendMenu(UINT nFlags, HMENU hSubMenu, LPCTSTR lpszNewItem)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ ATLASSERT(::IsMenu(hSubMenu));
+ return ::AppendMenu(m_hMenu, nFlags | MF_POPUP, (UINT_PTR)hSubMenu, lpszNewItem);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL AppendMenu(UINT nFlags, UINT_PTR nIDNewItem, HBITMAP hBmp)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::AppendMenu(m_hMenu, nFlags | MF_BITMAP, nIDNewItem, (LPCTSTR)hBmp);
+ }
+
+ BOOL AppendMenu(UINT nFlags, HMENU hSubMenu, HBITMAP hBmp)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ ATLASSERT(::IsMenu(hSubMenu));
+ return ::AppendMenu(m_hMenu, nFlags | (MF_BITMAP | MF_POPUP), (UINT_PTR)hSubMenu, (LPCTSTR)hBmp);
+ }
+#endif // !_WIN32_WCE
+
+ UINT CheckMenuItem(UINT nIDCheckItem, UINT nCheck)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return (UINT)::CheckMenuItem(m_hMenu, nIDCheckItem, nCheck);
+ }
+
+ UINT EnableMenuItem(UINT nIDEnableItem, UINT nEnable)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::EnableMenuItem(m_hMenu, nIDEnableItem, nEnable);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL HiliteMenuItem(HWND hWnd, UINT uIDHiliteItem, UINT uHilite)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::HiliteMenuItem(hWnd, m_hMenu, uIDHiliteItem, uHilite);
+ }
+
+ int GetMenuItemCount() const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuItemCount(m_hMenu);
+ }
+
+ UINT GetMenuItemID(int nPos) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuItemID(m_hMenu, nPos);
+ }
+
+ UINT GetMenuState(UINT nID, UINT nFlags) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuState(m_hMenu, nID, nFlags);
+ }
+
+ int GetMenuString(UINT nIDItem, LPTSTR lpString, int nMaxCount, UINT nFlags) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuString(m_hMenu, nIDItem, lpString, nMaxCount, nFlags);
+ }
+
+ int GetMenuStringLen(UINT nIDItem, UINT nFlags) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuString(m_hMenu, nIDItem, NULL, 0, nFlags);
+ }
+
+#ifndef _ATL_NO_COM
+ BOOL GetMenuString(UINT nIDItem, BSTR& bstrText, UINT nFlags) const
+ {
+ USES_CONVERSION;
+ ATLASSERT(::IsMenu(m_hMenu));
+ ATLASSERT(bstrText == NULL);
+
+ int nLen = GetMenuStringLen(nIDItem, nFlags);
+ if(nLen == 0)
+ {
+ bstrText = ::SysAllocString(OLESTR(""));
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+
+ nLen++; // increment to include terminating NULL char
+ CTempBuffer<TCHAR, _WTL_STACK_ALLOC_THRESHOLD> buff;
+ LPTSTR lpszText = buff.Allocate(nLen);
+ if(lpszText == NULL)
+ return FALSE;
+
+ if(!GetMenuString(nIDItem, lpszText, nLen, nFlags))
+ return FALSE;
+
+ bstrText = ::SysAllocString(T2OLE(lpszText));
+ return (bstrText != NULL) ? TRUE : FALSE;
+ }
+#endif // !_ATL_NO_COM
+
+#elif (_ATL_VER >= 0x0800)
+ int GetMenuItemCount() const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ATL::GetMenuItemCount(m_hMenu);
+ }
+
+ UINT GetMenuItemID(int nPos) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ATL::GetMenuItemID(m_hMenu, nPos);
+ }
+
+ UINT GetMenuState(UINT nID, UINT nFlags) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ATL::GetMenuState(m_hMenu, nID, nFlags);
+ }
+
+ int GetMenuString(UINT nIDItem, LPTSTR lpString, int nMaxCount, UINT nFlags) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ATL::GetMenuString(m_hMenu, nIDItem, lpString, nMaxCount, nFlags);
+ }
+
+ int GetMenuStringLen(UINT nIDItem, UINT nFlags) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ATL::GetMenuString(m_hMenu, nIDItem, NULL, 0, nFlags);
+ }
+#endif // (_ATL_VER >= 0x0800)
+
+#if defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+ int GetMenuString(UINT nIDItem, _CSTRING_NS::CString& strText, UINT nFlags) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+
+ int nLen = GetMenuStringLen(nIDItem, nFlags);
+ if(nLen == 0)
+ return 0;
+
+ nLen++; // increment to include terminating NULL char
+ LPTSTR lpstr = strText.GetBufferSetLength(nLen);
+ if(lpstr == NULL)
+ return 0;
+ int nRet = GetMenuString(nIDItem, lpstr, nLen, nFlags);
+ strText.ReleaseBuffer();
+ return nRet;
+ }
+#endif // defined(_WTL_USE_CSTRING) || defined(__ATLSTR_H__)
+
+ CMenuHandle GetSubMenu(int nPos) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return CMenuHandle(::GetSubMenu(m_hMenu, nPos));
+ }
+
+ BOOL InsertMenu(UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem = 0, LPCTSTR lpszNewItem = NULL)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::InsertMenu(m_hMenu, nPosition, nFlags, nIDNewItem, lpszNewItem);
+ }
+
+ BOOL InsertMenu(UINT nPosition, UINT nFlags, HMENU hSubMenu, LPCTSTR lpszNewItem)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ ATLASSERT(::IsMenu(hSubMenu));
+ return ::InsertMenu(m_hMenu, nPosition, nFlags | MF_POPUP, (UINT_PTR)hSubMenu, lpszNewItem);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL InsertMenu(UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem, HBITMAP hBmp)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::InsertMenu(m_hMenu, nPosition, nFlags | MF_BITMAP, nIDNewItem, (LPCTSTR)hBmp);
+ }
+
+ BOOL InsertMenu(UINT nPosition, UINT nFlags, HMENU hSubMenu, HBITMAP hBmp)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ ATLASSERT(::IsMenu(hSubMenu));
+ return ::InsertMenu(m_hMenu, nPosition, nFlags | (MF_BITMAP | MF_POPUP), (UINT_PTR)hSubMenu, (LPCTSTR)hBmp);
+ }
+
+ BOOL ModifyMenu(UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem = 0, LPCTSTR lpszNewItem = NULL)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::ModifyMenu(m_hMenu, nPosition, nFlags, nIDNewItem, lpszNewItem);
+ }
+
+ BOOL ModifyMenu(UINT nPosition, UINT nFlags, HMENU hSubMenu, LPCTSTR lpszNewItem)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ ATLASSERT(::IsMenu(hSubMenu));
+ return ::ModifyMenu(m_hMenu, nPosition, nFlags | MF_POPUP, (UINT_PTR)hSubMenu, lpszNewItem);
+ }
+
+ BOOL ModifyMenu(UINT nPosition, UINT nFlags, UINT_PTR nIDNewItem, HBITMAP hBmp)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::ModifyMenu(m_hMenu, nPosition, nFlags | MF_BITMAP, nIDNewItem, (LPCTSTR)hBmp);
+ }
+
+ BOOL ModifyMenu(UINT nPosition, UINT nFlags, HMENU hSubMenu, HBITMAP hBmp)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ ATLASSERT(::IsMenu(hSubMenu));
+ return ::ModifyMenu(m_hMenu, nPosition, nFlags | (MF_BITMAP | MF_POPUP), (UINT_PTR)hSubMenu, (LPCTSTR)hBmp);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL RemoveMenu(UINT nPosition, UINT nFlags)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::RemoveMenu(m_hMenu, nPosition, nFlags);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL SetMenuItemBitmaps(UINT nPosition, UINT nFlags, HBITMAP hBmpUnchecked, HBITMAP hBmpChecked)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::SetMenuItemBitmaps(m_hMenu, nPosition, nFlags, hBmpUnchecked, hBmpChecked);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL CheckMenuRadioItem(UINT nIDFirst, UINT nIDLast, UINT nIDItem, UINT nFlags)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::CheckMenuRadioItem(m_hMenu, nIDFirst, nIDLast, nIDItem, nFlags);
+ }
+
+ BOOL GetMenuItemInfo(UINT uItem, BOOL bByPosition, LPMENUITEMINFO lpmii) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return (BOOL)::GetMenuItemInfo(m_hMenu, uItem, bByPosition, lpmii);
+ }
+
+ BOOL SetMenuItemInfo(UINT uItem, BOOL bByPosition, LPMENUITEMINFO lpmii)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return (BOOL)::SetMenuItemInfo(m_hMenu, uItem, bByPosition, lpmii);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL InsertMenuItem(UINT uItem, BOOL bByPosition, LPMENUITEMINFO lpmii)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return (BOOL)::InsertMenuItem(m_hMenu, uItem, bByPosition, lpmii);
+ }
+
+ UINT GetMenuDefaultItem(BOOL bByPosition = FALSE, UINT uFlags = 0U) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuDefaultItem(m_hMenu, (UINT)bByPosition, uFlags);
+ }
+
+ BOOL SetMenuDefaultItem(UINT uItem = (UINT)-1, BOOL bByPosition = FALSE)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::SetMenuDefaultItem(m_hMenu, uItem, (UINT)bByPosition);
+ }
+
+ BOOL GetMenuItemRect(HWND hWnd, UINT uItem, LPRECT lprcItem) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuItemRect(hWnd, m_hMenu, uItem, lprcItem);
+ }
+
+ int MenuItemFromPoint(HWND hWnd, POINT point) const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::MenuItemFromPoint(hWnd, m_hMenu, point);
+ }
+
+// Context Help Functions
+ BOOL SetMenuContextHelpId(DWORD dwContextHelpId)
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::SetMenuContextHelpId(m_hMenu, dwContextHelpId);
+ }
+
+ DWORD GetMenuContextHelpId() const
+ {
+ ATLASSERT(::IsMenu(m_hMenu));
+ return ::GetMenuContextHelpId(m_hMenu);
+ }
+#endif // !_WIN32_WCE
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CAccelerator
+
+template <bool t_bManaged>
+class CAcceleratorT
+{
+public:
+ HACCEL m_hAccel;
+
+// Constructor/destructor/operators
+ CAcceleratorT(HACCEL hAccel = NULL) : m_hAccel(hAccel)
+ { }
+
+ ~CAcceleratorT()
+ {
+ if(t_bManaged && m_hAccel != NULL)
+ ::DestroyAcceleratorTable(m_hAccel);
+ }
+
+ CAcceleratorT<t_bManaged>& operator =(HACCEL hAccel)
+ {
+ Attach(hAccel);
+ return *this;
+ }
+
+ void Attach(HACCEL hAccel)
+ {
+ if(t_bManaged && m_hAccel != NULL)
+ ::DestroyAcceleratorTable(m_hAccel);
+ m_hAccel = hAccel;
+ }
+
+ HACCEL Detach()
+ {
+ HACCEL hAccel = m_hAccel;
+ m_hAccel = NULL;
+ return hAccel;
+ }
+
+ operator HACCEL() const { return m_hAccel; }
+
+ bool IsNull() const { return m_hAccel == NULL; }
+
+// Create/destroy methods
+ HACCEL LoadAccelerators(ATL::_U_STRINGorID accel)
+ {
+ ATLASSERT(m_hAccel == NULL);
+ m_hAccel = ::LoadAccelerators(ModuleHelper::GetResourceInstance(), accel.m_lpstr);
+ return m_hAccel;
+ }
+
+ HACCEL CreateAcceleratorTable(LPACCEL pAccel, int cEntries)
+ {
+ ATLASSERT(m_hAccel == NULL);
+ ATLASSERT(pAccel != NULL);
+ m_hAccel = ::CreateAcceleratorTable(pAccel, cEntries);
+ return m_hAccel;
+ }
+
+ void DestroyObject()
+ {
+ if(m_hAccel != NULL)
+ {
+ ::DestroyAcceleratorTable(m_hAccel);
+ m_hAccel = NULL;
+ }
+ }
+
+// Operations
+#ifndef _WIN32_WCE
+ int CopyAcceleratorTable(LPACCEL lpAccelDst, int cEntries)
+ {
+ ATLASSERT(m_hAccel != NULL);
+ ATLASSERT(lpAccelDst != NULL);
+ return ::CopyAcceleratorTable(m_hAccel, lpAccelDst, cEntries);
+ }
+
+ int GetEntriesCount() const
+ {
+ ATLASSERT(m_hAccel != NULL);
+ return ::CopyAcceleratorTable(m_hAccel, NULL, 0);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL TranslateAccelerator(HWND hWnd, LPMSG pMsg)
+ {
+ ATLASSERT(m_hAccel != NULL);
+ ATLASSERT(::IsWindow(hWnd));
+ ATLASSERT(pMsg != NULL);
+ return ::TranslateAccelerator(hWnd, m_hAccel, pMsg);
+ }
+};
+
+typedef CAcceleratorT<false> CAcceleratorHandle;
+typedef CAcceleratorT<true> CAccelerator;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CIcon
+
+template <bool t_bManaged>
+class CIconT
+{
+public:
+ HICON m_hIcon;
+
+// Constructor/destructor/operators
+ CIconT(HICON hIcon = NULL) : m_hIcon(hIcon)
+ { }
+
+ ~CIconT()
+ {
+ if(t_bManaged && m_hIcon != NULL)
+ ::DestroyIcon(m_hIcon);
+ }
+
+ CIconT<t_bManaged>& operator =(HICON hIcon)
+ {
+ Attach(hIcon);
+ return *this;
+ }
+
+ void Attach(HICON hIcon)
+ {
+ if(t_bManaged && m_hIcon != NULL)
+ ::DestroyIcon(m_hIcon);
+ m_hIcon = hIcon;
+ }
+
+ HICON Detach()
+ {
+ HICON hIcon = m_hIcon;
+ m_hIcon = NULL;
+ return hIcon;
+ }
+
+ operator HICON() const { return m_hIcon; }
+
+ bool IsNull() const { return m_hIcon == NULL; }
+
+// Create/destroy methods
+ HICON LoadIcon(ATL::_U_STRINGorID icon)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ m_hIcon = ::LoadIcon(ModuleHelper::GetResourceInstance(), icon.m_lpstr);
+ return m_hIcon;
+ }
+
+ HICON LoadIcon(ATL::_U_STRINGorID icon, int cxDesired, int cyDesired, UINT fuLoad = 0)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ m_hIcon = (HICON) ::LoadImage(ModuleHelper::GetResourceInstance(), icon.m_lpstr, IMAGE_ICON, cxDesired, cyDesired, fuLoad);
+ return m_hIcon;
+ }
+
+#ifndef _WIN32_WCE
+ HICON LoadOEMIcon(LPCTSTR lpstrIconName)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(IsOEMIcon(lpstrIconName));
+ m_hIcon = ::LoadIcon(NULL, lpstrIconName);
+ return m_hIcon;
+ }
+
+ HICON CreateIcon(int nWidth, int nHeight, BYTE cPlanes, BYTE cBitsPixel, CONST BYTE* lpbANDbits, CONST BYTE *lpbXORbits)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(lpbANDbits != NULL);
+ ATLASSERT(lpbXORbits != NULL);
+ m_hIcon = ::CreateIcon(ModuleHelper::GetResourceInstance(), nWidth, nHeight, cPlanes, cBitsPixel, lpbANDbits, lpbXORbits);
+ return m_hIcon;
+ }
+
+ HICON CreateIconFromResource(PBYTE pBits, DWORD dwResSize, DWORD dwVersion = 0x00030000)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(pBits != NULL);
+ m_hIcon = ::CreateIconFromResource(pBits, dwResSize, TRUE, dwVersion);
+ return m_hIcon;
+ }
+
+ HICON CreateIconFromResourceEx(PBYTE pbBits, DWORD cbBits, DWORD dwVersion = 0x00030000, int cxDesired = 0, int cyDesired = 0, UINT uFlags = LR_DEFAULTCOLOR)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(pbBits != NULL);
+ ATLASSERT(cbBits > 0);
+ m_hIcon = ::CreateIconFromResourceEx(pbBits, cbBits, TRUE, dwVersion, cxDesired, cyDesired, uFlags);
+ return m_hIcon;
+ }
+#endif // !_WIN32_WCE
+
+ HICON CreateIconIndirect(PICONINFO pIconInfo)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(pIconInfo != NULL);
+ m_hIcon = ::CreateIconIndirect(pIconInfo);
+ return m_hIcon;
+ }
+
+#ifndef _WIN32_WCE
+ HICON ExtractIcon(LPCTSTR lpszExeFileName, UINT nIconIndex)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(lpszExeFileName != NULL);
+ m_hIcon = ::ExtractIcon(ModuleHelper::GetModuleInstance(), lpszExeFileName, nIconIndex);
+ return m_hIcon;
+ }
+
+ HICON ExtractAssociatedIcon(HINSTANCE hInst, LPTSTR lpIconPath, LPWORD lpiIcon)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(lpIconPath != NULL);
+ ATLASSERT(lpiIcon != NULL);
+ m_hIcon = ::ExtractAssociatedIcon(hInst, lpIconPath, lpiIcon);
+ return m_hIcon;
+ }
+#endif // !_WIN32_WCE
+
+ BOOL DestroyIcon()
+ {
+ ATLASSERT(m_hIcon != NULL);
+ BOOL bRet = ::DestroyIcon(m_hIcon);
+ if(bRet != FALSE)
+ m_hIcon = NULL;
+ return bRet;
+ }
+
+// Operations
+#ifndef _WIN32_WCE
+ HICON CopyIcon()
+ {
+ ATLASSERT(m_hIcon != NULL);
+ return ::CopyIcon(m_hIcon);
+ }
+
+ HICON DuplicateIcon()
+ {
+ ATLASSERT(m_hIcon != NULL);
+ return ::DuplicateIcon(NULL, m_hIcon);
+ }
+#endif // !_WIN32_WCE
+
+ BOOL DrawIcon(HDC hDC, int x, int y)
+ {
+ ATLASSERT(m_hIcon != NULL);
+#ifndef _WIN32_WCE
+ return ::DrawIcon(hDC, x, y, m_hIcon);
+#else // CE specific
+ return ::DrawIconEx(hDC, x, y, m_hIcon, 0, 0, 0, NULL, DI_NORMAL);
+#endif // _WIN32_WCE
+ }
+
+ BOOL DrawIcon(HDC hDC, POINT pt)
+ {
+ ATLASSERT(m_hIcon != NULL);
+#ifndef _WIN32_WCE
+ return ::DrawIcon(hDC, pt.x, pt.y, m_hIcon);
+#else // CE specific
+ return ::DrawIconEx(hDC, pt.x, pt.y, m_hIcon, 0, 0, 0, NULL, DI_NORMAL);
+#endif // _WIN32_WCE
+ }
+
+ BOOL DrawIconEx(HDC hDC, int x, int y, int cxWidth, int cyWidth, UINT uStepIfAniCur = 0, HBRUSH hbrFlickerFreeDraw = NULL, UINT uFlags = DI_NORMAL)
+ {
+ ATLASSERT(m_hIcon != NULL);
+ return ::DrawIconEx(hDC, x, y, m_hIcon, cxWidth, cyWidth, uStepIfAniCur, hbrFlickerFreeDraw, uFlags);
+ }
+
+ BOOL DrawIconEx(HDC hDC, POINT pt, SIZE size, UINT uStepIfAniCur = 0, HBRUSH hbrFlickerFreeDraw = NULL, UINT uFlags = DI_NORMAL)
+ {
+ ATLASSERT(m_hIcon != NULL);
+ return ::DrawIconEx(hDC, pt.x, pt.y, m_hIcon, size.cx, size.cy, uStepIfAniCur, hbrFlickerFreeDraw, uFlags);
+ }
+
+#ifndef _WIN32_WCE
+ BOOL GetIconInfo(PICONINFO pIconInfo) const
+ {
+ ATLASSERT(m_hIcon != NULL);
+ ATLASSERT(pIconInfo != NULL);
+ return ::GetIconInfo(m_hIcon, pIconInfo);
+ }
+
+#if (_WIN32_WINNT >= 0x0600)
+ BOOL GetIconInfoEx(PICONINFOEX pIconInfo) const
+ {
+ ATLASSERT(m_hIcon != NULL);
+ ATLASSERT(pIconInfo != NULL);
+ return ::GetIconInfoEx(m_hIcon, pIconInfo);
+ }
+#endif // (_WIN32_WINNT >= 0x0600)
+
+#if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+ HRESULT LoadIconMetric(ATL::_U_STRINGorID icon, int lims)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ USES_CONVERSION;
+ return ::LoadIconMetric(ModuleHelper::GetResourceInstance(), T2CW(icon.m_lpstr), lims, &m_hIcon);
+ }
+
+ HRESULT LoadIconWithScaleDown(ATL::_U_STRINGorID icon, int cx, int cy)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ USES_CONVERSION;
+ return ::LoadIconWithScaleDown(ModuleHelper::GetResourceInstance(), T2CW(icon.m_lpstr), cx, cy, &m_hIcon);
+ }
+
+ HRESULT LoadOEMIconMetric(LPCTSTR lpstrIconName, int lims)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(IsOEMIcon(lpstrIconName));
+ return ::LoadIconMetric(NULL, (LPCWSTR)lpstrIconName, lims, &m_hIcon);
+ }
+
+ HRESULT LoadOEMIconWithScaleDown(LPCTSTR lpstrIconName, int cx, int cy)
+ {
+ ATLASSERT(m_hIcon == NULL);
+ ATLASSERT(IsOEMIcon(lpstrIconName));
+ USES_CONVERSION;
+ return ::LoadIconWithScaleDown(NULL, (LPCWSTR)lpstrIconName, cx, cy, &m_hIcon);
+ }
+#endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
+#endif // !_WIN32_WCE
+
+ // Helper
+#ifndef _WIN32_WCE
+ static bool IsOEMIcon(LPCTSTR lpstrIconName)
+ {
+#if (WINVER >= 0x0600)
+ return (lpstrIconName == IDI_APPLICATION || lpstrIconName == IDI_ASTERISK || lpstrIconName == IDI_EXCLAMATION ||
+ lpstrIconName == IDI_HAND || lpstrIconName == IDI_QUESTION || lpstrIconName == IDI_WINLOGO ||
+ lpstrIconName == IDI_SHIELD);
+#else // !(WINVER >= 0x0600)
+ return (lpstrIconName == IDI_APPLICATION || lpstrIconName == IDI_ASTERISK || lpstrIconName == IDI_EXCLAMATION ||
+ lpstrIconName == IDI_HAND || lpstrIconName == IDI_QUESTION || lpstrIconName == IDI_WINLOGO);
+#endif // !(WINVER >= 0x0600)
+ }
+#endif // !_WIN32_WCE
+};
+
+typedef CIconT<false> CIconHandle;
+typedef CIconT<true> CIcon;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CCursor
+
+// protect template member from a winuser.h macro
+#ifdef CopyCursor
+ #undef CopyCursor
+#endif
+
+template <bool t_bManaged>
+class CCursorT
+{
+public:
+ HCURSOR m_hCursor;
+
+// Constructor/destructor/operators
+ CCursorT(HCURSOR hCursor = NULL) : m_hCursor(hCursor)
+ { }
+
+ ~CCursorT()
+ {
+ if(t_bManaged && m_hCursor != NULL)
+ DestroyCursor();
+ }
+
+ CCursorT<t_bManaged>& operator =(HCURSOR hCursor)
+ {
+ Attach(hCursor);
+ return *this;
+ }
+
+ void Attach(HCURSOR hCursor)
+ {
+ if(t_bManaged && m_hCursor != NULL)
+ DestroyCursor();
+ m_hCursor = hCursor;
+ }
+
+ HCURSOR Detach()
+ {
+ HCURSOR hCursor = m_hCursor;
+ m_hCursor = NULL;
+ return hCursor;
+ }
+
+ operator HCURSOR() const { return m_hCursor; }
+
+ bool IsNull() const { return m_hCursor == NULL; }
+
+// Create/destroy methods
+ HCURSOR LoadCursor(ATL::_U_STRINGorID cursor)
+ {
+ ATLASSERT(m_hCursor == NULL);
+ m_hCursor = ::LoadCursor(ModuleHelper::GetResourceInstance(), cursor.m_lpstr);
+ return m_hCursor;
+ }
+
+ HCURSOR LoadSysCursor(LPCTSTR lpstrCursorName)
+ {
+ ATLASSERT(m_hCursor == NULL);
+#if (WINVER >= 0x0500)
+ ATLASSERT(lpstrCursorName == IDC_ARROW || lpstrCursorName == IDC_IBEAM || lpstrCursorName == IDC_WAIT ||
+ lpstrCursorName == IDC_CROSS || lpstrCursorName == IDC_UPARROW || lpstrCursorName == IDC_SIZE ||
+ lpstrCursorName == IDC_ICON || lpstrCursorName == IDC_SIZENWSE || lpstrCursorName == IDC_SIZENESW ||
+ lpstrCursorName == IDC_SIZEWE || lpstrCursorName == IDC_SIZENS || lpstrCursorName == IDC_SIZEALL ||
+ lpstrCursorName == IDC_NO || lpstrCursorName == IDC_APPSTARTING || lpstrCursorName == IDC_HELP ||
+ lpstrCursorName == IDC_HAND);
+#else // !(WINVER >= 0x0500)
+ ATLASSERT(lpstrCursorName == IDC_ARROW || lpstrCursorName == IDC_IBEAM || lpstrCursorName == IDC_WAIT ||
+ lpstrCursorName == IDC_CROSS || lpstrCursorName == IDC_UPARROW || lpstrCursorName == IDC_SIZE ||
+ lpstrCursorName == IDC_ICON || lpstrCursorName == IDC_SIZENWSE || lpstrCursorName == IDC_SIZENESW ||
+ lpstrCursorName == IDC_SIZEWE || lpstrCursorName == IDC_SIZENS || lpstrCursorName == IDC_SIZEALL ||
+ lpstrCursorName == IDC_NO || lpstrCursorName == IDC_APPSTARTING || lpstrCursorName == IDC_HELP);
+#endif // !(WINVER >= 0x0500)
+ m_hCursor = ::LoadCursor(NULL, lpstrCursorName);
+ return m_hCursor;
+ }
+
+ // deprecated
+ HCURSOR LoadOEMCursor(LPCTSTR lpstrCursorName)
+ {
+ return LoadSysCursor(lpstrCursorName);
+ }
+
+ HCURSOR LoadCursor(ATL::_U_STRINGorID cursor, int cxDesired, int cyDesired, UINT fuLoad = 0)
+ {
+ ATLASSERT(m_hCursor == NULL);
+ m_hCursor = (HCURSOR) ::LoadImage(ModuleHelper::GetResourceInstance(), cursor.m_lpstr, IMAGE_CURSOR, cxDesired, cyDesired, fuLoad);
+ return m_hCursor;
+ }
+
+#ifndef _WIN32_WCE
+ HCURSOR LoadCursorFromFile(LPCTSTR pstrFilename)
+ {
+ ATLASSERT(m_hCursor == NULL);
+ ATLASSERT(pstrFilename != NULL);
+ m_hCursor = ::LoadCursorFromFile(pstrFilename);
+ return m_hCursor;
+ }
+#endif // !_WIN32_WCE
+
+#if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
+ HCURSOR CreateCursor(int xHotSpot, int yHotSpot, int nWidth, int nHeight, CONST VOID *pvANDPlane, CONST VOID *pvXORPlane)
+ {
+ ATLASSERT(m_hCursor == NULL);
+ m_hCursor = ::CreateCursor(ModuleHelper::GetResourceInstance(), xHotSpot, yHotSpot, nWidth, nHeight, pvANDPlane, pvXORPlane);
+ return m_hCursor;
+ }
+#endif // !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
+
+#ifndef _WIN32_WCE
+ HCURSOR CreateCursorFromResource(PBYTE pBits, DWORD dwResSize, DWORD dwVersion = 0x00030000)
+ {
+ ATLASSERT(m_hCursor == NULL);
+ ATLASSERT(pBits != NULL);
+ m_hCursor = (HCURSOR)::CreateIconFromResource(pBits, dwResSize, FALSE, dwVersion);
+ return m_hCursor;
+ }
+
+ HCURSOR CreateCursorFromResourceEx(PBYTE pbBits, DWORD cbBits, DWORD dwVersion = 0x00030000, int cxDesired = 0, int cyDesired = 0, UINT uFlags = LR_DEFAULTCOLOR)
+ {
+ ATLASSERT(m_hCursor == NULL);
+ ATLASSERT(pbBits != NULL);
+ ATLASSERT(cbBits > 0);
+ m_hCursor = (HCURSOR)::CreateIconFromResourceEx(pbBits, cbBits, FALSE, dwVersion, cxDesired, cyDesired, uFlags);
+ return m_hCursor;
+ }
+#endif // !_WIN32_WCE
+
+ BOOL DestroyCursor()
+ {
+ ATLASSERT(m_hCursor != NULL);
+#if !defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)))
+ BOOL bRet = ::DestroyCursor(m_hCursor);
+ if(bRet != FALSE)
+ m_hCursor = NULL;
+ return bRet;
+#else // !(!defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))))
+ ATLTRACE2(atlTraceUI, 0, _T("Warning: This version of Windows CE does not have ::DestroyCursor()\n"));
+ return FALSE;
+#endif // !(!defined(_WIN32_WCE) || ((_WIN32_WCE >= 0x400) && !(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))))
+ }
+
+// Operations
+#ifndef _WIN32_WCE
+ HCURSOR CopyCursor()
+ {
+ ATLASSERT(m_hCursor != NULL);
+ return (HCURSOR)::CopyIcon((HICON)m_hCursor);
+ }
+#endif // !_WIN32_WCE
+
+#if (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+ BOOL GetCursorInfo(LPCURSORINFO pCursorInfo)
+ {
+ ATLASSERT(m_hCursor != NULL);
+ ATLASSERT(pCursorInfo != NULL);
+ return ::GetCursorInfo(pCursorInfo);
+ }
+#endif // (WINVER >= 0x0500) && !defined(_WIN32_WCE)
+};
+
+typedef CCursorT<false> CCursorHandle;
+typedef CCursorT<true> CCursor;
+
+
+///////////////////////////////////////////////////////////////////////////////
+// CResource - Wraps a generic Windows resource.
+// Use it with custom resource types other than the
+// standard RT_CURSOR, RT_BITMAP, etc.
+
+class CResource
+{
+public:
+ HGLOBAL m_hGlobal;
+ HRSRC m_hResource;
+
+// Constructor/destructor
+ CResource() : m_hGlobal(NULL), m_hResource(NULL)
+ { }
+
+ ~CResource()
+ {
+ Release();
+ }
+
+// Load methods
+ bool Load(ATL::_U_STRINGorID Type, ATL::_U_STRINGorID ID)
+ {
+ ATLASSERT(m_hResource == NULL);
+ ATLASSERT(m_hGlobal == NULL);
+
+ m_hResource = ::FindResource(ModuleHelper::GetResourceInstance(), ID.m_lpstr, Type.m_lpstr);
+ if(m_hResource == NULL)
+ return false;
+
+ m_hGlobal = ::LoadResource(ModuleHelper::GetResourceInstance(), m_hResource);
+ if(m_hGlobal == NULL)
+ {
+ m_hResource = NULL;
+ return false;
+ }
+
+ return true;
+ }
+
+#ifndef _WIN32_WCE
+ bool LoadEx(ATL::_U_STRINGorID Type, ATL::_U_STRINGorID ID, WORD wLanguage)
+ {
+ ATLASSERT(m_hResource == NULL);
+ ATLASSERT(m_hGlobal == NULL);
+
+ m_hResource = ::FindResourceEx(ModuleHelper::GetResourceInstance(), ID.m_lpstr, Type.m_lpstr, wLanguage);
+ if(m_hResource == NULL)
+ return false;
+
+ m_hGlobal = ::LoadResource(ModuleHelper::GetResourceInstance(), m_hResource);
+ if(m_hGlobal == NULL)
+ {
+ m_hResource = NULL;
+ return false;
+ }
+
+ return true;
+ }
+#endif // !_WIN32_WCE
+
+// Misc. operations
+ DWORD GetSize() const
+ {
+ ATLASSERT(m_hResource != NULL);
+ return ::SizeofResource(ModuleHelper::GetResourceInstance(), m_hResource);
+ }
+
+ LPVOID Lock()
+ {
+ ATLASSERT(m_hResource != NULL);
+ ATLASSERT(m_hGlobal != NULL);
+ LPVOID pVoid = ::LockResource(m_hGlobal);
+ ATLASSERT(pVoid != NULL);
+ return pVoid;
+ }
+
+ void Release()
+ {
+ if(m_hGlobal != NULL)
+ {
+ FreeResource(m_hGlobal);
+ m_hGlobal = NULL;
+ m_hResource = NULL;
+ }
+ }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Toolbar resource descriptor
+
+struct _AtlToolBarData
+{
+ WORD wVersion;
+ WORD wWidth;
+ WORD wHeight;
+ WORD wItemCount;
+
+ WORD* items()
+ { return (WORD*)(this+1); }
+};
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Global functions for loading resources
+
+inline HACCEL AtlLoadAccelerators(ATL::_U_STRINGorID table)
+{
+ return ::LoadAccelerators(ModuleHelper::GetResourceInstance(), table.m_lpstr);
+}
+
+inline HMENU AtlLoadMenu(ATL::_U_STRINGorID menu)
+{
+ return ::LoadMenu(ModuleHelper::GetResourceInstance(), menu.m_lpstr);
+}
+
+inline HBITMAP AtlLoadBitmap(ATL::_U_STRINGorID bitmap)
+{
+ return ::LoadBitmap(ModuleHelper::GetResourceInstance(), bitmap.m_lpstr);
+}
+
+#ifdef OEMRESOURCE
+inline HBITMAP AtlLoadSysBitmap(ATL::_U_STRINGorID bitmap)
+{
+#ifdef _DEBUG
+ WORD wID = (WORD)bitmap.m_lpstr;
+ ATLASSERT(wID >= 32734 && wID <= 32767);
+#endif // _DEBUG
+ return ::LoadBitmap(NULL, bitmap.m_lpstr);
+}
+#endif // OEMRESOURCE
+
+inline HCURSOR AtlLoadCursor(ATL::_U_STRINGorID cursor)
+{
+ return ::LoadCursor(ModuleHelper::GetResourceInstance(), cursor.m_lpstr);
+}
+
+inline HCURSOR AtlLoadSysCursor(LPCTSTR lpCursorName)
+{
+#if (WINVER >= 0x0500)
+ ATLASSERT(lpCursorName == IDC_ARROW || lpCursorName == IDC_IBEAM || lpCursorName == IDC_WAIT ||
+ lpCursorName == IDC_CROSS || lpCursorName == IDC_UPARROW || lpCursorName == IDC_SIZE ||
+ lpCursorName == IDC_ICON || lpCursorName == IDC_SIZENWSE || lpCursorName == IDC_SIZENESW ||
+ lpCursorName == IDC_SIZEWE || lpCursorName == IDC_SIZENS || lpCursorName == IDC_SIZEALL ||
+ lpCursorName == IDC_NO || lpCursorName == IDC_APPSTARTING || lpCursorName == IDC_HELP ||
+ lpCursorName == IDC_HAND);
+#else // !(WINVER >= 0x0500)
+ ATLASSERT(lpCursorName == IDC_ARROW || lpCursorName == IDC_IBEAM || lpCursorName == IDC_WAIT ||
+ lpCursorName == IDC_CROSS || lpCursorName == IDC_UPARROW || lpCursorName == IDC_SIZE ||
+ lpCursorName == IDC_ICON || lpCursorName == IDC_SIZENWSE || lpCursorName == IDC_SIZENESW ||
+ lpCursorName == IDC_SIZEWE || lpCursorName == IDC_SIZENS || lpCursorName == IDC_SIZEALL ||
+ lpCursorName == IDC_NO || lpCursorName == IDC_APPSTARTING || lpCursorName == IDC_HELP);
+#endif // !(WINVER >= 0x0500)
+ return ::LoadCursor(NULL, lpCursorName);
+}
+
+inline HICON AtlLoadIcon(ATL::_U_STRINGorID icon)
+{
+ return ::LoadIcon(ModuleHelper::GetResourceInstance(), icon.m_lpstr);
+}
+
+#ifndef _WIN32_WCE
+inline HICON AtlLoadSysIcon(LPCTSTR lpIconName)
+{
+#if (WINVER >= 0x0600)
+ ATLASSERT(lpIconName == IDI_APPLICATION || lpIconName == IDI_ASTERISK || lpIconName == IDI_EXCLAMATION ||
+ lpIconName == IDI_HAND || lpIconName == IDI_QUESTION || lpIconName == IDI_WINLOGO ||
+ lpIconName == IDI_SHIELD);
+#else // !(WINVER >= 0x0600)
+ ATLASSERT(lpIconName == IDI_APPLICATION || lpIconName == IDI_ASTERISK || lpIconName == IDI_EXCLAMATION ||
+ lpIconName == IDI_HAND || lpIconName == IDI_QUESTION || lpIconName == IDI_WINLOGO);
+#endif // !(WINVER >= 0x0600)
+ return ::LoadIcon(NULL, lpIconName);
+}
+#endif // !_WIN32_WCE
+
+inline HBITMAP AtlLoadBitmapImage(ATL::_U_STRINGorID bitmap, UINT fuLoad = LR_DEFAULTCOLOR)
+{
+ return (HBITMAP)::LoadImage(ModuleHelper::GetResourceInstance(), bitmap.m_lpstr, IMAGE_BITMAP, 0, 0, fuLoad);
+}
+
+inline HCURSOR AtlLoadCursorImage(ATL::_U_STRINGorID cursor, UINT fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE, int cxDesired = 0, int cyDesired = 0)
+{
+ return (HCURSOR)::LoadImage(ModuleHelper::GetResourceInstance(), cursor.m_lpstr, IMAGE_CURSOR, cxDesired, cyDesired, fuLoad);
+}
+
+inline HICON AtlLoadIconImage(ATL::_U_STRINGorID icon, UINT fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE, int cxDesired = 0, int cyDesired = 0)
+{
+ return (HICON)::LoadImage(ModuleHelper::GetResourceInstance(), icon.m_lpstr, IMAGE_ICON, cxDesired, cyDesired, fuLoad);
+}
+
+#ifdef OEMRESOURCE
+inline HBITMAP AtlLoadSysBitmapImage(WORD wBitmapID, UINT fuLoad = LR_DEFAULTCOLOR)
+{
+ ATLASSERT(wBitmapID >= 32734 && wBitmapID <= 32767);
+ ATLASSERT((fuLoad & LR_LOADFROMFILE) == 0); // this one doesn't load from a file
+ return (HBITMAP)::LoadImage(NULL, MAKEINTRESOURCE(wBitmapID), IMAGE_BITMAP, 0, 0, fuLoad);
+}
+#endif // OEMRESOURCE
+
+inline HCURSOR AtlLoadSysCursorImage(ATL::_U_STRINGorID cursor, UINT fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE, int cxDesired = 0, int cyDesired = 0)
+{
+#ifdef _DEBUG
+ WORD wID = (WORD)cursor.m_lpstr;
+ ATLASSERT((wID >= 32512 && wID <= 32516) || (wID >= 32640 && wID <= 32648) || (wID == 32650) || (wID == 32651));
+ ATLASSERT((fuLoad & LR_LOADFROMFILE) == 0); // this one doesn't load from a file
+#endif // _DEBUG
+ return (HCURSOR)::LoadImage(NULL, cursor.m_lpstr, IMAGE_CURSOR, cxDesired, cyDesired, fuLoad);
+}
+
+inline HICON AtlLoadSysIconImage(ATL::_U_STRINGorID icon, UINT fuLoad = LR_DEFAULTCOLOR | LR_DEFAULTSIZE, int cxDesired = 0, int cyDesired = 0)
+{
+#ifdef _DEBUG
+ WORD wID = (WORD)icon.m_lpstr;
+ ATLASSERT(wID >= 32512 && wID <= 32517);
+ ATLASSERT((fuLoad & LR_LOADFROMFILE) == 0); // this one doesn't load from a file
+#endif // _DEBUG
+ return (HICON)::LoadImage(NULL, icon.m_lpstr, IMAGE_ICON, cxDesired, cyDesired, fuLoad);
+}
+
+#if (_ATL_VER < 0x0700)
+inline int AtlLoadString(UINT uID, LPTSTR lpBuffer, int nBufferMax)
+{
+ return ::LoadString(ModuleHelper::GetResourceInstance(), uID, lpBuffer, nBufferMax);
+}
+#else
+
+using ATL::AtlLoadString;
+
+#endif // (_ATL_VER < 0x0700)
+
+#ifdef _WIN32_WCE // CE only direct access to the resource
+inline LPCTSTR AtlLoadString(UINT uID)
+{
+ LPCTSTR s = (LPCTSTR)::LoadString(ModuleHelper::GetResourceInstance(), uID, NULL, 0);
+#ifdef DEBUG // Check for null-termination
+ if(s != NULL)
+ // Note: RC -n <file.rc> compiles null-terminated resource strings
+ ATLASSERT(s[*((WORD*)s -1) - 1] == L'\0');
+#endif
+ return s;
+}
+#endif // _WIN32_WCE
+
+inline bool AtlLoadString(UINT uID, BSTR& bstrText)
+{
+ USES_CONVERSION;
+ ATLASSERT(bstrText == NULL);
+
+ LPTSTR lpstrText = NULL;
+ int nRes = 0;
+ for(int nLen = 256; ; nLen *= 2)
+ {
+ ATLTRY(lpstrText = new TCHAR[nLen]);
+ if(lpstrText == NULL)
+ break;
+ nRes = ::LoadString(ModuleHelper::GetResourceInstance(), uID, lpstrText, nLen);
+ if(nRes < nLen - 1)
+ break;
+ delete [] lpstrText;
+ lpstrText = NULL;
+ }
+
+ if(lpstrText != NULL)
+ {
+ if(nRes != 0)
+ bstrText = ::SysAllocString(T2OLE(lpstrText));
+ delete [] lpstrText;
+ }
+
+ return (bstrText != NULL) ? true : false;
+}
+
+}; // namespace WTL
+
+#endif // __ATLUSER_H__
diff --git a/plugins/XSoundNotify/src/wtl/include/atlwinx.h b/plugins/XSoundNotify/src/wtl/include/atlwinx.h new file mode 100644 index 0000000000..629d29778f --- /dev/null +++ b/plugins/XSoundNotify/src/wtl/include/atlwinx.h @@ -0,0 +1,525 @@ +// Windows Template Library - WTL version 8.1
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//
+// This file is a part of the Windows Template Library.
+// The use and distribution terms for this software are covered by the
+// Common Public License 1.0 (http://opensource.org/licenses/cpl1.0.php)
+// which can be found in the file CPL.TXT at the root of this distribution.
+// By using this software in any fashion, you are agreeing to be bound by
+// the terms of this license. You must not remove this notice, or
+// any other, from this software.
+
+#ifndef __ATLWINX_H__
+#define __ATLWINX_H__
+
+#pragma once
+
+#ifndef __ATLAPP_H__
+ #error atlwinx.h requires atlapp.h to be included first
+#endif
+
+#if (_ATL_VER >= 0x0700)
+ #include <atlwin.h>
+#endif // (_ATL_VER >= 0x0700)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Classes in this file:
+//
+// _U_RECT
+// _U_MENUorID
+// _U_STRINGorID
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Command Chaining Macros
+
+#define CHAIN_COMMANDS(theChainClass) \
+ if(uMsg == WM_COMMAND) \
+ CHAIN_MSG_MAP(theChainClass)
+
+#define CHAIN_COMMANDS_ALT(theChainClass, msgMapID) \
+ if(uMsg == WM_COMMAND) \
+ CHAIN_MSG_MAP_ALT(theChainClass, msgMapID)
+
+#define CHAIN_COMMANDS_MEMBER(theChainMember) \
+ if(uMsg == WM_COMMAND) \
+ CHAIN_MSG_MAP_MEMBER(theChainMember)
+
+#define CHAIN_COMMANDS_ALT_MEMBER(theChainMember, msgMapID) \
+ if(uMsg == WM_COMMAND) \
+ CHAIN_MSG_MAP_ALT_MEMBER(theChainMember, msgMapID)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Macros for parent message map to selectively reflect control messages
+
+// NOTE: ReflectNotifications is a member of ATL's CWindowImplRoot
+// (and overridden in 2 cases - CContainedWindowT and CAxHostWindow)
+// Since we can't modify ATL, we'll provide the needed additions
+// in a separate function (that is not a member of CWindowImplRoot)
+
+namespace WTL
+{
+
+inline LRESULT WtlReflectNotificationsFiltered(HWND hWndParent, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled,
+ UINT uMsgFilter = WM_NULL, UINT_PTR idFromFilter = 0, HWND hWndChildFilter = NULL)
+{
+ if((uMsgFilter != WM_NULL) && (uMsgFilter != uMsg))
+ {
+ // The notification message doesn't match the filter.
+ bHandled = FALSE;
+ return 1;
+ }
+
+ HWND hWndChild = NULL;
+ UINT_PTR idFrom = 0;
+
+ switch(uMsg)
+ {
+ case WM_COMMAND:
+ if(lParam != NULL) // not from a menu
+ {
+ hWndChild = (HWND)lParam;
+ idFrom = (UINT_PTR)LOWORD(wParam);
+ }
+ break;
+ case WM_NOTIFY:
+ hWndChild = ((LPNMHDR)lParam)->hwndFrom;
+ idFrom = ((LPNMHDR)lParam)->idFrom;
+ break;
+#ifndef _WIN32_WCE
+ case WM_PARENTNOTIFY:
+ switch(LOWORD(wParam))
+ {
+ case WM_CREATE:
+ case WM_DESTROY:
+ hWndChild = (HWND)lParam;
+ idFrom = (UINT_PTR)HIWORD(wParam);
+ break;
+ default:
+ hWndChild = ::GetDlgItem(hWndParent, HIWORD(wParam));
+ idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
+ break;
+ }
+ break;
+#endif // !_WIN32_WCE
+ case WM_DRAWITEM:
+ if(wParam) // not from a menu
+ {
+ hWndChild = ((LPDRAWITEMSTRUCT)lParam)->hwndItem;
+ idFrom = (UINT_PTR)wParam;
+ }
+ break;
+ case WM_MEASUREITEM:
+ if(wParam) // not from a menu
+ {
+ hWndChild = ::GetDlgItem(hWndParent, ((LPMEASUREITEMSTRUCT)lParam)->CtlID);
+ idFrom = (UINT_PTR)wParam;
+ }
+ break;
+ case WM_COMPAREITEM:
+ if(wParam) // not from a menu
+ {
+ hWndChild = ((LPCOMPAREITEMSTRUCT)lParam)->hwndItem;
+ idFrom = (UINT_PTR)wParam;
+ }
+ break;
+ case WM_DELETEITEM:
+ if(wParam) // not from a menu
+ {
+ hWndChild = ((LPDELETEITEMSTRUCT)lParam)->hwndItem;
+ idFrom = (UINT_PTR)wParam;
+ }
+ break;
+ case WM_VKEYTOITEM:
+ case WM_CHARTOITEM:
+ case WM_HSCROLL:
+ case WM_VSCROLL:
+ hWndChild = (HWND)lParam;
+ idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
+ break;
+ case WM_CTLCOLORBTN:
+ case WM_CTLCOLORDLG:
+ case WM_CTLCOLOREDIT:
+ case WM_CTLCOLORLISTBOX:
+ case WM_CTLCOLORMSGBOX:
+ case WM_CTLCOLORSCROLLBAR:
+ case WM_CTLCOLORSTATIC:
+ hWndChild = (HWND)lParam;
+ idFrom = (UINT_PTR)::GetDlgCtrlID(hWndChild);
+ break;
+ default:
+ break;
+ }
+
+ if((hWndChild == NULL) ||
+ ((hWndChildFilter != NULL) && (hWndChildFilter != hWndChild)))
+ {
+ // Either hWndChild isn't valid, or
+ // hWndChild doesn't match the filter.
+ bHandled = FALSE;
+ return 1;
+ }
+
+ if((idFromFilter != 0) && (idFromFilter != idFrom))
+ {
+ // The dialog control id doesn't match the filter.
+ bHandled = FALSE;
+ return 1;
+ }
+
+ ATLASSERT(::IsWindow(hWndChild));
+ LRESULT lResult = ::SendMessage(hWndChild, OCM__BASE + uMsg, wParam, lParam);
+ if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC))
+ {
+ // Try to prevent problems with WM_CTLCOLOR* messages when
+ // the message wasn't really handled
+ bHandled = FALSE;
+ }
+
+ return lResult;
+}
+
+}; // namespace WTL
+
+// Try to prevent problems with WM_CTLCOLOR* messages when
+// the message wasn't really handled
+#define REFLECT_NOTIFICATIONS_EX() \
+{ \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if((lResult == 0) && (uMsg >= WM_CTLCOLORMSGBOX) && (uMsg <= WM_CTLCOLORSTATIC)) \
+ bHandled = FALSE; \
+ if(bHandled) \
+ return TRUE; \
+}
+
+#define REFLECT_NOTIFICATIONS_MSG_FILTERED(uMsgFilter) \
+ { \
+ bHandled = TRUE; \
+ lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, NULL); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFICATIONS_ID_FILTERED(idFromFilter) \
+ { \
+ bHandled = TRUE; \
+ lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, idFromFilter, NULL); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFICATIONS_HWND_FILTERED(hWndChildFilter) \
+ { \
+ bHandled = TRUE; \
+ lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, WM_NULL, 0, hWndChildFilter); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFICATIONS_MSG_ID_FILTERED(uMsgFilter, idFromFilter) \
+ { \
+ bHandled = TRUE; \
+ lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, idFromFilter, NULL); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFICATIONS_MSG_HWND_FILTERED(uMsgFilter, hWndChildFilter) \
+ { \
+ bHandled = TRUE; \
+ lResult = WTL::WtlReflectNotificationsFiltered(m_hWnd, uMsg, wParam, lParam, bHandled, uMsgFilter, 0, hWndChildFilter); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_COMMAND(id, code) \
+ if(uMsg == WM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_COMMAND_ID(id) \
+ if(uMsg == WM_COMMAND && id == LOWORD(wParam)) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_COMMAND_CODE(code) \
+ if(uMsg == WM_COMMAND && code == HIWORD(wParam)) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_COMMAND_RANGE(idFirst, idLast) \
+ if(uMsg == WM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_COMMAND_RANGE_CODE(idFirst, idLast, code) \
+ if(uMsg == WM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFY(id, cd) \
+ if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFY_ID(id) \
+ if(uMsg == WM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFY_CODE(cd) \
+ if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFY_RANGE(idFirst, idLast) \
+ if(uMsg == WM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECT_NOTIFY_RANGE_CODE(idFirst, idLast, cd) \
+ if(uMsg == WM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
+ { \
+ bHandled = TRUE; \
+ lResult = ReflectNotifications(uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Reflected message handler macros for message maps (for ATL 3.0)
+
+#if (_ATL_VER < 0x0700)
+
+#define REFLECTED_COMMAND_HANDLER(id, code, func) \
+ if(uMsg == OCM_COMMAND && id == LOWORD(wParam) && code == HIWORD(wParam)) \
+ { \
+ bHandled = TRUE; \
+ lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_COMMAND_ID_HANDLER(id, func) \
+ if(uMsg == OCM_COMMAND && id == LOWORD(wParam)) \
+ { \
+ bHandled = TRUE; \
+ lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_COMMAND_CODE_HANDLER(code, func) \
+ if(uMsg == OCM_COMMAND && code == HIWORD(wParam)) \
+ { \
+ bHandled = TRUE; \
+ lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_COMMAND_RANGE_HANDLER(idFirst, idLast, func) \
+ if(uMsg == OCM_COMMAND && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
+ { \
+ bHandled = TRUE; \
+ lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_COMMAND_RANGE_CODE_HANDLER(idFirst, idLast, code, func) \
+ if(uMsg == OCM_COMMAND && code == HIWORD(wParam) && LOWORD(wParam) >= idFirst && LOWORD(wParam) <= idLast) \
+ { \
+ bHandled = TRUE; \
+ lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_NOTIFY_HANDLER(id, cd, func) \
+ if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom && cd == ((LPNMHDR)lParam)->code) \
+ { \
+ bHandled = TRUE; \
+ lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_NOTIFY_ID_HANDLER(id, func) \
+ if(uMsg == OCM_NOTIFY && id == ((LPNMHDR)lParam)->idFrom) \
+ { \
+ bHandled = TRUE; \
+ lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_NOTIFY_CODE_HANDLER(cd, func) \
+ if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code) \
+ { \
+ bHandled = TRUE; \
+ lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_NOTIFY_RANGE_HANDLER(idFirst, idLast, func) \
+ if(uMsg == OCM_NOTIFY && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
+ { \
+ bHandled = TRUE; \
+ lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#define REFLECTED_NOTIFY_RANGE_CODE_HANDLER(idFirst, idLast, cd, func) \
+ if(uMsg == OCM_NOTIFY && cd == ((LPNMHDR)lParam)->code && ((LPNMHDR)lParam)->idFrom >= idFirst && ((LPNMHDR)lParam)->idFrom <= idLast) \
+ { \
+ bHandled = TRUE; \
+ lResult = func((int)wParam, (LPNMHDR)lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+#endif // (_ATL_VER < 0x0700)
+
+
+///////////////////////////////////////////////////////////////////////////////
+// Dual argument helper classes (for ATL 3.0)
+
+#if (_ATL_VER < 0x0700)
+
+namespace ATL
+{
+
+class _U_RECT
+{
+public:
+ _U_RECT(LPRECT lpRect) : m_lpRect(lpRect)
+ { }
+ _U_RECT(RECT& rc) : m_lpRect(&rc)
+ { }
+ LPRECT m_lpRect;
+};
+
+class _U_MENUorID
+{
+public:
+ _U_MENUorID(HMENU hMenu) : m_hMenu(hMenu)
+ { }
+ _U_MENUorID(UINT nID) : m_hMenu((HMENU)LongToHandle(nID))
+ { }
+ HMENU m_hMenu;
+};
+
+class _U_STRINGorID
+{
+public:
+ _U_STRINGorID(LPCTSTR lpString) : m_lpstr(lpString)
+ { }
+ _U_STRINGorID(UINT nID) : m_lpstr(MAKEINTRESOURCE(nID))
+ { }
+ LPCTSTR m_lpstr;
+};
+
+}; // namespace ATL
+
+#endif // (_ATL_VER < 0x0700)
+
+
+namespace WTL
+{
+
+///////////////////////////////////////////////////////////////////////////////
+// Forward notifications support for message maps (for ATL 3.0)
+
+#if (_ATL_VER < 0x0700)
+
+// forward notifications support
+#define FORWARD_NOTIFICATIONS() \
+ { \
+ bHandled = TRUE; \
+ lResult = WTL::Atl3ForwardNotifications(m_hWnd, uMsg, wParam, lParam, bHandled); \
+ if(bHandled) \
+ return TRUE; \
+ }
+
+static LRESULT Atl3ForwardNotifications(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+ LRESULT lResult = 0;
+ switch(uMsg)
+ {
+ case WM_COMMAND:
+ case WM_NOTIFY:
+#ifndef _WIN32_WCE
+ case WM_PARENTNOTIFY:
+#endif // !_WIN32_WCE
+ case WM_DRAWITEM:
+ case WM_MEASUREITEM:
+ case WM_COMPAREITEM:
+ case WM_DELETEITEM:
+ case WM_VKEYTOITEM:
+ case WM_CHARTOITEM:
+ case WM_HSCROLL:
+ case WM_VSCROLL:
+ case WM_CTLCOLORBTN:
+ case WM_CTLCOLORDLG:
+ case WM_CTLCOLOREDIT:
+ case WM_CTLCOLORLISTBOX:
+ case WM_CTLCOLORMSGBOX:
+ case WM_CTLCOLORSCROLLBAR:
+ case WM_CTLCOLORSTATIC:
+ lResult = ::SendMessage(::GetParent(hWnd), uMsg, wParam, lParam);
+ break;
+ default:
+ bHandled = FALSE;
+ break;
+ }
+ return lResult;
+}
+
+#endif // (_ATL_VER < 0x0700)
+
+}; // namespace WTL
+
+#endif // __ATLWINX_H__
diff --git a/plugins/XSoundNotify/src/xsn_main.cpp b/plugins/XSoundNotify/src/xsn_main.cpp new file mode 100644 index 0000000000..5bd0c3b530 --- /dev/null +++ b/plugins/XSoundNotify/src/xsn_main.cpp @@ -0,0 +1,105 @@ +/*
+Miranda plugin template, originally by Richard Hughes
+http://miranda-icq.sourceforge.net/
+
+This file is placed in the public domain. Anybody is free to use or
+modify it as they wish with no restriction.
+There is no warranty.
+*/
+
+#include "Common.h"
+
+HINSTANCE hInst;
+int hLangpack;
+
+PLUGININFOEX pluginInfo = {
+ sizeof(PLUGININFOEX),
+ __PLUGIN_NAME,
+ PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
+ __DESCRIPTION,
+ __AUTHOR,
+ __AUTHOREMAIL,
+ __COPYRIGHT,
+ __AUTHORWEB,
+ UNICODE_AWARE,
+ // {08B86253-EC6E-4D09-B7A9-64ACDF0627B8}
+ {0x8b86253, 0xec6e, 0x4d09, {0xb7, 0xa9, 0x64, 0xac, 0xdf, 0x6, 0x27, 0xb8}}
+};
+
+extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ hInst = hinstDLL;
+ return TRUE;
+}
+
+static INT_PTR PluginMenuCommand(WPARAM wParam, LPARAM lParam)
+{
+ try
+ {
+ SoundNotifyDataStorage storage;
+ storage.init();
+ SettingsDialog dlg(storage);
+ if (dlg.DoModal() == IDOK)
+ storage.commit();
+ }
+ catch (...)
+ {
+ MessageBox(0, TEXT("Unknown error occured while configuring"), TEXT("XSoundNotify Error"), MB_OK | MB_ICONERROR);
+ }
+
+ return 0;
+}
+
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ return &pluginInfo;
+}
+
+INT processEvent(WPARAM wParam, LPARAM lParam)
+{
+ try
+ {
+ if (!isReceiveMessage(lParam))
+ return 0;
+
+ xsn_string sound = getContactSound((HANDLE)wParam);
+ if (!sound.empty())
+ PlaySound(sound.c_str(), nullptr, SND_ASYNC | SND_FILENAME);
+ }
+ catch (std::exception & )
+ {
+ // log
+ }
+ catch (...)
+ {
+ // log
+ }
+
+ return 0;
+}
+
+extern "C" int __declspec(dllexport) Load()
+{
+ mir_getLP(&pluginInfo);
+
+ CLISTMENUITEM mi;
+
+ CreateServiceFunction("XSoundNotify/MenuCommand", PluginMenuCommand);
+ ZeroMemory(&mi, sizeof(mi));
+ mi.cbSize = sizeof(mi);
+ mi.position = -0x7FFFFFFF;
+ mi.flags = 0;
+ mi.hIcon = LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
+ mi.pszName = LPGEN("&XSoundNotify Plugin");
+ mi.pszService = "XSoundNotify/MenuCommand";
+ Menu_AddMainMenuItem(&mi);
+ HookEvent(ME_DB_EVENT_ADDED, processEvent);
+
+ return 0;
+}
+
+extern "C" int __declspec(dllexport) Unload(void)
+{
+ return 0;
+}
+
diff --git a/plugins/!NotAdopted/XSoundNotify/xsn_types.cpp b/plugins/XSoundNotify/src/xsn_types.cpp index da0cc5b3f9..0c831ef4d6 100644 --- a/plugins/!NotAdopted/XSoundNotify/xsn_types.cpp +++ b/plugins/XSoundNotify/src/xsn_types.cpp @@ -1,4 +1,4 @@ -#include "xsn_types.h"
+#include "Common.h"
XSN_Variant::XSN_Variant()
{
diff --git a/plugins/!NotAdopted/XSoundNotify/xsn_types.h b/plugins/XSoundNotify/src/xsn_types.h index 43f4434fea..e6c7cdda49 100644 --- a/plugins/!NotAdopted/XSoundNotify/xsn_types.h +++ b/plugins/XSoundNotify/src/xsn_types.h @@ -1,11 +1,6 @@ #ifndef __XSN_TYPES
#define __XSN_TYPES
-#include <string>
-#include <windows.h>
-#include <newpluginapi.h>
-#include <m_database.h>
-
#ifndef UNICODE
typedef std::string xsn_string;
#else
diff --git a/plugins/!NotAdopted/XSoundNotify/xsn_utils.cpp b/plugins/XSoundNotify/src/xsn_utils.cpp index d597776e8d..1e0ad8c57d 100644 --- a/plugins/!NotAdopted/XSoundNotify/xsn_utils.cpp +++ b/plugins/XSoundNotify/src/xsn_utils.cpp @@ -1,6 +1,4 @@ -#include "xsn_utils.h"
-#include <m_protocols.h>
-#include <boost/lexical_cast.hpp>
+#include "Common.h"
void initModuleConvertTable(ModuleConvertTable & table)
{
diff --git a/plugins/!NotAdopted/XSoundNotify/xsn_utils.h b/plugins/XSoundNotify/src/xsn_utils.h index 66bdef2526..5c2a519c7c 100644 --- a/plugins/!NotAdopted/XSoundNotify/xsn_utils.h +++ b/plugins/XSoundNotify/src/xsn_utils.h @@ -1,9 +1,6 @@ #ifndef _XSN_UTILS_H
#define _XSN_UTILS_H
-#include "xsn_types.h"
-#include "SoundNotifyData.h"
-
void initModuleConvertTable(ModuleConvertTable & table);
bool isReceiveMessage(LPARAM event);
|