<?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[Labels (statics) Hintergrundfarbe]]></title><description><![CDATA[<p>Hi Leute <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ich habe folgendes Problem: Ich habe mir ein paar labels erstellt.<br />
Dazu habe ich logischerweis die windowclass &quot;static&quot; mit dem stil ua. SS_CENTER<br />
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<br />
ab, und setze die Farben dementsprechend. Doch leider bleibt immer links und rechts des LabelTextes ein weisser Streifen übrig. Lässt sich das vermeiden?</p>
<p>Für Eure Antwort wäre ich sehr dankbar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>gruss</p>
<p>folgender code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = &quot;WindowsApp&quot;;

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 (&amp;wincl))
        return 0;

    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           &quot;Windows App&quot;,       /* 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 (&amp;messages, NULL, 0, 0))
    {
        TranslateMessage(&amp;messages);
        DispatchMessage(&amp;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[] = {&quot;Label 1&quot;, &quot;Label 2&quot;, &quot;Label 3&quot;};
	char * szButtonCaption[] = {&quot;Button 1&quot;, &quot;Button 2&quot;, &quot;Button 3&quot;};
	int i;

    switch (message)                  
    {
        case WM_DESTROY:
            PostQuitMessage (0);       
            break;
		case WM_CREATE:
			cxChar = LOWORD(GetDialogBaseUnits());
			cyChar = HIWORD(GetDialogBaseUnits());

			hInstance = ((LPCREATESTRUCT)lParam)-&gt;hInstance;

			for(i = 0; i &lt; 3; i++){
				hwndLabel[i] = CreateWindowEx(
					0, &quot;static&quot;, szLabelCaption[i],
					WS_CHILD| WS_VISIBLE| SS_CENTER,
					0, 0, 0, 0, hwnd, (HMENU) i,
					hInstance, NULL);

				hwndButton[i] = CreateWindowEx(
					0, &quot;button&quot;, szButtonCaption[i],
					WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
					0, 0, 0, 0, hwnd, (HMENU) i + 3,
					hInstance, NULL);

			}

			hwndGroupbox = CreateWindowEx(
				0, &quot;button&quot;, &quot;buttons&quot;,
				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 &lt; 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;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/119193/labels-statics-hintergrundfarbe</link><generator>RSS for Node</generator><lastBuildDate>Sat, 04 Jul 2026 17:07:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/119193.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 29 Aug 2005 12:24:30 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Labels (statics) Hintergrundfarbe on Mon, 29 Aug 2005 12:24:30 GMT]]></title><description><![CDATA[<p>Hi Leute <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>Ich habe folgendes Problem: Ich habe mir ein paar labels erstellt.<br />
Dazu habe ich logischerweis die windowclass &quot;static&quot; mit dem stil ua. SS_CENTER<br />
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<br />
ab, und setze die Farben dementsprechend. Doch leider bleibt immer links und rechts des LabelTextes ein weisser Streifen übrig. Lässt sich das vermeiden?</p>
<p>Für Eure Antwort wäre ich sehr dankbar <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p>gruss</p>
<p>folgender code:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = &quot;WindowsApp&quot;;

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 (&amp;wincl))
        return 0;

    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           &quot;Windows App&quot;,       /* 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 (&amp;messages, NULL, 0, 0))
    {
        TranslateMessage(&amp;messages);
        DispatchMessage(&amp;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[] = {&quot;Label 1&quot;, &quot;Label 2&quot;, &quot;Label 3&quot;};
	char * szButtonCaption[] = {&quot;Button 1&quot;, &quot;Button 2&quot;, &quot;Button 3&quot;};
	int i;

    switch (message)                  
    {
        case WM_DESTROY:
            PostQuitMessage (0);       
            break;
		case WM_CREATE:
			cxChar = LOWORD(GetDialogBaseUnits());
			cyChar = HIWORD(GetDialogBaseUnits());

			hInstance = ((LPCREATESTRUCT)lParam)-&gt;hInstance;

			for(i = 0; i &lt; 3; i++){
				hwndLabel[i] = CreateWindowEx(
					0, &quot;static&quot;, szLabelCaption[i],
					WS_CHILD| WS_VISIBLE| SS_CENTER,
					0, 0, 0, 0, hwnd, (HMENU) i,
					hInstance, NULL);

				hwndButton[i] = CreateWindowEx(
					0, &quot;button&quot;, szButtonCaption[i],
					WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
					0, 0, 0, 0, hwnd, (HMENU) i + 3,
					hInstance, NULL);

			}

			hwndGroupbox = CreateWindowEx(
				0, &quot;button&quot;, &quot;buttons&quot;,
				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 &lt; 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;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/860599</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/860599</guid><dc:creator><![CDATA[linu*x*bie]]></dc:creator><pubDate>Mon, 29 Aug 2005 12:24:30 GMT</pubDate></item></channel></rss>