Labels (statics) Hintergrundfarbe
-
Hi Leute

Ich habe folgendes Problem: Ich habe mir ein paar labels erstellt.
Dazu habe ich logischerweis die windowclass "static" mit dem stil ua. SS_CENTER
genutzt. Soweit ist ales OK. Doch ich möchte gern die Hintergrundfarbe der labels an die des parentfensters anpassen. Dazu fange ich die WM_CTLCOLORSTATIC
ab, und setze die Farben dementsprechend. Doch leider bleibt immer links und rechts des LabelTextes ein weisser Streifen übrig. Lässt sich das vermeiden?Für Eure Antwort wäre ich sehr dankbar

gruss
folgender code:
#include <windows.h> LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); char szClassName[ ] = "WindowsApp"; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { HWND hwnd; MSG messages; WNDCLASSEX wincl; wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(200, 200, 100)); if (!RegisterClassEx (&wincl)) return 0; hwnd = CreateWindowEx ( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ "Windows App", /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 544, /* The programs width */ 375, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); ShowWindow (hwnd, nFunsterStil); UpdateWindow(hwnd); while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static int cxChar, cyChar, cxClient, cyClient; static HWND hwndLabel[3], hwndButton[3], hwndGroupbox; static HINSTANCE hInstance; HDC hdc; char * szLabelCaption[] = {"Label 1", "Label 2", "Label 3"}; char * szButtonCaption[] = {"Button 1", "Button 2", "Button 3"}; int i; switch (message) { case WM_DESTROY: PostQuitMessage (0); break; case WM_CREATE: cxChar = LOWORD(GetDialogBaseUnits()); cyChar = HIWORD(GetDialogBaseUnits()); hInstance = ((LPCREATESTRUCT)lParam)->hInstance; for(i = 0; i < 3; i++){ hwndLabel[i] = CreateWindowEx( 0, "static", szLabelCaption[i], WS_CHILD| WS_VISIBLE| SS_CENTER, 0, 0, 0, 0, hwnd, (HMENU) i, hInstance, NULL); hwndButton[i] = CreateWindowEx( 0, "button", szButtonCaption[i], WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 0, 0, 0, 0, hwnd, (HMENU) i + 3, hInstance, NULL); } hwndGroupbox = CreateWindowEx( 0, "button", "buttons", WS_CHILD|WS_VISIBLE|BS_GROUPBOX, 0, 0, 100, 100, hwnd, (HMENU) 6, hInstance, NULL); break; case WM_SIZE: cxClient = LOWORD(lParam); cyClient = HIWORD(lParam); MoveWindow(hwndGroupbox, cxChar, cyChar, cxChar * (lstrlen(szButtonCaption[0]) + 4), cyChar * 7, TRUE); for(i = 0; i < 3; i++){ MoveWindow(hwndButton[i], cxChar * 2, cyChar * (i * 2 + 2), cxChar * (strlen(szButtonCaption[i]) + 2), cyChar * 7 / 4, TRUE); MoveWindow(hwndLabel[i], cxClient/4 * 3, cyClient / 5 * (i + 1), lstrlen(szLabelCaption[i]) * cxChar, cyChar, TRUE); } break; case WM_CTLCOLORSTATIC: hdc = (HDC) wParam; SetBkColor(hdc, RGB(200, 200, 0)); SetTextColor(hdc, RGB(255, 0, 0)); return (LRESULT) GetCurrentObject(hdc, OBJ_BRUSH); break; default: return DefWindowProc (hwnd, message, wParam, lParam); } return 0; }