Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Where to Put ShowWindow

Where to Put ShowWindow

Scheduled Pinned Locked Moved C / C++ / MFC
comwindows-adminhelplearning
13 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GauranG Shah
    wrote on last edited by
    #1

    Hello Friends, I want my application to run in the background. And it displays only when some cliked in taskbar icon. But I am not getting where to put the ShowWindow(hWnd,SW_HIDE); to hide the window.so that it doesn't appeare when It is loaded at startup.(I have set the registry, so that it runs at startup). I have tryed to put it in following places but getting errors. case WM_INITDIALOG: { //If I use the ShowWindow in the begining of the WM_INITDIALOG. //I am geeting 02 as Error Code. Which Means "The system cannot find the file specified. " if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); ... ... //If I use the ShowWindow at the End of the WM_INITDIALOG. //I am geeting 170 as Error Code. Which Means "The requested resource is in use." if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); }

    [ Screen Capture ][ Tool Tip ]

    H C T M D 5 Replies Last reply
    0
    • G GauranG Shah

      Hello Friends, I want my application to run in the background. And it displays only when some cliked in taskbar icon. But I am not getting where to put the ShowWindow(hWnd,SW_HIDE); to hide the window.so that it doesn't appeare when It is loaded at startup.(I have set the registry, so that it runs at startup). I have tryed to put it in following places but getting errors. case WM_INITDIALOG: { //If I use the ShowWindow in the begining of the WM_INITDIALOG. //I am geeting 02 as Error Code. Which Means "The system cannot find the file specified. " if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); ... ... //If I use the ShowWindow at the End of the WM_INITDIALOG. //I am geeting 170 as Error Code. Which Means "The requested resource is in use." if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); }

      [ Screen Capture ][ Tool Tip ]

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Why you dont set your program to minimize when its running?

      1 Reply Last reply
      0
      • G GauranG Shah

        Hello Friends, I want my application to run in the background. And it displays only when some cliked in taskbar icon. But I am not getting where to put the ShowWindow(hWnd,SW_HIDE); to hide the window.so that it doesn't appeare when It is loaded at startup.(I have set the registry, so that it runs at startup). I have tryed to put it in following places but getting errors. case WM_INITDIALOG: { //If I use the ShowWindow in the begining of the WM_INITDIALOG. //I am geeting 02 as Error Code. Which Means "The system cannot find the file specified. " if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); ... ... //If I use the ShowWindow at the End of the WM_INITDIALOG. //I am geeting 170 as Error Code. Which Means "The requested resource is in use." if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); }

        [ Screen Capture ][ Tool Tip ]

        C Offline
        C Offline
        chandu004
        wrote on last edited by
        #3

        GauranG33 wrote:

        .(I have set the registry, so that it runs at startup).

        can you please guide me how you have achieved this. this is great because, i have been trying this since a couple of months but in vain. and to your question, i have temporary solution. 1.set the dialog properties in such a way that, it does not have any border. so that, it will be always running in the background, and gets displayed only if the user clicks the icon in the taskbar. 2.if you know, how to track the GetFocus and Lost Focus events, then, i can suggest a better solution. gud luck.

        Suggestion to the members: prefix your main thread subject with [SOLVED] if it is solved. chandu.

        1 Reply Last reply
        0
        • G GauranG Shah

          Hello Friends, I want my application to run in the background. And it displays only when some cliked in taskbar icon. But I am not getting where to put the ShowWindow(hWnd,SW_HIDE); to hide the window.so that it doesn't appeare when It is loaded at startup.(I have set the registry, so that it runs at startup). I have tryed to put it in following places but getting errors. case WM_INITDIALOG: { //If I use the ShowWindow in the begining of the WM_INITDIALOG. //I am geeting 02 as Error Code. Which Means "The system cannot find the file specified. " if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); ... ... //If I use the ShowWindow at the End of the WM_INITDIALOG. //I am geeting 170 as Error Code. Which Means "The requested resource is in use." if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); }

          [ Screen Capture ][ Tool Tip ]

          T Offline
          T Offline
          Tony Hill
          wrote on last edited by
          #4

          Try reading this page http://www.codeproject.com/dialog/dlgboxtricks.asp[^]

          1 Reply Last reply
          0
          • G GauranG Shah

            Hello Friends, I want my application to run in the background. And it displays only when some cliked in taskbar icon. But I am not getting where to put the ShowWindow(hWnd,SW_HIDE); to hide the window.so that it doesn't appeare when It is loaded at startup.(I have set the registry, so that it runs at startup). I have tryed to put it in following places but getting errors. case WM_INITDIALOG: { //If I use the ShowWindow in the begining of the WM_INITDIALOG. //I am geeting 02 as Error Code. Which Means "The system cannot find the file specified. " if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); ... ... //If I use the ShowWindow at the End of the WM_INITDIALOG. //I am geeting 170 as Error Code. Which Means "The requested resource is in use." if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); }

            [ Screen Capture ][ Tool Tip ]

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            Why not just create the main window without the WS_VISIBLE flag so you don't have to worry about hiding it? Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            N 1 Reply Last reply
            0
            • G GauranG Shah

              Hello Friends, I want my application to run in the background. And it displays only when some cliked in taskbar icon. But I am not getting where to put the ShowWindow(hWnd,SW_HIDE); to hide the window.so that it doesn't appeare when It is loaded at startup.(I have set the registry, so that it runs at startup). I have tryed to put it in following places but getting errors. case WM_INITDIALOG: { //If I use the ShowWindow in the begining of the WM_INITDIALOG. //I am geeting 02 as Error Code. Which Means "The system cannot find the file specified. " if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); ... ... //If I use the ShowWindow at the End of the WM_INITDIALOG. //I am geeting 170 as Error Code. Which Means "The requested resource is in use." if( ! ShowWindow(hWndDlg,SW_HIDE) ) //Hide the main window dError = GetLastError(); }

              [ Screen Capture ][ Tool Tip ]

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              See here.


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              G 2 Replies Last reply
              0
              • D David Crow

                See here.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                G Offline
                G Offline
                GauranG Shah
                wrote on last edited by
                #7

                Hey Thanx David. I see the Solution you have suggested, but the problem is the solution is for MFC Application while I am using Win32 API . Can You help me with this. ??? I have tried somthing like this. but the Same thing. Errors, I have Taken the Global Boolean flag First. But dont know where to initialize it to True. So I have initialize it in WM_INITDIALOG.

                case WM_WINDOWPOSCHANGING:
                if(First)
                {
                if ( ! ShowWindow(hWndDlg,SW_HIDE) )
                dError = GetLastError();
                First = FALSE;
                }
                break;

                case WM_INITDIALOG :

                 First  = TRUE;
                  ...
                  ...
                

                break;

                [ Screen Capture ][ Tool Tip ]

                D 1 Reply Last reply
                0
                • M Mark Salsbery

                  Why not just create the main window without the WS_VISIBLE flag so you don't have to worry about hiding it? Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  N Offline
                  N Offline
                  Nelek
                  wrote on last edited by
                  #8

                  If this solution is taken... The controls can not be used while the window is invisible, but if you use other things as triggers (for example a timer) then the code will be called anyways. Am I right? But if you make the WS_VISIBLE away, and in some conditions need the window another time... can you make it visible with the ShowWindow (TRUE) ??? Or won't be posible because the property has not been set?

                  Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you ;)

                  M 1 Reply Last reply
                  0
                  • D David Crow

                    See here.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    G Offline
                    G Offline
                    GauranG Shah
                    wrote on last edited by
                    #9

                    I have got the Idea to do do this. I am using the timer in WM_INIT for about 100 msec. and in the WM_TIMER I am using ShowWinow() to hide the Dialog. Currently It is working fine. But I just want to know will this work all the time. Or there will be the case it can fail. the Code I am using is as follows

                    case WM_TIMER:
                    ShowWindow(hWndDlg, FALSE);
                    KillTimer(hWndDlg,0);

                    	break;
                    

                    case WM_INITDIALOG:
                    ...
                    ...
                    SetTimer(hWndDlg,0,100,0);
                    break;

                    [ Screen Capture ][ Tool Tip ]

                    M 1 Reply Last reply
                    0
                    • G GauranG Shah

                      Hey Thanx David. I see the Solution you have suggested, but the problem is the solution is for MFC Application while I am using Win32 API . Can You help me with this. ??? I have tried somthing like this. but the Same thing. Errors, I have Taken the Global Boolean flag First. But dont know where to initialize it to True. So I have initialize it in WM_INITDIALOG.

                      case WM_WINDOWPOSCHANGING:
                      if(First)
                      {
                      if ( ! ShowWindow(hWndDlg,SW_HIDE) )
                      dError = GetLastError();
                      First = FALSE;
                      }
                      break;

                      case WM_INITDIALOG :

                       First  = TRUE;
                        ...
                        ...
                      

                      break;

                      [ Screen Capture ][ Tool Tip ]

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      GauranG33 wrote:

                      I have tried somthing like this. but the Same thing. Errors,

                      Because you did not remove the SWP_SHOWWINDOW flag.


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      1 Reply Last reply
                      0
                      • N Nelek

                        If this solution is taken... The controls can not be used while the window is invisible, but if you use other things as triggers (for example a timer) then the code will be called anyways. Am I right? But if you make the WS_VISIBLE away, and in some conditions need the window another time... can you make it visible with the ShowWindow (TRUE) ??? Or won't be posible because the property has not been set?

                        Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you ;)

                        M Offline
                        M Offline
                        Mark Salsbery
                        wrote on last edited by
                        #11

                        It just creates the window hidden.  It won't get any messages from user like mouse messages because it's not visible.  It will still get messages from timers or messages you send to it. It's just hidden...ShowWindow(SW_SHOW) will make it visible. Hidden windows are common.  The CSocketWnd used by the CAsyncSocket class is an example of a hidden window. Mark

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        N 1 Reply Last reply
                        0
                        • G GauranG Shah

                          I have got the Idea to do do this. I am using the timer in WM_INIT for about 100 msec. and in the WM_TIMER I am using ShowWinow() to hide the Dialog. Currently It is working fine. But I just want to know will this work all the time. Or there will be the case it can fail. the Code I am using is as follows

                          case WM_TIMER:
                          ShowWindow(hWndDlg, FALSE);
                          KillTimer(hWndDlg,0);

                          	break;
                          

                          case WM_INITDIALOG:
                          ...
                          ...
                          SetTimer(hWndDlg,0,100,0);
                          break;

                          [ Screen Capture ][ Tool Tip ]

                          M Offline
                          M Offline
                          Mark Salsbery
                          wrote on last edited by
                          #12

                          I'm still wondering why this has to be so complicated. If you never show the window to begin with then there's no reason to go through all of this to hide it. Mark

                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                          1 Reply Last reply
                          0
                          • M Mark Salsbery

                            It just creates the window hidden.  It won't get any messages from user like mouse messages because it's not visible.  It will still get messages from timers or messages you send to it. It's just hidden...ShowWindow(SW_SHOW) will make it visible. Hidden windows are common.  The CSocketWnd used by the CAsyncSocket class is an example of a hidden window. Mark

                            Mark Salsbery Microsoft MVP - Visual C++ :java:

                            N Offline
                            N Offline
                            Nelek
                            wrote on last edited by
                            #13

                            Ok, thank you.

                            Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you ;)

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups