<?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[Häufige Gui-Updates lassen GUI abstürzen]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich brauche mal wieder die Hilfe von Leuten, die mehr Ahnung von der Materie haben, als ich.</p>
<p>Ich habe ein Programm, bei dem von einer Hardware in sehr umfangreichen Maße Daten ausgelesen und teilweise live verarbeitet werden. Hierfür laufen viele Threads, wodurch der gesamte PC relativ an seinen Leistungsgrenzen ist, aber es funktioniert.</p>
<p>Nur manchmal kommt nach einiger Zeit der Messung der Zeitpunkt, dass die GUI nicht mehr aktualisiert wird oder werden kann, was nicht nur mein Programm, sondern ganz Windows betrifft.</p>
<p>Ich lasse in einem kleinen Fenster gewisse Messwerte zur Kontrolle ständig aktualisieren und neuerdings auch farblich hervorheben. Zudem blink ein Button, der anzeigt, welcher Mess-Modus gerade aktiv ist. Ich habe subjektiv das Gefühl, dass diese neuen Hervorhebungen für die deutlich schwächere GUI-Leistung ist und ich gehe davon aus, dass ich vielleicht irgendwie Speicher nicht mehr freigebe, wodurch der schon sehr beanspruchte RAM irgendwann Probleme macht.</p>
<p>Hiermit lasse ich den Button blinken, die Funktion wird halbsekündlich von einem Timer, der auch andere Aufgaben übernimmt, angestoßen:</p>
<pre><code class="language-cpp">void Klasse::SetSelectedMode(int iIDC)
{
    InvalidateRect (GetDlgItem(m_hwndDialogInfo, iRecentButtonIDC), NULL, TRUE);
    UpdateWindow(GetDlgItem(m_hwndDialogInfo, iRecentButtonIDC));

    iRecentButtonIDC = iIDC;

    HWND hStatusText = GetDlgItem(m_hwndDialogInfo, iIDC);

    RECT rect;

    if(hStatusText != NULL)
    {
        HDC hDC = GetWindowDC(hStatusText);
        GetClientRect(hStatusText, &amp;rect);

        HPEN hPen;
        if(!bActiveButtonSelected || !m_bMeasLoopThreadRunning)
        {
            hPen = CreatePen(PS_SOLID, 4 , RGB(0,205,0));
            bActiveButtonSelected = true;
        }
        else
        {
            hPen = CreatePen(PS_SOLID, 4 , ::GetSysColor(COLOR_BTNFACE));
            bActiveButtonSelected = false;
        }

        SetTextColor(hDC, RGB(0,0,255));
//        SetBkMode(hDC,TRANSPARENT); 
        PAINTSTRUCT ps;
        BeginPaint(hStatusText, &amp;ps);

        SelectObject(hDC, hPen);

        MoveToEx(hDC,rect.top+1, rect.left+1, NULL);
        LineTo(hDC,rect.right-1, rect.top+1);
        LineTo(hDC,rect.right-1, rect.bottom-1);
        LineTo(hDC,rect.left+1, rect.bottom-1);
        LineTo(hDC,rect.left+1, rect.top);

        DeleteObject(hPen);
        EndPaint(hStatusText, &amp;ps);
    }
}
</code></pre>
<p>Hiermit färbe ich die Messergebnisse ein (Auszug):</p>
<pre><code class="language-cpp">BOOL CALLBACK DialogProcMeasInfo(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  ...

  switch(uMsg)
  {
       case WM_CTLCOLORSTATIC:
            {
                if(GetDlgItem(hwndDlg, IDC_STATIC_NUM_VALID_PHOTONS) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_INVALID_PHOTONS) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_PHOTONFRAME_OFFSET) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_RECEIVED_PHOTONFRAMES) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_TRANSFER_DURATION) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_FIFO_USAGE) == (HWND)lParam
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_DROPPED_PHOTONFRAMES) == (HWND)lParam)
                {
                    SetTextColor((HDC) wParam,RGB(0,0,255));
                    SetBkColor((HDC) wParam,GetSysColor(COLOR_BTNFACE));
                    return (int)CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
                }
                else if(GetDlgItem(hwndDlg, IDC_STATIC_NUM_VALID_PHOTONS2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_INVALID_PHOTONS2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_PHOTONFRAME_OFFSET2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_RECEIVED_PHOTONFRAMES2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_TRANSFER_DURATION2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_FIFO_USAGE2) == (HWND)lParam
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_DROPPED_PHOTONFRAMES2) == (HWND)lParam)
                {
                    SetTextColor((HDC) wParam,RGB(245,0,0));
                    SetBkColor((HDC) wParam,GetSysColor(COLOR_BTNFACE));
                    return (int)CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
                }
                return 0;
            }
  }

}
</code></pre>
<p>Bin ich irgendwo zu sehr ressourcenverschwendent oder habe ich etwas vergessen? Was kann ich besser machen?</p>
<p>Vielen Dank für eure Hilfe,<br />
Jonson</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/296183/häufige-gui-updates-lassen-gui-abstürzen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 02:00:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/296183.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 29 Nov 2011 16:24:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Häufige Gui-Updates lassen GUI abstürzen on Tue, 29 Nov 2011 16:24:15 GMT]]></title><description><![CDATA[<p>Hallo Leute,</p>
<p>ich brauche mal wieder die Hilfe von Leuten, die mehr Ahnung von der Materie haben, als ich.</p>
<p>Ich habe ein Programm, bei dem von einer Hardware in sehr umfangreichen Maße Daten ausgelesen und teilweise live verarbeitet werden. Hierfür laufen viele Threads, wodurch der gesamte PC relativ an seinen Leistungsgrenzen ist, aber es funktioniert.</p>
<p>Nur manchmal kommt nach einiger Zeit der Messung der Zeitpunkt, dass die GUI nicht mehr aktualisiert wird oder werden kann, was nicht nur mein Programm, sondern ganz Windows betrifft.</p>
<p>Ich lasse in einem kleinen Fenster gewisse Messwerte zur Kontrolle ständig aktualisieren und neuerdings auch farblich hervorheben. Zudem blink ein Button, der anzeigt, welcher Mess-Modus gerade aktiv ist. Ich habe subjektiv das Gefühl, dass diese neuen Hervorhebungen für die deutlich schwächere GUI-Leistung ist und ich gehe davon aus, dass ich vielleicht irgendwie Speicher nicht mehr freigebe, wodurch der schon sehr beanspruchte RAM irgendwann Probleme macht.</p>
<p>Hiermit lasse ich den Button blinken, die Funktion wird halbsekündlich von einem Timer, der auch andere Aufgaben übernimmt, angestoßen:</p>
<pre><code class="language-cpp">void Klasse::SetSelectedMode(int iIDC)
{
    InvalidateRect (GetDlgItem(m_hwndDialogInfo, iRecentButtonIDC), NULL, TRUE);
    UpdateWindow(GetDlgItem(m_hwndDialogInfo, iRecentButtonIDC));

    iRecentButtonIDC = iIDC;

    HWND hStatusText = GetDlgItem(m_hwndDialogInfo, iIDC);

    RECT rect;

    if(hStatusText != NULL)
    {
        HDC hDC = GetWindowDC(hStatusText);
        GetClientRect(hStatusText, &amp;rect);

        HPEN hPen;
        if(!bActiveButtonSelected || !m_bMeasLoopThreadRunning)
        {
            hPen = CreatePen(PS_SOLID, 4 , RGB(0,205,0));
            bActiveButtonSelected = true;
        }
        else
        {
            hPen = CreatePen(PS_SOLID, 4 , ::GetSysColor(COLOR_BTNFACE));
            bActiveButtonSelected = false;
        }

        SetTextColor(hDC, RGB(0,0,255));
//        SetBkMode(hDC,TRANSPARENT); 
        PAINTSTRUCT ps;
        BeginPaint(hStatusText, &amp;ps);

        SelectObject(hDC, hPen);

        MoveToEx(hDC,rect.top+1, rect.left+1, NULL);
        LineTo(hDC,rect.right-1, rect.top+1);
        LineTo(hDC,rect.right-1, rect.bottom-1);
        LineTo(hDC,rect.left+1, rect.bottom-1);
        LineTo(hDC,rect.left+1, rect.top);

        DeleteObject(hPen);
        EndPaint(hStatusText, &amp;ps);
    }
}
</code></pre>
<p>Hiermit färbe ich die Messergebnisse ein (Auszug):</p>
<pre><code class="language-cpp">BOOL CALLBACK DialogProcMeasInfo(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  ...

  switch(uMsg)
  {
       case WM_CTLCOLORSTATIC:
            {
                if(GetDlgItem(hwndDlg, IDC_STATIC_NUM_VALID_PHOTONS) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_INVALID_PHOTONS) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_PHOTONFRAME_OFFSET) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_RECEIVED_PHOTONFRAMES) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_TRANSFER_DURATION) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_FIFO_USAGE) == (HWND)lParam
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_DROPPED_PHOTONFRAMES) == (HWND)lParam)
                {
                    SetTextColor((HDC) wParam,RGB(0,0,255));
                    SetBkColor((HDC) wParam,GetSysColor(COLOR_BTNFACE));
                    return (int)CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
                }
                else if(GetDlgItem(hwndDlg, IDC_STATIC_NUM_VALID_PHOTONS2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_INVALID_PHOTONS2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_PHOTONFRAME_OFFSET2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_RECEIVED_PHOTONFRAMES2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_TRANSFER_DURATION2) == (HWND)lParam 
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_FIFO_USAGE2) == (HWND)lParam
                    || GetDlgItem(hwndDlg, IDC_STATIC_NUM_DROPPED_PHOTONFRAMES2) == (HWND)lParam)
                {
                    SetTextColor((HDC) wParam,RGB(245,0,0));
                    SetBkColor((HDC) wParam,GetSysColor(COLOR_BTNFACE));
                    return (int)CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
                }
                return 0;
            }
  }

}
</code></pre>
<p>Bin ich irgendwo zu sehr ressourcenverschwendent oder habe ich etwas vergessen? Was kann ich besser machen?</p>
<p>Vielen Dank für eure Hilfe,<br />
Jonson</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2150570</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2150570</guid><dc:creator><![CDATA[Jonson86]]></dc:creator><pubDate>Tue, 29 Nov 2011 16:24:15 GMT</pubDate></item><item><title><![CDATA[Reply to Häufige Gui-Updates lassen GUI abstürzen on Tue, 29 Nov 2011 16:58:54 GMT]]></title><description><![CDATA[<p>Du kannst ja mal im Taskmanager die Spalte &quot;GDI-Handles&quot; einblenden und die Anzahl deines Prozesses beobachten.<br />
Was auffällt:</p>
<pre><code class="language-cpp">HDC hDC = GetWindowDC(hStatusText);

// ReleaseDC fehlt
</code></pre>
<p>Irgendwann ist die maximale Anzahl an Handles erreicht und es läuft eben nix mehr.</p>
<p>Das Ganze schreit natürlich geradezu nach RAII, damit solche Fehler nicht wieder auftreten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2150581</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2150581</guid><dc:creator><![CDATA[Hmmh]]></dc:creator><pubDate>Tue, 29 Nov 2011 16:58:54 GMT</pubDate></item><item><title><![CDATA[Reply to Häufige Gui-Updates lassen GUI abstürzen on Tue, 29 Nov 2011 17:02:48 GMT]]></title><description><![CDATA[<p>Wann aktualisierst du denn dein GUI? Mit jedem neuen Messwert?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2150584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2150584</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Tue, 29 Nov 2011 17:02:48 GMT</pubDate></item></channel></rss>