1. Roland Smith
  2. PowerBuilder
  3. Friday, 10 May 2019 20:20 PM UTC

I have my PowerBuilder app sitting on monitor #2. If I connect to my laptop (with Remote Desktop) from another one that only has one monitor, I am finding it impossible to access the app.

Non PowerBuilder apps seem to notice the change and shift over to monitor #1.

How would I implement this feature in my PowerBuilder app?

 

Roland Smith Accepted Answer Pending Moderation
  1. Saturday, 11 May 2019 03:14 AM UTC
  2. PowerBuilder
  3. # 1

I found an even easier to use function MonitorFromWindow:

https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-monitorfromwindow

You just have to pass the window handle.

 

Now the question is where to call it? I tried the Activate event and it appears to work. Where are you calling MonitorFromRect ?

 

Comment
  1. John Fauss
  2. Tuesday, 14 May 2019 00:24 AM UTC
Our app utilizes the PFC framework, but essentially we call it from the Open event of the base class ancestor window. This has worked flawlessly for several years.
  1. Helpful
  1. Roland Smith
  2. Tuesday, 14 May 2019 01:52 AM UTC
But if you leave the app running on monitor 2 and then remote in from a computer with only one monitor, the app won't be accessible.

I did some research and WM_DISPLAYCHANGE is the proper event but PowerBuilder doesn't map that event so I am going to use the Activate event. If the app is running and I click the icon on the taskbar, it shifts over to monitor 1. If I start it and the saved position is on monitor 2, it shifts to monitor 1.
  1. Helpful
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 10 May 2019 22:54 PM UTC
  2. PowerBuilder
  3. # 2

Hi, Roland -

I assume your app restores it's last known position and size when it opens, so it needs to be a little smarter.

Consider using the WinAPI MonitorFromRect function. Pass in a Windows rect structure loaded with your app's desired x,y,w,h properties (all values in pixels) as the first argument and zero as the second argument. Windows will pass back a monitor handle of the monitor that contains the largest portion of the rectangle (the app window). It returns zero if NO monitor contains any portion of the rectangle.

If you get a monitor handle return value of zero, force your app's window to position itself at 0,0 or 100,100, etc.

I've also used this technique for detecting when a sheet window will open outside of the MDI Client area.

HTH

- John

Comment
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.