Link to home
Start Free TrialLog in
Avatar of fyf7262284
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(hwndScr =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(hdc,abs(ptEnd.x -ptBeg.x),//?????attation: hdc belong to hwnd,but why create a bitmap about screen
                                                                          abs(ptEnd.y -ptBeg.y));
                    SelectObject(hdcMem,hBitmap);
                    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,SRCCOPY);
                    DeleteDC(hdcMem);
                    ReleaseDC(hwnd,hdc);
                    InvalidateRect(hwnd,NULL,TRUE);

              }
            
              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) ;
}


Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

What is the question?
Avatar of fyf7262284
fyf7262284

ASKER

question is inside the program!the place with "????" mark :
hBitmap =CreateCompatibleBitmap(hdc,abs(ptEnd.x -ptBeg.xabs(ptEnd.y -ptBeg.y));),
//?????attation: hdc belong to hwnd,but why create a bitmap about screen
                                                             
                 
It looks like VNC code ;-)
ASKER CERTIFIED SOLUTION
Avatar of GloomyFriar
GloomyFriar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial