0
我想在C#中使用win10这个帖子来处理这个问题。SendInput to minimized window while you're working on other windows。'GetProcessIdOfThread'总是返回零
我跟着最好的答案做,我觉得这并不像“GetProcessIdOfThread”工作始终返回0
下面是代码:
public MainWindow()
{
InitializeComponent();
IntPtr NotepadHandle = FindWindow("Notepad", "Untitled - Notepad");
if (NotepadHandle == IntPtr.Zero)
{
MessageBox.Show("Notepad is not running.");
return;
}
uint noteid = GetProcessIdOfThread(NotepadHandle);
uint selfid = GetCurrentThreadId();
bool attach = AttachThreadInput(selfid, noteid, true);
if (attach == false)
{
MessageBox.Show("attach fail");
return;
}
}
难道我误解了什么? 谢谢!
如果函数成功,则返回值是与指定线程关联的进程的进程标识符。如果函数失败,返回值为零。要获得扩展的错误信息,请调用'GetLastError'。 – Marusyk
但是不要直接调用'GetLastError' - 使用['Marshal.GetLastWin32Error'](https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getlastwin32error(v = vs。 100).aspx)并阅读其中的文档以获取其他要求。 –