jeudi 22 mars 2018

ScreenToClient not getting the window client

First let me pull up a quote from MSDN on ScreenToClient:

The new coordinates are relative to the upper-left corner of the specified window's client area.

Now, I am basically making a paint-like application and I just made a simple program that checks if the left mouse button is being held, captures the current coordinates with GetCursorPos and ScreenToClient and draws with SetPixel.

case WM_PAINT: 
    {
        if (GetKeyState(VK_LBUTTON) & 256 && !bStopDrawing)
        {
            HDC hDc = GetDC(hWnd);

            SetCapture(hWnd);
            POINT lpCursorPoint;
            GetCursorPos(&lpCursorPoint);
            ScreenToClient(hWnd, &lpCursorPoint);

            SetPixel(hDc, lpCursorPoint.x, lpCursorPoint.y, RGB(1, 1, 1));

            ReleaseCapture();
            DeleteDC(hDc);
        }

        return 0;
    }

Now, the problem comes when i try to move or resize the window. Instead of doing that, it draws behind the title bar of the window. Correct me if I'm wrong but the title bar is not part of the window client area, correct?

If you guys could point me in the right direction about this, it would be great.

Read before posting: If you want to tell me about my use of GetDC, well, I don't think it has anything to do with GetCursorPos, but regardless, using BeingPaint and EndPaint wasn't working for some reason so I had to use this. This just before you burn me for using it :D

Aucun commentaire:

Enregistrer un commentaire