1. William Hong
  2. PowerBuilder
  3. Monday, 8 April 2024 07:42 AM UTC

A window named w_main with a button is created at first. When the button on w_main is clicked, a new window will be opened. This code is in new window's open event.

x = w_main.x + w_main.width
y = w_main.y

But there is an obvious gap between the two windows. How can I eliminate this gap?

Attachments (1)
William Hong Accepted Answer Pending Moderation
  1. Wednesday, 10 April 2024 10:06 AM UTC
  2. PowerBuilder
  3. # 1

Figure it out finally, and this is the code.

In the second window open event:

post event ue_postopen(0,0)

In the ue_postopen event:

RECT windowRect, extendedFrameBounds;
int borderWidth

GetWindowRect(Handle(this), REF windowRect)
DwmGetWindowAttribute(Handle(this),  9, REF extendedFrameBounds, 16)
borderWidth = GetSystemMetrics(5);	

x = w_main.x + w_main.width - PixelsToUnits ((windowRect.right - extendedFrameBounds.right) + (extendedFrameBounds.left - windowRect.left) + borderWidth, XPixelsToUnits!)
y = w_main.y

Declaration part:

FUNCTION long GetWindowRect(ulong hwnd, REF RECT lpRect) LIBRARY "user32.dll"
FUNCTION int GetSystemMetrics(int nIndex) LIBRARY "user32.dll";
FUNCTION long DwmGetWindowAttribute(ulong hwnd, long dwAttribute, REF RECT pvAttribute, long cbAttribute) LIBRARY "dwmapi.dll"
$PBExportHeader$rect.srs
global type rect from structure
	long		left
	long		top
	long		right
	long		bottom
end type
Comment
  1. John Fauss
  2. Wednesday, 10 April 2024 13:19 PM UTC
Thank you for sharing the solution, William! FYI - If you need to migrate this code to 64-bit, change the data type of the "hwnd" argument in both external function declarations and in the calling code from ULong (UnsignedLong) to Longptr. Good luck on your project!
  1. Helpful 2
There are no comments made yet.
David Peace (Powersoft) Accepted Answer Pending Moderation
  1. Tuesday, 9 April 2024 13:07 PM UTC
  2. PowerBuilder
  3. # 2

We have used this code successfuilly in one of our Apps:

int new_x, new_y

this.height=w_bookings.height
new_x = w_bookings.workspacewidth() + w_bookings.workspacex() + 60
new_y = w_bookings.y
this.x = new_x
this.y = new_y

return 1

 

W_bookings is on the left and the current window is on the right. Hope that helps.

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 9 April 2024 02:26 AM UTC
  2. PowerBuilder
  3. # 3

In addition to Benjamin's excellent response, here is some additional information regarding the use of the DwmGetWindowAttribute API call:

    https://stackoverflow.com/questions/12744117/get-drop-shadow-dimensions-of-window

What will you do if the first window is positioned too close to the right edge of the physical screen to be able to see the entire contents of the second window? I don't know what your use-case for this proposed functionality is, but what you are wanting to do may not work well in all possible situations.

Best regards, John

Comment
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Monday, 8 April 2024 08:27 AM UTC
  2. PowerBuilder
  3. # 4

Looks like the window size attributes in PB include the drop shadow areas that double as resize handles. You can try using DwmGetWindowAttribute to get to the actual size or hardcode the difference.

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