001.
public
static
class
User32
002.
{
003.
public
const
Int32 CURSOR_SHOWING = 0x00000001;
004.
005.
[StructLayout(LayoutKind.Sequential)]
006.
public
struct
ICONINFO
007.
{
008.
public
bool
fIcon;
009.
public
Int32 xHotspot;
010.
public
Int32 yHotspot;
011.
public
IntPtr hbmMask;
012.
public
IntPtr hbmColor;
013.
}
014.
015.
[StructLayout(LayoutKind.Sequential)]
016.
public
struct
POINT
017.
{
018.
public
Int32 x;
019.
public
Int32 y;
020.
}
021.
022.
[StructLayout(LayoutKind.Sequential)]
023.
public
struct
CURSORINFO
024.
{
025.
public
Int32 cbSize;
026.
public
Int32 flags;
027.
public
IntPtr hCursor;
028.
public
POINT ptScreenPos;
029.
}
030.
031.
[DllImport(
"user32.dll"
)]
032.
public
static
extern
bool
GetCursorInfo(
out
CURSORINFO pci);
033.
034.
[DllImport(
"user32.dll"
)]
035.
public
static
extern
IntPtr CopyIcon(IntPtr hIcon);
036.
037.
[DllImport(
"user32.dll"
)]
038.
public
static
extern
bool
DrawIcon(IntPtr hdc,
int
x,
int
y, IntPtr hIcon);
039.
040.
[DllImport(
"user32.dll"
)]
041.
public
static
extern
bool
GetIconInfo(IntPtr hIcon,
out
ICONINFO piconinfo);
042.
}
043.
044.
static
void
Main(
string
[] args)
045.
{
046.
Socket socket;
047.
string
_ip = File.ReadAllText(
"getIP.txt"
);
048.
049.
050.
Console.WriteLine(_ip);
051.
052.
using
(socket =
new
Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
053.
{
054.
055.
socket.Connect(_ip,9050);
056.
057.
while
(
true
)
058.
{
059.
var bounds = Screen.PrimaryScreen.Bounds;
060.
var bitmap =
new
Bitmap(bounds.Width, bounds.Height);
061.
try
062.
{
063.
while
(
true
)
064.
{
065.
using
(var graphics = Graphics.FromImage(bitmap))
066.
{
067.
graphics.CopyFromScreen(bounds.X, 0, bounds.Y, 0, bounds.Size);
068.
069.
////////////////////////////////////////
070.
User32.CURSORINFO cursorInfo;
071.
cursorInfo.cbSize = Marshal.SizeOf(
typeof
(User32.CURSORINFO));
072.
073.
if
(User32.GetCursorInfo(
out
cursorInfo))
074.
{
075.
076.
if
(cursorInfo.flags == User32.CURSOR_SHOWING)
077.
{
078.
079.
var iconPointer = User32.CopyIcon(cursorInfo.hCursor);
080.
User32.ICONINFO iconInfo;
081.
int
iconX, iconY;
082.
083.
if
(User32.GetIconInfo(iconPointer,
out
iconInfo))
084.
{
085.
086.
iconX = cursorInfo.ptScreenPos.x - ((
int
)iconInfo.xHotspot);
087.
iconY = cursorInfo.ptScreenPos.y - ((
int
)iconInfo.yHotspot);
088.
089.
090.
User32.DrawIcon(graphics.GetHdc(), iconX, iconY, cursorInfo.hCursor);
091.
092.
093.
graphics.ReleaseHdc();
094.
}
095.
}
096.
}
097.
////////////////////////////////////////
098.
099.
}
100.
byte
[] imageData;
101.
using
(var stream =
new
MemoryStream())
102.
{
103.
bitmap.Save(stream, ImageFormat.Png);
104.
imageData = stream.ToArray();
105.
}
106.
var lengthData = BitConverter.GetBytes(imageData.Length);
107.
if
(socket.Send(lengthData) < lengthData.Length)
break
;
108.
if
(socket.Send(imageData) < imageData.Length)
break
;
109.
Thread.Sleep(10);
110.
}
111.
}
112.
catch
(Exception)
113.
{
114.
115.
116.
break
;
117.
}
118.
119.
}
120.
}
121.
Application.Exit();
122.
}