MoveToEx/ LineTo confusion

/*
*This program has been skimmed down to include only the problematic parts and for clearness*

My problem is with MoveToEx and LineTo:
In MoveToEx and LineTo, step 4, (first MoveToEx/LineTo call) why is it that I don't need to put an extra
coordinate/pixel in the last parameter like I did for the middle section of the rect
structure in step 3? I thought I would need to, or else the line would'nt be drawn exactly
where I excluded one extra coordinate/pixel for the middle-top part...

In the second MoveToEx and LineTo calls, last parameter, I can see why I need to subtract one pixel/coordinate
because the middle-bottom part was subtracted by one in step 2. So it matches. That is,
unless, I got this all wrong(?)

I know it could be an end-point exclusive/inclusive problem but I don't see how it possibly can.

From the MSDN Documentation for MoveToEx, it does'nt specify whether or not it's exclusive or inclusive.
It Probably does'nt matter(?). But for LineTo, I'm not sure if the documentation for it is trying to say it's
end-point exclusive:
"The LineTo function draws a line from the current position up to, but not including, the specified point."
is that implying LineTo is end-point exclusive?

This is causing me so MUCH confusion and I don't see why such small details, like this, aren't explained
in the MSDN documentation or a Windows Programming book, because, something like this could mess up your program
(like now) someday and could be kinda hard to track down.

I hope someone can enlighten me on this, rather, difficult problem.

Thanks,
x_eddy_x.

p.s, the problem concentrates in PaintBackground()
*/

#include <windows.h>

static void PaintBackground(HWND, HDC, int, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

char szCaption[] = "Project84";
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                           PSTR szCmdLine, int iCmdShow)
{
      char szClassName[] = "Project84";
      HWND        hwnd;
      MSG         msg;
      WNDCLASS    wc;

      wc.cbClsExtra    = 0;
      wc.cbWndExtra    = 0;
      wc.hbrBackground = NULL;
      wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
      wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
      wc.hInstance     = hInstance;
      wc.lpfnWndProc   = WndProc;
      wc.lpszClassName = szClassName;
      wc.lpszMenuName  = NULL;
      wc.style         = CS_HREDRAW | CS_VREDRAW;

      if ( !RegisterClass(&wc) )
      {
            MessageBox(NULL, "Project84::RegisterClass Failed!",
                  szCaption, MB_ICONERROR);

            return 0;
      }

      if ( !(hwnd = CreateWindow(szClassName,
            szCaption,
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            CW_USEDEFAULT,
            NULL,
            NULL,
            hInstance,
            NULL)) )
      {
            MessageBox(NULL, "Project84::CreateWindow Failed!",
                  szCaption, MB_ICONERROR);

            return 0;
      }

      ShowWindow(hwnd, iCmdShow);
      UpdateWindow(hwnd);

      while ( GetMessage(&msg, NULL, 0, 0) )
      {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
      }

      return msg.message;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
      HDC         hdc;
      PAINTSTRUCT ps;

      static int cxClient;
      static int cyClient;

      switch ( iMsg )
      {

      case WM_SIZE :
            cxClient = LOWORD(lParam);
            cyClient = HIWORD(lParam);
            return 0;

      case WM_ERASEBKGND :
            return 1;

      case WM_PAINT :
            hdc = BeginPaint(hwnd, &ps);

            PaintBackground(hwnd, hdc, cxClient, cyClient);

            EndPaint(hwnd, &ps);
            return 0;

      case WM_DESTROY :
            PostQuitMessage(0);
            return 0;

      default :
            break;
      }

      return DefWindowProc(hwnd, iMsg, wParam, lParam);
}


//*************************************************
//* This function paints the client area into three
//* sections; the top, middle and bottom - blue,
//* white, blue respectively
//*************************************************
static void PaintBackground(HWND hwnd, HDC hdc,
                                          int cxClient, int cyClient)
{
      RECT rect;

      //*********************************************
      //* Step 1: Paint the top section; blue
      //*********************************************

      //clip the top section for paint
      rect.left   = 0;
      rect.top    = 0;
      rect.right  = cxClient;
      rect.bottom = cyClient / 3;
      
      // change brush to blue and paint top section
      SelectObject(hdc, CreateSolidBrush(RGB(210, 233, 255)));
      FillRect(hdc, &rect, (HBRUSH)GetCurrentObject(hdc, OBJ_BRUSH));


      //********************************************
      //* Step 2: Paint the middle section; white
      //********************************************

      // change brush to white and delete old brush
      DeleteObject(SelectObject(hdc, GetStockObject(WHITE_BRUSH)));

      // clip middle section for paint
      rect.left   = 0;
      rect.top    = (cyClient / 3) + 1; /* exclude/clip one extra coordinate/pixel for line*/
      rect.right  = cxClient;
      rect.bottom = ((cyClient) - (cyClient / 3)) - 1; /* exclude/clip one coordinate/pixel for line*/

      // paint middle section white
      FillRect(hdc, &rect, (HBRUSH)GetCurrentObject(hdc, OBJ_BRUSH));


      //**********************************************
      //* Step 3: Paint bottom section; blue
      //**********************************************

      // change brush back to blue
      SelectObject(hdc, CreateSolidBrush(RGB(210, 233, 255)));

      // clip bottom section for paint
      rect.left    = 0;
      rect.top     = (cyClient) - (cyClient / 3);
      rect.right   = cxClient;
      rect.bottom  = cyClient;

      // paint bottom section blue
      FillRect(hdc, &rect, (HBRUSH)GetCurrentObject(hdc, OBJ_BRUSH));

      // change brush back to default; white, and delete old brush
      DeleteObject(SelectObject(hdc, GetStockObject(WHITE_BRUSH)));


      //***********************************************
      //* Step 4: Draw two lines in the middle-top and
      //* middle-bottom parts; where the one extra pixel was
      //* cliped in Step 3
      //***********************************************

      // draw middle-top line
      MoveToEx(hdc, 0, cyClient / 3, NULL);
      LineTo(hdc, cxClient, cyClient / 3);

      // draw middle-bottom line
      MoveToEx(hdc, 0, ((cyClient) - (cyClient / 3)) - 1, NULL);
      LineTo(hdc, cxClient, ((cyClient) - (cyClient / 3)) - 1);
}
x_eddy_xAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

novitiateCommented:
static void PaintBackground(HWND hwnd, HDC hdc,
                                   int cxClient, int cyClient)
{
     RECT rect;

     //*********************************************
     //* Step 1: Paint the top section; blue
     //*********************************************

       int oneThird = cyClient / 3;

     //clip the top section for paint
     rect.left   = 0;
     rect.top    = 0;
     rect.right  = cxClient;
     rect.bottom = oneThird;
     
     // change brush to blue and paint top section
     SelectObject(hdc, CreateSolidBrush(RGB(210, 233, 255)));
     FillRect(hdc, &rect, (HBRUSH)GetCurrentObject(hdc, OBJ_BRUSH));

     //**********************************************
     //* Step 3: Paint bottom section; blue
     //**********************************************

       // clip bottom section for paint
     rect.top     = (cyClient - oneThird);
     rect.bottom  = cyClient;

     // paint bottom section blue
     FillRect(hdc, &rect, (HBRUSH)GetCurrentObject(hdc, OBJ_BRUSH));


     //********************************************
     //* Step 2: Paint the middle section; white
     //********************************************

     // change brush to white and delete old brush
     DeleteObject(SelectObject(hdc, GetStockObject(WHITE_BRUSH)));

     // clip middle section for paint
     rect.top    = oneThird; /* exclude/clip one extra coordinate/pixel for line*/
     rect.bottom = cyClient - oneThird ; //exclude/clip one coordinate/pixel for line*/

     // paint middle section white
     FillRect(hdc, &rect, (HBRUSH)GetCurrentObject(hdc, OBJ_BRUSH));

     //***********************************************
     //* Step 4: Draw two lines in the middle-top and
     //* middle-bottom parts; where the one extra pixel was
     //* cliped in Step 3
     //***********************************************

     // draw middle-top line
     MoveToEx(hdc, 0, oneThird, NULL);
     LineTo(hdc, cxClient, oneThird);

     // draw middle-bottom line
     MoveToEx(hdc, 0, cyClient - oneThird, NULL);
     LineTo(hdc, cxClient, cyClient - oneThird);
}

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
x_eddy_xAuthor Commented:
Problem solved solely.

xeddyx
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.