Archived

This topic is now archived and is closed to further replies.

Tonic151

Win console, Minimize to System Tray

Recommended Posts

Tonic151    128
Hi,, i do a lot of programming in normal console mode.. and i'm looking for some working examples of how to minimize my program to teh system tray.. i've done a bunch of search's but all i come up with is needing windows message handling.. and MFC stuff.. would anyone have anything that specificly works for a console app.. i'd be mucho apprecieated!!' I'm programming in a mix of c/c++ using DevC++ g++ 2.59.3 compiler... [edited by - Tonic151 on August 31, 2003 6:57:33 PM]

Share this post


Link to post
Share on other sites
C-Junkie    1099
No, for a console app.

For a windows app, it involves hiding your windows and creating an icon in the tray with something like ShellNotifyIcon or something

Share this post


Link to post
Share on other sites
Tonic151    128
quote:
Original post by C-Junkie
No, for a console app.

For a windows app, it involves hiding your windows and creating an icon in the tray with something like ShellNotifyIcon or something


dam theres no hack or anything of the sort to acomplish this?? anyone else ever try to get this working?

Share this post


Link to post
Share on other sites
Tonic151    128
quote:
Original post by DukeAtreides076
I think if you have XP or 2k you can get a HANDLE to the console window...and then you can hide it.


i''ve looked into it. but it needs a windows message handler to get the systemtray icon clicks.. any god way about writting one seperate from winmain since i use main()...

Share this post


Link to post
Share on other sites
Colin Jeanne    1114
Use GetConsoleWindow() to retrieve the HWND to the console then use GetWindowLongPtr() to subclass the console. Handle the tray notifications from your custom message handler and call CallWindowProc() instead of DefWindowProc() at the end.


Colin Jeanne | Invader''s Realm

Share this post


Link to post
Share on other sites
LessBread    1415
Here''s some code for getting the handle to the console window on W9x. YMMV



////////////////////////////////////////////////////////////////////////

// G E T C O N S O L E H A N D L E 9 X ------------------------------

HWND __stdcall GetConsoleWindow9X(void)
{

HWND hConWnd = NULL;
WIN32_FIND_DATA fd;
HANDLE ff;

static TCHAR szTempTitle[] = TEXT("MyWin9xConsole");
static TCHAR szTempString[MAX_PATH];

if( GetConsoleTitle(szTempString, sizeof(szTempString)/sizeof(TCHAR) ) > 0 )
{
SetConsoleTitle(szTempTitle);
hConWnd = FindWindow(TEXT("tty"), szTempTitle);
SetConsoleTitle(szTempString);
}

// fallback method - could be written differently

if ( !hConWnd )
{
ZeroMemory(&szTempTitle, sizeof(szTempTitle) );
if ( GetModuleFileName(NULL, szTempString, MAX_PATH) > 0 )
{
ff = FindFirstFile(szTempString, &fd);
if ( ff != INVALID_HANDLE_VALUE )
{
ZeroMemory(&szTempString, sizeof(szTempString) );
for ( int i = 0; fd.cFileName[i] != ''.''; i++ )
{
szTempString[i] = fd.cFileName[i];
}
hConWnd = FindWindow(TEXT("tty"), szTempString);
}
FindClose(ff);
}
}
return( hConWnd );
}

Share this post


Link to post
Share on other sites