Hiding it.

This is a discussion on Hiding it. within the C++ Programming forums, part of the General Programming Boards category; I'm relatively new to programming and such but I'm looking for just a quick fix (not for school or anything, ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    8

    Hiding it.

    I'm relatively new to programming and such but I'm looking for just a quick fix (not for school or anything, I don't go to college or anything ). I'm looking to find out how to hide the main dosish window that pops up. I'd like to keep it hidden from view or something if possible. Any help would be greatly appreciated as soon as possible.

    BTW: I'm using [i]system("app.exe -param"); for launching an application within the application. It's not reading anything from the launched application either. I'm kinda looking for the application to exit after executing the other application if it's possible.
    Last edited by Sintax; 11-15-2004 at 01:12 PM.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,200
    Just a question: why would you like the commandprompt not to show up?? This sounds fishy to me.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    8
    lol.. Actually, after posting this, I thought "man, I sound like I'm creating a virus or something." heh... It's not quite like that. Actually, there's this game which I usually launch through a shortcut but to switch between online and offline mode, you have to rename a certain file, so I just used C++ to automate it but the window stays in view and I'd rather have it hidden.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    What game is it?

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    8
    It's actually a server file for Battlefield 1942. When I play at LANs, I usually set up with different settings that me and my friends enjoy.

  6. #6
    Banned
    Join Date
    Oct 2004
    Posts
    250
    if you are trying to hide a window use
    Code:
    ShowWindow(hwnd,SW_HIDE,0,0);
    that will stop the window been shown when you press clt alt dlt but i dont know how to hide a process just yet

  7. #7
    Registered User
    Join Date
    Nov 2004
    Posts
    8
    What header would you need to include to use ShowWindow()?

  8. #8
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    windows.h - it's part of the Win32 SDK - your compiler may or may not have that library.

  9. #9
    Registered User
    Join Date
    Nov 2004
    Posts
    8
    heh.. It appears to but tells me hwnd is unidentified.

    [EDIT]Fixed I guess
    I do get a problem where I can't use ShowWindow(hwnd,SW_HIDE,0,0) as it says ShowWindow doesn't take 4 parameters.
    Last edited by Sintax; 11-15-2004 at 03:10 PM.

  10. #10
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    I just did a search of the board for "hide and console" (without the quotes) in the C++ forum. Several interesting threads appeared with potential solutions (including more information on the problem you are having here). Try reading those.

  11. #11
    Registered User
    Join Date
    Nov 2004
    Posts
    8
    Will check right now. Thanx.

  12. #12
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You're going to need to do this entire program in Win32, which I don't recommend (since you hadn't even heard of the API) if there is another option. I don't think there is, however.

  13. #13
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    This will do the trick:
    Code:
    ShowWindow(GetConsoleWindow(), SW_HIDE);
    Just remember to include <windows.h>.
    Last edited by Sang-drax; 11-15-2004 at 03:13 PM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  14. #14
    #include<xErath.h> xErath's Avatar
    Join Date
    Jun 2004
    Posts
    722
    Well, you're new to programming, but copy paste doesn't hurt anybody... so if you're interested.

    It could be better like this (quoted from the FAQ) :
    Code:
    #include <windows.h> 
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
    {
      char szPath[] = PUT_YOUR_EXE_NAME_HERE;
      PROCESS_INFORMATION pi;  //Gives info on the thread and..
                               //..process for the new process
      STARTUPINFO si;          //Defines how to start the program
    
      ZeroMemory(&si,sizeof(si)); //Zero the STARTUPINFO struct
      si.cb = sizeof(si);         //Must set size of structure
    
      BOOL bRet = CreateProcess(
            szPath, //Path to executable file
            NULL,   //Command string - not needed here
            NULL,   //Process handle not inherited
            NULL,   //Thread handle not inherited
            FALSE,  //No inheritance of handles
            0,      //No special flags
            NULL,   //Same environment block as this prog
            NULL,   //Current directory - no separate path
            &si,    //Pointer to STARTUPINFO
            π);   //Pointer to PROCESS_INFORMATION
    
      if(bRet == FALSE)
      {
        MessageBox(HWND_DESKTOP,"Unable to start program","",MB_OK);
        return 1;
      }
    
      CloseHandle(pi.hProcess);   //Close handle to process
      CloseHandle(pi.hThread);    //Close handle to thread
    
      return 0;
    }
    Some things you should know.
    If you want to use this example, you have to compile and link your code as a Win32 application. Don't worry, you don't have to pay any fees to MS.
    Simply open your IDE, choose a new Win32 project, or Win32 GUI application.. whatever. Just don't choose something that states library or console. Then add your source files to the project, or create new files, and copy/paste. Then compile, link and your new brand application doesn't have any console or graphical window, althouh you can easilly see the process in the Task Manager.
    The way this code is written, your application is stated and this process ends.

    If your compiler, or IDE don't have win32 libs, or you're not using windows, then.. just use the old system(...) stuff, or read throughly the FAQ entry...
    Last edited by xErath; 11-15-2004 at 05:44 PM.

  15. #15
    Banned
    Join Date
    Oct 2004
    Posts
    250
    here is a working example of using sw_hide it will hide the window mIRC
    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    int main()
    {
    	HWND hwnd = FindWindow(NULL, "mIRC");
    	ShowWindow(hwnd,SW_HIDE);
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trying to use complex.h classes, some keyword is hiding it
    By indigo0086 in forum C++ Programming
    Replies: 4
    Last Post: 02-05-2008, 10:10 PM
  2. Hiding the password
    By NoFearXD in forum C++ Programming
    Replies: 7
    Last Post: 06-30-2007, 07:20 AM
  3. help hiding text
    By mmongoose in forum C++ Programming
    Replies: 10
    Last Post: 07-17-2005, 12:40 AM
  4. Hiding a folder
    By nextstep in forum Windows Programming
    Replies: 16
    Last Post: 03-20-2005, 02:07 PM
  5. Hiding the console.
    By knave in forum C++ Programming
    Replies: 3
    Last Post: 07-10-2003, 12:19 AM

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