summaryrefslogtreecommitdiff
path: root/alf/alfspacer.cpp
blob: 545dfbc90c6f59de2494c1e96ab0c5049b7945e4 (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
#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;
}