From 9279dd93c3997a51b227d3380b4da659fcbdff96 Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Wed, 9 Jan 2019 20:52:10 +0100 Subject: add spacer widget --- alf/alf.cpp | 2 ++ alf/alf.h | 4 ++++ alf/alfpriv.h | 4 ++++ alf/alfspacer.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 alf/alfspacer.cpp (limited to 'alf') diff --git a/alf/alf.cpp b/alf/alf.cpp index 64b4cc4..6f8d28a 100644 --- a/alf/alf.cpp +++ b/alf/alf.cpp @@ -343,6 +343,7 @@ ALF_CreateApplication(HINSTANCE hInstance) ALF_RegisterComboClass(app); ALF_RegisterPanelClass(app); + ALF_RegisterSpacerClass(app); return app; } @@ -352,6 +353,7 @@ ALF_TeardownApplication(ALFAPP app) { UnregisterClass(app->comboClass, app->hInstance); UnregisterClass(app->panelClass, app->hInstance); + UnregisterClass(app->spacerClass, app->hInstance); HeapFree(GetProcessHeap(), 0, app); } diff --git a/alf/alf.h b/alf/alf.h index 79883be..0c32a20 100644 --- a/alf/alf.h +++ b/alf/alf.h @@ -250,6 +250,10 @@ ALF_ComboBoxSetText(HWND combo, const TCHAR *text); HWND ALF_AddPanel(HWND parent, WORD id, UINT x, UINT y); +// spacer +HWND +ALF_AddSpacer(HWND parent, WORD id, UINT x, UINT y, UINT cptWidth, UINT cptHeight, DWORD layoutFlags); + #ifdef __cplusplus } // extern C #endif diff --git a/alf/alfpriv.h b/alf/alfpriv.h index ec7a447..775d421 100644 --- a/alf/alfpriv.h +++ b/alf/alfpriv.h @@ -32,6 +32,7 @@ struct ALFAppPriv { HINSTANCE hInstance; TCHAR *comboClass; TCHAR *panelClass; + TCHAR *spacerClass; }; int @@ -49,6 +50,9 @@ ALF_RegisterComboClass(ALFAPP app); void ALF_RegisterPanelClass(ALFAPP app); +void +ALF_RegisterSpacerClass(ALFAPP app); + void ALF_BuildRandomClassName(const TCHAR *prefix, TCHAR *buf, DWORD cchBuf); diff --git a/alf/alfspacer.cpp b/alf/alfspacer.cpp new file mode 100644 index 0000000..545dfbc --- /dev/null +++ b/alf/alfspacer.cpp @@ -0,0 +1,58 @@ +#include "alfpriv.h" + +void +ALF_RegisterSpacerClass(ALFAPP app) +{ + WNDCLASS cls; + ZeroMemory(&cls, sizeof(cls)); + + TCHAR classNameBuf[256]; + ALF_BuildRandomClassName(TEXT("ALFSpacer"), classNameBuf, 256); + + cls.hInstance = app->hInstance; + cls.hCursor = LoadCursor(NULL, (LPTSTR)IDC_ARROW); + if (LOBYTE(LOWORD(GetVersion())) >= 4) { + cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); + } else { + // NT 3.x has white dialog backgrounds + cls.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + } + cls.lpszClassName = classNameBuf; + cls.cbWndExtra = sizeof(void*); + cls.lpfnWndProc = DefWindowProc; + + ATOM classatom = RegisterClass(&cls); + if (!classatom) + MessageBox(NULL, TEXT("FATAL: Could not register spacer class"), NULL, MB_OK); + + app->spacerClass = MAKEINTATOM(classatom); +} + +HWND +ALF_AddSpacer(HWND parent, WORD id, UINT x, UINT y, UINT cptWidth, UINT cptHeight, DWORD layoutFlags) +{ + ALFAPP app = ALF_ApplicationFromWindow(parent); + + HWND hwndSpacer = CreateWindowEx(0, + app->spacerClass, + TEXT(""), + WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, + 0, 0, 0, 0, + parent, + (HMENU)(int)id, + (HINSTANCE)GetWindowLongPtr(parent, GWLP_HINSTANCE), + (void*)app); + + ALFWidgetLayoutParams p; + ZeroMemory(&p, sizeof(p)); + p.hwnd = hwndSpacer; + p.x = x; + p.y = y; + p.width = cptWidth; + p.height = cptHeight; + p.flags = layoutFlags; + + ALF_AddWidgetEx(parent, &p); + + return hwndSpacer; +} -- cgit v1.2.3