Thread: Showing and Hiding a Window

  1. #1
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183

    Showing and Hiding a Window

    Hi,
    I was writing a program an interface kind of like windows installer wizards or other wizards. For example, I have a main screen, you choose an option and click next. The new window is exactly the same size, and the buttons in the corner are still there. However, new stuff appears in the middle. My problem is, I didn't want to put all the different buttons on one dialog and just show and hide them depending on what I'm doing. So I decided to have several different dialogs. Once I tried it out, though, I found out if you moved the new dialog, you could still see the main screen behind it. So I thought I would try to use
    Code:
    ShowWindow(hwnd, SW_HIDE);
    and it works, but the little bar containing the program name at the bottom of the screen disappears! Does anyone know how to keep this from happening or know a better way? Thanks.
    Last edited by mikeman118; 10-13-2007 at 11:46 AM.

  2. #2
    Registered User
    Join Date
    Oct 2007
    Posts
    66
    This is a bad hack I guess but can't you show a fake window that has a dialog off-screen or something when you hide your main window?
    "When your work speaks for itself - don't interrupt!"

    -Samantha Ingraham.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Can you possilby use SetLayeredWindowAttributes and make your window totally transparent? That is, the window is there but you just can't see it.

  4. #4
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Just use Child Windows. What you do is place all controls/buttons of a group into a child window and then just show/hide that child window when you want to show/hide the group of controls. Its a hell of a lot easier than messing with ShowWindow. Believe me, you don't want to start messing around with SW_HIDE. I used it to get my apps to minimize to tray, but along with that it did some other nasty things when trying to redraw the window and its taskbar icon (i.e. I had to put a lot of hack-ish code in some obscure places just to get my window and all of its owned windows to redraw/redisplay properly after a call to ShowWindow(SW_HIDE)).

  5. #5
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    So what should I use with the child windows, EnableWindow?

  6. #6
    Registered Abuser
    Join Date
    Jun 2006
    Location
    Toronto
    Posts
    591
    Ironically, ShowWindow(hwndChild, SW_HIDE) (though SW_HIDE does not cause the same evilness with child windows as it does with displayed windows). You can use EnableWindow in addition to that if you're extra paranoid (like me), but generally hiding the child window should be enough.

    So you would set it up like this:
    Code:
    INT_PTR
    MainWindowProc(...)
    {
        WM_CREATE:
           // create child window class
           WNDCLASSEX wcxChild;
           // fill out its fields
           ...
           wcxChild.lpszClassName = Child1Name;  // give child1 class a name
           wcxChild.lpfnWndProc = Child1Proc; // give it a window function
           RegisterClassex(&wcxChild); // register it
           // create child window 1
           CreateWindow(WS_EX_CONTROLPARENT, child1Name,..., WS_CHILD | WS_VISIBLE, x, y, w, h, hwndParent, child1ID, hInst, ...);
    
           wcxChild.lpszClassName = Child2Name;  // give child2 class a name
           wcxChild.lpfnWndProc = Child2Proc;  // give it a window function
           RegisterClassex(&wcxChild);   // register it
           CreateWindow(..., child2Name, ... child2ID,...);
    
           // repeat these steps (name, func, register, create) for each child window
           ...
    
          WM_NCDESTROY:
             // after this window is destroyed, if you no longer
             // need the child windows, unregister their classes to free memory
             // (no need to do this if your entire app is exiting though)
             Unregister(Child1Name, hInst);
             Unregister(Child2Name, hInst);
             ...
    }
    
    INT_PTR
    Child1Proc(...)
    {
        WM_CREATE:
            // create child1 controls here
            ....
         WM_COMMAND:
           // hande child1 messages here (or you can pass them onto parent)
    }
    
    
    INT_PTR
    Child2Proc(...)
    {
        WM_CREATE:
            // create child2 controls here
            ....
         WM_COMMAND:
           // hande child2 messages here (or you can pass them onto parent)
    }
    
    ...

  7. #7
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    Is it possible to do this in a resource file, instead of at runtime (like you have above)?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic window contents
    By @nthony in forum Windows Programming
    Replies: 0
    Last Post: 01-21-2007, 04:44 PM
  2. Window Flicker
    By JaWiB in forum Windows Programming
    Replies: 6
    Last Post: 09-20-2005, 10:46 PM
  3. Showing & hiding menu items
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-07-2005, 06:28 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM