give the focus back to the application that I took it from-VBForums
Results 1 to 3 of 3

Thread: give the focus back to the application that I took it from

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    3,877

    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.

  2. #2
    March 2015 Winner kfcSmitty's Avatar
    Join Date
    May 2005
    Location
    Kingston, Ontario
    Posts
    2,125

    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

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Sitting in an empty room trying to forget the past
    Posts
    3,877

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.