2010-11-17 94 views
0

我想通过点击右键来使我的运行应用程序。请注意,我不希望同样的应用程序的新实例,但通过使用SetForegroundWindow我可以使用查找窗口而不使用RegisterClass和CreateWindow

我曾尝试使用AfxRegisterClassCreatewindow(Previos后here)将同一应用程序的前面,但这个创建一个新的窗口,并onclik带来新窗口而不是我目前的应用程序。有没有办法让我的应用程序,而不是新创建的窗口。

+1

您可以在不调用'CreateWindow()'的情况下始终使用'FindWindow()'。我不明白你的问题 - 你想确保只有一个应用程序实例在运行吗? – 2010-11-17 09:55:33

+0

@在计算机上,如果我想在不使用Create Window的情况下使用FindWindow,则句柄变为NULL。如果你想看看[源代码](http://stackoverflow.com/questions/4201728/bringwindowtotop-is-not-working-even-if-i-get-the-handle-to-class-窗口“FindWindow”) – Simsons 2010-11-17 10:22:51

回答

0

可能使用互斥锁更好,但是,可以使用FindWindow。像这样:

HWND hwnd = FindWindow(NULL, "My App's Hopefully Unique Title"); 
if (hwnd) 
{ 
    SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); 
    SetFocus(hwnd); 
} 
+0

+1修复mismoderation,你真的不需要CreateWindow。 – MSalters 2010-11-17 10:28:37

+0

@ MSalters,我不明白原因,但是当我RegisterClass,然后尝试Findwindow我得到NULL,但是当我使用FindWindow(CreateWindow后),我获得它的句柄。我有以前的所有代码[post](http://stackoverflow.com/questions/4201728/bringwindowtotop-is-not-working-even-if-i-get-the-handle-to-class-window“BringWindowToTop是不工作,即使我得到类窗口的句柄“) – Simsons 2010-11-17 10:51:16

+0

这是因为**没有**窗口来查找,如果你还没有创建它。 – wj32 2010-11-17 10:52:21

相关问题