title: c - win32 api rectangle is not drawn if hdc passed to method
body: <p>I have been playing with C and win32 recently and the following has me balked:</p>
  
  <pre><code>     case WM_PAINT:
           g_crntRect = (RECT*) malloc(sizeof(RECT));
           GetWindowRect(hwnd, g_crntRect);
  
           hpen = CreatePen(PS_SOLID, 1, RGB(255,25,5));
  
           hdc = BeginPaint (hwnd, &amp;ps) ;
  
           oldPen = SelectObject(hdc, hpen);
           drawRects(hwnd, hdc);
           //Rectangle(hdc, 0, 0, 840, 525);
  
           SelectObject(hdc,oldPen);
           DeleteObject(hpen);
  
           EndPaint (hwnd, &amp;ps) ;
           return 0 ;
  </code></pre>
  
  <p>So, if I call my own method above for drawing rectangles, it draws nothing, however the call to draw the rectangle in the WM_PAINT that I have commented above succeeds without a problem.</p>
  
  <p>Here is my method:</p>
  
  <pre><code>BOOL drawRects(HWND hwnd, HDC hdc)
  {
  
  char buffer[50];
  BOOL res = FALSE;
  RECT tempRect = {0};
  char quadStr[6] = "";
  int i = 0;
  quadStr[i]='*';
  OutputDebugString("Going to draw");
  for (i = 1; i &lt;= 4; i++)
  {
      //get rect for each quadrent from the parent
      OutputDebugString("inside for");
      getRect(g_crntRect, &amp;tempRect, i);
  
      OutputDebugString("got rectr");;
      res = Rectangle(hdc, tempRect.right, tempRect.top, tempRect.right, tempRect.bottom);
  
      if (res == FALSE)
      {
          OutputDebugString("false");;
          sprintf(buffer, "Error: %ld", GetLastError());
          OutputDebugString(buffer);
      }
      else
      {
          OutputDebugString("drew");;
      }
  
      quadStr[i]='*';
      printRect(quadStr, &amp;tempRect);
  }
  
  return TRUE;
  </code></pre>
  
  <p>}</p>
  
  <p>Looking at debug output, everything seems fine. Proper values are being passed into the Rectangle method. However, I wonder if I am not passing HDC correctly?</p>
  
  <p>Any ideas?</p>