简体   繁体   中英

Can I use Find window without using RegisterClass and CreateWindow

I am trying to bring my running application on click of windows rightclick. Please note I dont want a new instance of the same application but bringing the same application to the front by using SetForegroundWindow

I have tried using AfxRegisterClass and Createwindow (Previos post here ) but this creates a new window and onclik bring the new window instead of my current application. Is there a way I can bring up my app instead of newly created window.

Probably better to use mutexes, but yes, you can use FindWindow for that. Something like this:

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM