Solved

i dont understand these code!

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

17 Experts available now in Live!

Get 1:1 Help Now