ShowWindow(SW_HIDE) problem

This is a discussion on ShowWindow(SW_HIDE) problem within the Windows Programming forums, part of the Platform Specific Boards category; hi, im using visual c++ 6.0 with MFC and if i minimize my dialog window to the taskbar (not by ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    103

    ShowWindow(SW_HIDE) problem

    hi, im using visual c++ 6.0 with MFC and if i minimize my dialog window to the taskbar (not by code) and then use ShowWindow(SW_HIDE); on it, then i use ShowWindow(SW_RESTORE); to show it back again and then if i click the window from the taskbar to minimize it it just won't work anymore, i have to right click the window from the taskbar to fix it and make it minimize by clicking the window from the taskbar again..


    note that there isn't any problem if i just minimize it first by code by using ShowWindow(SW_MINIMIZE);

    does anybody know how to fix this? or is it a windows bug that cannot be fixed?

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    I'm assuming you have a mainwindow then create a modeless dialog.

    I made a VS6 project. Created a dialog with min and max boxes, and parented to the desktop. Made menu items for showing the dialog, hiding the dialog, and restoring the dialog.

    I run the application. Click the menu item to show the dialog (this creates it and shows it). Then I minimize the dialog with the min box. This puts the dialog in the taskbar. Both the application and dialog show in the taskbar. Then I click the hide menu item. This removes the dialog from the taskbar. Then I click the restore menu item. This shows the dialog back where it was before it was minimized. It is on top of the main window and it shows in the taskbar. I right click on the dialog in the taskbar and select minimize. It works for me.

    If you did things differently you'll have to explain what you did.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    Quote Originally Posted by DaveH View Post
    I'm assuming you have a mainwindow then create a modeless dialog.

    I made a VS6 project. Created a dialog with min and max boxes, and parented to the desktop. Made menu items for showing the dialog, hiding the dialog, and restoring the dialog.

    I run the application. Click the menu item to show the dialog (this creates it and shows it). Then I minimize the dialog with the min box. This puts the dialog in the taskbar. Both the application and dialog show in the taskbar. Then I click the hide menu item. This removes the dialog from the taskbar. Then I click the restore menu item. This shows the dialog back where it was before it was minimized. It is on top of the main window and it shows in the taskbar. I right click on the dialog in the taskbar and select minimize. It works for me.

    If you did things differently you'll have to explain what you did.
    ah sorry for not explaining things better, here is my code:
    Code:
    void CTESTDlg::OnClose() 
    {
        ShowWindow(SW_HIDE);
        ShowWindow(SW_RESTORE);
    //  CDialog::OnClose();
    }
    anyway thanks to somebody who helped me i have found a solution and it seems to work:
    Code:
    void CTESTDlg::OnClose() 
    {
        ShowWindow(SW_HIDE);
        ShowWindow(SW_RESTORE);
        SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, NULL);
    //  CDialog::OnClose();
    }
    thing is im not 100% sure it is the right way, it seems that problem happens because i commented CDialog::OnClose(); which must be doing something important..

    is there a way to see the CDialog::OnClose() source code to see what it is happening there?

    thanks

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    Why are you hiding then restoring in onclose?

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    this is just a test project but my program hides the window on Close event and adds it to system tray where it is restored from there.. its like any program that goes to tray when you close it instead of just closing

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    But hiding and restoring in succession isn't doing anything. It just keeps the window where it is, no?

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    Quote Originally Posted by DaveH View Post
    But hiding and restoring in succession isn't doing anything. It just keeps the window where it is, no?
    its just a test program and i placed restore there so it saves me a lot of trouble

    i know it never closes unless you end task it but it reproduces the problem like on my main program

    try and test it if you want..


    edit:
    its the same thing if i place the restore code in a button in a different window
    Last edited by eXistenZ; 09-04-2008 at 09:10 AM.

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    actually the solution i posted doesn't work good all the time

    on double click events it does weird things

    if anybody knows a solution for this please post one..

    thanks

  9. #9
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    I would suggest adding a delay between the hide and show. Sleep(1000); shoudl do the trick. That will give your message loop time to process the WM_ messages generted.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    I'm still confused on how you are making your dialog. Is it the main window of the application or is it a secondary window?

    CDialog::OnClose is going to destroy the window. I'm sure thats not what you want to do.


    Edit : This link may help. http://www.codeproject.com/KB/shell/systemtray.aspx
    Last edited by DaveH; 09-04-2008 at 11:36 AM.

  11. #11
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    Quote Originally Posted by DaveH View Post
    I'm still confused on how you are making your dialog. Is it the main window of the application or is it a secondary window?

    CDialog::OnClose is going to destroy the window. I'm sure thats not what you want to do.


    Edit : This link may help. http://www.codeproject.com/KB/shell/systemtray.aspx
    it is the main window created modally, why is that so important?

    the problem is that CDialog::OnClose() function does something which i don't know (i wish i knew), i deleted that line to prevent the window from closing and it probably expects the window to be closed which isn't, thats why clicking the window from the taskbar won't minimize it anymore..

    edit: and by that i mean LEFT CLICKING the window from the taskbar not right clicking - select minimize menu that never has a problem and always works, its just that left clicking it won't minimize it anymore

    edit2: sorry that link doesn't help because my problem is about using ShowWindow(SW_HIDE) line code in the WM_CLOSE event of the dialog and deleting the CDialog::OnClose() line from it (which seems to not be a good idea, because it does some important things i don't know about, thats why on a double click event on a system tray icon for example, showing the window and then left clicking the window from the taskbar won't minimize it anymore, it probably expects the window to be closed or something, it is closed by right clicking the window from the taskbar - Close)
    Last edited by eXistenZ; 09-04-2008 at 02:30 PM.

  12. #12
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    The dialog creation was important because I couldn't reproduce your problem. I was trying to help, but couldn't without all the information.

    The link could help because it is about sending a window to the system tray and re-opening the window from the tray icon. I looked at the code and it works. Again trying to help.

  13. #13
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    Quote Originally Posted by DaveH View Post
    The dialog creation was important because I couldn't reproduce your problem. I was trying to help, but couldn't without all the information.

    The link could help because it is about sending a window to the system tray and re-opening the window from the tray icon. I looked at the code and it works. Again trying to help.
    i wasn't trying to be mean, sorry if i made you think that :P

    im just having a lot of problems and it never ends

    by the way my application doesn't hide or go to tray when i click the minimize button, only when i click the close button

    thanks

  14. #14
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Quote Originally Posted by eXistenZ View Post
    it is the main window created modally, why is that so important?
    Because MFC calls CDialog::EndDialog() on modal dialogs but calls an over-ride to CWnd::OnClose() for modeless ones?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  15. #15
    Registered User
    Join Date
    Dec 2004
    Posts
    103
    Quote Originally Posted by novacain View Post
    Because MFC calls CDialog::EndDialog() on modal dialogs but calls an over-ride to CWnd::OnClose() for modeless ones?
    oh sorry then, i didn't know about that

    i still tested on both modeless and modal dialogs and it is the same problem and i handle only WM_CLOSE on them

    thanks

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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