1. Rick Domogalik
  2. PowerBuilder
  3. Thursday, 26 March 2020 12:54 PM UTC

I have a small stand alone application that is fired when a user adds a document to our database.  I want to make it so that the application always sits on top of any other window/program that the user has open on their computer and ideally, the user cannot click outside of the application until they fill in the info on the sheet and click ok, or cancel.  So in a nutshell, I want it to lock up the computer until the user deals with the window.

I have tried using SetForegroundWindow( HWND ) and this pops it to the top, but can easily be pushed to the back again with a click outside the program.

 

Anyone have some code to accomplish this?

 

Rick

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 26 March 2020 16:20 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Rick;

   FWIW:  I have done this before by basically coding the Window's "Deactivate" event, issuing a POST SetFocus() and then a Yield() command. That had the effect of holding the user on my Window dialogue until they completed the processing task that I wanted them to. Then I would close the Window by setting an instance variable (ie "ib_ok_2_Close = TRUE) where the Deactivate event would then ignore the Deactivate event code.

HTH

Regards ... Chris

Comment
  1. Rick Domogalik
  2. Wednesday, 1 April 2020 12:29 PM UTC
Chris

Thanks for the advise. Do you have an example of how you implemented this in the deactivate event? I tried to follow the above suggestion and not keeping focus on the window. It still allows the user to click outside the window and push it behind other windows.



Here is what I put in the Deactivate event:

if ib_ok_to_close = true then

//ok to close

else

//keep open

post setfocus()

yield()

end if
  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 1 April 2020 17:21 PM UTC
Hi Rick .. that example was to keep a Child or Pop-Up window in focus within the *same* PB application.

For a general "keep in focus" PB App vs other MS-Windows apps that are running. still use the Deactivate Event but then issue the commands ...

Yield()

SetForegroundWindow()

Regards ... Chris
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Thursday, 26 March 2020 14:03 PM UTC
  2. PowerBuilder
  3. # 1

Greetings, Rick -

You are describing what Windows calls "application modal" behavior. The underlying issue is that this behavior is predicated on a single application, not multiple.

A PB window of type Response within a single PB application implements this behavior. By having this other "response-like" window in a separate application (process/thread), you're attempting to make Windows mimic application modal interaction, or synchronize behavior between two threads. This might be technically doable utilizing the Windows API, given enough time and Red Bull (or Mountain Dew) - but probably not feasible. Could you implement the functionality provided by the other application in a response window added to your PB app?

Regards, John

Comment
  1. Michael Kramer
  2. Thursday, 26 March 2020 18:52 PM UTC
I agree with John.

ALSO: You risk coming in conflict with system security if your app takes precedence towards the user over all other functionality running on user's machine.

/Michael
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.