Console Window Control

This is a discussion on Console Window Control within the C++ Programming forums, part of the General Programming Boards category; Hi All, New to this so if I screw up, sorry My question: I want to know if there is ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    1

    Console Window Control

    Hi All,

    New to this so if I screw up, sorry

    My question: I want to know if there is a way to:

    1. Remove the "X" from the upper right corner of a console window so that a user cannot close it from there. OR

    2. Make a console window start minimized such that nothing shows in the task bar but an icon shows in the system tray.

    Anyone have any ideas/experience with this? I've searched MSDN and all over the place and haven't found anything. I'm hoping that's just because I haven't found the right resource yet and not that it's just not possible to do.

    Thanks!

    David

  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    ive never seen a console window put into the system tray,
    but that doesnt mean its impossible, i have seen
    a window program without the window (errr)
    umm i mean they never created a window for it so it just ran
    without a taskbar entry or a system tray entry.
    The onyl place you could find it was in the task manager.

    If it possible for your program you could try to create it
    in a windows specfic application and just never go
    about creating a window.

    Im not to sure about everything that went into this
    im just going off what i saw. Hopefully will
    put you in the right direction, i have visited these boards
    for a while now, prolly for about a year or two before i
    actually registered and i cant remember any good responses
    to this question, which i think was asked a few times before.

    I did do a board search trying to come up with some good
    stuff for you but i couldnt find anything. So good luck,
    i hoping if you understand enough or have done soem winAPI
    application that you might beable to get somewhere with this.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,646
    For system tran icons:
    The Taskbar -> Using the Taskbar
    Or search these boards with "Shell_NotifyIcon".
    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    HWND MyGetConsoleWindow()
    {
        // NOTE: if you have 2000/XP and latest Platform SDK, then you can simply 
        //       call GetConsoleWindow()
        char title[MAX_PATH];
    
        if (GetConsoleTitleA(title, sizeof(title)))
        {
            return FindWindowA(NULL, title);
        }//if
    
        return 0;
    }//MyGetConsoleWindow
    
    bool HideConsoleWindow()
    {
        HWND hwnd;
    
        if ((hwnd = MyGetConsoleWindow()) &&
            ShowWindow(hwnd, SW_HIDE))
        {
            return true;        
        }//if
    
        return false;
    }//HideConsoleWindow
    
    bool DisableSystemMenuClose()
    {
        HWND hwnd;
        HMENU sysmenu;
        
        if ((hwnd = MyGetConsoleWindow()) &&
            (sysmenu = GetSystemMenu(hwnd, FALSE)) &&
            DeleteMenu(sysmenu, SC_CLOSE, MF_BYCOMMAND))
        {
            return true;
        }//if
    
        return false;
    }//DisableSystemMenuClose
    
    int main()
    {
        if (!DisableSystemMenuClose())
        {
            cerr << "DisableSystemMenuClose() failed, ec = " 
                 << GetLastError() << endl;
            return 1;
        }//if
    
        cout << "Just try and close me!" << endl;
    
        Sleep(10 * 1000);
        
        if (!HideConsoleWindow())
        {
            cerr << "HideConsoleWindow() failed, ec = " 
                 << GetLastError() << endl;
            return 2;
        }//if
    
        MessageBoxA(NULL, "You can't see me!", "Ha-Ha", MB_OK);
    
        return 0;
    }//main
    gg

  4. #4
    Banned
    Join Date
    Jun 2005
    Posts
    594
    wow that is cool code, very nice post

  5. #5
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374
    Hey that's nice

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 07:14 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 05:23 AM
  4. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  5. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 04:36 PM

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