使用 c++,我创建了一个具有“WNDCLASS”结构的窗口。然后,我再次将“CreateWindow”与系统类“按钮”一起使用,并将父句柄设置为已创建的窗口句柄。如何从窗口中删除此按钮?我曾尝试调用“DestroyWindow”函数,但没有任何反应。如果我不能,有没有办法完全擦除窗口并在没有按钮的情况下重新绘制所有内容,这样它就不会出现?
#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 );
clientwindow = CreateWindow( TEXT("BUTTON"),TEXT("BUTTON"),WS_VISIBLE | WS_CHILD,100,100,100,100,hWnd,(HMENU)1,NULL,NULL);
UpdateWindow( hWnd );
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;
}