Hello @Davit ,
This can be achieved if it is possible to draw on a full screen, but only show drawing on a specific rectangle. In that case I can regularly update the rectangle when my window is moved. Is this possible in winapi?
You can use CreateCompatibleDC to create a memory device context, and draw in memdc. Then use the StretchBlt function to copy the graphics to the drawing window.
Some code for reference:
HDC memdc = CreateCompatibleDC(hdc);
HDC child_hdc = GetDC(Child_hwnd);
HBITMAP membitmap = CreateCompatibleBitmap(hdc, 800, 600);
SelectObject(memdc, membitmap);
BitBlt(memdc, 0, 0, 800, 600, hdc, 0, 0, SRCCOPY);
MoveToEx(memdc, 10, 10, (LPPOINT)NULL);
LineTo(memdc, 100, 100);
MoveToEx(memdc, 200, 200, (LPPOINT)NULL);
LineTo(memdc, 300, 300);
StretchBlt(child_hdc,0,0,400,300, memdc,0,0,800,600, SRCCOPY);
Like this:
When you move the main window, you will receive a WM_MOVE message. Use the InvalidateRect function in WM_MOVE to update the rectangle.
I would like the drawing to be attached to its screen position, and I would like it to disappear when it goes outside of the window area (i.e. when the window is moved).
PtInRect is what you need.
Determine whether the four coordinates of the drawing window are in the main window, if not, use ShowWindow to hide the drawing window.
ShowWindow(Child_hwnd, SW_HIDE);
----------
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.