Dag,
Ik heb de volgende code van internet afgeplukt en geconverteerd naar 64-bit. Echter krijg ik een Run-time Error 438 bij het oproepen van de eerste function. Het frustrerende hiervan is dat er geen code wordt gehighlight. Heb ik ergens een vertalingsfout gemaakt? Ben ik code aan het gebruiken wat verouderd is?
Input vanuit Module1:
Code vanuit module 2.
Het centeren van de userfrom wil ik afhankelijk maken van het scherm, niet de applicatie.
Alvast bedankt.
Ik heb de volgende code van internet afgeplukt en geconverteerd naar 64-bit. Echter krijg ik een Run-time Error 438 bij het oproepen van de eerste function. Het frustrerende hiervan is dat er geen code wordt gehighlight. Heb ik ergens een vertalingsfout gemaakt? Ben ik code aan het gebruiken wat verouderd is?
Input vanuit Module1:
Code:
Option Explicit
Public Userform1 as Object
sub main()
With Userform1
Module2.Display_Center (ivForm)
.Show vbModeless
End With
end sub
Code vanuit module 2.
Code:
Private Declare PtrSafe Function GetSystemMetrics Lib "USER32" (ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetDeviceCaps Lib "gdi32" (ByVal hDC As LongPtr, ByVal nIndex As Long) As Long
Private Declare PtrSafe Function GetDC Lib "USER32" (ByVal hWnd As LongPtr) As LongPtr
Private Declare PtrSafe Function ReleaseDC Lib "USER32" (ByVal hWnd As LongPtr, ByVal hDC As LongPtr) As Long
Private Const LOGPIXELSX As Long = 88
Private Const LOGPIXELSY As Long = 90
Private Const PointsPerInch = 72
Private Const sm_cxscreen As Long = 0
Private Const sm_cyscreen As Long = 1
Public Enum SystemMetricsConstants
smScreenWidth = sm_cxscreen
smScreenHeight = sm_cyscreen
End Enum
Public Function SystemMetrics(ByVal uindex As SystemMetricsConstants) As Long
SystemMetrics = GetSystemMetrics(uindex)
End Function
Public Function PointsPerPixelX() As Double
Dim hDC As LongPtr
Dim lDotsPerInch As Long
hDC = GetDC(0)
lDotsPerInch = GetDeviceCaps(hDC, LOGPIXELSX)
PointsPerPixelX = PointsPerInch / lDotsPerInch
ReleaseDC 0, hDC
End Function
Public Function PointsPerPixely() As Double
Dim hDC As LongPtr
Dim lDotsPerInch As Long
hDC = GetDC(0)
lDotsPerInch = GetDeviceCaps(hDC, LOGPIXELSX)
PointsPerPixely = PointsPerInch / lDotsPerInch
ReleaseDC 0, hDC
End Function
Sub Display_Center(ivForm As Object)
xheight = SystemMetrics(smScreenHeight)
xwidth = SystemMetrics(smScreenWidth)
With ivForm
If xwidth / xheight > 1.5 Then
.Left = xwidth * PointsPerPixelX / 4 - .Width / 2
Else
.Left = xwidth * PointsPerPixelX / 2 - .Width / 2
End If
.Top = xheight * PointsPerPixely / 2 - .Height / 2
End With
End Sub
Het centeren van de userfrom wil ik afhankelijk maken van het scherm, niet de applicatie.
Alvast bedankt.