Create Window Control
Helper functions that create STATIC and EDIT controls at runtime with a standard font.
When you build a dialog's contents in code instead of a template, these four helpers keep the CreateWindowEx boilerplate out of your message loop. CreateStaticControl and CreateEditControl wrap CreateWindowEx with position, size, style and extended-style parameters and apply the default GUI font via WM_SETFONT; the two Simple variants pre-bake the usual edit-box and label styles so common cases are one line each. Use them whenever you need to lay out controls programmatically.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HWND CreateStaticControl(HWND xDialog, int xHoriz, int xVert, int xWidth, int xHeight, int Style, int StyleEx, char *Text)
{
HWND Handle = CreateWindowEx(
StyleEx,
"STATIC",
Text,
Style,
xHoriz,
xVert,
xWidth,
xHeight,
xDialog,
NULL,
MainInstance,
NULL
);
SendMessage(Handle, (UINT) WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), (LPARAM) MAKELPARAM(FALSE,0) );
return Handle;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HWND CreateEditControl(HWND xDialog, int xHoriz, int xVert, int xWidth, int xHeight, int Style, int StyleEx, char *Text)
{
HWND Handle = CreateWindowEx(
StyleEx,
"EDIT",
Text,
Style,
xHoriz,
xVert,
xWidth,
xHeight,
xDialog,
NULL,
MainInstance,
NULL
);
SendMessage(Handle, (UINT) WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), (LPARAM) MAKELPARAM(FALSE,0) );
return Handle;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HWND CreateSimpleEditControl(HWND xDialog, int xHoriz, int xVert, int xWidth, char *xText)
{
int xHeight = 25;
int xStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL;
int xStyleEx = WS_EX_CLIENTEDGE;
return CreateEditControl(xDialog, xHoriz, xVert, xWidth, xHeight, xStyle, xStyleEx, xText);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
HWND CreateSimpleStaticControl(HWND xDialog, int xHoriz, int xVert, int xWidth, char *xText)
{
int xHeight = 15;
int xStyle = WS_CHILD | WS_VISIBLE;
int xStyleEx = 0;
return CreateStaticControl(xDialog, xHoriz, xVert, xWidth, xHeight, xStyle, xStyleEx, xText);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////