Thursday, December 6, 2012

VB Fungsi API - Mengetahui Ukuran Screen Yang Sebenarnya

Contoh fungsi API untuk mengetahui ukuran layar (screen) yang sebenarnya (dikurangi tinggi taskbar).

Option Explicit

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Function ScreenWidth() As Single
    Dim R As RECT
    GetWindowRect GetDesktopWindow(), R
    ScreenWidth = R.Right * Screen.TwipsPerPixelX
End Function

Public Function ScreenHeight() As Single
    Dim R As RECT
    GetWindowRect GetDesktopWindow(), R
    ScreenHeight = R.Bottom * Screen.TwipsPerPixelY
End Function