<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[TrayIcon Menue]]></title><description><![CDATA[<p>Moin, ich weiß nicht warum, aber mein Menue wird nicht erzeugt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /><br />
hoffe ihr steigt da durch. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<pre><code>// Main.cpp
#include	&lt;windows.h&gt;
#include    &lt;windowsx.h&gt;
#include	&lt;shellapi.h&gt;
#include    &lt;iostream.h&gt;

#include    &quot;CpuLoad.h&quot;
#include    &quot;MinimizeToTray.h&quot;

struct sAuslastung
{
    int CpuEins;
    int CpuZwei;
    int CpuDrei;
    int CpuVier;
    int Ram;
}Auslastung;

int main()
{
    HWND hwnd = GetConsoleHwnd();
    MSG messages;

    minimize(hwnd);

    while(GetMessage (&amp;messages, NULL, 0, 0))
    {
        TranslateMessage(&amp;messages);
        DispatchMessage(&amp;messages);

        CpuUpdate();

        Sleep(1000);

        Auslastung.CpuEins = CpuLoad(0);
        Auslastung.CpuZwei = CpuLoad(1);
        cout &lt;&lt; Auslastung.CpuZwei;
       // Auslastung.CpuDrei = CpuLoad(2);
       // Auslastung.CpuVier = CpuLoad(3);

        MEMORYSTATUS lpBuffer;
        lpBuffer.dwLength = sizeof(MEMORYSTATUS);
        GlobalMemoryStatus (&amp;lpBuffer);

        Auslastung.Ram = lpBuffer.dwMemoryLoad;

        //Ausgabe
    }

    CpuExit();

    return 0;
}
// Ende Main.cpp
</code></pre>
<pre><code>// MinimizeToTray.h

#ifndef     _TRAY_H_
#define     _TRAY_H_

#include    &lt;windowsx.h&gt;
#include	&lt;windows.h&gt;
#include	&lt;shellapi.h&gt;

HWND GetConsoleHwnd();
int minimize(HWND hwnd);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

#define     IDI_ICON        0
#define     IDI_TRAYICON    1
#define     IDM_TRAYEXIT    2
#define     IDM_TRAYABOUT   3

#endif

//Ende header
</code></pre>
<pre><code>//MinimizeToTray.cpp
#include &quot;MinimizeToTray.h&quot;

HWND GetConsoleHwnd()
   {
       #define MY_BUFSIZE 1024 // Buffer size for console window titles.
       HWND hwnd;         // This is what is returned to the caller.

       char pszNewWindowTitle[MY_BUFSIZE];
       char pszOldWindowTitle[MY_BUFSIZE];

       GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
       wsprintf(pszNewWindowTitle,&quot;%d/%d&quot;, GetTickCount(), GetCurrentProcessId());
       SetConsoleTitle(pszNewWindowTitle);
       Sleep(40);
       hwnd=FindWindow(NULL, pszNewWindowTitle);
       SetConsoleTitle(pszOldWindowTitle);

       return(hwnd);
   }

int minimize(HWND hwnd)
{
    NOTIFYICONDATA nid = { 0 };
    nid.cbSize = sizeof(NOTIFYICONDATA); //this helps the OS determine stuff. (I have no idea, but it is necessary.
    nid.hWnd = hwnd; //the hWnd and uID members allow the OS to uniquely identify your icon. One window (the hWnd) can have more than one icon, as long as they have unique uIDs.
    nid.uID = IDI_TRAYICON; //sorry, had forgotten this in my original example. but without, the function probably wouldn't work
    nid.uFlags = //some flags that determine the tray's behavior:
        NIF_MESSAGE
        | NIF_ICON //we're adding an icon
        | NIF_TIP;
    nid.uCallbackMessage = (WM_USER + 1); //this message must be handled in hwnd's window procedure. more info below.
    nid.hIcon = (HICON)LoadImage( //load up the icon:
        GetModuleHandle(NULL), //get the HINSTANCE to this program
        &quot;CPU.ico&quot;,
        IMAGE_ICON, //tells the versatile LoadImage function that we are loading an icon
        16, 16, //x and y values. we want a 16x16-pixel icon for the tray.
        LR_LOADFROMFILE);
    strcpy (nid.szTip, &quot;Dies ist die In-Tray .EXE der Projektdatei&quot;);
    Shell_NotifyIcon(NIM_ADD, &amp;nid);
    //ShowWindow(hwnd, SW_HIDE);

    return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    POINT pt;
    switch(message)
    {
        case (WM_USER + 1):
        {
            if (wParam != IDI_TRAYICON) break; //Falsches ICON
            if (lParam == WM_LBUTTONUP) //Left Button UP
            {
                //BallonTip
                break;
            }
            else if (lParam == WM_RBUTTONUP) //Right Button UP
            {
                SetForegroundWindow(hWnd);

                HMENU TrayMenu = NULL;
                TrayMenu = CreatePopupMenu();

                AppendMenu(TrayMenu, MF_STRING, IDM_TRAYEXIT, &quot;Exit&quot;);
                AppendMenu(TrayMenu, MF_STRING, IDM_TRAYABOUT, &quot;About&quot;);

                GetCursorPos(&amp;pt);

                UINT clicked = TrackPopupMenu(TrayMenu, TPM_RETURNCMD | TPM_NONOTIFY /*don't send me WM_COMMAND messages about this window, instead return the identifier of the clicked menu item*/, pt.x, pt.y, 0, hWnd, NULL); //display the menu. you MUST #include &lt;windowsx.h&gt; to use those two macros.
                SendMessage(hWnd, WM_NULL, 0, 0); //send benign message to window to make sure the menu goes away.

                if (clicked == IDM_TRAYEXIT) PostQuitMessage(0);
                else if (clicked == IDM_TRAYABOUT) MessageBox(hWnd, &quot;Tray Example: Demonstrates minimizing a window to the tray.&quot;, &quot;About Tray Example&quot;, MB_OK | MB_ICONINFORMATION);
            }
            break;
        }
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}

//Ende MinimizeToTray.cpp
</code></pre>
<p>Ich hab einfach mal fast alles hier reingezogen. Mein Problem ist, dass ich kein Menue erzeugen kann. Ich glaube dass der fehler in der Callback funktion liegt. Aber vllt. liege ich auch falsch.<br />
Hoffe mir kann einer helfen</p>
<p>mfg</p>
<p>CMW</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/221754/trayicon-menue</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 23:11:12 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/221754.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Sep 2008 20:57:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to TrayIcon Menue on Tue, 02 Sep 2008 21:01:39 GMT]]></title><description><![CDATA[<p>Moin, ich weiß nicht warum, aber mein Menue wird nicht erzeugt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /><br />
hoffe ihr steigt da durch. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
<pre><code>// Main.cpp
#include	&lt;windows.h&gt;
#include    &lt;windowsx.h&gt;
#include	&lt;shellapi.h&gt;
#include    &lt;iostream.h&gt;

#include    &quot;CpuLoad.h&quot;
#include    &quot;MinimizeToTray.h&quot;

struct sAuslastung
{
    int CpuEins;
    int CpuZwei;
    int CpuDrei;
    int CpuVier;
    int Ram;
}Auslastung;

int main()
{
    HWND hwnd = GetConsoleHwnd();
    MSG messages;

    minimize(hwnd);

    while(GetMessage (&amp;messages, NULL, 0, 0))
    {
        TranslateMessage(&amp;messages);
        DispatchMessage(&amp;messages);

        CpuUpdate();

        Sleep(1000);

        Auslastung.CpuEins = CpuLoad(0);
        Auslastung.CpuZwei = CpuLoad(1);
        cout &lt;&lt; Auslastung.CpuZwei;
       // Auslastung.CpuDrei = CpuLoad(2);
       // Auslastung.CpuVier = CpuLoad(3);

        MEMORYSTATUS lpBuffer;
        lpBuffer.dwLength = sizeof(MEMORYSTATUS);
        GlobalMemoryStatus (&amp;lpBuffer);

        Auslastung.Ram = lpBuffer.dwMemoryLoad;

        //Ausgabe
    }

    CpuExit();

    return 0;
}
// Ende Main.cpp
</code></pre>
<pre><code>// MinimizeToTray.h

#ifndef     _TRAY_H_
#define     _TRAY_H_

#include    &lt;windowsx.h&gt;
#include	&lt;windows.h&gt;
#include	&lt;shellapi.h&gt;

HWND GetConsoleHwnd();
int minimize(HWND hwnd);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

#define     IDI_ICON        0
#define     IDI_TRAYICON    1
#define     IDM_TRAYEXIT    2
#define     IDM_TRAYABOUT   3

#endif

//Ende header
</code></pre>
<pre><code>//MinimizeToTray.cpp
#include &quot;MinimizeToTray.h&quot;

HWND GetConsoleHwnd()
   {
       #define MY_BUFSIZE 1024 // Buffer size for console window titles.
       HWND hwnd;         // This is what is returned to the caller.

       char pszNewWindowTitle[MY_BUFSIZE];
       char pszOldWindowTitle[MY_BUFSIZE];

       GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
       wsprintf(pszNewWindowTitle,&quot;%d/%d&quot;, GetTickCount(), GetCurrentProcessId());
       SetConsoleTitle(pszNewWindowTitle);
       Sleep(40);
       hwnd=FindWindow(NULL, pszNewWindowTitle);
       SetConsoleTitle(pszOldWindowTitle);

       return(hwnd);
   }

int minimize(HWND hwnd)
{
    NOTIFYICONDATA nid = { 0 };
    nid.cbSize = sizeof(NOTIFYICONDATA); //this helps the OS determine stuff. (I have no idea, but it is necessary.
    nid.hWnd = hwnd; //the hWnd and uID members allow the OS to uniquely identify your icon. One window (the hWnd) can have more than one icon, as long as they have unique uIDs.
    nid.uID = IDI_TRAYICON; //sorry, had forgotten this in my original example. but without, the function probably wouldn't work
    nid.uFlags = //some flags that determine the tray's behavior:
        NIF_MESSAGE
        | NIF_ICON //we're adding an icon
        | NIF_TIP;
    nid.uCallbackMessage = (WM_USER + 1); //this message must be handled in hwnd's window procedure. more info below.
    nid.hIcon = (HICON)LoadImage( //load up the icon:
        GetModuleHandle(NULL), //get the HINSTANCE to this program
        &quot;CPU.ico&quot;,
        IMAGE_ICON, //tells the versatile LoadImage function that we are loading an icon
        16, 16, //x and y values. we want a 16x16-pixel icon for the tray.
        LR_LOADFROMFILE);
    strcpy (nid.szTip, &quot;Dies ist die In-Tray .EXE der Projektdatei&quot;);
    Shell_NotifyIcon(NIM_ADD, &amp;nid);
    //ShowWindow(hwnd, SW_HIDE);

    return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    POINT pt;
    switch(message)
    {
        case (WM_USER + 1):
        {
            if (wParam != IDI_TRAYICON) break; //Falsches ICON
            if (lParam == WM_LBUTTONUP) //Left Button UP
            {
                //BallonTip
                break;
            }
            else if (lParam == WM_RBUTTONUP) //Right Button UP
            {
                SetForegroundWindow(hWnd);

                HMENU TrayMenu = NULL;
                TrayMenu = CreatePopupMenu();

                AppendMenu(TrayMenu, MF_STRING, IDM_TRAYEXIT, &quot;Exit&quot;);
                AppendMenu(TrayMenu, MF_STRING, IDM_TRAYABOUT, &quot;About&quot;);

                GetCursorPos(&amp;pt);

                UINT clicked = TrackPopupMenu(TrayMenu, TPM_RETURNCMD | TPM_NONOTIFY /*don't send me WM_COMMAND messages about this window, instead return the identifier of the clicked menu item*/, pt.x, pt.y, 0, hWnd, NULL); //display the menu. you MUST #include &lt;windowsx.h&gt; to use those two macros.
                SendMessage(hWnd, WM_NULL, 0, 0); //send benign message to window to make sure the menu goes away.

                if (clicked == IDM_TRAYEXIT) PostQuitMessage(0);
                else if (clicked == IDM_TRAYABOUT) MessageBox(hWnd, &quot;Tray Example: Demonstrates minimizing a window to the tray.&quot;, &quot;About Tray Example&quot;, MB_OK | MB_ICONINFORMATION);
            }
            break;
        }
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
}

//Ende MinimizeToTray.cpp
</code></pre>
<p>Ich hab einfach mal fast alles hier reingezogen. Mein Problem ist, dass ich kein Menue erzeugen kann. Ich glaube dass der fehler in der Callback funktion liegt. Aber vllt. liege ich auch falsch.<br />
Hoffe mir kann einer helfen</p>
<p>mfg</p>
<p>CMW</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1575596</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1575596</guid><dc:creator><![CDATA[CMW]]></dc:creator><pubDate>Tue, 02 Sep 2008 21:01:39 GMT</pubDate></item><item><title><![CDATA[Reply to TrayIcon Menue on Wed, 03 Sep 2008 06:10:44 GMT]]></title><description><![CDATA[<p>Deine WndProc wird doch gar nicht benutzt! Woher glabst Du denn, dass die WndProc einen Bezug zu Deinem System bekommt?</p>
<p>Dein grndsätzlicher Fehler: Du hast eine Consolen Applikation gebaut und keine Windows Anwendung!</p>
<p>Und versuche sagr nicht: Du kannst ein Consolen Fenster nicht subclassen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1575656</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1575656</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 03 Sep 2008 06:10:44 GMT</pubDate></item><item><title><![CDATA[Reply to TrayIcon Menue on Wed, 03 Sep 2008 08:16:11 GMT]]></title><description><![CDATA[<p>d.h. wenn ich das ganze mit Borland Trubo c++ als VCL anwendung schreibe, funktioniert der code?<br />
2. Frage wie schreibe ich dafür die messagemap?</p>
<p>danke schonmal für die antwort</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1575728</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1575728</guid><dc:creator><![CDATA[CMW]]></dc:creator><pubDate>Wed, 03 Sep 2008 08:16:11 GMT</pubDate></item><item><title><![CDATA[Reply to TrayIcon Menue on Wed, 03 Sep 2008 08:47:03 GMT]]></title><description><![CDATA[<p>Ich kann Dir nur sagen, dass Du eine Windows-UI Applikation brauchst, wie da sin VS geht kann ich Dir sagen!</p>
<p>Ich habe von so einem Kram wie &quot;Borland&quot; keine Ahnung und ich will es auch nicht wissen... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1575742</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1575742</guid><dc:creator><![CDATA[Martin Richter]]></dc:creator><pubDate>Wed, 03 Sep 2008 08:47:03 GMT</pubDate></item></channel></rss>