title: WinAPI C++ set child "window" Edit (input text field) to difrent background color
body: <p>I am trying to set the background color of the Edit control to, for example, blue (just trying), or what I would like to use more is <code>LTGRAY_BRUSH</code>. I have already tried a lot of answers to similar questions, but nothing works.</p>
  <p>Code piece I tried:</p>
  <pre class="lang-cpp prettyprint-override"><code>case WM_CTLCOLOREDIT:
      if (LOWORD(wParam) == 11) {
          HDC hdc = (HDC)wParam;
          SetBkColor(hdc, RGB(0,0,255));
          SetDCBrushColor(hdc, RGB(0,0,255));
          return (LRESULT)GetStockObject(DC_BRUSH);
      }
  </code></pre>
  <p>Complete code so far:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;Windows.h&gt;
  #include &lt;cassert&gt;
  
  HWND hWndEdit;
  wchar_t buffer[1024];
  
  LRESULT CALLBACK MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
      switch (uMsg) {
      case WM_CLOSE:
      case WM_DESTROY:
          PostQuitMessage(0);
          return 0;
          break;
      case WM_COMMAND:
          if (LOWORD(wParam) == 10) {
              GetWindowText(hWndEdit, buffer, 1024);
              MessageBox(hWnd, buffer, L&quot;Button gedrückt&quot;, MB_OK);
          }
          break;
      case WM_CTLCOLOREDIT:
          if (LOWORD(wParam) == 11) {
              HDC hdc = (HDC)wParam;
              SetBkColor(hdc, RGB(0,0,255));
              SetDCBrushColor(hdc, RGB(0,0,255));
              return (LRESULT)GetStockObject(DC_BRUSH);
          }
      }
      return DefWindowProc(hWnd, uMsg, wParam, lParam);
  }
  
  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
      
      HWND hWnd;
      HWND hButton;
      WNDCLASS wc;
      MSG msg;
  
      wc.style = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc = MessageHandler;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
      wc.lpszMenuName = NULL;
      wc.lpszClassName = L&quot;WINAPITest&quot;;
  
      assert(RegisterClass(&amp;wc));
  
      hWnd = CreateWindow(L&quot;WINAPITest&quot;, L&quot;WinAPI Tutorial&quot;, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, 0, 0, hInstance, 0);
      hButton = CreateWindow(L&quot;button&quot;, L&quot;OK&quot;, WS_VISIBLE | BS_DEFPUSHBUTTON | WS_TABSTOP | WS_CHILD, 100, 100, 200, 50, hWnd, (HMENU)10, hInstance, 0);
      hWndEdit = CreateWindow(L&quot;edit&quot;, L&quot;Tastzyklen&quot;, WS_TABSTOP | WS_CHILD | WS_BORDER | WS_VISIBLE, 100, 48, 200, 50, hWnd, (HMENU)11, 0, 0);
  
      ShowWindow(hWnd, nCmdShow);
      UpdateWindow(hWnd);
  
      while (true) {
          BOOL result = GetMessage(&amp;msg, 0, 0, 0);
          if (result &gt; 0) {
              TranslateMessage(&amp;msg);
              DispatchMessage(&amp;msg);
          }
          else {
              return result;
          }
      }
  }
  </code></pre>
  <p>Is what I want to do possible? I want the Edit control from the beginning to have a different background color from the main window.</p>
  <p>It's hard to find useful resources to learn from about this topic. Primarily, I want the above question answered, but if someone can guide me to a resource that can help me understand all of this better and possible the answer I am given, I would appreciate it.</p>
  <p>Why does the Edit control have two backgrounds colors?</p>
  <p><a href="https://i.stack.imgur.com/bvQrX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bvQrX.png" alt="image" /></a></p>
  <p>Blue is <code>SetBkColor</code> and Grey is <code>SetDCBruchColor</code>.</p>