-
Dec 4th, 2017, 10:24 AM
#1
Thread Starter
PowerPoster
give the focus back to the application that I took it from
I'm sure this answer is out there somewhere, but I can't seem to hit upon it.
In my windows application, users can have a "case" open which will get a lock on the case (i.e. the record in the database) and no one else can open it. Because other people are locked out, we want to limit having a case open to 15 minutes if the user isn't actively clicking in it. When their 15 minutes is up, I put up a dialog where they have three choices: 1) close the case and free the locks 2) keep it open and get 15 more minutes 3) navigate to the case. The form that tells them their time is up beeps and is TopMost = true to make sure they notice it if, for example, they are in Excel, or Outlook, or an Internet browser window.
If the user clicks 1) close the case and free the locks, I want to do that behind the scenes and let them stay in the application they were working in before my interruption. But because I am running my code to perhaps save data, my code takes the focus away from whatever else the user was doing. But if he chooses 1), it's so he can continue with whatever else he was doing. So he (actually "she" = owner of the company) has asked, "Unless user chooses to go to the case, focus should return to users previous app."
How do I know what this previous app was?
There are 10 kinds of people in this world. Those who understand binary, and those who don't.
-
Dec 4th, 2017, 12:09 PM
#2
Re: give the focus back to the application that I took it from
Before you bring you dialog up you could use the Windows API to get the foreground window handle
http://www.pinvoke.net/default.aspx/...regroundwindow
Then you could set focus to it again
http://pinvoke.net/default.aspx/user...regroundWindow
-
Dec 4th, 2017, 01:49 PM
#3
Thread Starter
PowerPoster
Re: give the focus back to the application that I took it from
OK, my test went well. I've released it to my control group of testers to see how it goes for them. Thank you.
There are 10 kinds of people in this world. Those who understand binary, and those who don't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|