Resize child window

Started by
30 comments, last by Decrius 17 years, 11 months ago
In the debugger, in a watch window, put 1400,hr. You get "Invalid window handle". What is the value of the two window handles you pass in?
Advertisement
You mean the hwnd's?

HWND hChild;HWND Create_Window_Child1(HWND hParent, char *Classname, int win_width, int win_height);HWND Create_Window_Main(char *Classname, char *Title, int x, int y, int width, int height, BYTE type, DWORD flags){........blahdyblah........hChild1 = Create_Window_Child1(hWnd, Classname, win_width, win_height);}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               );}LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){    static PAINTSTRUCT ps;    switch(uMsg)    {........case WM_SIZE:        {            PostMessage(hWnd, WM_PAINT, 0, 0);                    bool bRet;		    bRet = SetWindowPos(hChild1, hWnd, 1, 28, (((LOWORD(lParam)-10)/2)-2), (((HIWORD(lParam)-100)/2)-1), SWP_NOZORDER);		    if(bRet == 0) {            DWORD dwErr = GetLastError();            char str[255];            sprintf(str, "Error %d", dwErr);            MessageBox(NULL, str, "Message", MB_OK);}........            return 0;        }}



Thats the code for the first Child window, thats what you required, didn't you?

Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Use the debugger and put a breakpoint at the SetWindowPos line, and take a look what the values of hChild1 and hWnd are. Alternatively, use sprintf() to print their values as pointers ("%p" or "0x%08X" will do).
Sorry, but I don't know what you mean.

I just press F9 and it compiles and runs...I don't know what you mean with debugger and put a breakpoint somewhere. And how can I sprintf() the values?

Sorry, but I'm not yet familiar with IDE's and compiler/debugger etc. neither my english is well enough :(.

However, thanks so far for the help :)

Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Okay, I found out what a breakpoint is, and placed it on the line. And how can I read the value's of hWnd etc.?

Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
It means that the HWND variable you pass to SetWindowPos is not a handle to a valid window, that is you are not telling SetWindowPos to resize your window.
You need to make sure that the hChild1 is actually the window you wish to resize.
If they are then make sure that you use global variables to store their handles, and that you have no colliding names. Make sure only one single variable in your program has the name hChild1.
I'm quite sure of that. And I declared the HWND's in a header (not in a function). So it should be global, shouldn't it? Well, I placed the code a few reply's ago, I don't know what's wrong. Maybe you guys can find out?

Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Quote:Original post by Decrius
Okay, I found out what a breakpoint is, and placed it on the line. And how can I read the value's of hWnd etc.?
That depends on your compiler. Using Visual C, you can enter the variable names in a watch window.

For showing them with sprint, something like this will do:
if(bRet == 0){   char str[255];   sprintf(str, "hChild1=0x%08X, hWnd=0x%08X", hChild1, hWnd);   MessageBox(NULL, str, "Message", MB_OK);}
Just to replace the code you ahev at the moment. If either is NULL (0x00000000), or 0xcccccccc then there's a problem.
hChild1 has 0x00000->

So I'll need to find the error tomorrow.

Thanks a lot for the help :D

Sleeping time :P ;)

Decrius
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
Well, I got it all to work, the resizing part. But I'm not satisfied yet :P. What I did to solve the problem that the Child windows had an error was:

HWND Create_Window_Child1(HWND hParent, char *Classname){    return CreateWindowEx(                 WS_EX_CLIENTEDGE, // give it a standard border                 "EDIT",                 NULL,                 WS_VISIBLE | WS_CHILD,                 0, 0, 0, 0,                 hParent,                 NULL, GetModuleHandle(0), NULL               );}


As you might notice, I used for the Classname "EDIT" instead of the Classname of the main window. "EDIT" is a predefined classname, which will allow you to write text in the child windows. However, this is not what I require, I want to run OpenGL in the windows, so writing is it isn't allowed. What Classname should I use? Make another class...? Use the Classname of the main window (which didn't worked)? Use another Classname...?

The x, y, Δx and Δy are '0', because at the WM_SIZE part I already give them x and y etc. values.

Thanks anyways,

Decrius

EDIT: The value I give to this function (Classname) isn't used in the function, but might be handy for if I DO have to give it the Classname, and yes...I'm too lazy to remove it, and if I do need it place it :P.
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora

This topic is closed to new replies.

Advertisement