summaryrefslogtreecommitdiff
path: root/widgetfactory.c
blob: b5b914210f900ed604f5e6280c8bebf78b09e093 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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;
}