コード例 #1
0
ファイル: WinApi.cs プロジェクト: phillipwei/Tracking.Self
        public Rectangle GetWindowRectangle(IntPtr hWnd)
        {
            var rectangle = new NativeWinApi.Rectangle();
            NativeWinApi.GetWindowRect(hWnd, ref rectangle);

            return new Rectangle(
                rectangle.Left,
                rectangle.Top,
                Math.Abs(rectangle.Right - rectangle.Left),
                Math.Abs(rectangle.Bottom - rectangle.Top)
            );
        }
コード例 #2
0
ファイル: WinApi.cs プロジェクト: phillipwei/Tracking.Self
        // NOTE: It's super important the consumer realizes they are responsible for the memory usage of Bitmap -- if
        // you don't dispose, you are hosed. 
        public Bitmap CaptureWindow(IntPtr hwnd, PixelFormat pixelFormat)
        {
            if (!NativeWinApi.IsWindow(hwnd))
            {
                return null;
            }

            // _logger.DebugFormat("CaptureWindow({0},{1})", hwnd, pixelFormat);
            var rectangle = new NativeWinApi.Rectangle();
            NativeWinApi.GetWindowRect(hwnd, ref rectangle);
            var bmp = new Bitmap(rectangle.Width, rectangle.Height, pixelFormat);
            
            using (var gfxBmp = Graphics.FromImage(bmp))
            {
                var hdcBitmap = gfxBmp.GetHdc();
                NativeWinApi.PrintWindow(hwnd, hdcBitmap, NativeWinApi.PrintWindowFlag.PW_DEFAULT);
                gfxBmp.ReleaseHdc(hdcBitmap);
            }

            return bmp;
        }
コード例 #3
0
ファイル: WinApi.cs プロジェクト: phillipwei/Tracking.Self
 public void RefreshNotificationArea()
 {
     var startBarHandle = NativeWinApi.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Shell_TrayWnd", "");
     var trayHandle = NativeWinApi.FindWindowEx(startBarHandle, IntPtr.Zero, "TrayNotifyWnd", "");
     var notifyHandle = NativeWinApi.FindWindowEx(trayHandle, IntPtr.Zero, "SysPager", "");
     var notifyIconsHandle = NativeWinApi.FindWindowEx(notifyHandle, IntPtr.Zero, "ToolbarWindow32", "Notification Area");
     if (notifyIconsHandle == IntPtr.Zero)
     {
         notifyIconsHandle = NativeWinApi.FindWindowEx(notifyHandle, IntPtr.Zero, "ToolbarWindow32", "User Promoted Notification Area");
     }
     var notifyRectangle = new NativeWinApi.Rectangle();
     NativeWinApi.GetClientRect(notifyIconsHandle, ref notifyRectangle);
     for (var x = notifyRectangle.Left; x < notifyRectangle.Right; x += 5)
     {
         for (var y = notifyRectangle.Top; y < notifyRectangle.Bottom; y += 5)
         {
             NativeWinApi.SendMessage(notifyIconsHandle, NativeWinApi.Messages.WM_MOUSEMOVE, IntPtr.Zero, CreateMouseClickCoordinates(x, y));
         }
     }
 }