如题,下面这段代码在VC中可直接用,那么在C#中该怎么调用
LASTINPUTINFO lpi;
lpi.cbSize = sizeof(lpi);
GetLastInputInfo(&lpi);//获取上次输入操作的时间。
DWORD dwTickCount = ::GetTickCount();
if ((::GetTickCount()-lpi.dwTime)>1000*60)//1分钟
{
MessageBox("已闲置超过1分钟!");
}
解决方案
20
在vs2008的工具菜单中有一个”win32 api tool”, 可以查看大部分 windows api 和结构体在 vb 和 c# 中的使用语法.
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct tagLASTINPUTINFO {
/// UINT->unsigned int
public uint cbSize;
/// DWORD->unsigned int
public uint dwTime;
}
public partial class NativeMethods {
/// Return Type: BOOL->int
///plii: PLASTINPUTINFO->tagLASTINPUTINFO*
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint="GetLastInputInfo")]
[return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
public static extern bool GetLastInputInfo([System.Runtime.InteropServices.OutAttribute()] out tagLASTINPUTINFO plii) ;
}