Suppose u have a structure
struct HANDLES
{
HINSTANCE hInstance;
HWND parent;
HWND childwindow1;
HWND childwindow2;
HWND childwindow3;
HWND childwindow4;
};
Now declare object for this handle
HANDLES handles;
Now create parent window like this at bool WINAPI InitInstance(HINSTANCE hInstance, int nCmdShow)
handles.parent = CreateWindowEx(0,
className,
windowName,
WS_VISIBLE | WS_POPUP,
0, 0,
coordinates.width, coordinates.height,
NULL,
NULL,
hInstance,
NULL);
where coordinates is an object and width & height are data member of COORDINATES.
Now create the child window under WM_CREATE.
HWND *buttons = &(handles.childwindow1);
for(int i = MIN_BUTTON; i <= MAX_BUTTON; i++) // MIN_BUTTON = 0 & MAX_BUTTON = 3
{
*buttons = CreateWindowEx(WS_EX_TOPMOST,
TEXT("button"),
L"",
WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
btns[i].x, btns[i].y,
btns[i].width,btns[i].height,
handles.parent,
(HMENU) ((short)(INITIAL_BUTTON + i)), //(INITIAL_BUTTON + i) is id for your child window
handles.hInstance, NULL) ;
buttons++;
}
where "btns[4]" is an object of struct "AXIS"
AXIS btns[4];
struct AXIS
{
short int x;
short int y;
short int width;
short int height;
short int widthSrc;
short int heightSrc;
};
and for each child window there is a different value which is specified from btns[0] to btns[3].
So in this way u can create your window using structure.
Yes its a good habit to use structure which reduces code segment and easy to implement.