ClipCurSor
.Confines the cursor to a rectangular area on the screen
Parameters
lpRect
Type: const RECT*
A pointer to the structure that contains the screen coordinates of the upper-left and lower-right corners of the confining rectangle. If this parameter is NULL,
.the cursor is free to move anywhere on the screen
Dim ptClientUL As POINTAPI 'client area upper lef corner
Dim ptClientLR As POINTAPI 'client area lower right corner
Static rcBmp As RECT
WM_CREATE
(hdc=GetDC(hwnd
(hdcCompat=CreateCompatibleDC(hdc
SelectObject hdcCompat, hbmp
((hpenDot=CreatePen(PS_DOT,1,RGB(0, 0, 0
SetRect rcBmp, 1, 1, 34, 34
WM_PAINT
BeginPaint hwnd,ps
Rectangle ps.hdc,rcBmp.left,rcBmp.top,rcBmp.right, rcBmp.bottom
StretchBlt ps.hdc,rcBmp.left+1,rcBmp.top+1,(rcBmp.right-rcBmp.left)-2,(rcBmp.bottom-rcBmp.top)-2, hdcCompat,0,0,32,32,SRCCOPY
EndPaint hwnd,ps
WM_MOVE,WM_SIZE
'Convert the client coordinates of the client-area rectangle to screen coordinates and save them in a rectangle.The rectangle is passed to the ClipCursor function during WM_LBUTTONDOWN processing.
GetClientRect hwnd,rcClient
ptClientUL.x = rcClient.left
ptClientUL.y = rcClient.top
ptClientLR.x = rcClient.right
ptClientLR.y = rcClient.bottom ClientToScreen hwnd,ptClientUL ClientToScreen hwnd,ptClientLR
SetRect rcClient,ptClientUL.x, ptClientUL.y,ptClientLR.x,ptClientLR.y)
WM_LBUTTONDOWN
ClipCursor rcClient
pt.x = (LONG) LOWORD(lParam)
pt.y = (LONG) HIWORD(lParam)
if (PtInRect(&rcBmp, pt)) Then
hdc=GetDC(hwnd)
SelectObject hdc,hpenDot
Rectangle hdc,rcBmp.left,rcBmp.top, rcBmp.right,rcBmp.bottom)
fDragRect=TRUE
ReleaseDC hwnd,hdc
WM_LBUTTONUP
' Release the mouse cursor.
ClipCursor 0