Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Code Snippets Code Examples

Capture window under mouse

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Capture window under mouse Private Const SRCCOPY = &HCC0020 Private Type POINTAPI X As Long Y As Long End Type Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Sub Form_Load() Timer1.Enabled = True Timer1.Interval = 400 SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 1 Form1.AutoRedraw = True End Sub Private Sub Timer1_Timer() Dim xy As POINTAPI Dim wnd As Long, wndc As Long GetCursorPos xy wnd = WindowFromPoint(xy.X, xy.Y) wndc = GetDC(wnd) Form1.Refresh BitBlt Me.hdc, 0, 0, Screen.Width, Screen.Height, wndc, 0, 0, SRCCOPY End Sub