PowerShell C# printWindow () Вывод не работаетC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 PowerShell C# printWindow () Вывод не работает

Сообщение Anonymous »

Я теперь принял немного похожий подход и все еще используя вызов PrintWindow () API, но если я могу работать, то я смогу достичь того, что я хочу. Я получаю ошибку показано на изображении ниже < /p>

». Вызвание метода не удалось, потому что [Screencapture] не содержит метод с именем 'printwindow'". Какова причина моей ошибки и как правильно ее исправить?

Код: Выделить всё

$code = @'
using System;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;

public class ScreenCapture
{

[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll")]
public static extern bool PrintWindow(IntPtr hWnd, IntPtr hdcBlt, int nFlags);

public static Bitmap PrintWindow(IntPtr hwnd)
{
RECT rc;
GetWindowRect(hwnd, out rc);

Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
IntPtr hdcBitmap = gfxBmp.GetHdc();

PrintWindow(hwnd, hdcBitmap, 0);

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

bmp.Save(@"C:\TestScreenshot.png", ImageFormat.Png);

return bmp;
}

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
private int _Left;
private int _Top;
private int _Right;
private int _Bottom;

public RECT(RECT Rectangle) : this(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom)
{
}
public RECT(int Left, int Top, int Right, int Bottom)
{
_Left = Left;
_Top = Top;
_Right = Right;
_Bottom = Bottom;
}

public int X {
get { return _Left; }
set { _Left = value; }
}
public int Y {
get { return _Top; }
set { _Top = value; }
}
public int Left {
get { return _Left; }
set { _Left = value; }
}
public int Top {
get { return _Top; }
set { _Top = value; }
}
public int Right {
get { return _Right; }
set { _Right = value; }
}
public int Bottom {
get { return _Bottom; }
set { _Bottom = value; }
}
public int Height {
get { return _Bottom - _Top; }
set { _Bottom = value + _Top; }
}
public int Width {
get { return _Right - _Left; }
set { _Right = value + _Left; }
}
public Point Location {
get { return new Point(Left, Top); }
set {
_Left = value.X;
_Top = value.Y;
}
}
public Size Size {
get { return new Size(Width, Height); }
set {
_Right = value.Width + _Left;
_Bottom = value.Height + _Top;
}
}

public static implicit operator Rectangle(RECT Rectangle)
{
return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height);
}
public static implicit operator RECT(Rectangle Rectangle)
{
return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
}
public static bool operator ==(RECT Rectangle1, RECT Rectangle2)
{
return Rectangle1.Equals(Rectangle2);
}
public static bool operator !=(RECT Rectangle1, RECT Rectangle2)
{
return !Rectangle1.Equals(Rectangle2);
}

public override string ToString()
{
return "{Left: " + _Left + "; " + "Top: " + _Top + "; Right: " + _Right + "; Bottom: " + _Bottom + "}";
}

public override int GetHashCode()
{
return ToString().GetHashCode();
}

public bool Equals(RECT Rectangle)
{
return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right &&  Rectangle.Bottom == _Bottom;
}

public override bool Equals(object Object)
{
if (Object is RECT) {
return Equals((RECT)Object);
} else if (Object is Rectangle) {
return Equals(new RECT((Rectangle)Object));
}

return false;
}
}

}

'@

# Loads/Adds User Add-Type (With correct Assemblies)
Add-type $code -ReferencedAssemblies 'System.Windows.Forms','System.Drawing'

# Creates the object for the Function (ScreenShotAC.ScreenCapture)
$ScreenCapture = New-Object ScreenCapture

# Grabs
$Handle = (Get-Process -Name Notepad).MainWindowHandle
$ScreenCapture.PrintWindow($Handle)
Я пробовал различные другие решения в PowerShell, но это самое близкое, что я получил для получения printwindow () , работая с помощью вызова в PowerShell. В идеале я бы хотел, чтобы текущий код работал, если кто -то не сможет очистить то, что я сделал, и объяснить указанные изменения.

Подробнее здесь: https://stackoverflow.com/questions/764 ... ot-working
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Скриншот игры с использованием PrintWindow
    Anonymous » » в форуме C#
    0 Ответы
    8 Просмотры
    Последнее сообщение Anonymous
  • Скриншот неактивного окна PrintWindow + win32gui
    Anonymous » » в форуме Python
    0 Ответы
    34 Просмотры
    Последнее сообщение Anonymous
  • PrintWindow Отправить сообщение WM_PAINT или WM_PRINT?
    Anonymous » » в форуме C++
    0 Ответы
    2 Просмотры
    Последнее сообщение Anonymous
  • Powershell SDK получает доступ к значениям объектов Powershell?
    Anonymous » » в форуме C#
    0 Ответы
    35 Просмотры
    Последнее сообщение Anonymous
  • Powershell SDK получает доступ к значениям объектов Powershell?
    Anonymous » » в форуме C#
    0 Ответы
    28 Просмотры
    Последнее сообщение Anonymous

Вернуться в «C#»