How is it possible to positioning the form exactly over the element?
VBA Code:
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Const SPI_GETWORKAREA& = 48
Private Declare Function SystemParametersInfo Lib "user32" _
Alias "SystemParametersInfoA" _
(ByVal uAction As Long, _
ByVal uParam As Long, _
lpvParam As Any, _
ByVal fuWinIni As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Const HWND_DESKTOP As Long = 0
Private Const LOGPIXELSX As Long = 88
Private Const LOGPIXELSY As Long = 90
Public Sub LeftClickUp_PosOverElement(obelem As Element)
Dim pTargetPoint As POINTAPI
Dim lRetVal As Long
Dim rc As RECT
lRetVal = GetCursorPos(pTargetPoint)
Call SystemParametersInfo(SPI_GETWORKAREA, 0&, rc, 0&)
'positioning of the form ****
frmToTest.Top = ((rc.Top + pTargetPoint.y) * TwipsPerPixelY / 20) - frmToTest.Height / 2
frmToTest.Left = ((rc.Left + pTargetPoint.x) * TwipsPerPixelX / 20) - frmToTest.Width / 2
'check top border
If (((rc.Top + pTargetPoint.y) * TwipsPerPixelY / 20) - frmToTest.Height / 2) < 0 Then
frmToTest.Top = 0
End If
'check bottom border
If (rc.Top + pTargetPoint.y + frmToTest.Height / 2) > rc.Bottom Then
frmToTest.Top = rc.Bottom * TwipsPerPixelY / 20 - frmToTest.Height
End If
'check left border
If (((rc.Left + pTargetPoint.x) * TwipsPerPixelX / 20) - frmToTest.Width / 2) < 0 Then
frmToTest.Left = 0
End If
'check right border
If (rc.Left + pTargetPoint.x + frmToTest.Width / 2) > rc.Right Then
frmToTest.Left = rc.Right * TwipsPerPixelX / 20 - frmToTest.Width
End If
frmToTest.Init obelem 'hand over all properties to the procedure "Init"
obelem.LeftClickUp 'release the button
End Sub
Function TwipsPerPixelX() As Single
Dim lngDC As Long
lngDC = GetDC(HWND_DESKTOP)
TwipsPerPixelX = 1440 / GetDeviceCaps(lngDC, LOGPIXELSX)
ReleaseDC HWND_DESKTOP, lngDC
End Function
Function TwipsPerPixelY() As Single
Dim lngDC As Long
lngDC = GetDC(HWND_DESKTOP)
TwipsPerPixelY = 1440 / GetDeviceCaps(lngDC, LOGPIXELSY)
ReleaseDC HWND_DESKTOP, lngDC
End Function
VBA Code:
'BottomRight:
frmToTest.Top = rc.Bottom * TwipsPerPixelY / 20 - frmToTest.Height
frmToTest.Left = rc.Right * TwipsPerPixelX / 20 - frmToTest.Width
'BottomLeft:
frmToTest.Top = rc.Bottom * TwipsPerPixelY / 20 - frmToTest.Height
frmToTest.Left = rc.Left * TwipsPerPixelX / 20 '- frmToTest.Width
'TopRight:
frmToTest.Top = rc.Top * TwipsPerPixelY / 20 ' frmToTest.Height
frmToTest.Left = rc.Right * TwipsPerPixelX / 20 - frmToTest.Width
'TopLeft:
frmToTest.Top = rc.Top * TwipsPerPixelY / 20 '- frmToTest.Height
frmToTest.Left = rc.Left * TwipsPerPixelX / 20 '- frmToTest.Width
'Center:
frmToTest.Top = (rc.Bottom / 2) * TwipsPerPixelY / 20 - frmToTest.Height / 2
frmToTest.Left = (rc.Right / 2) * TwipsPerPixelX / 20 - frmToTest.Width / 2
This document governs the use of our Community Forum. By registering and using the platform, you accept these conditions.
The COPA-DATA Community Forum serves to encourage the exchange of information and experience about the zenon software between forum users respectively zenon users.
Please mind that any published information on the Community Forum is the subjective opinion and view based on the experience and the level of knowledge of the author. COPA-DATA does not overtake any responsibility for the content and the accuracy of the shared information.
Users of the Community Forum are encouraged to share only well-founded experiences and to point out any risks associated with the implementation of proposed solutions to problems. COPA-DATA at its absolute discretion, reserves the right to moderate the forum. In this connection COPA-DATA may remove any information containing false facts, potentially dangerous solutions, bad language or content that may insult, degrade or discriminate others. COPA-DATA may block a non-complying user from forum access if the user violated this provision.
COPA-DATA reserves the right to change this document from time to time at own discretion.
Ing. Punzenberger COPA-DATA GmbH
Karolingerstraße 7b · 5020 Salzburg · Austria
www.copadata.com