Solved

i dont understand these code!

Posted on 2003-12-03
4
218 Views
Last Modified: 2013-11-20
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) ;
}


0
Comment
Question by:fyf7262284
  • 2
4 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 9872751
What is the question?
0
 
LVL 1

Author Comment

by:fyf7262284
ID: 9879042
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
                                                             
                 
0
 
LVL 6

Expert Comment

by:GloomyFriar
ID: 9881280
It looks like VNC code ;-)
0
 
LVL 6

Accepted Solution

by:
GloomyFriar earned 20 total points
ID: 9881308
As far as I understand there is supposed that the window
received WM _ RBUTTONUP or WM _ LBUTTONUP is foreground.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 55
unable to delete all specified values regedit 38 410
bigDiff challenge 17 106
EvenOdd challenge 10 108
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question