Theme dumper almost finished, but not working correctly

svn path=/trunk/; revision=6676
This commit is contained in:
KJK::Hyperion 2003-11-17 02:36:36 +00:00
parent dfabfaeccf
commit 38b48068ac
2 changed files with 297 additions and 129 deletions

View file

@ -5,7 +5,7 @@
<VERSION value="BCB.06.00"/> <VERSION value="BCB.06.00"/>
<PROJECT value="themedump.exe"/> <PROJECT value="themedump.exe"/>
<OBJFILES value="themedump.obj"/> <OBJFILES value="themedump.obj"/>
<RESFILES value=""/> <RESFILES value="themedump.res"/>
<IDLFILES value=""/> <IDLFILES value=""/>
<IDLGENFILES value=""/> <IDLGENFILES value=""/>
<DEFFILE value=""/> <DEFFILE value=""/>
@ -25,7 +25,7 @@
<RELEASELIBPATH value="$(BCB)\lib\release"/> <RELEASELIBPATH value="$(BCB)\lib\release"/>
<LINKER value="ilink32"/> <LINKER value="ilink32"/>
<USERDEFINES value="_DEBUG"/> <USERDEFINES value="_DEBUG"/>
<SYSDEFINES value="NO_STRICT;_NO_VCL;_RTLDLL;USEPACKAGES"/> <SYSDEFINES value="NO_STRICT;_NO_VCL;USEPACKAGES"/>
<MAINSOURCE value="themedump.cpp"/> <MAINSOURCE value="themedump.cpp"/>
<INCLUDEPATH value=".;$(BCB)\include;$(BCB)\include\vcl"/> <INCLUDEPATH value=".;$(BCB)\include;$(BCB)\include\vcl"/>
<LIBPATH value=".;$(BCB)\lib\obj;$(BCB)\lib"/> <LIBPATH value=".;$(BCB)\lib\obj;$(BCB)\lib"/>
@ -45,11 +45,12 @@
<LINKER> <LINKER>
<ALLOBJ value="c0x32.obj $(PACKAGES) $(OBJFILES)"/> <ALLOBJ value="c0x32.obj $(PACKAGES) $(OBJFILES)"/>
<ALLRES value="$(RESFILES)"/> <ALLRES value="$(RESFILES)"/>
<ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cw32mti.lib"/> <ALLLIB value="$(LIBFILES) $(LIBRARIES) uxtheme.lib import32.lib cw32mt.lib"/>
<OTHERFILES value=""/> <OTHERFILES value=""/>
</LINKER> </LINKER>
<FILELIST> <FILELIST>
<FILE FILENAME="themedump.cpp" FORMNAME="" UNITNAME="themedump" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/> <FILE FILENAME="themedump.cpp" FORMNAME="" UNITNAME="themedump" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="themedump.rc" FORMNAME="" UNITNAME="themedump.rc" CONTAINERID="RCCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
</FILELIST> </FILELIST>
<BUILDTOOLS> <BUILDTOOLS>
</BUILDTOOLS> </BUILDTOOLS>

View file

@ -10,8 +10,10 @@
#include <map> #include <map>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define UNICODE
#include <windows.h> #include <windows.h>
#include <commctrl.h>
#include <uxtheme.h>
#include <tmschema.h> #include <tmschema.h>
#ifdef __BORLANDC__ #ifdef __BORLANDC__
@ -38,7 +40,10 @@ namespace tmdump
}; };
static tm_enums_t tm_enums; static tm_enums_t tm_enums;
static std::list<tm_property_t> tm_properties;
typedef std::list<tm_property_t> tm_properties_t;
static tm_properties_t tm_properties;
typedef std::map<int, std::wstring> tm_states_t; typedef std::map<int, std::wstring> tm_states_t;
typedef std::map<std::wstring, tm_states_t> tm_state_enums_t; typedef std::map<std::wstring, tm_states_t> tm_state_enums_t;
@ -286,52 +291,6 @@ namespace tmdump
LPWSTR states; LPWSTR states;
}; };
class state_link: public std::unary_function<struct state_mapping_t, void>
{
private:
tm_classes_t::iterator m_class;
public:
void operator()(const struct state_mapping_t& mapping_)
{
// switch to a new class
if(mapping_.classname)
m_class = tm_classes.find(std::wstring(mapping_.classname));
// no mapping, or class not found
if(mapping_.states == NULL || m_class == tm_classes.end()) return;
tm_state_enums_t::iterator states =
tm_state_enums.find(std::wstring(mapping_.states));
// unknown set of states
if(states == tm_state_enums.end()) return;
tm_parts_t::iterator part = m_class->second.find(mapping_.partid);
// unknown part
if(part == m_class->second.end()) return;
// success
part->second.states = states;
}
};
}
int main(int argc, char * argv[])
{
try
{
struct TMSCHEMAINFO const & schema = *GetSchemaInfo();
// build the tables of properties, classes, parts and states
std::for_each
(
schema.pPropTable,
schema.pPropTable + schema.iPropCount,
tmdump::schema_scan()
);
static const tmdump::state_mapping_t state_map[] = static const tmdump::state_mapping_t state_map[] =
{ {
{ L"BUTTON", 0, NULL }, { L"BUTTON", 0, NULL },
@ -454,13 +413,221 @@ int main(int argc, char * argv[])
{ NULL, WP_VERTTHUMB, L"HORZTHUMB" }, { NULL, WP_VERTTHUMB, L"HORZTHUMB" },
}; };
class state_link: public std::unary_function<struct state_mapping_t, void>
{
private:
tm_classes_t::iterator m_class;
public:
void operator()(const struct state_mapping_t& mapping_)
{
// switch to a new class
if(mapping_.classname)
m_class = tm_classes.find(std::wstring(mapping_.classname));
// no mapping, or class not found
if(mapping_.states == NULL || m_class == tm_classes.end()) return;
tm_state_enums_t::iterator states =
tm_state_enums.find(std::wstring(mapping_.states));
// unknown set of states
if(states == tm_state_enums.end()) return;
tm_parts_t::iterator part = m_class->second.find(mapping_.partid);
// unknown part
if(part == m_class->second.end()) return;
// success
part->second.states = states;
}
};
}
int main(int argc, char * argv[])
{
try
{
struct TMSCHEMAINFO const & schema = *GetSchemaInfo();
// build the tables of properties, classes, parts and states
std::for_each std::for_each
( (
state_map, schema.pPropTable,
state_map + sizeof(state_map) / sizeof(state_map[0]), schema.pPropTable + schema.iPropCount,
tmdump::schema_scan()
);
// link parts to states
std::for_each
(
tmdump::state_map,
tmdump::state_map + sizeof(tmdump::state_map) / sizeof(tmdump::state_map[0]),
tmdump::state_link() tmdump::state_link()
); );
::InitCommonControls();
::SetThemeAppProperties(STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS);
// dump the current values of all properties
for
(
tmdump::tm_classes_t::iterator p = tmdump::tm_classes.begin();
p != tmdump::tm_classes.end();
++ p
)
{
const std::wstring& class_name = p->first;
// open the theme data for the current class
class htheme_t
{
public:
HTHEME m_handle;
htheme_t(HTHEME handle_): m_handle(handle_) { }
~htheme_t() { ::CloseThemeData(m_handle); }
operator HTHEME() { return m_handle; }
}
data = ::OpenThemeData(NULL, class_name.c_str());
// failure
if(data == NULL)
{
std::fwprintf
(
stderr,
L"OpenThemeData(\"%s\") failed, error %d\n",
class_name.c_str(),
GetLastError()
);
continue;
}
// class name
std::fwprintf(stdout, L"%s\n", p->first.c_str());
// dump system properties
for
(
tmdump::tm_properties_t::iterator p = tmdump::tm_properties.begin();
p != tmdump::tm_properties.end();
++ p
)
{
switch(p->type)
{
case TMT_POSITION:
case TMT_MARGINS:
case TMT_RECT:
case TMT_INTLIST:
continue;
}
// property name
std::fwprintf(stdout, L"\t%s = ", p->name.c_str());
HRESULT hres;
switch(p->type)
{
// string
case TMT_STRING:
case TMT_FILENAME: // FIXME
{
WCHAR buffer[256];
if(FAILED(hres = GetThemeSysString(data, p->id, buffer, 256))) break;
std::fwprintf(stdout, L"string: \"%s\"", buffer);
break;
}
// integer
case TMT_INT:
{
int val;
if(FAILED(hres = GetThemeSysInt(data, p->id, &val))) break;
std::fwprintf(stdout, L"int: %d", val);
break;
}
// boolean
case TMT_BOOL:
{
SetLastError(0);
BOOL val = GetThemeSysBool(data, p->id);
if(FAILED(hres = GetLastError())) break;
std::fwprintf(stdout, L"bool: %s", val ? L"true" : L"false");
break;
}
// color
case TMT_COLOR:
{
SetLastError(0);
COLORREF val = GetThemeSysColor(data, p->id);
if(FAILED(hres = GetLastError())) break;
std::fwprintf
(
stdout,
L"rgb: %d, %d, %d",
GetRValue(val),
GetGValue(val),
GetBValue(val)
);
break;
}
// size
case TMT_SIZE:
{
SetLastError(0);
int val = GetThemeSysSize(data, p->id);
if(FAILED(hres = GetLastError())) break;
std::fwprintf(stdout, L"size: %d", val);
break;
}
// font
case TMT_FONT:
{
LOGFONTW val;
if(FAILED(hres = GetThemeSysFont(data, p->id, &val))) break;
std::fwprintf(stdout, L"font: %s", val.lfFaceName);
break;
}
// enumerated integer
case TMT_ENUM:
{
int val;
if(FAILED(hres = GetThemeSysInt(data, p->id, &val))) break;
std::fwprintf(stdout, L"enum(%s): ", p->enum_type->first.c_str());
tmdump::tm_enum_t::iterator enumval = p->enum_type->second.find(val);
if(enumval == p->enum_type->second.end())
std::fwprintf(stdout, L"<%d>", val);
else
std::fwprintf(stdout, L"%s", enumval->second.c_str());
break;
}
}
if(FAILED(hres)) std::fwprintf(stdout, L"<error %08X>", hres);
std::fputwc(L'\n', stdout);
}
}
} }
catch(std::exception e) catch(std::exception e)
{ {