summaryrefslogtreecommitdiff
path: root/redo/comctl32_windows.c
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-07-17 20:05:47 -0400
committerPietro Gagliardi <[email protected]>2014-07-17 20:05:47 -0400
commit8fee588a1da781c8823dcb7d0538cf1ec7022b39 (patch)
tree8f526ea3715e4d73e16f00ca7e392b273ed2a455 /redo/comctl32_windows.c
parent0adac4d3ca1ec91e6364fe11276323803418c2ff (diff)
Migrated comctl32_windows.go to C.
Diffstat (limited to 'redo/comctl32_windows.c')
-rw-r--r--redo/comctl32_windows.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/redo/comctl32_windows.c b/redo/comctl32_windows.c
new file mode 100644
index 0000000..d621d2a
--- /dev/null
+++ b/redo/comctl32_windows.c
@@ -0,0 +1,63 @@
+/* 17 july 2014 */
+
+#include "winapi_windows.h"
+
+static ULONG_PTR comctlManifestCookie;
+static HMODULE comctl32;
+
+DWORD initCommonControls(LPCWSTR manifest, char **errmsg)
+{
+ ACTCTX actctx;
+ HANDLE ac;
+ INITCOMMONCONTROLSEX icc;
+ FARPROC f;
+ /* TODO does this take WINAPI? */
+ BOOL (*WINAPI ficc)(const LPINITCOMMONCONTROLSEX);
+
+ ZeroMemory(&actctx, sizeof (ACTCTX));
+ actctx.cbSize = sizeof (ACTCTX);
+ actctx.dwFlags = ACTCTX_FLAG_SET_PROCESS_DEFAULT;
+ actctx.lpSource = manifest;
+ ac = CreateActCtx(&actctx);
+ if (ac == INVALID_HANDLE_VALUE) {
+ *errmsg = "error creating activation context for synthesized manifest file";
+ return GetLastError();
+ }
+ if (ActivateActCtx(ac, &comctlManifestCookie) == FALSE) {
+ *errmsg = "error activating activation context for synthesized manifest file";
+ return GetLastError();
+ }
+
+ ZeroMemory(&icc, sizeof (INITCOMMONCONTROLSEX));
+ icc.dwSize = sizeof (INITCOMMONCONTROLSEX);
+ icc.dwICC = ICC_PROGRESS_CLASS;
+
+ comctl32 = LoadLibraryW(L"comctl32.dll");
+ if (comctl32 == NULL) {
+ *errmsg = "error loading comctl32.dll";
+ return GetLastError();
+ }
+
+ /* GetProcAddress() only takes a multibyte string */
+#define LOAD(fn) f = GetModuleHandle(comctl32, fn); \
+ if (f == NULL) { \
+ *errmsg = "error loading " fn "()"; \
+ return GetLastError(); \
+ }
+
+ LOAD("InitCommonControlsEx");
+ ficc = (BOOL (*WINAPI)(const LPINITCOMMONCONTROLSEX)) f;
+ LOAD("SetWindowSubclass");
+ fv_SetWindowSubclass = (BOOL (*WINAPI)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR)) f;
+ LOAD("RemoveWindowSubclass");
+ fv_RemoveWindowSubclass = (BOOL (*WINAPI)(HWND, SUBCLASSPROC, UINT_PTR)) f;
+ LOAD("DefSubclassProc");
+ fv_DefSubclassProc = (LRESULT (*WINAPI)(HWND, UINT, WPARAM, LPARAM)) f;
+
+ if ((*ficc)(&icc) == FALSE) {
+ *errmsg = "error initializing Common Controls (comctl32.dll)";
+ return GetLastError();
+ }
+
+ return 0;
+}