Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

1

07.11.2007, 15:30

Backgroundcolor von static control

Hallo,

Ich such jetzt schon eine ganze Weile im Internet nach einer einfach Lösung aber finde einfach nix dazu, deswegen hoffe ich, dass ihr mir vielleicht helfen könnt.

Eigentlich möchte ich einfach so simpel wie möglich die Hintergrundfarbe eines Static Controls verändern. Ich hab da verschiedene herangehensweisen mit Pinseln gelesen, aber ich hatte eigentlich gehofft, dass es einfacher geht... per SendMessage an das control oder per messageabfrage in der callback funktion.

Würde mich sehr freuen, wenn mir da jemand weiterhelfen könnte : )

Bye und danke schonmal fürs lesen,
Mystify

2

07.11.2007, 16:13

http://msdn2.microsoft.com/en-us/library/bb787524.aspx
http://msdn2.microsoft.com/en-us/library/ms532365.aspx

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
case WM_CTLCOLORSTATIC:
{
    ::HWND hWndCtrl = reinterpret_cast<::HWND>(lParam);
    if (hWndCtrl == hMyStaticCtrl)
    {
        ::HDC hDC = reinterpret_cast<::HDC>(wParam);
        ::RECT rcClient = { 0 };
        ::GetClientRect(hWndCtrl, &rcClient);
        ::HBRUSH hBrush = ::CreateSolidBrush(RGB(103, 13, 14));
        ::FillRect(hDC, &rcClient, hBrush);
        ::DeleteObject(hBrush);
        ::SetBkMode(hDC, TRANSPARENT);
    }
}
usw. ... ist ja nicht so schwer :P Bei RGB(r, g, b) für r, g, b deine Werte einsetzen und hMyStaticCtrl durch dein Static Control Fensterhandle ersetzen ...
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

3

07.11.2007, 18:41

erstmal vielen dank für deine schnelle antwort,
Allerdings hab ich da irgendwas noch net ganz gecheckt. Also den Befehl FillRectangle kennt mein compiler nicht - er meint das gehört nicht zum standart namespace.

Also hab ichs mit FillRect probiert und da scheiter ich grad an den zu übergebenden Parametern.

Weiß jetzt nicht sicher ob FillRect vlt was volkommen anderes ist und wenn nicht, bräucht ich nen tip wegen den parametern.

baba, mystify

TrommlBomml

Community-Fossil

Beiträge: 2 117

Wohnort: Berlin

Beruf: Software-Entwickler

  • Private Nachricht senden

4

07.11.2007, 18:47

@msdn ;)

5

07.11.2007, 19:34

Hab es dir oben hingeschrieben ...
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

6

07.11.2007, 22:28

wenn ich genau das eingebe was du mir beschrieben hast (natürlich mit eigenem handling etc.....) ist er mit den doppelten klammern "::RECT rcClient = {}; " unzufrieden und sagt er braucht 2 Parameter bei der GetClientRect funktion...

wenn ich folgendes eingebe:


Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
case WM_CTLCOLOREDIT:
            { 
                 ::HWND hWndCtrl = reinterpret_cast<::HWND>(lParam); 
                    if (hWndCtrl == vText[1]) 
                    {   
                        ::HDC hDC = reinterpret_cast<::HDC>(wParam); 
                        ::RECT rcClient ; 
                        ::GetClientRect(vText[1],&rcClient); 
                        ::HBRUSH hBrush = ::CreateSolidBrush(RGB(250, 13, 14)); 
                        ::FillRect(hDC, &rcClient, hBrush); 
                        ::DeleteObject(hBrush); 
                        ::SetBkMode(hDC, TRANSPARENT); 
                     } 
            }break;



kommen weder fehler noch warnungen...allerdings verändert sich auch die hintergrundfarbe nicht D:

7

07.11.2007, 22:34

Es war die Rede von Static und nicht von Edit, richtig? Guck mal nochmal oben ... das ist etwas anders als deins :P
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

8

07.11.2007, 23:19

shit, du hast natürlich recht. Allerdings ändert sich die farbe auch net wenn ich das edit durch static ersetze D:

9

03.01.2008, 12:25

Hallo,

Ich bin grad wieder dazu gekommen, mich mal wieder an mein Projekt zu setzen und hab festgestellt, dass ich es immernoch nicht gepackt hab diese Hintergrundfarbe von dem Static Controll zu ändern.

Ich hab genau das gemacht was mir hier im Threat empfohlen wurde... keine Fehlermeldung aber die Hintergrundfarbe is immernoch dieses standart grau.

Hier der Code auf dens wahrscheinlich ankommt:

Quellcode

1
2
3
4
5
6
7
8
9
Test = CreateWindow ("STATIC",
                          "Blub",
                          WS_VISIBLE | WS_CHILD,
                          200,200,
                          50,440,
                          hWnd,
                          (HMENU) ID_TEST,
                          hInst,
                          NULL);


Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
case WM_CTLCOLORSTATIC:
            { 
                 ::HWND hWndCtrl = reinterpret_cast<::HWND>(lParam); 
                    if (hWndCtrl == Test) 
                    {   
                        
                        ::HDC hDC = reinterpret_cast<::HDC>(wParam); 
                        ::RECT rcClient ; 
                        ::GetClientRect(Test,&rcClient); 
                        ::HBRUSH hBrush = ::CreateSolidBrush(RGB(250, 13, 14)); 
                        ::FillRect(hDC, &rcClient, hBrush); 
                        ::DeleteObject(hBrush); 
                        ::SetBkMode(hDC, TRANSPARENT); 
                        
                        
                    
                     } 
            }break;


für weitere hilfe bzw. tips worans liegen könnte wär ich echt dankbar :)

bye, Max

10

03.01.2008, 13:01

Hmm als was ist Test definiert? static? Naja mach es mal so:

C-/C++-Quelltext

1
2
3
hTest = ::CreateWindowA("STATIC", "Blub", WS_VISIBLE | WS_CHILD,
                    200, 200, 50, 440, hWnd, reinterpret_cast<::HMENU>(IDC_STC_TEST), hInstance, NULL); 
if (hTest == NULL) throw std::runtime_error("could not create controls");


C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
case WM_CTLCOLORSTATIC:
{
    const ::HWND hWndCtrl(reinterpret_cast<::HWND>(lParam));
    if (hWndCtrl == ::GetDlgItem(hWnd, IDC_STC_TEST))
    {   
        ::HDC hDC(reinterpret_cast<::HDC>(wParam));
        // get rect

        ::RECT rect;
        ::GetClientRect(hWndCtrl, &rect);

        // fill rect

        ::HBRUSH hBrush(::CreateSolidBrush(RGB(250, 13, 14)));
        ::FillRect(hDC, &rect, hBrush);
        ::DeleteObject(hBrush);
        ::SetBkMode(hDC, TRANSPARENT);
    }
}break; 
so sollte es gehen ;) Achja ID_TEST ist IDC_STC_TEST ...
Devil Entertainment :: Your education is our inspiration
Der Spieleprogrammierer :: Community Magazin
Merlin - A Legend awakes :: You are a dedicated C++ (DirectX) programmer and you have ability to work in a team? Contact us!
Siedler II.5 RttR :: The old settlers-style is comming back!

Also known as (D)Evil

Werbeanzeige