我试图带一个窗口前景.我正在使用此代码.但它不起作用.有人可以帮忙吗?
ShowWindowAsync(wnd.hWnd, SW_SHOW);
SetForegroundWindow(wnd.hWnd);
// Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
// Converted to Delphi by Ray Lischner
// Published in The Delphi Magazine 55, page 16
// Converted to C# by Kevin Gale
IntPtr foregroundWindow = GetForegroundWindow();
IntPtr Dummy = IntPtr.Zero;
uint foregroundThreadId = GetWindowThreadProcessId(foregroundWindow, Dummy);
uint thisThreadId = GetWindowThreadProcessId(wnd.hWnd, Dummy);
if (AttachThreadInput(thisThreadId, foregroundThreadId, true))
{
BringWindowToTop(wnd.hWnd); // IE 5.5 related hack
SetForegroundWindow(wnd.hWnd);
AttachThreadInput(thisThreadId, foregroundThreadId, false);
}
if (GetForegroundWindow() != wnd.hWnd)
{
// Code by Daniel P. Stasinski
// …Run Code Online (Sandbox Code Playgroud) 我已经编写了一段代码来模拟鼠标点击,这在我的Vista中运行良好.但是当我在Windows 7中测试它时,它没有生成click事件.有人可以帮忙吗?我正在添加下面的代码段.谢谢,Nikil
[DllImport("user32.dll")]
static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
System.Windows.Forms.Cursor.Hide();
System.Windows.Forms.Cursor.Position = new System.Drawing.Point(xinc + rct.Left, yinc + rct.Top);
int X = System.Windows.Forms.Cursor.Position.X;
int y = System.Windows.Forms.Cursor.Position.Y;
mouse_event((int)(MouseEventFlags.LEFTDOWN), 0, 0, 0, 0);
mouse_event((int)(MouseEventFlags.LEFTUP), 0, 0, 0, 0);
System.Windows.Forms.Cursor.Position = new System.Drawing.Point(0, 0);
System.Windows.Forms.Cursor.Show();
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个类似于目标c中类型'id'的实现,它可以在运行时使用任何类型.是否可以在c#中执行此操作?
让我解释一下我的要求
id abc;// a common type which can hold any object during runtime
if(cond1)
{
Option1 opt1 = new Option1();//opt1 is an object of user defined class Option1
abc = opt1;
}
else if(cond2)
{
Option2 opt2 = new Option2();
abc = opt2;
}
...
Run Code Online (Sandbox Code Playgroud)
我怎样才能在c#中做同样的事情?谢谢,Nikil.