2012-01-03 2 views
1

이 코드는 창 주위에 100x100 크기의 상자에 그려진 이미지를 커서 주위로 캡처하려고합니다. BitBlt 여기에 어느 위치에 0을 반환하지 않습니다, 그리고 난 문제가 BitBlt의 첫 번째 함수 호출, 내가 전역으로 선언 된 HDC입니다 메타로 창 배경에서 이미지를 복사하려고하는 중이 야 꽤 확신 해요. . 메모리에 전체적으로 HDC를 만들려고 노력하면서, 나는 공백의 비트 맵을 만들고로드하고 새로운 이미지를 그 핸들과 결합 된 핸들로 캡처하려고 시도했지만, 그 모든 작업은 지우개처럼 작동하여 흰색 상자를 그렸습니다. 커서가 움직일 때 주위를 가리 킵니다. 관련 코드는 아래에 있습니다. mouseRect 및 clientRect는 각각 커서 주변의 상자 및 클라이언트 사각형과 관련된 전역 변수입니다. 어떤 도움을 주셔서 감사합니다, 감사합니다! 코드를 고정클라이언트 창에서 이미지 캡처 win32 C++

case WM_CREATE: 
    hInstance = ((LPCREATESTRUCT) lParam)->hInstance; 
    GetClientRect(hWnd, &clientRect); 
    hdc = GetDC(hWnd); 
    meta = CreateCompatibleDC(hdc); 
    return 0; 


case WM_MOUSEMOVE:  
    x = LOWORD(lParam); 
    y = HIWORD(lParam); 
    hdc = GetDC(hWnd); 
    BitBlt(hdc, mouseRect.left, mouseRect.top, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, meta, 0, 0, SRCCOPY); 
    ReleaseDC(hWnd, meta); 
    meta = CreateCompatibleDC(hdc); 
    if(y<50) 
     mouseRect.top = 0; 
    else 
     mouseRect.top = y-50; 
    if(x<50) 
     mouseRect.left = 0; 
    else 
     mouseRect.left = x-50; 
    if(clientRect.right-x<50) 
     mouseRect.right = clientRect.right; 
    else 
     mouseRect.right = x+50; 
    if(clientRect.bottom-y<50) 
     mouseRect.bottom = clientRect.bottom; 
    else 
     mouseRect.bottom = y+50; 
    BitBlt(meta, 0, 0, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, hdc, mouseRect.left, mouseRect.top, SRCCOPY); 
    ReleaseDC(hWnd, hdc); 
    return 0; 

답변

0

, 여기에 수정 WM_MOUSEMOVE 코드

case WM_MOUSEMOVE:  
x = LOWORD(lParam); 
y = HIWORD(lParam); 
hdc = GetDC(hWnd); 
BitBlt(hdc, mouseRect.left, mouseRect.top, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, hdcMemDC, 0, 0, SRCCOPY); 
ReleaseDC(hWnd, hdcMemDC); 
if(y<50) 
    mouseRect.top = 0; 
else 
    mouseRect.top = y-50; 
if(x<50) 
    mouseRect.left = 0; 
else 
    mouseRect.left = x-50; 
if(clientRect.right-x<50) 
    mouseRect.right = clientRect.right; 
else 
    mouseRect.right = x+50; 
if(clientRect.bottom-y<50) 
    mouseRect.bottom = clientRect.bottom; 
else 
    mouseRect.bottom = y+50; 
hdcMemDC = CreateCompatibleDC(hdc); 
hbmScreen = CreateCompatibleBitmap(hdc, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top); 
SelectObject(hdcMemDC,hbmScreen);  
if(!BitBlt(hdcMemDC, 0, 0, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, hdc, mouseRect.left, mouseRect.top, SRCCOPY)) 
{ 
    MessageBox(hWnd, "BitBlt has failed", "Failed", MB_OK); 
} 
ReleaseDC(hWnd, hdc); 
return 0; 
입니다
관련 문제