diff options
Diffstat (limited to 'widgetfactory.cpp')
| -rw-r--r-- | widgetfactory.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/widgetfactory.cpp b/widgetfactory.cpp new file mode 100644 index 0000000..478d57f --- /dev/null +++ b/widgetfactory.cpp @@ -0,0 +1,113 @@ +#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; + + BOOL (*pSetProcessDpiAware)(void); + pSetProcessDpiAware = (BOOL (*)(void))GetProcAddress(GetModuleHandle(L"user32.dll"), "SetProcessDPIAware"); + if (pSetProcessDpiAware) + pSetProcessDpiAware(); + + 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; + + ALFAPP app = ALF_CreateApplication(hInstance); + + ALF_RegisterWindowClass(app, &cparams); + + ALFWindowInstanceParams params; + ZeroMemory(¶ms, sizeof(params)); + params.windowStyle = WS_OVERLAPPEDWINDOW; + + HWND win = ALF_InstantiateWindow(app, TEXT("DummyClass"), ¶ms); + + 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_SetDefaultButton(win, ID_B1); + + //EnableWindow(ALF_WidgetHwndById(win, ID_LBL3), FALSE); + + ALF_ResizeWindow(win, 1, 1); + + ALF_ShowModal(win); + + DestroyWindow(win); + + return 0; +} |
