WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Align Dialog in Corner


You have 3 things to configure in code:
  1. Set MyDialogWidth & MyDialogHeight to the real dialog width & height
  2. Change the dialogx and dialogy to MyDialogX and MyDialogY
  3. Set the number to which corner to align the dialog to.
;Configure the params for the dialog location
iPixelsPerHorizontalDU   = WinMetrics(-6)
iPixelsPerVerticalDU   = WinMetrics(-5)
iTBLocation      = LocateTaskBar()
iResolutionX     = WinMetrics(0)
iResolutionY     = WinMetrics(1)
sWorkArea      = SysParamInfo(48, "", 0)

iLeft       = ItemExtract(1, sWorkArea, ",")
iTop       = ItemExtract(2, sWorkArea, ",")
iRight       = ItemExtract(3, sWorkArea, ",")
iBottom       = ItemExtract(4, sWorkArea, ",")

iTitleBarHeight     = WinMetrics(4)

;These params come from the dialog
MyDialogWidth     = 118
MyDialogHeight     = 197

; Align Window
; 0 = top left
; 1 = top right
; 2 = bottom right
; 3 = bottom left

; TBLocation
; 0 = Bottom
; 1 = Top
; 2 = Left
; 3 = Right

iAlignDialog     = 3   ;<---------  Change this to determine which corner to align to.

Select iAlignDialog
 Case 0 ;Align to Top Left
   If iTBLocation == 0 || iTBLocation == 3
    ; iTBLocation 0 is Bottom, iTBLocation 3 is Right
    MyDialogX  = 0
    MyDialogY  = 0
   EndIf

   If iTBLocation  == 1 ;Top
    MyDialogX  = 0
    MyDialogY  = Int(Floor(iTop/iPixelsPerVerticalDU))
   EndIf

   If iTBLocation  == 2;Left
    MyDialogX  = Int(Floor(iLeft/iPixelsPerHorizontalDU))
    MyDialogY  = 0
   EndIf
  Break
 Case 1 ;Align to Top Right
   If iTBLocation == 0 || iTBLocation == 2 ;0 - bottom, 2 Left
    MyDialogX  = Int(Floor(iResolutionX/iPixelsPerHorizontalDU - MyDialogWidth))
    MyDialogY  = 0
   EndIf

   If iTBLocation   == 1 ;top
    MyDialogX  = Int(Floor(iResolutionX/iPixelsPerHorizontalDU - MyDialogWidth))
    MyDialogY  = Int(Floor(iTop/iPixelsPerVerticalDU))
   EndIf

   If iTBLocation  == 3 ;Right
    MyDialogX  = Int(Floor(iRight/iPixelsPerHorizontalDU - MyDialogWidth))
    MyDialogY  = 0
   EndIf
  Break
 Case 2 ;Align to Bottom Right
   If iTBLocation  == 0 ;Bottom
    MyDialogX  = Int(Floor(iResolutionX/iPixelsPerHorizontalDU - MyDialogWidth))
    MyDialogY  = Int(Floor(iBottom/iPixelsPerVerticalDU - (MyDialogHeight+(iTitleBarHeight/iPixelsPerVerticalDU))))
   EndIf

   If iTBLocation  == 1 ;Top
    MyDialogX  = Int(Floor(iResolutionX/iPixelsPerHorizontalDU - MyDialogWidth))
    MyDialogY  = Int(Floor(iBottom/iPixelsPerVerticalDU - (MyDialogHeight+(iTitleBarHeight/iPixelsPerVerticalDU))))
   EndIf

   If iTBLocation  == 2 ;Left
    MyDialogX  = Int(Floor(iResolutionX/iPixelsPerHorizontalDU - MyDialogWidth))
    MyDialogY  = Int(Floor(iResolutionY/iPixelsPerVerticalDU - (MyDialogHeight+(iTitleBarHeight/iPixelsPerVerticalDU))))
   EndIf

   If iTBLocation  == 3 ;Right
    MyDialogX  = Int(Floor(iRight/iPixelsPerHorizontalDU - MyDialogWidth))
    MyDialogY  = Int(Floor(iResolutionY/iPixelsPerVerticalDU - (MyDialogHeight+(iTitleBarHeight/iPixelsPerVerticalDU))))
   EndIf
  Break
 Case 3 ;Align to Bottom Left
   If iTBLocation  == 0 ;Bottom
    MyDialogX  = 0
    MyDialogY  = Int(Floor(iBottom/iPixelsPerVerticalDU - (MyDialogHeight+(iTitleBarHeight/iPixelsPerVerticalDU))))
   EndIf

   If iTBLocation  == 1 || iTBLocation == 3
    MyDialogX  = 0
    MyDialogY  = Int(Floor(iResolutionY/iPixelsPerVerticalDU - (MyDialogHeight+(iTitleBarHeight/iPixelsPerVerticalDU))))
   EndIf

   If iTBLocation  == 2 ;Left
    MyDialogX  = Int(Floor(iLeft/iPixelsPerHorizontalDU))
    MyDialogY  = Int(Floor(iResolutionY/iPixelsPerVerticalDU - (MyDialogHeight+(iTitleBarHeight/iPixelsPerVerticalDU))))
   EndIf

  Break
EndSelect

#DefineFunction LocateTaskBar()
 sWorkArea      = SysParamInfo(48, "", 0)
 iResolutionX     = WinMetrics(0)
 iResolutionY     = WinMetrics(1)

 iLeft       = ItemExtract(1, sWorkArea, ",")
 iTop       = ItemExtract(2, sWorkArea, ",")
 iRight       = ItemExtract(3, sWorkArea, ",")
 iBottom       = ItemExtract(4, sWorkArea, ",")

 If iBottom      <> iResolutionY
  iTBLocation     = 0 ;"Bottom"
 EndIf

 If iLeft == 0 && iRight == iResolutionX && iBottom == iResolutionY
  iTBLocation     = 1 ;"Top"
 EndIf

 If iTop == 0 && iRight == iResolutionX && iBottom == iResolutionY
  iTBLocation     = 2 ;Left"
 EndIf

 If iBottom == iResolutionY && iRight <> iResolutionX && iBottom == iResolutionY
  iTBLocation     = 3 ;"Right"
 EndIf

 ;This can be used to prove it.
 ;sText = StrCat("Work Area (L, T, R, B) = ", sWorkArea, @CRLF, "Task bar is on - ", iTBLocation, @CRLF)
 ;sText = StrCat(sText, "iLeft = ", iLeft, @CRLF)
 ;sText = StrCat(sText, "iTop = ", iTop, @CRLF)
 ;sText = StrCat(sText, "iRight = ", iRight, @CRLF)
 ;sText = StrCat(sText, "iBottom = ", iBottom, @CRLF)
 ;sText = StrCat(sText, "iResolutionX = ", iResolutionX, @CRLF)
 ;sText = StrCat(sText, "iResolutionY = ", iResolutionY, @CRLF)
 ;Message("", sText)
 Return iTBLocation
#EndFunction

Article ID:   W16937
File Created: 2007:07:03:14:27:06
Last Updated: 2007:07:03:14:27:06