Hiding window

This is a discussion on Hiding window within the Windows Programming forums, part of the Platform Specific Boards category; Code: /**************************** * ClipApp * * Ronak Patel * * xlnk@hotmail.com * ****************************/ #include <windows.h> #define ID_FILE_EXIT 9001 #define ID_FILE_HIDE ...

  1. #1
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186

    Hiding window

    Code:
    /****************************
     *    ClipApp               *
     *    Ronak Patel           *
     *    xlnk@hotmail.com      *
     ****************************/
    
    #include <windows.h>
    
    #define ID_FILE_EXIT        9001
    #define ID_FILE_HIDE		9002
    #define ID_FILE_UNHIDE		9003
    #define ID_INFO_WHERE       9004
    #define ID_INFO_ABOUT       9005
    #define IDC_MAIN_EDIT	    101
    
    
    const char g_szClassName[] = "g_sxWindowsClass";
    const char g_sxMenuName[] = "g_sxMenuName";
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        switch(msg)
        {
    
            case WM_CREATE:
            {
                // TEXT BOX
    
                HFONT hfDefault;
                HWND hEdit;
    
                hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
                    WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL,
                    0, 0, 100, 100, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
                if(hEdit == NULL)
                    MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
    
                //hfDefault = GetStockObject(DEFAULT_GUI_FONT);
                SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    
                HMENU hMenu, hSubMenu;
    
                // MENU
                hMenu = CreateMenu();
    
                hSubMenu = CreatePopupMenu();
    			AppendMenu(hSubMenu, MF_STRING, ID_FILE_HIDE, "H&ide");
    			AppendMenu(hSubMenu, MF_STRING, ID_FILE_UNHIDE, "U&nhide");
    			AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
                AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
    
                hSubMenu = CreatePopupMenu();
                AppendMenu(hSubMenu, MF_STRING, ID_INFO_WHERE, "&Where");
                AppendMenu(hSubMenu, MF_STRING, ID_INFO_ABOUT, "&About");
                AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Info");
    
                SetMenu(hwnd, hMenu);
            }
            break;
    
            case WM_SIZE:
            {
                HWND hEdit;
                RECT rcClient;
    
                GetClientRect(hwnd, &rcClient);
    
                hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT);
                SetWindowPos(hEdit, NULL, 0, 0, rcClient.right,rcClient.bottom, SWP_NOZORDER);
            }
            break;
    
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case ID_FILE_EXIT:
                        PostQuitMessage(0);
                    break;
    				case ID_FILE_HIDE:
    				{
    					ShowWindow(GetDlgItem(hwnd,IDC_MAIN_EDIT),SW_HIDE);
    				}
    				break;
    				case ID_FILE_UNHIDE:
    				{
    					ShowWindow(GetDlgItem(hwnd,IDC_MAIN_EDIT),SW_SHOW);
    				}
    				break;
    				case ID_INFO_WHERE:
                    {
                        char szFileName[MAX_PATH];
                        HINSTANCE hInstance = GetModuleHandle(NULL);
    
                        GetModuleFileName(hInstance, szFileName, MAX_PATH);
                        MessageBox(hwnd, szFileName, "File Location:", MB_OK);
                    }
                    break;
                    case ID_INFO_ABOUT:
                        MessageBox(hwnd, "ClipApp (xlnk@hotmail.com)", "About ClipApp:", MB_OK);
                    break;
                }
            break;
    
    
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
    
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        LPSTR lpCmdLine, int nCmdShow)
    {
        WNDCLASSEX wc;
        HWND hwnd;
        MSG Msg;
    
        wc.cbSize        = sizeof(WNDCLASSEX);
        wc.style         = 0;
        wc.lpfnWndProc   = WndProc;
        wc.cbClsExtra    = 0;
        wc.cbWndExtra    = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
        wc.lpszMenuName  = g_sxMenuName;
        wc.lpszClassName = g_szClassName;
        wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
        if(!RegisterClassEx(&wc))
        {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        hwnd = CreateWindowEx(
            0,
            g_szClassName,
            "ClipApp",
            WS_OVERLAPPEDWINDOW,                   // WS_SYSMENU |WS_MINIMIZEBOX
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            640, 480,
            HWND_DESKTOP,
            NULL,
            hInstance,
            NULL);
    
        if(hwnd == NULL)
        {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    
        ShowWindow(hwnd, nCmdShow);
        UpdateWindow(hwnd);
    
        while(GetMessage(&Msg, NULL, 0, 0))
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
        return Msg.wParam;
    }
    As you can see I have a basic, single text box. Now as of right now when the user clicks 'hide' under 'file' the whole text box disappears, and when the user clicks 'unhide' the text box reappears. Thats almost what I want it to do, the only problem is, the whole text box disappears, where as I want it to fade, where you can see the text in the text box but its uneditable. For example, if you have a checkbox which is unclickable. I'm using the ShowWindow() function but i'm guessing there is another function to do what I want done?

    Thanks!
    the best things in life are simple.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    EnableWindow(HWND, BOOL);

    This does both.

    BTW: good to see a fellow Houstonian on the board

  3. #3
    Registered User xlnk's Avatar
    Join Date
    Mar 2002
    Posts
    186
    indeed.

    Thanks alot I got it working.
    the best things in life are simple.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  3. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 09:01 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21