title: Painting a Win32 child window
body: <p>Hello all I have been trying to paint to my child window outside of WM_PAINT and Instead of painting on the child window it paints off of the window onto the screen I think it may be because of the location of x and y but shouldn't point (0,0) be the top left of the child window not of my actual screen?
  Here is what the code I wrote to try to paint onto the child window:</p>
  
  <pre><code>#pragma warning(disable:4996)
  #pragma comment(lib, "Ws2_32.lib")
  #include &lt;Windows.h&gt;
  #define WIDTH 800
  #define HEIGHT 600
  #define CLASS_NAME "Class"
  #define IDC_MAIN_EDIT   101
  #define IDC_WINDOW 102
  int x = 0, y = 0;
  LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  void print_line(HWND hwnd, char *Msg);
  void Println();
  int Run();
  int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  {
  
      WNDCLASSEX  wcex = { 0 };
      MSG         msg;
      HWND        hwnd = NULL;
      wcex.cbSize = sizeof(WNDCLASSEX);
      wcex.style = CS_VREDRAW | CS_OWNDC;
      wcex.lpfnWndProc = WndProc;
      wcex.cbClsExtra = 0;
      wcex.cbWndExtra = 0;
      wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
      wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
      wcex.hbrBackground = NULL;
      wcex.lpszMenuName = NULL;
      wcex.lpszClassName = CLASS_NAME;
      wcex.hInstance = hInstance;
      wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
      if (!RegisterClassEx(&amp;wcex))
      {
          MessageBoxA(NULL, "Failed to register class", "Error", MB_OK | MB_ICONERROR);
          return -1;
      }
      hwnd = CreateWindow(CLASS_NAME //Name of the window class
          , CLASS_NAME//Title of the window
          , WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN// the window style
          , 0 //x Postition of the window
          , 0// y position of the windpo
          , WIDTH, HEIGHT, // Width and Height
          NULL,//Parent window(we have no parent window)
          NULL,//Menu(we are not using menu's)
          hInstance,//application handle
          NULL);//Creates the window
      if (!hwnd)
      {
          MessageBoxA(NULL, "Failed to register class", "Error", MB_OK | MB_ICONERROR);
          return -2;
      }
      ShowWindow(hwnd, nCmdShow);
      return Run();
  }
  LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  {
      HWND hEdit = NULL;
      HWND hWindow = NULL;
      #define Print(msg2) print_line(hWindow, msg2)
  
      switch (msg)
      {
      case WM_CREATE:
  
          hWindow = CreateWindowEx(WS_EX_CLIENTEDGE, "Window", "",
              WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL | WS_CLIPSIBLINGS,
              0, 0, WIDTH, HEIGHT - 25, hwnd, (HMENU)IDC_WINDOW, GetModuleHandle(NULL), NULL);
  
          hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
              WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_AUTOHSCROLL,
              0, 535, WIDTH, 25, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
  
  
          break;
      case WM_DESTROY:
          PostQuitMessage(0);
          break;
      case WM_COMMAND:
          Print("Hello");
          break;
      default:
          return (DefWindowProc(hwnd, msg, wParam, lParam));
  
      }
  }
  int Run()
  {
  
  
  
      MSG msg = { 0 };
  
      WSAData wsa;
      WORD DllVersion = MAKEWORD(2, 1);
      if (WSAStartup(DllVersion, &amp;wsa) != 0) return -1;
  
      while (msg.message != WM_QUIT)
      {
          if (PeekMessage(&amp;msg, 0, 0, 0, PM_REMOVE))
          {
              TranslateMessage(&amp;msg);
              DispatchMessage(&amp;msg);
  
  
          }
  
      }
      return 0;
  }
  void print_line(HWND hwnd, char *Msg)
  {
  
      HDC hdc;
  
      hdc = GetDC(hwnd);
      TextOut(hdc,
  
          x,
          y,
  
          Msg,
          strlen(Msg));
  
  
      ReleaseDC(hwnd, hdc);
  
  }
  void Println()
  {
      x = 0;
      y += 20;
  }
  </code></pre>
  
  <p>Yes I know there are other questions concerning this topic but none of them seemed to answer my question or address any of the problems I have been experiencing while trying to paint on the child window.</p>