-
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
-
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.
-
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
-
wow that is cool code, very nice post
-