summaryrefslogtreecommitdiff
path: root/widgetfactory.c
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2018-12-26 11:47:20 +0100
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2018-12-26 11:47:20 +0100
commit061759e716ba8326efaa7f1328991ddd91085ad6 (patch)
tree8ff7c829af00ea7d9c9a4545392610af1ca2f1de /widgetfactory.c
initial commit
Diffstat (limited to 'widgetfactory.c')
-rw-r--r--widgetfactory.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/widgetfactory.c b/widgetfactory.c
new file mode 100644
index 0000000..b5b9142
--- /dev/null
+++ b/widgetfactory.c
@@ -0,0 +1,103 @@
+#include "alf/alf.h"
+
+enum {
+ ID_LBLHELLO,
+ ID_LBL2,
+ ID_LBL3,
+ ID_ED1,
+ ID_B1,
+ ID_B2,
+ ID__MAX
+};
+
+static HBRUSH red;
+static HBRUSH green;
+static HBRUSH blue;
+static HBRUSH white;
+
+LRESULT
+handleMessage(void *closure, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+ (void)closure;
+
+ if (msg == WM_CTLCOLORSTATIC) {
+ DWORD id = GetDlgCtrlID((HWND)lparam);
+ HDC hdcStatic = (HDC)wparam;
+ if (id == ID_LBLHELLO) {
+ SetTextColor(hdcStatic, RGB(0,0,0));
+ SetBkColor(hdcStatic, RGB(255,0,0));
+ return (LRESULT)red;
+ } else if (id == ID_LBL2) {
+ SetTextColor(hdcStatic, RGB(0,0,0));
+ SetBkColor(hdcStatic, RGB(0,255,0));
+ return (LRESULT)green;
+ } else if (id == ID_LBL3) {
+ SetTextColor(hdcStatic, RGB(255,255,255));
+ SetBkColor(hdcStatic, RGB(0,0,255));
+ return (LRESULT)blue;
+ } else {
+ SetTextColor(hdcStatic, RGB(0,0,0));
+ SetBkColor(hdcStatic, RGB(255,255,255));
+ return (LRESULT)white;
+ }
+ }
+
+ return ALF_DefWindowProc(hwnd, msg, wparam, lparam);
+}
+
+int CALLBACK
+wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
+{
+ (void)hPrevInstance;
+ (void)lpCmdLine;
+ (void)nCmdShow;
+
+ red = CreateSolidBrush(RGB(255,0,0));
+ green = CreateSolidBrush(RGB(0,255,0));
+ blue = CreateSolidBrush(RGB(0,0,255));
+ white = CreateSolidBrush(RGB(255,255,255));
+
+ ALFWindowClassParams cparams;
+ ZeroMemory(&cparams, sizeof(cparams));
+
+ cparams.className = TEXT("DummyClass");
+ cparams.vtbl.message = handleMessage;
+
+ ALF_RegisterWindowClass(hInstance, &cparams);
+
+ ALFWindowInstanceParams params;
+ ZeroMemory(&params, sizeof(params));
+ params.windowStyle = WS_OVERLAPPEDWINDOW;
+
+ HWND win = ALF_InstantiateWindow(hInstance, TEXT("DummyClass"), &params);
+
+ ALF_AddLabel(win, ID_LBL2, 1, 0, L"Hello, 2!\nblub");
+
+ HWND hwndLabel = CreateWindow(
+ L"STATIC",
+ L"Hello World!",
+ WS_CHILD | WS_VISIBLE | SS_LEFT,
+ 0, 0, 50, 25,
+ win,
+ (HMENU)ID_LBLHELLO,
+ hInstance,
+ NULL);
+ ALF_AddWidget(win, 0, 0, hwndLabel, 5000, 1000, ALF_MESSAGEFONT);
+
+ ALF_AddLabel(win, ID_LBL3, 0, 1, L"Good Morning my &Angel!");
+
+ ALF_AddEdit(win, ID_ED1, 1, 1, L"Happy Birthday!");
+
+ ALF_AddButton(win, ID_B1, 2, 1, L"&Go!");
+ ALF_AddButton(win, ID_B2, 0, 2, L"Oh m&y god,\r\nwho the hell cares?");
+
+ ALF_RecalculateLayout(win);
+
+ ALF_ResizeWindow(win, 1, 1);
+
+ ALF_ShowModal(win);
+
+ DestroyWindow(win);
+
+ return 0;
+}