使用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;
}
是的,你使用DestroyWindow。如果您沒有發佈代碼片段,沒有人可以看到您的錯誤。 – 2013-05-12 10:38:46
嗨,謝謝你的回覆。我發佈了它。我試圖使用destroywindow並沒有任何反應 – joelyboy94 2013-05-12 15:02:14