#pragma once #define WIN32_LEAN_AND_MEAN #include #ifdef __cplusplus extern "C" { #endif typedef struct { int dpi; LOGFONT lfMessageFont; HFONT hMessageFont; } ALFWindowFonts; typedef struct { void (*create)(void * /*closure*/, HWND /*window*/); void (*destroy)(void * /*closure*/, HWND /*window*/); BOOL (*close)(void * /*closure*/, HWND /*window*/); void (*postdestroy)(void * /*closure*/); void (*applyfonts)(void * /*closure*/, HWND /*window*/, const ALFWindowFonts *fonts); LRESULT (*message)(void * /*closure*/, HWND, UINT, WPARAM, LPARAM); LRESULT (*command)(void * /*closure*/, HWND /*window*/, WORD /*notificationcode*/, WORD /*sourceid*/, HWND /*control*/); LRESULT (*notify)(void * /*closure*/, HWND /*window*/, WPARAM /*sourceid*/, NMHDR *); } ALFWindowVTable; // layout flags #define ALF_QUERYSIZE 0x01 #define ALF_APPLYSIZE 0x02 #define ALF_HEXPAND 0x04 #define ALF_VEXPAND 0x08 #define ALF_MESSAGEFONT 0x10 #define ALF_STATUSFONT 0x20 #define ALF_ICONTITLEFONT 0x40 // special value, means "send ALF_WM_APPLYFONTS message with full fonts struct" #define ALF_ALLFONTS (ALF_MESSAGEFONT | ALF_STATUSFONT | ALF_ICONTITLEFONT) // messages #define ALF_WM__BASE 0x2800 #define ALF_WM_QUERYSIZE (ALF_WM__BASE + 1) #define ALF_WM_APPLYLAYOUT (ALF_WM__BASE + 2) #define ALF_WM_UPDATEFONTS (ALF_WM__BASE + 3) #define ALF_WM_ADDWIDGET (ALF_WM__BASE + 4) #define ALF_WM_WIDGETBYID (ALF_WM__BASE + 5) #define ALF_WM_REMOVEWIDGET (ALF_WM__BASE + 6) #define ALF_WM_SETMODALRESULT (ALF_WM__BASE + 7) #define ALF_WM_GETMODALRESULT (ALF_WM__BASE + 8) #define ALF_WM_CENTIPOINTTOPX (ALF_WM__BASE + 9) #define ALF_WM_SETFOCUS (ALF_WM__BASE + 10) #define ALF_WM_GETAPPLICATION (ALF_WM__BASE + 11) #define ALF_WM_APPLYSIZE (ALF_WM__BASE + 12) #define ALF_WM_GETLAYOUTPARAMS (ALF_WM__BASE + 13) #define ALF_WM_SETLAYOUTPARAMS (ALF_WM__BASE + 14) #define ALF_WM_GETWIDGETATPOS (ALF_WM__BASE + 15) #define ALF_WM_APPLYFONTS (ALF_WM__BASE + 16) typedef struct { const TCHAR *className; UINT classStyle; ALFWindowVTable vtbl; } ALFWindowClassParams; typedef struct { HWND hwnd; UINT x; UINT y; UINT width; UINT height; DWORD flags; UINT margins[4]; } ALFWidgetLayoutParams; typedef struct ALFAppPriv *ALFAPP; typedef enum { ALF_DPI_AWARENESS_UNAWARE, ALF_DPI_AWARENESS_SYSTEM_AWARE, ALF_DPI_AWARENESS_PER_MONITOR_AWARE_V2 } ALFDpiAwareness; void ALF_SetDpiAwareness(ALFDpiAwareness awareness); ALFAPP ALF_CreateApplication(HINSTANCE hInstance); void ALF_TeardownApplication(ALFAPP app); LPTSTR ALF_RegisterWindowClass(ALFAPP app, const ALFWindowClassParams *params); void ALF_UnregisterWindowClass(ALFAPP app, LPCTSTR className); HWND ALF_InstantiateWindow(ALFAPP app, LPCTSTR className, HWND hwndParent, void *closure); void ALF_DestroyWindow(HWND win); ALFAPP ALF_ApplicationFromWindow(HWND hwnd); int ALF_CentipointsToPixels(HWND win, int cptValue); LRESULT ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); HWND ALF_AddLabel(HWND win, WORD id, UINT x, UINT y, const TCHAR *text); HWND ALF_AddEdit(HWND win, WORD id, UINT x, UINT y, const TCHAR *text); HWND ALF_AddButton(HWND win, WORD id, UINT x, UINT y, const TCHAR *text); void ALF_SetDefaultButton(HWND win, WORD id); void ALF_DestroyWidget(HWND win, WORD id); void ALF_AddWidget(HWND win, UINT x, UINT y, HWND widget, UINT cptWidth, UINT cptHeight, DWORD flags); void ALF_AddWidgetEx(HWND win, const ALFWidgetLayoutParams *params); HWND ALF_WidgetHwndById(HWND win, WORD id); void ALF_RecalculateLayout(HWND win); // Recalculates the window's DPI and all fonts and applies them to child widgets. // ALF does this automatically on a DPI or settings change so you shouldn't have // to call ALF_UpdateFonts(). If you have added new widgets and want to set their // fonts, call ALF_ApplyFonts() instead. // // Since widget sizes depend on the assigned font, you should probably // call ALF_RecalculateLayout() afterwards. void ALF_UpdateFonts(HWND win); // Applies window fonts to all children (depending on their layout flags). // also calls the applyfonts() virtual function. // // Call this after you have added new child widgets. // Since widget sizes depend on the assigned font, you should probably // call ALF_RecalculateLayout() afterwards. void ALF_ApplyFonts(HWND win); void ALF_ResizeWindow(HWND win, int cptWidth, int cptHeight); void ALF_ResizeWindowPx(HWND win, int pxWidth, int pxHeight); int ALF_ShowModal(HWND win); void ALF_SetModalResult(HWND win, int result); int ALF_GetModalResult(HWND win); void ALF_SetText(HWND hwnd, const TCHAR *text); void ALF_SetWidgetText(HWND parent, WORD id, const TCHAR *text); TCHAR * // free with HeapFree ALF_Text(HWND hwnd); TCHAR * // free with HeapFree ALF_WidgetText(HWND parent, WORD id); DWORD ALF_WidgetLayoutFlags(HWND parent, HWND widget); BOOL ALF_SetWidgetLayoutFlags(HWND parent, HWND widget, DWORD flags); static inline void ALF_AddWidgetLayoutFlag(HWND parent, HWND widget, DWORD flag) { ALF_SetWidgetLayoutFlags(parent, widget, ALF_WidgetLayoutFlags(parent, widget) | flag); } static inline void ALF_RemoveWidgetLayoutFlag(HWND parent, HWND widget, DWORD flag) { ALF_SetWidgetLayoutFlags(parent, widget, ALF_WidgetLayoutFlags(parent, widget) & ~flag); } BOOL ALF_WidgetLayoutPosition(HWND parent, HWND widget, UINT *pX, UINT *pY); BOOL ALF_SetWidgetLayoutPosition(HWND parent, HWND widget, UINT x, UINT y); BOOL ALF_WidgetLayoutSize(HWND parent, HWND widget, UINT *pCptWidth, UINT *pCptHeight); BOOL ALF_SetWidgetLayoutSize(HWND parent, HWND widget, UINT cptWidth, UINT cptHeight); HWND ALF_WidgetAtLayoutPosition(HWND parent, UINT x, UINT y); // combo box HWND ALF_AddEditableComboBox(HWND win, WORD id, UINT x, UINT y, const TCHAR *defaultText); HWND ALF_AddSelectionOnlyComboBox(HWND win, WORD id, UINT x, UINT y); int /* index */ ALF_ComboBoxAddString(HWND combo, const TCHAR *text); void ALF_ComboBoxInsertString(HWND combo, int index, const TCHAR *text); void ALF_ComboBoxRemoveString(HWND combo, int index); TCHAR * // free with HeapFree ALF_ComboBoxStringForIndex(HWND combo, int index); int ALF_ComboBoxCurrentIndex(HWND combo); void ALF_ComboBoxSetCurrentIndex(HWND combo, int index); TCHAR * // free with HeapFree ALF_ComboBoxCurrentText(HWND combo); void ALF_ComboBoxSetText(HWND combo, const TCHAR *text); // panel HWND ALF_AddPanel(HWND parent, WORD id, UINT x, UINT y); #ifdef __cplusplus } // extern C #endif