Registriert seit: 9. Okt 2004
15 Beiträge
|
Theme Func von C nach Delphi
12. Dez 2004, 13:25
Hallo,
ich habe da etwas brauchbares für mich gefunden. Leider ist der Source in C.
(war als Delphi Code nicht zu finden, außerdem ist die UxTheme.pas von Delphi
bei weitem nicht mit der kompletten API der DLL ausgestattet).
Habe schon versucht dieses Wirrwar nach Delphi zu coden, bin aber kläglich
gescheitert. Jetzt meine Bitte, Hoffnung das es irgend jemanden (beider Sprachen
mächtig) gibt der das hin bekommt.
vielen Dank andreas
Delphi-Quellcode:
+ //#include <stdlib.h>
+#include <stdio.h>
+ //#include <string.h>
+#include <windows.h>
+#include <uxtheme.h>
+
+typedef void* HTHEMEFILE;
+
+HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
+ DWORD dwColorNum, LPWSTR pszColorName);
+HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
+ DWORD dwSizeNum, LPWSTR pszSizeName);
+HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
+ LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
+ DWORD unknown);
+HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
+ DWORD dwColorNameLen, LPWSTR pszSizeName,
+ DWORD dwSizeNameLen);
+HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile);
+HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd);
+
+typedef HRESULT ( WINAPI*EnumTheme)(LPWSTR,LPWSTR,DWORD,LPWSTR);
+typedef int (*operation)(int,char*[]);
+
+typedef struct _CMDOPTS {
+ char *option;
+ int params;
+ operation oper;
+} CMDOPTS;
+
+int install(int argc, char *argv[]);
+int uninstall(int argc, char *argv[]);
+int info(int argc, char *argv[]);
+int help(int argc, char *argv[]);
+
+CMDOPTS opts[] = {
+ {"install", 1, install},
+ {"uninstall", 0, uninstall},
+ {"info", 0, info},
+ {"help", 0, help},
+};
+
+int install(int argc, char *argv[])
+{
+ HRESULT hr;
+ int ret = 0;
+ WCHAR szFile[MAX_PATH];
+ WCHAR szColor[60];
+ WCHAR szSize[60];
+ HTHEMEFILE hThemeFile;
+ char b[] = "\0";
+
+ MultiByteToWideChar(CP_ACP, 0, argv[2], -1, szFile, MAX_PATH);
+ if(argc >= 5) {
+ MultiByteToWideChar(CP_ACP, 0, argv[3], -1, szColor, sizeof(szColor)/sizeof(szColor[0]));
+ MultiByteToWideChar(CP_ACP, 0, argv[4], -1, szSize, sizeof(szSize)/sizeof(szSize[0]));
+ hr = OpenThemeFile(szFile, szColor, szSize, &hThemeFile, 0);
+ }
+ else {
+ hr = OpenThemeFile(szFile, NULL, NULL, &hThemeFile, 0);
+ }
+ if(FAILED(hr)) {
+ fprintf(stderr, "Failed to load theme %s: 0x%08lx\n", argv[2], hr);
+ return 2;
+ }
+ hr = ApplyTheme(hThemeFile, b, NULL);
+ if(FAILED(hr)) {
+ fprintf(stderr, "Failed to apply theme %s: 0x%08lx\n", argv[2], hr);
+ ret = 2;
+ }
+ CloseThemeFile(hThemeFile);
+ return ret;
+}
+
+int uninstall(int argc, char *argv[])
+{
+ HRESULT hr;
+ char b[] = "\0";
+ hr = ApplyTheme(NULL, b, NULL);
+ if(FAILED(hr)) {
+ fprintf(stderr, "Failed to uninstall theme: 0x%08lx\n", hr);
+ return 2;
+ }
+ return 0;
+}
+
+int enumValues(char *theme, char *type, EnumTheme enumtheme)
+{
+ HRESULT hr;
+ WCHAR szFile[MAX_PATH];
+ WCHAR szNameW[60];
+ char szNameA[60];
+ int index = 0;
+ MultiByteToWideChar(CP_ACP, 0, theme, -1, szFile, MAX_PATH);
+ while(SUCCEEDED(hr = enumtheme(szFile, NULL, index++, szNameW))) {
+ WideCharToMultiByte(CP_ACP, 0, szNameW, -1, szNameA, sizeof(szNameA)/sizeof(szNameA[0]), 0, 0);
+ printf("\t%s\n", szNameA);
+ }
+ if(hr == E_PROP_ID_UNSUPPORTED)
+ return 0;
+ fprintf(stderr, "Error enumerating %s: 0x%08lx\n", type, hr);
+ return 2;
+}
+
+int info(int argc, char *argv[])
+{
+ HRESULT hr;
+ WCHAR szThemeFileNameW[MAX_PATH];
+ char szThemeFileNameA[MAX_PATH];
+ WCHAR szColorNameW[60];
+ char szColorNameA[60];
+ WCHAR szSizeNameW[60];
+ char szSizeNameA[60];
+ char *pre = "";
+
+ if(argc >= 3) {
+ lstrcpy(szThemeFileNameA, argv[2]);
+ MultiByteToWideChar(CP_ACP, 0, szThemeFileNameA, -1, szThemeFileNameW, MAX_PATH);
+ hr = GetThemeDefaults(szThemeFileNameW,
+ szColorNameW, sizeof(szColorNameW)/sizeof(szColorNameW[0]),
+ szSizeNameW, sizeof(szSizeNameW)/sizeof(szSizeNameW[0]));
+ if(FAILED(hr)) {
+ fprintf(stderr, "Failed to get info on theme %s: 0x%08lx\n", szThemeFileNameA, hr);
+ return 2;
+ }
+ pre = "Default ";
+ }
+ else {
+ if(!IsThemeActive()) {
+ printf("Themeing is not enabled\n");
+ return 0;
+ }
+ hr = GetCurrentThemeName(szThemeFileNameW, sizeof(szThemeFileNameW)/sizeof(szThemeFileNameW[0]),
+ szColorNameW, sizeof(szColorNameW)/sizeof(szColorNameW[0]),
+ szSizeNameW, sizeof(szSizeNameW)/sizeof(szSizeNameW[0]));
+ if(FAILED(hr)) {
+ fprintf(stderr, "Failed to get info on current theme: 0x%08lx\n", hr);
+ return 2;
+ }
+ WideCharToMultiByte(CP_ACP, 0, szThemeFileNameW, -1, szThemeFileNameA, sizeof(szThemeFileNameA)/sizeof(szThemeFileNameA[0]), 0, 0);
+ printf("Installed theme:\n");
+ }
+ WideCharToMultiByte(CP_ACP, 0, szColorNameW, -1, szColorNameA, sizeof(szColorNameA)/sizeof(szColorNameA[0]), 0, 0);
+ WideCharToMultiByte(CP_ACP, 0, szSizeNameW, -1, szSizeNameA, sizeof(szSizeNameA)/sizeof(szSizeNameA[0]), 0, 0);
+
+ printf("File: %s\n", szThemeFileNameA);
+ printf("%sColor: %s\n", pre, szColorNameA);
+ printf("%sSize: %s\n", pre, szSizeNameA);
+
+ if(argc >= 3) {
+ printf("Colors:\n");
+ enumValues(szThemeFileNameA, "colors", EnumThemeColors);
+ printf("Sizes:\n");
+ enumValues(argv[2], "sizes", EnumThemeSizes);
+ }
+ return 0;
+}
+
+int help(int argc, char *argv[]) {
+ printf("winetheme install [theme] [color] [size]\n");
+ printf("\tInstall theme using color and size, if color and size\n");
+ printf("\tare omited, the default for the theme is used\n");
+ printf("winetheme uninstall\n");
+ printf("\tRemove installed theme\n");
+ printf("winetheme info [theme]\n");
+ printf("\tInformation about specified theme or, if omitted, installed theme\n");
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ int i;
+ operation oper = help;
+
+ if(argc > 1) {
+ for(i=0; i<sizeof(opts)/sizeof(opts[0]); i++) {
+ if(argc >= opts[i].params+2 && !strcmp(argv[1], opts[i].option)) {
+ oper = opts[i].oper;
+ break;
+ }
+ }
+ }
+ return oper(argc, argv);
+}
|