Console Program to Tray??????
-
Hello, I wrote simple program which one we can run via CMD on windows... it is write in Visual C++ i don't know how to do that when i start that progria, how can i run it in Background - for example in Tray icon... Can somebody help, or know that is possiable??
Thanks.
-
Oh shit I can't speak english very well but I try.
Would you that the prgram allways run in background?
If, you can use a "Windows-Programm" and not a "Console-Program".
If you have Visual Studio create a new projekt and a "Win32-Anwendung" (don' know the english word).
If you would that you can the program set in background and get it back you need WinApi too.
Maybe withFindWindow(...); ShowWindow(...);
I hope you anderstand me
-
For example
static int usage (char* basename) { printf("Work in background (TRAY ICON): %s -b\n", basename); return -1; } int main(int argc, char *argv[]) { printf(" \n TEST Program v0.1 \n \npress argument to:\n \n"); if(argc<2) { return usage(argv[0]); } else if(!strcmp(argv[1], "-b")) { [b]do STH in BAckground (Tray icon)[/b] } return 0; }
and then we run
CMDand run progrie
test.exe -b
then it is minimalise automaticaly to Tray Icon (bacgroiund)
That i Mean
-
To add an icon to the notification area:
Shell_NotifyIconTo hide and show the console:
GetConsoleWindow
ShowWindowTo receive notifications when you click the icon you need a (hidden) window:
RegisterClassEx
CreateWindowExYou need to create this window in a seperate thread so that your application can continue to run:
CreateThread
GetMessage
DispatchMessage
-
hmm, can You gave some examples??
thansk
-
Dieser Thread wurde von Moderator/in HumeSikkins aus dem Forum C++ in das Forum WinAPI verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Sorry i no nuderstand any world in Deutch...
-
That was a bot which moved your thread into an other forum...
-
Darez schrieb:
hmm, can You gave some examples??
i can give you an example if you pay me 20 €. :schland:
-
Maybe something like that... i haven't tested it yet....
#include <iostream> #include <windows.h> #include <tchar.h> #include "resource.h" bool AddTrayIcon(UINT, ::HICON, LPTSTR); int _tmain(int argc, _TCHAR* argv[]) { if (argc < 2) { if (!AddTrayIcon(11, ::LoadIcon(0, MAKEINTRESOURCE(IDI_ICON1)), _T("Test"))) return -1; ::ShowWindow(::GetConsoleWindow(), SW_HIDE); } else if(lstrcmp(argv[1], _T("-b"))) { std::cout << _T("Herzlich Willkommen!") << std::endl; } return 0; } bool AddTrayIcon(UINT nID, ::HICON hIcon, LPTSTR lpszTip) { if (!hIcon || !lpszTip) return false; ::NOTIFYICONDATA tnid; tnid.cbSize = sizeof(NOTIFYICONDATA); tnid.hWnd = ::GetConsoleWindow(); tnid.uID = nID; tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; tnid.uCallbackMessage = 0; tnid.hIcon = hIcon; lstrcpy(tnid.szTip, lpszTip); return (::Shell_NotifyIcon(NIM_ADD, &tnid) ? true : false); }
-
Hmmm no problem, thanks for help, i thought that Board it for Helping people, no money...Thanks
many thanks Devil:D
but....Compiling... main.cpp e:\project\main.cpp(620) : error C2039: 'GetConsoleWindow' : is not a member of '`global namespace'' e:\project\main.cpp(620) : error C3861: 'GetConsoleWindow': identifier not found Build log was saved at "file://e:\project\Debug\BuildLog.htm" Test - 2 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
sry ... hatte was vergessen... guck mal unter remarks bei folgendem link:
Referenzen:
GetConsoleWindow
-
Hmmm, I have got added kernel32.lib to project... and wnidows headers...
-
To compile an application that uses this function, define _WIN32_WINNT as 0x0500 or later. For more information, see Using the Windows Headers.
-
right... you should add the following:
#ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0500 #endif #include <iostream> #include <windows.h> #include <tchar.h> #include "resource.h" bool AddTrayIcon(UINT, ::HICON, LPTSTR); int _tmain(int argc, _TCHAR* argv[]) { if (argc < 2) { if (!AddTrayIcon(11, ::LoadIcon(0, MAKEINTRESOURCE(IDI_ICON1)), _T("Test"))) return -1; ::ShowWindow(::GetConsoleWindow(), SW_HIDE); } else if(lstrcmp(argv[1], _T("-b"))) { std::cout << _T("Herzlich Willkommen!") << std::endl; } return 0; } bool AddTrayIcon(UINT nID, ::HICON hIcon, LPTSTR lpszTip) { if (!hIcon || !lpszTip) return false; ::NOTIFYICONDATA tnid; tnid.cbSize = sizeof(NOTIFYICONDATA); tnid.hWnd = ::GetConsoleWindow(); tnid.uID = nID; tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; tnid.uCallbackMessage = 0; tnid.hIcon = hIcon; lstrcpy(tnid.szTip, lpszTip); return (::Shell_NotifyIcon(NIM_ADD, &tnid) ? true : false); }
-
Yes i add it and define alles
main.obj : error LNK2019: unresolved external symbol __imp__Shell_NotifyIconA@8 referenced in function "bool __cdecl AddTrayIcon(unsigned int,struct HICON__ *,char *)" (?AddTrayIcon@@YA_NIPAUHICON__@@PAD@Z) libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z) libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
i am learniing vc++
i was doing all the time on Linux and G++...
-
Linux and G++
But it is not possible to use the WinAPI Functions on a Linux machin...
Maybe you should use a windows machin and take a look at Microsoft Visual C++ 2005 Express Edition... then you only have to look into the MSDN Library ... there you will see that you have fergotten to link a special library
-
I mean that earlier i was working all the time on Linux...
now i am working and learning VC++ Expres 2005, and that program and that thread is about VC++, and i don't know what is that bug above.
-
@Darez:
I don't know how to get the console window minimized to a tray-icon, but you can try to simulate a pressed [ALT] + [TAB] key (this idea isn't pretty good if there are a lot of other windows open...). I saw example code for this (it was example code for fullscreen-mode, but it should be easy to replace the [ENTER]) in the web, but I forgot the link - sorry!
-
proggaholic
Hör auf so nen Mist zu erzählen... was soll das denn für nen unschöner Müll werden?Darez
I have just now tested my code and it functionated... You have fergotten to link a library...References:
Shell_NofifyIcon
-
Import library shell32.lib