<?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[Message zu Parent funktioniert nicht]]></title><description><![CDATA[<p>Servus an Alle,</p>
<p>Habe folgendes Problem und zwar will ich über ein Child Window die Farbe eines Dialogs ändern nur leider erkennt dieser meine Message erst gar nicht an. Vieleicht sieht jemand meinen Fehler oder kann um diesen &quot;bug&quot; herum coden.</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

const char szChildName[] = &quot;Farbtabelle&quot;;
const UINT WM_COLORCHANGED = WM_APP + 1;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
   MSG        msg;
   HWND       hWnd;
   WNDCLASS   wc;

   char       szAppName[] = &quot;Das Child Window&quot;;

   wc.cbClsExtra          = 0;
   wc.cbWndExtra          = 0;
   wc.hbrBackground       = (HBRUSH) GetStockObject(WHITE_BRUSH);
   wc.hCursor             = LoadCursor(NULL, IDC_ARROW);
   wc.hIcon               = LoadIcon(NULL, IDI_APPLICATION);
   wc.hInstance           = hInstance;
   wc.lpfnWndProc         = WndProc;
   wc.lpszClassName       = szAppName;
   wc.lpszMenuName        = NULL;
   wc.style               = CS_HREDRAW | CS_VREDRAW;
   RegisterClass(&amp;wc);

   wc.hbrBackground       = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
   wc.hIcon               = NULL;
   wc.lpfnWndProc         = ChildProc;
   wc.lpszClassName       = szChildName;
   RegisterClass(&amp;wc);

   hWnd = CreateWindow(   szAppName,
                          szAppName,
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

   ShowWindow(hWnd, iCmdShow);
   UpdateWindow(hWnd);

   while (GetMessage(&amp;msg, NULL, 0, 0))
   {
      TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
   }
   return msg.wParam;
}

LRESULT CALLBACK ChildProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   int i;

   static RECT    rect;
   static int     iAnzFarben;
   const  int     iKasten        = 12;
   const  int     iKastenOffset  = 15;

   switch (message)
   {
      case WM_SIZE:
      {
         rect.right  = LOWORD(lParam);
         rect.bottom = HIWORD(lParam);
         iAnzFarben  = (rect.right / iKastenOffset) - 2;
         return 0;
      }
      case WM_LBUTTONDOWN:
      {
         int d=0, e=0;

         for (i = 0; i &lt; iAnzFarben; i++)
         {
            if (15 + i * iKastenOffset                  &lt;= LOWORD(lParam) &amp;&amp;
                15 + i * iKastenOffset + iKasten        &gt;= LOWORD(lParam) &amp;&amp;
                rect.bottom / 2 - iKasten / 2           &lt;= HIWORD(lParam) &amp;&amp;
                rect.bottom / 2 - iKasten / 2 + iKasten &gt;= HIWORD(lParam))
            {
               int iColor = 255 * i / (iAnzFarben - 1);
               PostMessage(GetAncestor(hWnd,GA_PARENT), WM_COLORCHANGED,//#####WM_COLORCHANGED ist die Message an den Dialog
                           RGB(iColor, iColor, iColor), 0);

               MessageBox(hWnd,&quot;hu&quot;,&quot;at color&quot;,MB_OK);
               d=1;
               return 0;
            }
            if (d==0&amp;&amp;e==0)
            {
               MessageBox(hWnd,&quot;hu&quot;,&quot;at child&quot;,MB_OK);
               e=1;
            }
         }
         return 0;
      }
      case WM_PAINT:
      {
         HDC          hDC;
         PAINTSTRUCT  ps;

         hDC = BeginPaint(hWnd, &amp;ps);
         {
            for ( i = 0; i &lt; iAnzFarben; i++)
            {
               int    iColor    = 255 * i / (iAnzFarben - 1);
               HBRUSH hOldBrush = (HBRUSH) SelectObject(hDC,
                                  CreateSolidBrush(RGB(iColor, iColor, iColor)));
               Rectangle(hDC,  15 + i * iKastenOffset,
                               rect.bottom / 2 - iKasten / 2,
                               15 + i * iKastenOffset + iKasten,
                               rect.bottom / 2 - iKasten / 2 + iKasten);
               DeleteObject(SelectObject(hDC, hOldBrush));
            }
         }
         EndPaint(hWnd, &amp;ps);
         return 0;
      }
   }
   return DefWindowProc(hWnd, message, wParam, lParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

const UINT WM_COLORCHANGED = WM_APP + 1;
   static HWND    hChild;
   static RECT    rect;
   static int     iColor = RGB(255, 255, 255);

   switch (message)
   {
   case WM_CREATE:
      {
         GetClientRect(hWnd, &amp;rect);
         hChild = CreateWindow(  szChildName,
                                 NULL,
                                 WS_CHILD | WS_VISIBLE | WS_DLGFRAME,
                                 50,
                                 rect.bottom - 105,
                                 rect.right - 10,
                                 30,
                                 hWnd,
                                 NULL,
                                 ((LPCREATESTRUCT) lParam)-&gt;hInstance,
                                 NULL);
         return 0;
      }
      case WM_SIZE:
      {
         rect.right  = LOWORD(lParam);
         rect.bottom = HIWORD(lParam);

         MoveWindow(hChild, 50, rect.bottom - 105, rect.right - 10, 30, TRUE);

         return 0;
      }

      case WM_COLORCHANGED://#####hier sollte die Message bearbeitet werden
//doch leider kompiliert er erste gar nicht.Stattdessen:
/* [C++ Error] File1.c(167): E2313 Constant expression required
  [C++ Error] File1.c(167): E2172 Duplicate case
  [C++ Error] File1.c(173): E2128 Case outside of switch
  [C++ Error] File1.c(173): E2188 Expression syntax
  [C++ Warning] File1.c(195): W8070 Function should return a value
  [C++ Warning] File1.c(195): W8004 'WM_COLORCHANGED' is assigned a value that is never used
  [C++ Error] File1.c(196): E2040 Declaration terminated incorrectly
  [C++ Error] File1.c(197): E2190 Unexpected*/
      {
         iColor = wParam;
         InvalidateRect(hWnd, NULL, FALSE);
         return 0;
      } 
      case WM_PAINT:
      {
         PAINTSTRUCT    ps;
         HDC            hDC;

         hDC = BeginPaint(hWnd, &amp;ps);
         {
            HBRUSH hOldBrush = (HBRUSH) SelectObject(hDC,
                                              CreateSolidBrush(iColor));

            Rectangle(hDC, 0, 0, rect.right, rect.bottom);

            DeleteObject(SelectObject(hDC, hOldBrush));
         }
         EndPaint(hWnd, &amp;ps);
         return 0;
      }
      case WM_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }
   return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
<p>Bin um jede Hilfe erfreut <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>
]]></description><link>https://www.c-plusplus.net/forum/topic/119859/message-zu-parent-funktioniert-nicht</link><generator>RSS for Node</generator><lastBuildDate>Sun, 05 Jul 2026 05:22:17 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/119859.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 06 Sep 2005 11:47:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Message zu Parent funktioniert nicht on Tue, 06 Sep 2005 11:47:14 GMT]]></title><description><![CDATA[<p>Servus an Alle,</p>
<p>Habe folgendes Problem und zwar will ich über ein Child Window die Farbe eines Dialogs ändern nur leider erkennt dieser meine Message erst gar nicht an. Vieleicht sieht jemand meinen Fehler oder kann um diesen &quot;bug&quot; herum coden.</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

const char szChildName[] = &quot;Farbtabelle&quot;;
const UINT WM_COLORCHANGED = WM_APP + 1;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK ChildProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR szCmdLine, int iCmdShow)
{
   MSG        msg;
   HWND       hWnd;
   WNDCLASS   wc;

   char       szAppName[] = &quot;Das Child Window&quot;;

   wc.cbClsExtra          = 0;
   wc.cbWndExtra          = 0;
   wc.hbrBackground       = (HBRUSH) GetStockObject(WHITE_BRUSH);
   wc.hCursor             = LoadCursor(NULL, IDC_ARROW);
   wc.hIcon               = LoadIcon(NULL, IDI_APPLICATION);
   wc.hInstance           = hInstance;
   wc.lpfnWndProc         = WndProc;
   wc.lpszClassName       = szAppName;
   wc.lpszMenuName        = NULL;
   wc.style               = CS_HREDRAW | CS_VREDRAW;
   RegisterClass(&amp;wc);

   wc.hbrBackground       = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
   wc.hIcon               = NULL;
   wc.lpfnWndProc         = ChildProc;
   wc.lpszClassName       = szChildName;
   RegisterClass(&amp;wc);

   hWnd = CreateWindow(   szAppName,
                          szAppName,
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

   ShowWindow(hWnd, iCmdShow);
   UpdateWindow(hWnd);

   while (GetMessage(&amp;msg, NULL, 0, 0))
   {
      TranslateMessage(&amp;msg);
      DispatchMessage(&amp;msg);
   }
   return msg.wParam;
}

LRESULT CALLBACK ChildProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
   int i;

   static RECT    rect;
   static int     iAnzFarben;
   const  int     iKasten        = 12;
   const  int     iKastenOffset  = 15;

   switch (message)
   {
      case WM_SIZE:
      {
         rect.right  = LOWORD(lParam);
         rect.bottom = HIWORD(lParam);
         iAnzFarben  = (rect.right / iKastenOffset) - 2;
         return 0;
      }
      case WM_LBUTTONDOWN:
      {
         int d=0, e=0;

         for (i = 0; i &lt; iAnzFarben; i++)
         {
            if (15 + i * iKastenOffset                  &lt;= LOWORD(lParam) &amp;&amp;
                15 + i * iKastenOffset + iKasten        &gt;= LOWORD(lParam) &amp;&amp;
                rect.bottom / 2 - iKasten / 2           &lt;= HIWORD(lParam) &amp;&amp;
                rect.bottom / 2 - iKasten / 2 + iKasten &gt;= HIWORD(lParam))
            {
               int iColor = 255 * i / (iAnzFarben - 1);
               PostMessage(GetAncestor(hWnd,GA_PARENT), WM_COLORCHANGED,//#####WM_COLORCHANGED ist die Message an den Dialog
                           RGB(iColor, iColor, iColor), 0);

               MessageBox(hWnd,&quot;hu&quot;,&quot;at color&quot;,MB_OK);
               d=1;
               return 0;
            }
            if (d==0&amp;&amp;e==0)
            {
               MessageBox(hWnd,&quot;hu&quot;,&quot;at child&quot;,MB_OK);
               e=1;
            }
         }
         return 0;
      }
      case WM_PAINT:
      {
         HDC          hDC;
         PAINTSTRUCT  ps;

         hDC = BeginPaint(hWnd, &amp;ps);
         {
            for ( i = 0; i &lt; iAnzFarben; i++)
            {
               int    iColor    = 255 * i / (iAnzFarben - 1);
               HBRUSH hOldBrush = (HBRUSH) SelectObject(hDC,
                                  CreateSolidBrush(RGB(iColor, iColor, iColor)));
               Rectangle(hDC,  15 + i * iKastenOffset,
                               rect.bottom / 2 - iKasten / 2,
                               15 + i * iKastenOffset + iKasten,
                               rect.bottom / 2 - iKasten / 2 + iKasten);
               DeleteObject(SelectObject(hDC, hOldBrush));
            }
         }
         EndPaint(hWnd, &amp;ps);
         return 0;
      }
   }
   return DefWindowProc(hWnd, message, wParam, lParam);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

const UINT WM_COLORCHANGED = WM_APP + 1;
   static HWND    hChild;
   static RECT    rect;
   static int     iColor = RGB(255, 255, 255);

   switch (message)
   {
   case WM_CREATE:
      {
         GetClientRect(hWnd, &amp;rect);
         hChild = CreateWindow(  szChildName,
                                 NULL,
                                 WS_CHILD | WS_VISIBLE | WS_DLGFRAME,
                                 50,
                                 rect.bottom - 105,
                                 rect.right - 10,
                                 30,
                                 hWnd,
                                 NULL,
                                 ((LPCREATESTRUCT) lParam)-&gt;hInstance,
                                 NULL);
         return 0;
      }
      case WM_SIZE:
      {
         rect.right  = LOWORD(lParam);
         rect.bottom = HIWORD(lParam);

         MoveWindow(hChild, 50, rect.bottom - 105, rect.right - 10, 30, TRUE);

         return 0;
      }

      case WM_COLORCHANGED://#####hier sollte die Message bearbeitet werden
//doch leider kompiliert er erste gar nicht.Stattdessen:
/* [C++ Error] File1.c(167): E2313 Constant expression required
  [C++ Error] File1.c(167): E2172 Duplicate case
  [C++ Error] File1.c(173): E2128 Case outside of switch
  [C++ Error] File1.c(173): E2188 Expression syntax
  [C++ Warning] File1.c(195): W8070 Function should return a value
  [C++ Warning] File1.c(195): W8004 'WM_COLORCHANGED' is assigned a value that is never used
  [C++ Error] File1.c(196): E2040 Declaration terminated incorrectly
  [C++ Error] File1.c(197): E2190 Unexpected*/
      {
         iColor = wParam;
         InvalidateRect(hWnd, NULL, FALSE);
         return 0;
      } 
      case WM_PAINT:
      {
         PAINTSTRUCT    ps;
         HDC            hDC;

         hDC = BeginPaint(hWnd, &amp;ps);
         {
            HBRUSH hOldBrush = (HBRUSH) SelectObject(hDC,
                                              CreateSolidBrush(iColor));

            Rectangle(hDC, 0, 0, rect.right, rect.bottom);

            DeleteObject(SelectObject(hDC, hOldBrush));
         }
         EndPaint(hWnd, &amp;ps);
         return 0;
      }
      case WM_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }
   return DefWindowProc(hWnd, message, wParam, lParam);
}
</code></pre>
<p>Bin um jede Hilfe erfreut <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>
]]></description><link>https://www.c-plusplus.net/forum/post/866134</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/866134</guid><dc:creator><![CDATA[gg-coding]]></dc:creator><pubDate>Tue, 06 Sep 2005 11:47:14 GMT</pubDate></item><item><title><![CDATA[Reply to Message zu Parent funktioniert nicht on Tue, 06 Sep 2005 12:52:57 GMT]]></title><description><![CDATA[<p>das hier:</p>
<pre><code class="language-cpp">PostMessage(GetAncestor(hWnd,GA_PARENT), WM_COLORCHANGED, RGB(iColor, iColor, iColor), 0);
</code></pre>
<p>wird zu:</p>
<pre><code class="language-cpp">PostMessage(GetParent(hWnd), WM_COLORCHANGED, RGB(iColor, iColor, iColor), 0);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/866219</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/866219</guid><dc:creator><![CDATA[Airdamn]]></dc:creator><pubDate>Tue, 06 Sep 2005 12:52:57 GMT</pubDate></item><item><title><![CDATA[Reply to Message zu Parent funktioniert nicht on Tue, 06 Sep 2005 14:17:40 GMT]]></title><description><![CDATA[<p>Danke,</p>
<p>aber leider funktioniert es immernoch nicht,</p>
<p>er liefert immernoch die gleichen Fehler, und wenn ich es wieder ausklammer tut wieder alles(bis auf die msg eben)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/866332</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/866332</guid><dc:creator><![CDATA[gg-coding]]></dc:creator><pubDate>Tue, 06 Sep 2005 14:17:40 GMT</pubDate></item><item><title><![CDATA[Reply to Message zu Parent funktioniert nicht on Tue, 06 Sep 2005 14:40:26 GMT]]></title><description><![CDATA[<p>Also VC++ schluckt diesen Code so ohne Probleme. Aber versuche es anstelle von const UINT mal über ein #define <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>
]]></description><link>https://www.c-plusplus.net/forum/post/866345</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/866345</guid><dc:creator><![CDATA[flenders]]></dc:creator><pubDate>Tue, 06 Sep 2005 14:40:26 GMT</pubDate></item><item><title><![CDATA[Reply to Message zu Parent funktioniert nicht on Tue, 06 Sep 2005 14:51:56 GMT]]></title><description><![CDATA[<p>du hast die konstante auch zweimal definiert und sie wird bei jedem verlassen des scopes zerstört bzw. beim eintritt wieder erstellt. lösche sie mal aus der wndproc.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/866350</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/866350</guid><dc:creator><![CDATA[miller_m]]></dc:creator><pubDate>Tue, 06 Sep 2005 14:51:56 GMT</pubDate></item><item><title><![CDATA[Reply to Message zu Parent funktioniert nicht on Tue, 06 Sep 2005 15:14:01 GMT]]></title><description><![CDATA[<p>Naja als Const hat des auch nix gebracht, flenn<br />
Mit einfacher ini auch nicht....</p>
<p>Aber jetzt fiel mir gerade auf was das Problem ist.</p>
<p>Denn flenders meinte bei ihm tut des mit vc++.<br />
bei mir nun auch da ich statt c nun c++ compiler verwende, sorry.<br />
Leichtsinnsfehler (oder nur blöd wenn man c anclickt....)</p>
<p>Vielend dank trotzdem</p>
]]></description><link>https://www.c-plusplus.net/forum/post/866366</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/866366</guid><dc:creator><![CDATA[gg-coding]]></dc:creator><pubDate>Tue, 06 Sep 2005 15:14:01 GMT</pubDate></item><item><title><![CDATA[Reply to Message zu Parent funktioniert nicht on Tue, 06 Sep 2005 15:29:21 GMT]]></title><description><![CDATA[<p>warum kein sendmessage()?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/866379</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/866379</guid><dc:creator><![CDATA[lkj]]></dc:creator><pubDate>Tue, 06 Sep 2005 15:29:21 GMT</pubDate></item><item><title><![CDATA[Reply to Message zu Parent funktioniert nicht on Wed, 07 Sep 2005 06:34:38 GMT]]></title><description><![CDATA[<p>Nach meiner Änderung funktioniert es mit Digital Mars (Compiler) auch...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/866721</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/866721</guid><dc:creator><![CDATA[Airdamn]]></dc:creator><pubDate>Wed, 07 Sep 2005 06:34:38 GMT</pubDate></item></channel></rss>