How to delete a button at an other button's click win32 api with c?
<p>Hello everyone i have this problem that i have been trying to solve for a long time . I'm creating a win 32 gui application with C using code::blocks ;</p>

<p>and i wanted to create a menu using buttons so when you click on a button ; 
a list of buttons will appear; if you click on an other button the list will change and so on.</p>

<p>I managed to create the list of buttons , but when i need to destroy them the DestroyWindow function does nothing and the button remains (I've also tried Sending WM_CLOSE and WM_DESTROY messages to the button ) .
i will give a sample code and please tell me what am i doing wrong , it's driving me crazy.</p>

<p>PS: i'm using c and not c++ because i kinda have to.</p>

<p>Thank you all in advance</p>

<hr>

<pre><code>#include &lt;windows.h&gt;
#include &lt;wchar.h&gt;
#include &lt;stdbool.h&gt;
#define B 115
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg,WPARAM wParam, LPARAM lParam) 
{
  HWND button1,button2;
 switch(msg)
{case WM_CREATE:


           button1 =  CreateWindowW(L"Button", L"Button to push", WS_VISIBLE | WS_CHILD|BS_FLAT|BS_PUSHBUTTON|WS_BORDER,
                                    0,0, 100, 80, hwnd, (HMENU) B, GetModuleHandle(NULL), NULL);
            button2 =  CreateWindowW(L"Button", L"Button to kill", WS_VISIBLE | WS_CHILD|BS_FLAT|BS_PUSHBUTTON|WS_BORDER,
                                    100,0, 100, 80, hwnd, 0, GetModuleHandle(NULL), NULL);
        break; 

case WM_COMMAND:
         if(LOWORD(wParam)==B)
         {  
             DestroyWindow(button2); //here i destroy the button 2 if button 1 was clicked
         }
    break;
case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
}

return DefWindowProcW(hwnd, msg, wParam, lParam);
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
 {

MSG  msg;
HWND W;
WNDCLASSW ClassP;

ClassP.style         = CS_HREDRAW | CS_VREDRAW;
ClassP.cbClsExtra    = 0;
ClassP.cbWndExtra    = 0;
ClassP.lpszClassName = L"FenetrePrincipale";
ClassP.hInstance     = hInstance;
ClassP.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
ClassP.lpszMenuName  = NULL;
ClassP.lpfnWndProc   = WndProc;
ClassP.hCursor       = LoadCursor(NULL, IDC_ARROW);
ClassP.hIcon         = LoadIcon(NULL, IDI_ERROR);
RegisterClassW(&amp;ClassP);
W = CreateWindowW(ClassP.lpszClassName, L"PROBLEM SAMPLE CODE",
            WS_OVERLAPPEDWINDOW | WS_VISIBLE,
            100, 100, 300, 300, NULL, NULL, hInstance, NULL);
ShowWindow(W, nCmdShow);
UpdateWindow(W);
while (GetMessage(&amp;msg, NULL, 0, 0)) {

    DispatchMessage(&amp;msg);
}

return (int) msg.wParam;
}
</code></pre>