Hiding a dialog box

I have a dialog box and i have been trying to figure out how to hide it, but i cant get it to work, this is what i have in main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include "resource.h"

HINSTANCE hInst;

BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg)
    {
        case WM_INITDIALOG:
            /*
             * TODO: Add code to initialize the dialog.
             */
            return TRUE;

        case WM_CLOSE:
            EndDialog(hwndDlg, 0);
            return TRUE;

        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case Hide:
                    HWND hide = GetWindow(hwndDlg, uMsg);
                    ShowWindow(hide, SW_HIDE);
                    return TRUE;
            }
    }

    return FALSE;
}


int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    hInst = hInstance;

    // The user interface is a modal dialog box
    return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}


resource.rc:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include "resource.h"

DLG_MAIN DIALOGEX 6, 5, 194, 106

CAPTION "Hide"

FONT 8, "Tahoma"

STYLE 0x10CE0804

BEGIN
  CONTROL "Hide", Hide, "Button", 0x10010000, 138,  5, 96, 15
END



Resource.h:

1
2
3
4
5
6
7
#include <windows.h>

// ID of Main Dialog
#define DLG_MAIN 101

// ID of Button Controls
#define Hide 1 



This is what is supposed to hide the window:

1
2
HWND hide = GetWindow(hwndDlg, uMsg);
                    ShowWindow(hide, SW_HIDE);


It used to be GetConsoleWindow but that hid the CMD box, i want it to hide the window so i changed it to GetWindow and in the parameters are hwndDlg, uMsg. The code compiles fine but it doesnt hide the window? what parameters need to go in there? i dont get it?
This should be in the Windows Programming section. Aside from that you aren't passing ShowWindow() the valid handle for your dialog box. From within the message pump for the dialog you can just do ShowWindow(hwndDlg,SW_HIDE)
cool thanks :D
Last edited on
Topic archived. No new replies allowed.