Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

Help With Writing a program that will restore if it is already open

I am currently writing a program iin Visual C++ that runs in the backdrop and places a taskbar icon.  I have figured out how to place the taskbar icon and make the program restore if you click on the icon.  My problem now is that I wish to make it so that if you click on the desktop icon (like running the program again) instead of running another thread it just shows the form and transfers the focus to it.

I would really appreciate help
Thanks
MiDK
0
MiDK
Asked:
MiDK
1 Solution
 
PlanetCppCommented:
if you want a quick fix then you can just look for the other window.
in winmain before you create anything
HWND alreadythere = FindWindow(NULL,"your window's title");
alternately you can use
HWND alreadythere = FindWindow("mainwinclassname","");
if(alreadythere!=0)
{
//you said it was minimized so we restore it
ShowWindow(alreadythere,SW_RESTORE);
return 0; //exit winmain
}
//if i remember correctly when you restotre it the focus should go to that window.
this method isnt the greatest because other users can have your program running on there own accounts, but im guessing that not an issue.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now