Screen Coordinate Height Issues

Started by User_McUser, March 04, 2025, 11:22:39 AM

Previous topic - Next topic

User_McUser

According to all the documentation I've seen, the window position coordinate system is based on a 0,0 -> 1000,1000 rectangle.

If I start a dialog with coordinates (0,0) that's the upper-left corner, (0,500) should be left-aligned with the top of the dialog halfway down the screen, and (0,750) should be 3/4ths of the way down.

When I run this extremely basic dialog code (see below), the dialog is centered on my primary display instead of being all the way to the left and and 3/4ths the way down. If I use "522" it shows up at the bottom of the display; using 523 or up centers it instead. Guessing this is some sort of overflow behavior as it also ignores my "x" coordinate when this happens.

Code  winbatch Select
MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`WIL Dialog 1`
MyDialogX=0
MyDialogY=750
MyDialogWidth=114
MyDialogHeight=066
MyDialogNumControls=002
MyDialogProcedure=`DEFAULT`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`001,051,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`073,051,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

What am I doing wrong? 🤔

If it matters, I am connected to the system via a full-screen Microsoft Remote Desktop session.

td

WIL Dialogs coordinates are in dialog units, not virtual screen coordinates (1000X10000). This is discussed in the WIL help file and in the online document.

https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/Dialog_Units.htm
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

User_McUser

OK, fair enough I guess. Thanks for the elucidation. 👍

I'm trying to make my app to always dock itself on the edge of a chosen screen when multiple monitors are present, which requires extra logic to work out which is which and thus what the virtual coordinates are. I want to have to a universal method to position all the dialogs, boxes, and other windows that it opens. I guess my work around will be to start it at 0,0 then use WinPlace to move it to the desired location in the callback.

td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

User_McUser

Trying to write functions to convert between the different units used for screen stuff so I can better wrap my head around how it all works.

This logic seems to be working...

Key:
du -> dialog unit
su -> screen unit
px -> pixels

Conversion formula for height:
du --> px: du * WinMetrics(-6)
px --> du: px / WinMetrics(-6)

su --> px: su * (WinMetrics(1) / 1000)
px --> su: px / (WinMetrics(1) / 1000)

su --> du: ( (su * WinMetrics(1) ) / 1000) / WinMetrics(-6)
du --> su: (du * WinMetrics(-6) ) / (WinMetrics(1) / 1000)

Conversion formula for width:
du --> px: du * WinMetrics(-5)
px --> du: px / WinMetrics(-5)

su --> px: su * (WinMetrics(0) / 1000)
px --> su: px / (WinMetrics(0) / 1000)

su --> du: ( (su * WinMetrics(0) ) / 1000) / WinMetrics(-5)
du --> su: (du * WinMetrics(-5) ) / (WinMetrics(0) / 1000)

Which I wrote as follows:
Code  WinBatch Select
;Axis values are 1 = height, 0 = width

#DefineFunction duToPx(du,axis)
	if axis then
		return (du + 0.0) * (WinMetrics(-6) + 0.0)
	else
		return (du + 0.0) * (WinMetrics(-5) + 0.0)
	endif
	return -1
#EndFunction

#DefineFunction pxToDu(px,axis)
	if axis then
		return (px + 0.0) / (WinMetrics(-6) + 0.0)
	else
		return (px + 0.0) / (WinMetrics(-5) + 0.0)
	endif
	return -1
#EndFunction

#DefineFunction suToPx(su,axis)
	if axis then
		return ((su + 0.0) * ((WinMetrics(1) + 0.0)/1000.0))
	else
		return ((su + 0.0) * ((WinMetrics(0) + 0.0)/1000.0))
	endif
	return -1
#EndFunction

#DefineFunction pxToSu(px,axis)
	if axis then
		return (px + 0.0) / ((WinMetrics(1) + 0.0)/1000.0)
	else
		return (px + 0.0) / ((WinMetrics(0) + 0.0)/1000.0)
	endif
	return -1
#EndFunction

#DefineFunction suToDu(su,axis)
	if axis then
		return (((su + 0.0) * ((WinMetrics(1) + 0.0) / (1000.0))) / (WinMetrics(-6) + 0.0))
		
		else
		return (((su + 0.0) * ((WinMetrics(0) + 0.0) / (1000.0))) / (WinMetrics(-5) + 0.0))
	endif
	return -1
#EndFunction

#DefineFunction duToSu(du,axis)
	if axis then
		return ((du + 0.0) * (WinMetrics(-6) + 0.0)) / ((WinMetrics(1) + 0.0) / (1000.0))
	else
		return ((du + 0.0) * (WinMetrics(-5) + 0.0)) / ((WinMetrics(0) + 0.0) / (1000.0))
	endif
	return -1
#EndFunction

Note: the "0.0"s peppered all throughout are to cast everything as floats.

(Edited)


td

You don't need to make every term a float to get floating point math.

#DefineFunction duToSuA(du,axis)
   if axis then
      return ((du + 0.0) * (WinMetrics(-6) + 0.0)) / ((WinMetrics(1) + 0.0) / (1000.0))
   else
      return ((du + 0.0) * (WinMetrics(-5) + 0.0)) / ((WinMetrics(0) + 0.0) / (1000.0))
   endif
   return -1
#EndFunction

#DefineFunction duToSuB(du,axis)
   if axis then
      return (du * WinMetrics(-6)) / (WinMetrics(1) / 1000.0)
   else
      return (du * (WinMetrics(-5) + )) / (WinMetrics(0)  / 1000.0)
   endif
   return -1
#EndFunction

Message('Are They the Same?', duToSuA(150, 1):' = ? ':duToSuB(150, 1))
exit
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

<<This logic seems to be working...>>
Handy! Thanks User_McUser
The mind is everything; What you think, you become.