能不能通过已经存在的名称为"MutexNameString"的Mutex对象取得hWnd呢?

c#)我想利用Mutex来使程序只运行一份实例:
...
bool canCreate;
Mutex myMutex = new Mutex(true, "MutexNameString", out canCreate);
if(canCreate)
{
...
}
else
{
IntPtr hWnd = FindWindow(lpClassName, null);
ShowWindowAsync(hWnd, 1);
SetForegroundWindow(hWnd);
}
这里的lpClassName我是通过spy++查到的,有没有什么函数可以直接取得呢?

米脂
浏览 79回答 1
1回答

大话西游666

你这种方式是比较合理的方式,lpClassName 是要查的,而且也是固定的。如果你不用 lpClassName ,可以用程序的标题IntPtr hWnd = FindWindow(null, "标题");ShowWindowAsync(hWnd, 1);SetForegroundWindow(hWnd);
打开App,查看更多内容
随时随地看视频慕课网APP