Deleting child button window

Using c++, I have created a window with a "WNDCLASS" structure. I have then used "CreateWindow" again with the system class "button" and set the parent handle to the handle of the window already created. How can I delete this button in the program from the window? I have tried calling the "DestroyWindow" function but nothing happens. If I can't, is there a way to wipe the window completely and redraw everything again without the button so it does not appear?

thanks in advance

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <Windows.h>
#include <wchar.h>
HWND clientwindow;
RECT wr;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    

    switch (message)
    {
	case WM_COMMAND:
    	DestroyWindow( clientwindow );
		UpdateWindow( hWnd );
    	break;
    default:
    	return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

int WINAPI wWinMain( HINSTANCE hInst,HINSTANCE,LPWSTR,INT )
{
	
	WNDCLASSEX wc = { sizeof( WNDCLASSEX ),CS_CLASSDC,WndProc,0,0,
                      GetModuleHandle( NULL ),NULL,NULL,NULL,NULL,
                      L"jjclass",NULL };

    
	wc.hCursor = LoadCursor( NULL,IDC_ARROW );
    RegisterClassEx( &wc );
	
	
	wr.left = 650;
	wr.right = wr.left + 500;
	wr.top = 150;
	wr.bottom = wr.top + 500;
	AdjustWindowRect( &wr,WS_OVERLAPPEDWINDOW,FALSE );
    HWND hWnd = CreateWindowW( L"jjclass",L"my window",
                              WS_OVERLAPPEDWINDOW,wr.left,wr.top,wr.right-wr.left,wr.bottom-wr.top,
                              NULL,NULL,wc.hInstance,NULL );

    ShowWindow( hWnd,SW_SHOWDEFAULT );
    UpdateWindow( hWnd );
	
	clientwindow = CreateWindow( TEXT("BUTTON"),TEXT("BUTTON"),WS_VISIBLE | WS_CHILD,100,100,100,100,hWnd,(HMENU)1,NULL,NULL);
	
	
    MSG msg;
    ZeroMemory( &msg,sizeof( msg ) );
    while( msg.message != WM_QUIT )
    {
        if( PeekMessage( &msg,NULL,0,0,PM_REMOVE ) )
        {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
       
		
			
		
    }
    UnregisterClass( L"jjclass",wc.hInstance );
    return 0;
}
Just hide it using ShowWindow (clientwindow, SW_HIDE);
I tried that, and the button stops working; if you click it it doesn't appear to be pushed in, and i stop getting WM_COMMAND messages, but it is still there.
hide the window and handle the WM_PAINT message on your own
ShowWindow with SW_HIDE should have made the button disappear? The behaviour you describe sound like you've disabled it rather than hidden it.

You did say you wanted to get rid of the button? (Delete it, actually)

Andy

PS Child windows are usually be contructed in the WM_CREATE handler of the parent window.
Last edited on
Topic archived. No new replies allowed.