CursorClip Drawing Region
-
Hi all I tried to use CursorClip to limit my drawing region on SDI. Any easier way to do that? I need to limit my drawing region to a rectangle (400x400 pixels). Thanks;)
RECT rcClip; // new area for ClipCursor RECT rcOldClip; // previous area for ClipCursor // Record the area in which the cursor can move. GetClipCursor(&rcOldClip); // Get the dimensions of the application's window. rcClip = your_rectangle(400x400); // Confine the cursor to the application's window. ClipCursor(&rcClip); // // Process input from the confined cursor. // // Restore the cursor to its previous area. ClipCursor(&rcOldClip);
-
RECT rcClip; // new area for ClipCursor RECT rcOldClip; // previous area for ClipCursor // Record the area in which the cursor can move. GetClipCursor(&rcOldClip); // Get the dimensions of the application's window. rcClip = your_rectangle(400x400); // Confine the cursor to the application's window. ClipCursor(&rcClip); // // Process input from the confined cursor. // // Restore the cursor to its previous area. ClipCursor(&rcOldClip);
THanks for the code. But I am still quite confused.
// Get the dimensions of the application's window. rcClip = your_rectangle(400x400);
When I use GetClientRect(), it retrieved the coordinates of the top left of the client. However, when I am using SDI, there is menu and toolbar. Can you write more detailed? I am new to visual C++ but I have programming experience. Thanks;) -
THanks for the code. But I am still quite confused.
// Get the dimensions of the application's window. rcClip = your_rectangle(400x400);
When I use GetClientRect(), it retrieved the coordinates of the top left of the client. However, when I am using SDI, there is menu and toolbar. Can you write more detailed? I am new to visual C++ but I have programming experience. Thanks;)POINT p; GetClientRect(hwnd, &rcClip); p.x = rcClip.left; p.y = rcClip.top; ClientToScreen(hwnd, &p); OffsetRect(&rcClip, p.x, p.y); ClipCursor(&rcClip); ShowCursor(TRUE); ////////////////////////////// // The GetClientRect function retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner will be (0,0). // The ClientToScreen function replaces the client coordinates in the POINT structure with the screen coordinates. The screen coordinates are relative to the upper-left corner of the screen. // The OffsetRect function moves the specified rectangle by the specified offsets. // The ClipCursor function confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, Windows automatically adjusts the position to keep the cursor inside the rectangular area.