Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 10th, 2012  |  syntax: None  |  size: 2.03 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Capturing image in client window win32 c  
  2. case WM_CREATE:
  3.     hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
  4.     GetClientRect(hWnd, &clientRect);
  5.     hdc = GetDC(hWnd);
  6.     meta = CreateCompatibleDC(hdc);
  7.     return 0;
  8.  
  9.  
  10. case WM_MOUSEMOVE:    
  11.     x = LOWORD(lParam);
  12.     y = HIWORD(lParam);
  13.     hdc = GetDC(hWnd);
  14.     BitBlt(hdc, mouseRect.left, mouseRect.top, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, meta, 0, 0, SRCCOPY);
  15.     ReleaseDC(hWnd, meta);
  16.     meta = CreateCompatibleDC(hdc);
  17.     if(y<50)
  18.         mouseRect.top = 0;
  19.     else
  20.         mouseRect.top = y-50;
  21.     if(x<50)
  22.         mouseRect.left = 0;
  23.     else
  24.         mouseRect.left = x-50;
  25.     if(clientRect.right-x<50)
  26.         mouseRect.right = clientRect.right;
  27.     else
  28.         mouseRect.right = x+50;
  29.     if(clientRect.bottom-y<50)
  30.         mouseRect.bottom = clientRect.bottom;
  31.     else
  32.         mouseRect.bottom = y+50;
  33.     BitBlt(meta, 0,  0, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, hdc, mouseRect.left, mouseRect.top, SRCCOPY);
  34.     ReleaseDC(hWnd, hdc);
  35.     return 0;
  36.        
  37. case WM_MOUSEMOVE:    
  38. x = LOWORD(lParam);
  39. y = HIWORD(lParam);
  40. hdc = GetDC(hWnd);
  41. BitBlt(hdc, mouseRect.left, mouseRect.top, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, hdcMemDC, 0, 0, SRCCOPY);
  42. ReleaseDC(hWnd, hdcMemDC);
  43. if(y<50)
  44.     mouseRect.top = 0;
  45. else
  46.     mouseRect.top = y-50;
  47. if(x<50)
  48.     mouseRect.left = 0;
  49. else
  50.     mouseRect.left = x-50;
  51. if(clientRect.right-x<50)
  52.     mouseRect.right = clientRect.right;
  53. else
  54.     mouseRect.right = x+50;
  55. if(clientRect.bottom-y<50)
  56.     mouseRect.bottom = clientRect.bottom;
  57. else
  58.     mouseRect.bottom = y+50;
  59. hdcMemDC = CreateCompatibleDC(hdc);
  60. hbmScreen = CreateCompatibleBitmap(hdc, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top);
  61. SelectObject(hdcMemDC,hbmScreen);    
  62. if(!BitBlt(hdcMemDC, 0, 0, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, hdc, mouseRect.left, mouseRect.top, SRCCOPY))
  63. {
  64.     MessageBox(hWnd, "BitBlt has failed", "Failed", MB_OK);
  65. }
  66. ReleaseDC(hWnd, hdc);
  67. return 0;