Solved

i dont understand these code!

Posted on 2003-12-03
4
215 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 75
no14 challenge 14 62
Execute multiple curl cmds with sleep and send output to file 10 88
Thin secure Windows 10 5 73
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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 is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now