Invoke code compilation error

I try an Invoke code activity, in it, the c# coding is

IntPtr desemphasized textktop = GetDC(IntPtr.Zero);
while (true)
{
using (Graphics g = Graphics.FromHdc(desktop))
{
RECT rct = new RECT();
GetWindowRect(inhandle, ref rct);
Rectangle rect = new Rectangle(rct.Left - 2, rct.Top - 2, (rct.Right - rct.Left) + 2, (rct.Bottom - rct.Top) + 2);
Pen myPen = new Pen(System.Drawing.Color.Red, 5);
g.DrawRectangle(myPen, rect);
g.Dispose();
}
}

The Input argument to this invoke code activity is
inhandle, type IntPtr, Direction IN

And I go the compilation errors of the following :

Error ERROR Validation Error No compiled code to run
error CS0103: The name ‘GetDC’ does not exist in the current context At line 12
error CS0246: The type or namespace name ‘RECT’ could not be found (are you missing a using directive or an assembly reference?) At line 17
error CS0246: The type or namespace name ‘RECT’ could not be found (are you missing a using directive or an assembly reference?) At line 17
error CS0103: The name ‘GetWindowRect’ does not exist in the current context At line 18 try.xaml

I have put in System.Drawing, System.Windows in imported namespace,

don’t know how to resolve this,
can anyone help ?

Thanks

I have the same question for C# code as well.

Hi,

GetDC is Win32 API. If we want to use it, generally we need to declare as the following.

[DllImport("user32.dll")]
private  static extern IntPtr GetDC(IntPtr hwnd);

However Invoke Code activity seems not support it

How about using Graphics.CopyFromScreen method?