WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: User_McUser on July 09, 2025, 02:17:29 PM

Title: Box units?
Post by: User_McUser on July 09, 2025, 02:17:29 PM
What unit type does "BoxDrawButton" use for its coordinate values?

Going on the assumption that it's Dialog Units, I picked what I though were correct values but the resultant button's size is not what I am expecting.

Example of what I mean is below - I want the two buttons labeled "TEST" to be the same size. The width is almost right but the height is way off.

I'm clearly missing something. 🤔
Thanks in advance. 👍

Code (WinBatch) Select
BoxesUp("130,0,258,274", @NORMAL)
BoxMapMode(1,@OFF) ;Without this, the button is impossibly tiny.
BoxButtonDraw(1,1,"TEST","7,11,43,23")

MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`WIL Dialog 1`
MyDialogX=0
MyDialogY=0
MyDialogWidth=128
MyDialogHeight=264
MyDialogNumControls=002
MyDialogProcedure=`MainDialogCallBack`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`007,011,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"TEST",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`007,037,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

Dialog("MyDialog")
Title: Re: Box units?
Post by: JTaylor on July 10, 2025, 05:25:44 AM


"1000x1000 virtual screen size is based on the primary monitor in a multi-monitor display configuration."

Jim
Title: Re: Box units?
Post by: User_McUser on July 17, 2025, 09:19:42 AM
Quote from: JTaylor on July 10, 2025, 05:25:44 AM"1000x1000 virtual screen size is based on the primary monitor in a multi-monitor display configuration."

Jim

All my monitors are the same exact model at the same resolution so I don't see why this would make the buttons in my example be different sizes.

The problem, as far as I can tell, seems to be that the size of a button as defined in the Dialog block uses different units than the size information that goes into the BoxButtonDraw() function and I don't know how to convert between the two.

Thanks!
Title: Re: Box units?
Post by: JTaylor on July 17, 2025, 11:04:34 AM
Sorry.  I answered your first question.  Let me see if I can find the conversion. 

Jim
Title: Re: Box units?
Post by: User_McUser on July 17, 2025, 11:44:32 AM
Quote from: JTaylor on July 17, 2025, 11:04:34 AMSorry.  I answered your first question.  Let me see if I can find the conversion. 

Jim

No worries - I appreciate the assistance, thanks! 👍
Title: Re: Box units?
Post by: JTaylor on July 19, 2025, 07:31:10 AM
Sorry for delay.   Couldn't post the last few days but turned out it was a strange character in the text.

I think this will do what you want???  If not, maybe it will point you in the right direction.



; Step 1: Dialog Units  --  Pixels
#DefineFunction ToPixelsHorizontal(du)
   Return du * winmetrics(-6)
#EndFunction
 
#DefineFunction ToPixelsVertical(du)
   Return du * winmetrics(-5)
#EndFunction
 
; Step 2: Pixels  --  Box coordinates
#DefineFunction ToBoxHorizontal(px)
   Return (px * 1000) / winmetrics(0)
#EndFunction
 
#DefineFunction ToBoxVertical(px)
   Return (px * 1000) / winmetrics(1)
#EndFunction
 
; Example: Convert 100 DUs in both directions to Box units
 
; Step 1: Box  --  Pixels
#DefineFunction BoxToPixelsHorizontal(boxX)
   Return (boxX * winmetrics(0)) / 1000
#EndFunction
 
#DefineFunction BoxToPixelsVertical(boxY)
   Return (boxY * winmetrics(1)) / 1000
#EndFunction
 
; Step 2: Pixels  --  Dialog Units
#DefineFunction PixelsToDialogHorizontal(pxX)
   Return pxX / winmetrics(-6)
#EndFunction
 
#DefineFunction PixelsToDialogVertical(pxY)
   Return pxY / winmetrics(-5)
#EndFunction
 


Title: Re: Box units?
Post by: User_McUser on July 23, 2025, 11:57:45 AM
Thanks for the response - I would have replied sooner but I do not appear to be getting notifications when replies are added.

This did not solve my problem.

I think I may not be explaining the issue sufficiently. For the purposes of this example, I want a box with a button that is the same size on-screen as a button in a dialog. The dialog button is 50x50 dialog units.

I've tried converting Dialog Units to Screen Units and just using Dialog units straight; neither one works.

The attached JPG shows the results of the script. The "Test" button in the box uses converted units and the "Test2" button does not. Neither is the same size as the "Test" button in the dialog.

There must be a way to match these two but a solution eludes me.

unequal_buttons_sm.jpg
Title: Re: Box units?
Post by: spl on July 24, 2025, 08:09:20 AM
Quote from: User_McUser on July 23, 2025, 11:57:45 AMI want a box with a button that is the same size on-screen as a button in a dialog.

Why? If just to focus on inconsistencies in dlgunits... fine. But from a script perspective, what is the purpose?
Title: Re: Box units?
Post by: User_McUser on July 24, 2025, 09:23:31 AM
Quote from: spl on July 24, 2025, 08:09:20 AM
Quote from: User_McUser on July 23, 2025, 11:57:45 AMI want a box with a button that is the same size on-screen as a button in a dialog.

Why? If just to focus on inconsistencies in dlgunits... fine. But from a script perspective, what is the purpose?

I take offense at your implication that my post is intended to be anything other than a request for knowledge about how to properly use WinBatch to accomplish my goals.

I want to make a button that is in the location I want it to be in and is of the size that I want it to appear; I don't need a "reason" other than that.
Title: Re: Box units?
Post by: spl on July 24, 2025, 01:37:53 PM
Fine, then don't assume a question is an implication. It was just a question.
Title: Re: Box units?
Post by: JTaylor on July 25, 2025, 08:31:00 AM
Not sure if this will help or not but for what it is worth....  May be too much manual manipulation for my system.  Not sure if differences in font between dialog and box will matter or not.


GoSub Load_Routines

MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`WIL Dialog 1`
MyDialogX=-01
MyDialogY=-01
MyDialogWidth=128
MyDialogHeight=264
MyDialogNumControls=002
MyDialogProcedure=`MainDialogCallBack`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`007,011,036,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"TEST",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`007,037,036,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`


Decimals(0)
w = DialogToBoxHorizontal(MyDialogWidth)
h = DialogToBoxVertical(MyDialogHeight)

BoxesUp("530,200,258,274", @NORMAL)
BoxMapMode(1,@OFF) ;Without this, the button is impossibly tiny.
BoxButtonDraw(1,1,"TEST","7,11,":w:",":h)

Dialog("MyDialog")

:LOAD_ROUTINES

;--------------------------------------------------
; Dialog Units ? Pixels
;--------------------------------------------------

#DefineFunction ToPixelsHorizontal(du)
   Return ((du * winmetrics(-6)) / 2.8)
#EndFunction

#DefineFunction ToPixelsVertical(du)
   Return ((du * winmetrics(-5)) / 13.5)
#EndFunction

;--------------------------------------------------
; Pixels ? Box Units
;--------------------------------------------------

#DefineFunction ToBoxHorizontal(px)
   Return (px * 1000) / winmetrics(0)  ; winmetrics(0) = screen width in pixels
#EndFunction

#DefineFunction ToBoxVertical(px)
   Return (px * 1000) / winmetrics(1)  ; winmetrics(1) = screen height in pixels
#EndFunction

;--------------------------------------------------
; Combined: Dialog Units ? Box Units
;--------------------------------------------------

#DefineFunction DialogToBoxHorizontal(du)
   Return Ceiling(ToBoxHorizontal(ToPixelsHorizontal(du)))
#EndFunction

#DefineFunction DialogToBoxVertical(du)
   Return Ceiling(ToBoxVertical(ToPixelsVertical(du)))
#EndFunction


Return
Title: Re: Box units?
Post by: User_McUser on July 28, 2025, 12:07:48 PM
So the answer turned out to be very mundane - I was just missing some parenthesis and that changed my math.
Or to put it another way: (50 * Winmetrics(-6) / WinMetrics(0) / 1000) != (50 * WinMetrics(-6)) / (WinMetrics(0) / 1000)

Please Excuse My Dumb A** Self - forgot the order of operations. 🤦

Thanks again for your help @JTaylor! 🙂


Title: Re: Box units?
Post by: JTaylor on July 28, 2025, 01:07:18 PM
Glad you got it sorted.

Jim
Title: Re: Box units?
Post by: td on July 31, 2025, 08:18:11 AM
For those browsing this topic, here is a lengthy Tech Database article that explains the relationship between different screen coordinate systems. It also includes script snippets to convert from one system to another.

https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+Tutorials+Screen~Coordinates~Explained.txt (https://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+Tutorials+Screen~Coordinates~Explained.txt) 
Title: Re: Box units?
Post by: kdmoyers on August 01, 2025, 07:03:54 AM
Nice article!