비주얼 베이직 6.0이하에서는 화면의 크기를 트윕(twip)으로 표시한다.
1 2 |
Screen.TwipsPerPixelX Screen.TwipsPerPixelY |
VBA에서는 없기에 다음과 같은 함수를 이용해야 한다. (source : MSDN)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
Option Explicit Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _ ByVal hdc As Long) As Long Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, _ ByVal nIndex As Long) As Long Const HWND_DESKTOP As Long = 0 Const LOGPIXELSX As Long = 88 Const LOGPIXELSY As Long = 90 '-------------------------------------------------- Function TwipsPerPixelX() As Single '-------------------------------------------------- 'Returns the width of a pixel, in twips. '-------------------------------------------------- Dim lngDC As Long lngDC = GetDC(HWND_DESKTOP) TwipsPerPixelX = 1440& / GetDeviceCaps(lngDC, LOGPIXELSX) ReleaseDC HWND_DESKTOP, lngDC End Function '-------------------------------------------------- Function TwipsPerPixelY() As Single '-------------------------------------------------- 'Returns the height of a pixel, in twips. '-------------------------------------------------- Dim lngDC As Long lngDC = GetDC(HWND_DESKTOP) TwipsPerPixelY = 1440& / GetDeviceCaps(lngDC, LOGPIXELSY) ReleaseDC HWND_DESKTOP, lngDC End Function |