0

I'm having some problems with my child window. I use a button from the AppendMenu to open it, but after I close the child window, I can't open it anymore.

code:

WNDCLASSEX chwincl;

chwincl.hInstance = hThisInstance;
chwincl.lpszClassName = "Child";
chwincl.lpfnWndProc = ChildProcedure;
chwincl.style = CS_DBLCLKS;
chwincl.cbSize = sizeof(WNDCLASSEX);
chwincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
chwincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
chwincl.hCursor = LoadCursor(NULL, IDC_ARROW);
chwincl.lpszMenuName = NULL;
chwincl.cbClsExtra = 0;
chwincl.cbWndExtra = 0;
chwincl.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);

if (!RegisterClassEx(&chwincl))
    return 2;

chwnd = CreateWindowEx(0,
    "Child",
    "Add...",
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT,
    CW_USEDEFAULT,
    300,
    150,
    HWND_DESKTOP,
    NULL,
    hThisInstance,
    NULL);

I open the child window with this:

if (LOWORD(wParam) == ID_Click) {
        ShowWindow(chwnd, SW_SHOWDEFAULT);
        UpdateWindow(chwnd);
    }

And I close it with this:

DestroyWindow(chwnd);

Why can I only open my child window once?

Thanks

Tom Stuart
  • 85
  • 2
  • 9
  • This is not a minimal example. Please don't make people read through tons of unnecessary code. – chris Oct 25 '14 at 16:27
  • I'm sorry, I thought it would be necessary to see how I create my windows. – Tom Stuart Oct 25 '14 at 16:30
  • 1
    We want to see how you create your windows. However, it is hard to believe that all six grandchild windows are required to demonstrate the problem. I bet you can remove them. Similarly, I bet you can remove the custom paint handler, and the problem will still be there. Keep removing code until you get the smallest program that still demonstrates the problem. – Raymond Chen Oct 25 '14 at 16:38
  • 1
    Now you deleted too much. You need to produce the smallest complete program that still demonstrates the problem. Your previous attempt missed the "smallest" part of the requirements. Your second attempt missed the "complete program" part of the requirements. – Raymond Chen Oct 25 '14 at 16:40
  • 1
    I'm sorry, I changed it. – Tom Stuart Oct 25 '14 at 16:40
  • Still not there. You need a complete program. – David Heffernan Oct 25 '14 at 21:12

2 Answers2

1

DestroyWindow destroys the the window completely. After that call, it no longer exists. So you can't then show it again with ShowWindow - you have to actually create it again from scratch.

Instead of calling DestroyWindow to hide it, use ShowWindow(chwnd, SW_HIDE);

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
0

You need the flag SW_RESTORE in your ShowWindow call when restoring a minimized (or closed) window.

Yam Marcovic
  • 7,953
  • 1
  • 28
  • 38