1
class DoubleClickHover : Form
{
Thread T1;
System.Timers.Timer timer = new System.Timers.Timer(4000); //3 seconds
public DoubleClickHover()
{
T1 = new Thread(new ThreadStart(DoubleClickEvent));
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
}
#region Timer Mouse Double Click event
//Here, the timer for Timer click event will start when mouse hovers over an area
private void form_MouseHover(object sender, System.EventArgs e)
{
timer.Start();
}
private void form_MouseLeave(object sender, System.EventArgs e)
{
timer.Stop();
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
timer.Stop();
DoubleClickEvent();
}
//This method allows the user to click a file/folder by hovering/keeping still the mouse for specified time
public void DoubleClickEvent()
{
// Set the cursor position
// System.Windows.Forms.Cursor.Position();
DoClickMouse(0x2); // Left mouse button down
DoClickMouse(0x4); // Left mouse button up
DoClickMouse(0x2); // Left mouse button down
DoClickMouse(0x4); // Left mouse button up
}
static void DoClickMouse(int mouseButton)
{
var input = new INPUT()
{
dwType = 0, // Mouse input
mi = new MOUSEINPUT() { dwFlags = mouseButton }
};
if (SendInput(1, input, Marshal.SizeOf(input)) == 0)
{
throw new Exception();
}
}
[StructLayout(LayoutKind.Sequential)]
struct MOUSEINPUT
{
int dx;
int dy;
int mouseData;
public int dwFlags;
int time;
IntPtr dwExtraInfo;
}
struct INPUT
{
public uint dwType;
public MOUSEINPUT mi;
}
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint cInputs, INPUT input, int size);
#endregion
}
到的PInvoke函數「DoubleClickHover :: SendInput」呼叫具有不平衡堆棧。這很可能是因爲託管的PInvoke簽名與非託管目標籤名不匹配。檢查PInvoke簽名的調用約定和參數是否與目標非託管簽名相匹配。
請大家幫忙。 謝謝你
[DllImport(「user32.dll」,SetLastError = true)] static extern uint SendInput(uint nInputs,INPUT [] pInputs,int cbSize); – 2012-03-11 10:33:15