如何获取控制台坐标 我写了一个控制台小程序~需要获取这个控制台的坐标,怎么实现呢~? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 控制台的坐标?是说控制台上光标的位置吗?参考Console.CursorLeft Console.CursorTop属性 试试这个,不太完善,每次都打出两遍坐标(如果开多个Cmd窗口则更多),不过打出来的第一个应该就是当前窗口坐标了,因为FindWindowEx是从最顶层窗口开始搜索…… C# codeusing System;using System.Runtime.InteropServices;namespace ConsoleApplication4{ [StructLayout(LayoutKind.Sequential)] struct RECT { public int left; public int top; public int right; public int bottom; } unsafe class Program { static unsafe void Main(string[] args) { Console.Title = "MyProgram"; string szClassName = "ConsoleWindowClass"; IntPtr hwnd = IntPtr.Zero; RECT rect = new RECT(); do { hwnd = FindWindowEx(IntPtr.Zero, hwnd, szClassName, Console.Title); if (hwnd != null) { GetWindowRect(hwnd, &rect); Console.WriteLine(rect.left + " " + rect.top); } } while (hwnd != IntPtr.Zero); } [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool GetWindowRect(IntPtr hWnd, RECT* lpRect); }} 簡單的問題:什麽是面向用戶指令?如何理解.在線等... (50分)C#如何实现本地的两个程序间的通讯? 可能刚才的帖子没说清楚我要生成4位所有26个英文字母 谁来帮我看看这代码哪个地方有误? ^_^ 高手来这里看看 ^_^ 加密设计 [求助]xmlDocument能转换成flowDocument么 在treeview中, 怎樣在點擊鼠標時執行一個方法,獲得它的節點值 一个概念问题。高手帮忙解惑一下 有问题 InitializeComponent()方法内幕,高手指点。 List链表的泛型编程问题
参考Console.CursorLeft Console.CursorTop属性
using System;
using System.Runtime.InteropServices;namespace ConsoleApplication4
{
[StructLayout(LayoutKind.Sequential)]
struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
} unsafe class Program
{
static unsafe void Main(string[] args)
{
Console.Title = "MyProgram";
string szClassName = "ConsoleWindowClass";
IntPtr hwnd = IntPtr.Zero;
RECT rect = new RECT();
do
{
hwnd = FindWindowEx(IntPtr.Zero, hwnd, szClassName, Console.Title);
if (hwnd != null)
{
GetWindowRect(hwnd, &rect);
Console.WriteLine(rect.left + " " + rect.top);
}
}
while (hwnd != IntPtr.Zero);
} [DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool GetWindowRect(IntPtr hWnd, RECT* lpRect);
}
}