private void GoButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.WindowSelector.SelectedIndex > -1)
            {
                WindowSpec spec = this.WindowSelector.SelectedItem as WindowSpec;

                TargetWindow targetWin = new TargetWindow();
                targetWin.Port = int.Parse(this.PortInput.Text);
                targetWin.TCP  = (bool)this.UseTCP.IsChecked;

                User32Helper.tagWINDOWINFO info = spec.Info;
                User32Helper.GetWindowInfo(spec.Hwnd, ref info);

                long _windowWidth  = targetWin._windowWidth = info.rcWindow.right - info.rcWindow.left;
                long _windowHeight = targetWin._windowHeight = info.rcWindow.bottom - info.rcWindow.top;

                targetWin.MTContainer.Width  = _windowWidth;
                targetWin.MTContainer.Height = _windowHeight;

                long _windowLeft = targetWin._windowLeft = info.rcWindow.left + (info.cxWindowBorders / 2);
                long _windowTop  = targetWin._windowTop = info.rcWindow.top + (info.cyWindowBorders);

                Canvas.SetLeft(targetWin.MTContainer, (double)_windowLeft);
                Canvas.SetTop(targetWin.MTContainer, (double)_windowTop);

                targetWin.Show();
                this.Hide();
            }
        }
        private static bool Report(int hwnd, int lParam)
        {
            IntPtr        ptr  = new IntPtr(hwnd);
            tagWINDOWINFO info = new tagWINDOWINFO();

            GetWindowInfo(ptr, ref info);

            if (IsWindowVisible(ptr) && !IsIconic(ptr) && info.cxWindowBorders > 0 && info.cyWindowBorders > 0)
            {
                string title = GetText(new IntPtr(hwnd));

                if (title != "")
                {
                    WindowSpec spec = new WindowSpec();
                    spec.Caption = title;
                    spec.Hwnd    = ptr;
                    spec.Info    = info;

                    Bitmap            bm = GetWindowPreview(spec);
                    BitmapImage       bi = ConvertBitmapToBitmapImage(bm);
                    TransformedBitmap tb = new TransformedBitmap();
                    tb.BeginInit();
                    tb.Source = bi;

                    double ratio     = bi.Height / bi.Width;
                    double newHeight = 150 * ratio;
                    double scaleX    = 150 / bi.Width;
                    double scaleY    = newHeight / bi.Height;

                    ScaleTransform transform = new ScaleTransform(scaleX, scaleY);
                    tb.Transform = transform;
                    tb.EndInit();
                    spec.Preview = tb;
                    WindowNames.Add(spec);
                }
            }

            return(true);
        }
        static Bitmap GetWindowPreview(WindowSpec spec)
        {
            Rectangle rc;

            GetWindowRect(spec.Hwnd, out rc);

            if ((rc.Width > 0) && (rc.Height > 0))
            {
                Bitmap   bmp    = new Bitmap(rc.Width, rc.Height);
                Graphics gfxBmp = Graphics.FromImage(bmp);

                IntPtr hdcBitmap = gfxBmp.GetHdc();

                PrintWindow(spec.Hwnd, hdcBitmap, 0);

                gfxBmp.ReleaseHdc(hdcBitmap);
                gfxBmp.Dispose();

                return(bmp);
            }
            else
            {
                return(new Bitmap(1, 1));
            }

            /*
             * int height = spec.Info.rcWindow.bottom - spec.Info.rcWindow.top;
             * int width = spec.Info.rcWindow.right - spec.Info.rcWindow.left;
             *
             * Bitmap screen = new Bitmap(width, height);
             * Graphics g = Graphics.FromImage(screen);
             *
             * g.CopyFromScreen(spec.Info.rcWindow.left, spec.Info.rcWindow.top, 0, 0, new System.Drawing.Size(width, height));
             *
             * g.Dispose();
             *
             * return screen;
             */
        }
        static Bitmap GetWindowPreview(WindowSpec spec)
        {
            Rectangle rc;
            GetWindowRect(spec.Hwnd, out rc);

            if ((rc.Width > 0) && (rc.Height > 0))
            {
                Bitmap bmp = new Bitmap(rc.Width, rc.Height);
                Graphics gfxBmp = Graphics.FromImage(bmp);

                IntPtr hdcBitmap = gfxBmp.GetHdc();

                PrintWindow(spec.Hwnd, hdcBitmap, 0);

                gfxBmp.ReleaseHdc(hdcBitmap);
                gfxBmp.Dispose();

                return bmp;
            }
            else
            {
                return new Bitmap(1, 1);
            }
            /*
            int height = spec.Info.rcWindow.bottom - spec.Info.rcWindow.top;
            int width = spec.Info.rcWindow.right - spec.Info.rcWindow.left;

            Bitmap screen = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(screen);

            g.CopyFromScreen(spec.Info.rcWindow.left, spec.Info.rcWindow.top, 0, 0, new System.Drawing.Size(width, height));

            g.Dispose();

            return screen;
            */
        }
        private static bool Report(int hwnd, int lParam)
        {
            IntPtr ptr = new IntPtr(hwnd);
            tagWINDOWINFO info = new tagWINDOWINFO();
            GetWindowInfo(ptr, ref info);

            if (IsWindowVisible(ptr) && !IsIconic(ptr) && info.cxWindowBorders > 0 && info.cyWindowBorders > 0)
            {
                string title = GetText(new IntPtr(hwnd));

                if (title != "")
                {
                    WindowSpec spec = new WindowSpec();
                    spec.Caption = title;
                    spec.Hwnd = ptr;
                    spec.Info = info;

                    Bitmap bm = GetWindowPreview(spec);
                    BitmapImage bi = ConvertBitmapToBitmapImage(bm);
                    TransformedBitmap tb = new TransformedBitmap();
                    tb.BeginInit();
                    tb.Source = bi;

                    double ratio = bi.Height / bi.Width;
                    double newHeight = 150 * ratio;
                    double scaleX = 150 / bi.Width;
                    double scaleY =  newHeight / bi.Height;

                    ScaleTransform transform = new ScaleTransform(scaleX, scaleY);
                    tb.Transform = transform;
                    tb.EndInit();
                    spec.Preview = tb;
                    WindowNames.Add(spec);
                }
            }

            return true;
        }