Picture Ctrl farbe von Rechteck verändern *verzweifel*



  • Moin,
    hab ein Picture Ctrl als Rechteck und möchte die Farbe davon verändern.
    *ganz einfach dachte*

    Ich hab wie folgt versucht. Ersteinmal eine Control Variable(CMyStatic).
    Die Classe Sieht so aus:

    class CMyStatic : public CStatic
    {
    
        HBRUSH m_brush;
    
        HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
        {
    
            // Call the base class implementation first! Otherwise, it may
            // undo what we're trying to accomplish here.
            HBRUSH hbr = CDialog::OnCtlColor(
                pDC,
                pWnd,
                nCtlColor);
    
            // Set the background mode for text to transparent 
            // so background will show thru.
            pDC->SetBkColor(RGB(255,0,0));
    
            // Return handle to our CBrush object
            hbr = m_brush;
    
            return hbr;
    
        }
    
    };
    

    So nun alles schön und gut aber Compiler sagt:
    ".\CupToTarget.h(92): error C2248: "CWnd::OnCtlColor" : Kein Zugriff auf protected Element, dessen Deklaration in der Klasse "CWnd" erfolgte"



  • Ups...

    ...*peinlich* aber auch wenn ich den fehler beheb geht es nicht 😞

    HBRUSH hbr = CStatic::OnCtlColor(
    pDC,
    pWnd,
    nCtlColor);



  • OnCtlCOlor ist nicht virtual. Du musst die Message abfangen und nicht den Message-Handler überschreiben... Ausserdem bekommt das Parent die WM_CTLCOLOR und nicht das Fenster selber...



  • wird aber dann aber wieder zurückgesendet


Anmelden zum Antworten