0

I connect to the rdp server with this code

    axMsRdpClient8NotSafeForScripting1.Server = "161.4.11.26";
    axMsRdpClient8NotSafeForScripting1.AdvancedSettings8.RDPPort = 3389;
    axMsRdpClient8NotSafeForScripting1.UserName = "Administratоr";
    axMsRdpClient8NotSafeForScripting1.AdvancedSettings8.SmartSizing = true;
    axMsRdpClient8NotSafeForScripting1.DesktopWidth = this.Width;
    axMsRdpClient8NotSafeForScripting1.DesktopHeight = this.Height;
    axMsRdpClient8NotSafeForScripting1.AdvancedSettings.allowBackgroundInput = 1;
    axMsRdpClient8NotSafeForScripting1.SecuredSettings3.KeyboardHookMode = 1;
    axMsRdpClient8NotSafeForScripting1.AdvancedSettings8.AuthenticationLevel = 0;
    axMsRdpClient8NotSafeForScripting1.ColorDepth = 16;

    IMsRdpClientNonScriptable5 nonScriptable2 = (IMsRdpClientNonScriptable5)axMsRdpClient8NotSafeForScripting1.GetOcx();
    nonScriptable2.ClearTextPassword = "WwC0vv9";
    nonScriptable2.AllowCredentialSaving = false;
    nonScriptable2.AllowPromptingForCredentials = false;
    nonScriptable2.DisableConnectionBar = true;
    nonScriptable2.EnableCredSspSupport = true;

    axMsRdpClient8NotSafeForScripting1.Connect();

All the methods that take a picture of the server screen are bad methods. They do not work when the window is minimized. There are other methods and they try to get its coordinates with the Windows API and take a picture of it, but I want to get the same image that is being displayed in axMsRdpClient8NotSafeForScripting1 in bitmap.

It may be necessary to take a picture of each control separately at the same time in a window.

I really need this and no method worked for me


The following code works for me:

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);

    [DllImport("gdi32.dll")]
    public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);

    [DllImport("user32.dll")]
    private static extern IntPtr GetWindowDC(IntPtr hWnd);

    public Bitmap GetControlScreenshot(Control control)
    {
        Bitmap bmp = new Bitmap(control.Width, control.Height);
        using (Graphics gfx = Graphics.FromImage(bmp))
        {
            IntPtr hdcBitmap = gfx.GetHdc();
            try
            {
                IntPtr hdcControl = GetWindowDC(control.Handle);
                try
                {
                    BitBlt(hdcBitmap, 0, 0, control.Width, control.Height, hdcControl, 0, 0, 13369376);
                }
                finally
                {
                    ReleaseDC(control.Handle, hdcControl);
                }
            }
            finally
            {
                gfx.ReleaseHdc(hdcBitmap);
            }
        }
        return bmp;
    }

But it does not work when the window is minimized

How can I take a bitmap of the server screen if it's minimized?

Because all the codes try to take a picture of the page and save it, I say they are all bad. I want to directly save the image displayed by tcp in axhost mstsclib

0 Answers0