开发者

How to create window using structure concept so as to reduce code segment?

Suppose i have 5 window to be created in which one is parent and the fo开发者_开发百科ur window are child window. So on the parent window if i have to create four window then how should i implement the structure concept so as to reduce the code segment.?

Is this a good habit or not to use the structure concept?

Please reply thanks a lot.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜