Resize child window

Started by
30 comments, last by Decrius 17 years, 11 months ago
Hi, I made a window, in the window I created 4 child windows:

HWND Create_Window_Child1(HWND hParent, char *Classname, int win_width, int win_height)
{
    return CreateWindowEx(
                 WS_EX_CLIENTEDGE, // give it a standard border
                 Classname,
                 NULL,
                 WS_VISIBLE | WS_CHILD,
                 1, 28, (((win_width-10)/2)-2), (((win_height-100)/2)-1),
                 hParent,
                 NULL, GetModuleHandle(0), NULL
               );
}
HWND Create_Window_Child2(HWND hParent, char *Classname, int win_width, int win_height)
{
    return CreateWindowEx(
                 WS_EX_CLIENTEDGE, // give it a standard border
                 Classname,
                 NULL,
                 WS_VISIBLE | WS_CHILD,
                 1, 28+(((win_height-100)/2)-1)+4, (((win_width-10)/2)-2), (((win_height-100)/2)-2),
                 hParent,
                 NULL, GetModuleHandle(0), NULL
               );
}
HWND Create_Window_Child3(HWND hParent, char *Classname, int win_width, int win_height)
{
    return CreateWindowEx(
                 WS_EX_CLIENTEDGE, // give it a standard border
                 Classname,
                 NULL,
                 WS_VISIBLE | WS_CHILD,
                 1+(((win_width-10)/2)-2)+4, 28, (((win_width-10)/2)-2), (((win_height-100)/2)-2),
                 hParent,
                 NULL, GetModuleHandle(0), NULL
               );
}
HWND Create_Window_Child4(HWND hParent, char *Classname, int win_width, int win_height)
{
    return CreateWindowEx(
                 WS_EX_CLIENTEDGE, // give it a standard border
                 Classname,
                 NULL,
                 WS_VISIBLE | WS_CHILD,
                 1+(((win_width-10)/2)-2)+4, 28+(((win_height-100)/2)-1)+4, (((win_width-10)/2)-2), (((win_height-100)/2)-2),
                 hParent,
                 NULL, GetModuleHandle(0), NULL
               );
}

win_width and win_height are the sizes of the window (512x512). When I resize the window, I want that the 4 child windows will resize too, and not stay the same, but contract or expand. So I need to do something with the

case WM_SIZE:
{
return 0;
}

function. Should I use SendMessage( or MoveWindow( ? And how to use them, noone of them worked yet. I tried them all... Any suggestion is very appreciated :) Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Advertisement
SetWindowPos() is probably what you want.
Example:
SetWindowPos(hChild, hParent, x, y, width, height, 0);
Thank you for the reply.

So it should be:

SetWindowPos(hChild1, hWnd, 1, 28, (((LOWORD(lParam)-10)/2)-2), (((HIWORD(lParam)-100)/2)-1), 0);

But thats not working, the child isn't sizing at all. What's wrong?

Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Does it work if you call that outside your WM_SIZE handler? It works fine for me... Does SetWindowPos() return any error?
Well, when the program starts, the first Child (which I try to resize) has a different size on start up, but when I resize the window, nothing happens. How can I check if the function gives an error?

Thank you anyways, :)

Decrius

PS: or do I have to redraw the window?
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Quote:Return Values
Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.
The only reason I can think that the function would fail is if your window handles are invalid, however.

EDIT: You shouldn't have to redraw the window, Windows will do that for you.
I got some progress, the second parameter shouldn't be 'hWnd', but something like 'HWND_BOTTOM', 'HWND_NOTTOPMOST', 'HWND_TOP' or 'HWND_TOPMOST'. For nottopmost and topmost I see no difference. But for the bottom and top things, I see nothing until I resize the window, I see them flickering, flashing (whatever :p). The flashing border of the child grows if the window expands. But when I stop resizing the flashing is gone. Its like the child window is under the surface, but I don't see how to fix it...

Thanks so far anyways :)

Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
First try to resize the window to a fixed size, perhaps you have a negative width or something.. I don't know what happens if you do.

Here's how you can check for errors:
You might need to #include <stdio.h> for sprintf
BOOL bRet;bRet = SetWindowPos(	hChildWnd,	NULL,	0,	0,	500,	500,	SWP_NOZORDER);if(bRet == 0) {	DWORD dwErr = GetLastError();	char str[255];		sprintf(str, "Error %d", dwErr);	MessageBox(NULL, str, "Message", MB_OK);}
Quote:Original post by Decrius
I got some progress, the second parameter shouldn't be 'hWnd', but something like 'HWND_BOTTOM', 'HWND_NOTTOPMOST', 'HWND_TOP' or 'HWND_TOPMOST'. For nottopmost and topmost I see no difference. But for the bottom and top things, I see nothing until I resize the window, I see them flickering, flashing (whatever :p). The flashing border of the child grows if the window expands. But when I stop resizing the flashing is gone. Its like the child window is under the surface, but I don't see how to fix it...

No necessarily [wink]
Quote:hWndInsertAfter
[in] Handle to the window to precede the positioned window in the z-order. This parameter must be a window handle or one of the following values.
(Emphasis mine). Try what Erik Rufelt suggested, and see if that helps.
Thank you :)

I put it in the program, when I start up the program, I get one message box with:

Error: 1400

But when I resize the window I get nothing.

How to find out what error 1400 means?

Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora

This topic is closed to new replies.

Advertisement