[comp.windows.ms.programmer] Creating a Button inside a child process

darak@iplmail.orl.mmc.com (dara khani) (04/29/91)

 I am having a problem with creating a button inside a child process.
I have a parent window which create a child process (a window).
In the child process procedure I have a WM_CREATE case which calls 
the CreateWindow function to create a button:
 CreateWindow("button", "hi", WS_CHILD | WS_VISIBLE | WS_PUSHBUTTON,
               1,1, 30,30, hWnd, 1, hInst, NULL) 
I not sure if the order of the parameters are right ( I don't have the program with me).
hWnd is the handle of the child
hInst is the instance of the parent

the handle returned from the CreateWindow is NULL (button not created).
Now, if I put the same CreateWindow in the WM_PAINT part of the procedure 
( I know this is wrong) the button is created.

Can someone tell me why this doesn't work in WM_CREATE part and works
in WM_PAINT.

thanks in advance.

			DaRa

kentfo@polari.UUCP (Kent Forschmiedt) (05/02/91)

In article <1991Apr29.140448.2027@iplmail.orl.mmc.com>
 darak@iplmail.orl.mmc.com (dara khani) writes:
> CreateWindow("button", "hi", WS_CHILD | WS_VISIBLE | WS_PUSHBUTTON,
>               1,1, 30,30, hWnd, 1, hInst, NULL) 
>I not sure if the order of the parameters are right ( I don't have
> the program with me).
>hWnd is the handle of the child
>hInst is the instance of the parent
>
>the handle returned from the CreateWindow is NULL (button not created).
>Now, if I put the same CreateWindow in the WM_PAINT part of the procedure 
>( I know this is wrong) the button is created.

One common source of this sort of problem in WM_CREATE processing is
that in a WM_CREATE message, the hwnd is not entirely valid yet.  Use
data from the CREATESTRUCT pointed to by lParam, rather than using e.g. 
GetWindowWord(); the most common use I find is for getting hInstance:
((LPCREATESTRUCT)lParam)->hInstance

The CREATESTRUCT contains the stuff from the CreateWindow() call.
(Actually, it looks like a pointer to the actual arguments to the
CreateWindow() call, but I don't feel like running CodeView right
now, so I won't look and see)

-- 
Kent Forschmiedt ... kentfo@polari ... uw-beaver!sumax!polari!kentfo

Norbert_Unterberg@p4.f36.n245.z2.fidonet.org (Norbert Unterberg) (05/03/91)

 > From: darak@iplmail.orl.mmc.com (dara khani)
 >
 >
 > I have a parent window which create a child process (a window).
 > In the child process procedure I have a WM_CREATE case which calls
 > the CreateWindow function to create a button:
 >  CreateWindow("button", "hi", WS_CHILD | WS_VISIBLE | WS_PUSHBUTTON,
 >                1,1, 30,30, hWnd, 1, hInst, NULL)
 >
 > Can someone tell me why this doesn't work in WM_CREATE part and works
 > in WM_PAINT.

Maybe the hInst is not yet valid, because you do a hInst = hInstance; in 
WinMain() after the CreateWindow() call for the child?

Gruss    Norbert