DAY BY DAY---マウス移動をクライアント領域に制限する---

-----関数-----
まず始めに、クライアント領域に制限するために必要な関数を紹介。
・ClipCursor
・GetClientRect
・ClientToScreen
この3つを使います。これらの関数についてはMSDNでも見ておいてください。

-----一例-----
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
    RECT clientrc,cliprc;
    POINT topleft,rightbottom;
    switch (msg)
    {
    case WM_ACTIVATE: 
        if(LOWORD(wp) == WA_INACTIVE) 
        { 
            ClipCursor(NULL); 
        } 
        else
        {
            GetClientRect(hWnd,&clientrc);
            
            topleft.x = clientrc.left;
            topleft.y = clientrc.top;
            rightbottom.x = clientrc.right;
            rightbottom.y = clientrc.bottom;

            ClientToScreen(hWnd,&topleft);
            ClientToScreen(hWnd,&rightbottom);

            cliprc.left = topleft.x;
            cliprc.top  = topleft.y;
            cliprc.right = rightbottom.x;
            cliprc.bottom  = rightbottom.y;
            
            ClipCursor(&cliprc); 
        }
        break;
    case WM_DESTROY:
        PostQuitMessage (0);
        break;
    default:
        return DefWindowProc (hWnd, msg, wp, lp);
    }
    return FALSE;
}




戻る
 Copyright(C) 2006 DAY BY DAY. All rights reserved.