#pragma once #define WIN32_LEAN_AND_MEAN #include #ifdef __cplusplus extern "C" { #endif typedef struct { UINT 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*/); 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 *); BOOL (*pretranslatemessage)(void * /*closure*/, HWND /*window*/, MSG * /*message*/); void (*paint)(void * /*closure*/, HWND, HDC, RECT *); void (*windowposchanged)(void * /*closure*/, HWND, WINDOWPOS *); } ALFWindowVTable; typedef struct { void (*create)(void * /*closure*/, HWND /*panel*/); void (*destroy)(void * /*closure*/, HWND /*panel*/); LRESULT (*message)(void * /*closure*/, HWND, UINT, WPARAM, LPARAM); void (*paint)(void * /*closure*/, HWND, HDC, RECT * /*rcPaint*/); } ALFPanelVTable; // layout flags #define ALF_LAYOUT_SIZE_FIXED 0x00 #define ALF_LAYOUT_SIZE_QUERY 0x01 #define ALF_LAYOUT_SIZE_PUSHBUTTON 0x04 /* unimplemented */ #define ALF_LAYOUT_SIZE_STATICTEXT 0x05 /* unimplemented */ #define ALF_LAYOUT_SIZE_EDIT 0x06 #define ALF_LAYOUT_SIZE_RADIOBUTTON 0x07 /* unimplemented */ #define ALF_LAYOUT_SIZE_CHECKBOX 0x07 /* unimplemented */ #define ALF_LAYOUT_SIZETYPE_MASK 0x0f #define ALF_LAYOUT_INHERITFONT 0x10 #define ALF_LAYOUT_CUSTOMPOS 0x20 #define ALF_LAYOUT_SIZE_PX 0x40 #define ALF_LAYOUT_INHERITBGCOLOR 0x80 #define ALF_LAYOUT_TRANSPARENTBG 0x100 #define ALF_LAYOUT_SENDBGCHANGE 0x200 // label style flags #define ALF_LABEL_ALIGN_LEFT 0 #define ALF_LABEL_ALIGN_LEFT_LIKE_EDIT 1 #define ALF_LABEL_ALIGN_HCENTER 2 #define ALF_LABEL_ALIGN_RIGHT 3 #define ALF_LABEL_HALIGN_MASK 3 #define ALF_LABEL_ALIGN_TOP 0 #define ALF_LABEL_ALIGN_TOP_LIKE_EDIT 4 #define ALF_LABEL_ALIGN_VCENTER 8 #define ALF_LABEL_ALIGN_BOTTOM 12 #define ALF_LABEL_VALIGN_MASK 12 // notebook flags #define ALF_NOTEBOOK_SOLID_TAB_BACKGROUND 1 // 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_BACKGROUNDCHANGE (ALF_WM__BASE + 11) #define ALF_WM_APPLYSIZE (ALF_WM__BASE + 12) #define ALF_WM_SETBGCOLOR (ALF_WM__BASE + 13) #define ALF_WM_GETBGCOLOR (ALF_WM__BASE + 14) #define ALF_WM_GETWIDGETATPOS (ALF_WM__BASE + 15) #define ALF_WM_PRETRANSLATEMSG (ALF_WM__BASE + 16) #define ALF_WM_INVALIDATELAYOUT (ALF_WM__BASE + 17) #define ALF_WM_VALIDATELAYOUT (ALF_WM__BASE + 18) #define ALF_WM_LYT_GETWIDGETPOS (ALF_WM__BASE + 19) #define ALF_WM_LYT_SETWIDGETPOS (ALF_WM__BASE + 20) #define ALF_WM_LYT_GETWIDGTSIZE (ALF_WM__BASE + 21) #define ALF_WM_LYT_SETWIDGTSIZE (ALF_WM__BASE + 22) #define ALF_WM_LYT_GETWDGTFLAGS (ALF_WM__BASE + 23) #define ALF_WM_LYT_SETWDGTFLAGS (ALF_WM__BASE + 24) #define ALF_WM_LYT_GETCOLSIZE (ALF_WM__BASE + 25) #define ALF_WM_LYT_SETCOLSIZE (ALF_WM__BASE + 26) #define ALF_WM_LYT_GETCOLEXPAND (ALF_WM__BASE + 27) #define ALF_WM_LYT_SETCOLEXPAND (ALF_WM__BASE + 28) #define ALF_WM_LYT_GETCOLFLAGS (ALF_WM__BASE + 29) #define ALF_WM_LYT_SETCOLFLAGS (ALF_WM__BASE + 30) #define ALF_WM_LYT_GETROWSIZE (ALF_WM__BASE + 31) #define ALF_WM_LYT_SETROWSIZE (ALF_WM__BASE + 32) #define ALF_WM_LYT_GETROWEXPAND (ALF_WM__BASE + 33) #define ALF_WM_LYT_SETROWEXPAND (ALF_WM__BASE + 34) #define ALF_WM_LYT_GETROWFLAGS (ALF_WM__BASE + 35) #define ALF_WM_LYT_SETROWFLAGS (ALF_WM__BASE + 36) #define ALF_WM_LBL_GETSTYLE (ALF_WM__BASE + 201) #define ALF_WM_LBL_SETSTYLE (ALF_WM__BASE + 202) #define ALF_WM_PANEL_SETVTABLE (ALF_WM__BASE + 201) #define ALF_WM_NTBK_GETFLAGS (ALF_WM__BASE + 201) #define ALF_WM_NTBK_SETFLAGS (ALF_WM__BASE + 202) typedef DWORD ALFColor; #define ALF_COLOR_TRANSPARENT ((ALFColor)-1) #define ALF_COLOR_RGB(r, g, b) ((ALFColor)(((DWORD)(BYTE)r) | (((DWORD)(BYTE)g) << 8) | (((DWORD)(BYTE)b) << 16))) #define ALF_COLOR_SYS(i) ((ALFColor)(0x80000000 | (((DWORD)(BYTE)i) << 24))) typedef struct { const TCHAR *className; UINT classStyle; ALFWindowVTable vtbl; } ALFWindowClassParams; typedef enum { ALF_DPI_AWARENESS_UNAWARE, ALF_DPI_AWARENESS_SYSTEM_AWARE, ALF_DPI_AWARENESS_PER_MONITOR_AWARE_V2 } ALFDpiAwareness; void ALF_SetDpiAwareness(ALFDpiAwareness awareness); void ALF_Initialize(void); void ALF_UnInitialize(void); void * ALF_Alloc(SIZE_T nmemb, SIZE_T size); void * ALF_ReAlloc(void *ptr, SIZE_T nmemb, SIZE_T size); #define ALF_New(type, count) ((type *)ALF_Alloc((count), sizeof(type))) #define ALF_ReNew(ptr, type, count) ((type *)ALF_ReAlloc(ptr, (count), sizeof(type))) void ALF_Free(const void *p); COLORREF ALF_ColorToGdi(ALFColor color); LPTSTR ALF_RegisterWindowClass(HINSTANCE instance, const ALFWindowClassParams *params); void ALF_UnregisterWindowClass(HINSTANCE instance, LPCTSTR className); HWND ALF_InstantiateWindow(HINSTANCE instance, LPCTSTR className, HWND hwndParent, void *closure); void ALF_DestroyWindow(HWND win); BOOL ALF_PreTranslateMessage(HWND hwnd, MSG *message); 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, int x, int y, const TCHAR *text); HWND ALF_AddEdit(HWND win, WORD id, int x, int y, const TCHAR *text); HWND ALF_AddButton(HWND win, WORD id, int x, int y, const TCHAR *text); void ALF_SetDefaultButton(HWND win, WORD id); void ALF_DestroyWidget(HWND win, WORD id); void ALF_AddWidget(HWND win, int x, int y, HWND widget, int width, int height, DWORD flags); HWND ALF_WidgetHwndById(HWND win, WORD id); void ALF_InvalidateLayout(HWND win); // Sends ALF_WM_BACKGROUNDCHANGE to notify the window of a changed background // Only useful when you have overridden the window or panel pain() vfunc // when you use solid background colors, ALF will handle this automatically void ALF_InvalidateBackground(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(). void ALF_UpdateFonts(HWND win); // Sets the background color of the given window // Also, if the window is a child window, disables the ALF_LAYOUT_INHERITBGCOLOR flag // Only the following widgets have background colors: // - Top-Level window // - Panel // - Label // TODO: button, ... void ALF_SetBackgroundColor(HWND win, ALFColor color); ALFColor ALF_BackgroundColor(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 ALF_Free ALF_Text(HWND hwnd); TCHAR * // free with ALF_Free 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, int *pX, int *pY); BOOL ALF_SetWidgetLayoutPosition(HWND parent, HWND widget, int x, int y); BOOL ALF_WidgetLayoutMinSize(HWND parent, HWND widget, int *pWidth, int *pheight); BOOL ALF_SetWidgetLayoutMinSize(HWND parent, HWND widget, int width, int height); HWND ALF_WidgetAtLayoutPosition(HWND parent, int x, int y); int ALF_LayoutRowMinSize(HWND parent, int rowno); BOOL ALF_LayoutSetRowMinSize(HWND parent, int rowno, int rowsize); int ALF_LayoutColumnMinSize(HWND parent, int colno); BOOL ALF_LayoutSetColumnMinSize(HWND parent, int colno, int colsize); DWORD ALF_LayoutRowFlags(HWND parent, int rowno); BOOL ALF_LayoutSetRowFlags(HWND parent, int rowno, DWORD flags); DWORD ALF_LayoutColumnFlags(HWND parent, int colno); BOOL ALF_LayoutSetColumnFlags(HWND parent, int colno, DWORD flags); int ALF_LayoutRowExpandNumerator(HWND parent, int rowno); BOOL ALF_LayoutSetRowExpandNumerator(HWND parent, int rowno, int expand); int ALF_LayoutColumnExpandNumerator(HWND parent, int colno); BOOL ALF_LayoutSetColumnExpandNumerator(HWND parent, int colno, int expand); // combo box HWND ALF_AddEditableComboBox(HWND win, WORD id, int x, int y, const TCHAR *defaultText); HWND ALF_AddSelectionOnlyComboBox(HWND win, WORD id, int x, int 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 ALF_Free ALF_ComboBoxStringForIndex(HWND combo, int index); int ALF_ComboBoxCurrentIndex(HWND combo); void ALF_ComboBoxSetCurrentIndex(HWND combo, int index); TCHAR * // free with ALF_Free ALF_ComboBoxCurrentText(HWND combo); void ALF_ComboBoxSetText(HWND combo, const TCHAR *text); // panel HWND ALF_AddPanel(HWND parent, WORD id, int x, int y); void ALF_Panel_SetVTable(HWND panel, const ALFPanelVTable *vtbl, void *closure); LRESULT ALF_Panel_DefWindowProc(HWND panel, UINT msg, WPARAM wparam, LPARAM lparam); // tab control HWND ALF_AddNotebook(HWND parent, WORD id, int x, int y); HWND ALF_NotebookAddTab(HWND notebook, const TCHAR *title); int ALF_NotebookTabCount(HWND notebook); int ALF_NotebookTabIndex(HWND notebook, HWND tabPanel); int ALF_NotebookSelectedIndex(HWND notebook); HWND ALF_NotebookSelectedPanel(HWND notebook); HWND ALF_NotebookTabPanel(HWND notebook, int index); DWORD ALF_NotebookFlags(HWND notebook); void ALF_NotebookSetFlags(HWND notebook, DWORD flags); static inline void ALF_NotebookAddFlag(HWND notebook, DWORD flag) { ALF_NotebookSetFlags(notebook, ALF_NotebookFlags(notebook) | flag); } static inline void ALF_NotebookRemoveFlag(HWND notebook, DWORD flag) { ALF_NotebookSetFlags(notebook, ALF_NotebookFlags(notebook) & ~flag); } #ifdef __cplusplus } // extern C #endif