fyf7262284
asked on
i dont understand these code!
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static BOOL bCapturing, bBlocking ;
static HBITMAP hBitmap ;
static HWND hwndScr ;
static POINT ptBeg, ptEnd ;
BITMAP bm ;
HBITMAP hBitmapClip ;
HDC hdc, hdcMem ;
int iEnable ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_LBUTTONDOWN:
if(!bCapturing)
{
if(LockWindowUpdate(hwndSc r =GetDesktopWindow()))
{
bCapturing =TRUE;
SetCapture(hwnd);
SetCursor(LoadCursor(NULL, IDC_CROSS) );
}
else
MessageBeep(0);
}
return 0 ;
case WM_RBUTTONDOWN:
if(bCapturing)
{
bBlocking =TRUE;
ptBeg.x =LOWORD(lParam);
ptBeg.y =HIWORD(lParam);
ptEnd =ptBeg;
}
return 0 ;
case WM_MOUSEMOVE:
if (bBlocking)
{
ptEnd.x = LOWORD (lParam) ;
ptEnd.y = HIWORD (lParam) ;
}
return 0 ;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
if(bBlocking)
{
ptEnd.x =LOWORD(lParam);
ptEnd.y =HIWORD(lParam);
if(hBitmap)
{
DeleteObject(hBitmap);
hBitmap =NULL;
}
hdc =GetDC(hwnd);
hdcMem =CreateCompatibleDC(hdc);
hBitmap =CreateCompatibleBitmap(hd c,abs(ptEn d.x -ptBeg.x),//?????attation: hdc belong to hwnd,but why create a bitmap about screen
abs(ptEnd.y -ptBeg.y));
SelectObject(hdcMem,hBitma p);
StretchBlt(hdcMem,0,0,abs( ptEnd.x -ptBeg.x),abs(ptEnd.y -ptBeg.y),
hdc,ptBeg.x,ptBeg.y,ptEnd. x -ptBeg.x,ptEnd.y-ptBeg.y,S RCCOPY);
DeleteDC(hdcMem);
ReleaseDC(hwnd,hdc);
InvalidateRect(hwnd,NULL,T RUE);
}
if(bBlocking || bCapturing)
{
bBlocking =bCapturing =FALSE;
SetCursor(LoadCursor(NULL, IDC_ARROW) );
ReleaseCapture();
LockWindowUpdate(NULL);
}
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
if (hBitmap)
{
GetClientRect (hwnd, &rect) ;
hdcMem = CreateCompatibleDC (hdc) ;
SelectObject (hdcMem, hBitmap) ;
GetObject (hBitmap, sizeof (BITMAP), (PSTR) &bm) ;
SetStretchBltMode (hdc, COLORONCOLOR) ;
StretchBlt (hdc, 0, 0, rect.right, rect.bottom,
hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY) ;
DeleteDC (hdcMem) ;
}
EndPaint (hwnd, &ps) ;
return 0 ;
.......
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
{
static BOOL bCapturing, bBlocking ;
static HBITMAP hBitmap ;
static HWND hwndScr ;
static POINT ptBeg, ptEnd ;
BITMAP bm ;
HBITMAP hBitmapClip ;
HDC hdc, hdcMem ;
int iEnable ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_LBUTTONDOWN:
if(!bCapturing)
{
if(LockWindowUpdate(hwndSc
{
bCapturing =TRUE;
SetCapture(hwnd);
SetCursor(LoadCursor(NULL,
}
else
MessageBeep(0);
}
return 0 ;
case WM_RBUTTONDOWN:
if(bCapturing)
{
bBlocking =TRUE;
ptBeg.x =LOWORD(lParam);
ptBeg.y =HIWORD(lParam);
ptEnd =ptBeg;
}
return 0 ;
case WM_MOUSEMOVE:
if (bBlocking)
{
ptEnd.x = LOWORD (lParam) ;
ptEnd.y = HIWORD (lParam) ;
}
return 0 ;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
if(bBlocking)
{
ptEnd.x =LOWORD(lParam);
ptEnd.y =HIWORD(lParam);
if(hBitmap)
{
DeleteObject(hBitmap);
hBitmap =NULL;
}
hdc =GetDC(hwnd);
hdcMem =CreateCompatibleDC(hdc);
hBitmap =CreateCompatibleBitmap(hd
abs(ptEnd.y -ptBeg.y));
SelectObject(hdcMem,hBitma
StretchBlt(hdcMem,0,0,abs(
hdc,ptBeg.x,ptBeg.y,ptEnd.
DeleteDC(hdcMem);
ReleaseDC(hwnd,hdc);
InvalidateRect(hwnd,NULL,T
}
if(bBlocking || bCapturing)
{
bBlocking =bCapturing =FALSE;
SetCursor(LoadCursor(NULL,
ReleaseCapture();
LockWindowUpdate(NULL);
}
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
if (hBitmap)
{
GetClientRect (hwnd, &rect) ;
hdcMem = CreateCompatibleDC (hdc) ;
SelectObject (hdcMem, hBitmap) ;
GetObject (hBitmap, sizeof (BITMAP), (PSTR) &bm) ;
SetStretchBltMode (hdc, COLORONCOLOR) ;
StretchBlt (hdc, 0, 0, rect.right, rect.bottom,
hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY) ;
DeleteDC (hdcMem) ;
}
EndPaint (hwnd, &ps) ;
return 0 ;
.......
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
What is the question?
ASKER
question is inside the program!the place with "????" mark :
hBitmap =CreateCompatibleBitmap(hd c,abs(ptEn d.x -ptBeg.xabs(ptEnd.y -ptBeg.y));),
//?????attation: hdc belong to hwnd,but why create a bitmap about screen
hBitmap =CreateCompatibleBitmap(hd
//?????attation: hdc belong to hwnd,but why create a bitmap about screen
It looks like VNC code ;-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.