Screensize in points

Screensize in points

Anonymous
Not applicable
343 Views
3 Replies
Message 1 of 4

Screensize in points

Anonymous
Not applicable
I would like to keep my form centered vertically on the screen when it gets resized. VB provides the Screen.Height function but VBA apparently doesn't. I can use the GetSystemMetrics(SM_CYSCREEN) to get the screen height in pixels but VBA sizes appear to be in points. Is there a conversion factor for points to pixels? So far, I've stretched the window to its maximum height and read that value to set the maximum height, but that's sort of a dirty hack. Any ideas? Private Sub UserForm_Resize() 'Guess of the screen height by stretching the window as large as 'it could go yielded 777 - would be better to use the GetSystemMetrics 'but I don't know the conversion from points to pixels. hgt = Me.Height scrnhgt = 777 ' GetSystemMetrics(SM_CYSCREEN) Me.top = (scrnhgt - hgt) / 2 End Sub
0 Likes
344 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Check your monitor settings. Mine is set to:

1280 x 1024 @ 96 pixels per inch.

1024 pixels / 96 pixels per inch = 10.667 inches

There are 72 points per inch so: 10.667 * 72 = 768 points
0 Likes
Message 3 of 4

Anonymous
Not applicable
scrnhgt = GetSystemMetrics(SM_CYSCREEN) / GetDeviceCaps(GetDC(HWND_DESKTOP), LOGPIXELSY) * 72
0 Likes
Message 4 of 4

Anonymous
Not applicable
Thanks! FYI, this is what I used, insce GetDesktopWindow returns the handle... Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long Const SM_CXSCREEN = 0 'X Size of screen Const SM_CYSCREEN = 1 'Y Size of Screen Const LOGPIXELSX = 88 ' logical pixels per inch X axis Const LOGPIXELSY = 90 ' logical pixels per inch Y axis scrnhgt = GetSystemMetrics(SM_CYSCREEN) / GetDeviceCaps(GetDC(GetDesktopWindow), LOGPIXELSY) * 72
0 Likes