WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: erezpaz on February 12, 2017, 02:19:33 AM

Title: Keep boxup same size in each resulotion
Post by: erezpaz on February 12, 2017, 02:19:33 AM
Hi

I am using boxup to show a logo in the beginning of my script. If it distort if it run on any other screen with deferent resolution i got since it use relative coordinate 0 to 1000.
Is there a way to keep boxup size same size in any screen resolution? I do not want to use Dialog control since i am doing a lot of background processing and need to keep the box up until i finished it.

Thanks
Title: Re: Keep boxup same size in each resulotion
Post by: td on February 13, 2017, 07:57:57 AM
The Consolidated WIL Help file BoxBitmap documentation contains a discussion and examples of how to maintain the aspect ratio of a bitmap on monitors of varying  dimensions.   Basically, you need to adjust the virtual coordinates you pass to the BoxBitmap function so that the bitmap's aspect ratio is maintained.   

And there is  no reason why you can't use a WIL dialog, if you choose to do so.  WIL dialogs do not prevent you from performing a lot of background processing while they are displayed.
Title: Re: Keep boxup same size in each resulotion
Post by: td on February 13, 2017, 02:33:49 PM
A slightly enhanced version of one of the help file examples:


Code (winbatch) Select
; Calculate the box's aspect ratio when converted to
; square pixels.
; Note: since the boxes client area is used for the bitmap
; coordinate space, the title bar height is removed.
; (600 = 800 - 200)
nPxBoxWidth   = (600*WinMetrics(0))/1000.0
nPxBoxHeight  = ((600*WinMetrics(1))/1000.0) - WinMetrics(4)
nBoxAspect    = nPxBoxHeight/nPxBoxWidth

; Convert bitmap size into virtual coordinates
; that maintain the aspect ratio. This is done
; by using the box's aspect ratio to calculate
; the virtual coordinates that correspond to
; square pixels.
nBitWidth      = 628
nBitHeight     = 424
nScalingConst  = 1.6 ; Size it.
nVirtualWidth  = nBitWidth * nBoxAspect * nScalingConst
nVirtualHeight = nBitHeight * nScalingConst

; Create a coordinate string.
nLeft = 2
nTop  = 2
nX    = Int(nLeft+nVirtualWidth)
nY    = Int(nLeft+nVirtualHeight)
strBitmapCoords = nLeft:',':nTop:',':nX:',':nY

nBoxID       = 1
nStretchMode = 3

BoxesUp('200,200,800,800', @NORMAL)     
BoxCaption(nBoxID, "Foobar Bitmap Example")
BoxBitMap(nBoxID, strBitmapCoords, DirScript():'628x424.bmp', nStretchMode)
TimeDelay(5)
Title: Re: Keep boxup same size in each resulotion
Post by: td on February 14, 2017, 10:15:12 AM
Gilding the lily with more precise bitmap aspect ratio preservation.

Code (winbatch) Select
;; Output is the width and height of the input
;; window's client area.
#DefineFunction GetClientWH(_hWnd, _pnW, _pnH)
   strRect = $"LONG::left;
  LONG::top;
  LONG::right;
  LONG::bottom;$"
   
   hRect = DllStructAlloc(strRect)
   DllCall("user32.dll",  long:"GetClientRect", long:_hWnd, lpstruct:hRect)     
   nLeft = DllStructPeek(hRect, 'left')
   nTop  = DllStructPeek(hRect, 'top')
   nRight = DllStructPeek(hRect, 'right')
   nBottom = DllStructPeek(hRect, 'bottom')
   DllStructFree(hRect)
   
   ; Calculate width and height.
   *_pnW = nRight - nLeft
   *_pnH = nBottom - nTop
   return 1
#EndFunction

; Bitmap dimensions and desired size.
nBitWidth      = 628
nBitHeight     = 424
nScalingConst  = 1.65 ; Sizing factor.

; Bitmap origin in box's client area.
nLeft = 2
nTop  = 2

; Boilerplate parameters
nBoxID       = 1
nStretchMode = 3

BoxesUp('200,200,800,800', @NORMAL)     

; Get aspect ratio of client area in square pixels.
GetClientWH(DllhWnd(''), &nClientW, &nClientH)
nBoxAspect = nClientH/(nClientW*1.0)

; Calculate bitmap width and height preserving its aspect ratio.
nVirtualWidth  = nBitWidth * nBoxAspect * nScalingConst
nVirtualHeight = nBitHeight * nScalingConst
nX    = Int(nLeft+nVirtualWidth)
nY    = Int(nLeft+nVirtualHeight)
strBitmapCoords = nLeft:',':nTop:',':nX:',':nY

BoxCaption(nBoxID, "Foobar Bitmap Example")
BoxBitMap(nBoxID, strBitmapCoords, DirScript():'628x424.bmp', nStretchMode)
TimeDelay(5)
Title: Re: Keep boxup same size in each resulotion
Post by: td on February 16, 2017, 02:06:16 PM
Another example that fills a box's client area with a bitmap while maintaining the bitmaps aspect ratio and native size.

Code (winbatch) Select
; Bitmap dimensions.
nBitWidth      = 628
nBitHeight     = 424

; Box coordinates
nBoxL = 200
nBoxT = 200
          ;; Assumes title bar and the regular sizing border.
nBoxW = (1000 * (nBitWidth + (WinMetrics(32) * 2)))/WinMetrics(0) + nBoxL
nBoxH = (1000 * (nBitHeight + WinMetrics(4) + (WinMetrics(33) * 2)))/WinMetrics(1) + nBoxT
strCoords = nBoxL:',':nBoxT:',':nBoxW:',':nBoxH

nBoxId = 1
nStretchMode = 3
BoxesUp(strCoords, @NORMAL)
BoxCaption(nBoxID, "Foobar Bitmap Example 3")
BoxBitMap(nBoxId, '0,0,1000,1000', DirScript():'628x424.bmp', nStretchMode)

TimeDelay(5)
Title: Re: Keep boxup same size in each resulotion
Post by: erezpaz on February 17, 2017, 06:57:22 AM
The last code is perfect! Thanks!
Title: Re: Keep boxup same size in each resulotion
Post by: kdmoyers on February 22, 2017, 04:23:00 AM
Nice examples here Tony, thanks!