2012-01-03 12 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; 
です
関連する問題