Recently I've been doing some Windows API programming and I came across a problem. I want to make a console program that accepts commands, when the command 'win' shows up it will create a window with some automated features.

Lets say I had a command sendfile [file-path] [where]. I'd like the GUI to allow me to browse the file, and select where from a list of some kind. But the problem I'm having is I'm unsure how to make it so when you close the GUI window it will simply hide and I can call it back through my console window. Currently I've managed to make it go away once but when you try win again it doesn't show up. I also made it so every time you type win it will create the window. That works but it wont save previous data on the forum because it is destroying it and recreating.

Does anyone know how to cancel the close event and make the window hide instead.?

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    switch (message)
        case WM_DESTROY:
        case WM_QUIT:
            // cancel ?
            return DefWindowProc (hwnd, message, wParam, lParam);

    return 0;

Thank you in advance for reading my long and useless explanation.

The ShowWindow(hwnd,SW_HIDE) will hide the window without destroying it as you wanted, but to get it back you'll need to call ShowWindow(hwnd,SW_SHOW). You'll need a way to get hold of the keypress or whatever you're using to reactivate the window, which may be tricky.

Remember that once the window is hidden, keypresses will no longer come to the wndproc, but instead will go to whatever window was underneath.

It wasn't working, when I showed again it wouldn't show up. I believe the close event is still being called and the window's code destructs the window making it no longer usable.

Any other ideas?

Are you sure that the Window isn't destroyed? Check in task manager.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.