示例#1
0
        protected virtual Image GetBitmapFromHandle(IntPtr handle)
        {
            Image ret;

            Win32ApiWrapper.Rect winRect = new Win32ApiWrapper.Rect();
            Win32ApiWrapper.GetWindowRect(handle, ref winRect);

            IntPtr hdcSrc  = Win32ApiWrapper.GetWindowDC(handle);
            IntPtr hdcDest = Win32ApiWrapper.CreateCompatibleDC(hdcSrc);

            IntPtr hBitmap = Win32ApiWrapper.CreateCompatibleBitmap(hdcSrc, winRect.GetWidth(), winRect.GetHeight());
            IntPtr hOld    = Win32ApiWrapper.SelectObject(hdcDest, hBitmap);

            Win32ApiWrapper.BitBlt(hdcDest, 0, 0, winRect.GetWidth(), winRect.GetHeight(), hdcSrc, 0, 0, Win32ApiWrapper.RasterOptions.SRC_COPY);

            Win32ApiWrapper.SelectObject(hdcDest, hOld);

            Win32ApiWrapper.DeleteDC(hdcDest);
            Win32ApiWrapper.ReleaseDC(handle, hdcSrc);

            ret = Image.FromHbitmap(hBitmap);

            Win32ApiWrapper.DeleteObject(hBitmap);

            return(ret);
        }
示例#2
0
        private void Deregister()
        {
            IntPtr ret = Interlocked.Exchange(ref this.hook, IntPtr.Zero);

            if (ret != IntPtr.Zero)
            {
                Win32ApiWrapper.UnhookWindowsHookEx(ret);
            }
        }
示例#3
0
        private void Register()
        {
            Deregister();
            using (Process p = Process.GetCurrentProcess())
                using (ProcessModule curMod = p.MainModule)
                {
                    this.hook = Win32ApiWrapper.SetWindowsHookEx(Win32ApiWrapper.HookType.WH_KEYBOARD_LL,
                                                                 this.callback,
                                                                 Win32ApiWrapper.GetModuleHandle(curMod.ModuleName),
                                                                 0); // Thread.CurrentThread.ManagedThreadId);
                }

            System.Windows.Forms.Application.Run();
        }
示例#4
0
        private IntPtr LowLevelKeyboardHook(int nCode, IntPtr wParam, IntPtr lParam)
        {
            WindowsMessage msg          = (WindowsMessage)wParam;
            bool           cntrlPressed = (Win32ApiWrapper.GetAsyncKeyState((int)VirtualKeyCode.VK_CONTROL) & 0x8000) != 0;

            if (nCode >= 0 && msg == WindowsMessage.WM_KEYUP)
            {
                KBDLLHook d = (KBDLLHook)Marshal.PtrToStructure(lParam, typeof(KBDLLHook));
                if (d.vkCode == (int)VirtualKeyCode.VK_INSERT && cntrlPressed)
                {
                    ThreadMsgQueue <Image> .Enqueue(generator.GetFocusedWindowImage());
                }
            }

            return(Win32ApiWrapper.CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam));
        }
示例#5
0
 public Image GetFocusedWindowImage()
 {
     return(GetBitmapFromHandle(Win32ApiWrapper.GetForegroundWindow()));
 }
示例#6
0
 public Image GetScreenImage()
 {
     return(GetBitmapFromHandle(Win32ApiWrapper.GetDesktopWindow()));
 }