HOME > エクセルVBA > サンプル > GetSystemMetrics

GetSystemMetrics


【ファイル名】GetSystemMetrics.xlsm
【バージョン】Ver 1.0.0.0
【作成日】2021年05月23日
【動作確認】Windows 10
【必要なソフト】Microsoft Excel 2010
【ダウンロード】GetSystemMetrics.zip
【説明】Windows APIのGetSystemMetrics関数で、幅と高さなどのシステムメトリックの値を取得するサンプルです。

プロシージャーの「Print_SystemMetrics」を実行すると、GetSystemMetrics関数の結果をイミディエイト ウィンドウに出力します。

【外部リンク】Windows > Apps > Win32 > API > Sysinfoapi.h > GetSystemInfo function

Module1
Option Explicit

#If Win64 Then
  ' https://docs.microsoft.com/ja-jp/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsysteminfo
  Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#Else
  Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#End If

Private Sub Print_SystemMetrics()
  Debug.Print "SM_CXSCREEN = " & GetSystemMetrics(SM_CXSCREEN)
  Debug.Print "SM_CYSCREEN = " & GetSystemMetrics(SM_CYSCREEN)
  Debug.Print "SM_CXVSCROLL = " & GetSystemMetrics(SM_CXVSCROLL)
  Debug.Print "SM_CYHSCROLL = " & GetSystemMetrics(SM_CYHSCROLL)
  Debug.Print "SM_CYCAPTION = " & GetSystemMetrics(SM_CYCAPTION)
  Debug.Print "SM_CXBORDER = " & GetSystemMetrics(SM_CXBORDER)
  Debug.Print "SM_CYBORDER = " & GetSystemMetrics(SM_CYBORDER)
  Debug.Print "SM_CXDLGFRAME = " & GetSystemMetrics(SM_CXDLGFRAME)
  Debug.Print "SM_CYDLGFRAME = " & GetSystemMetrics(SM_CYDLGFRAME)
  Debug.Print "SM_CYVTHUMB = " & GetSystemMetrics(SM_CYVTHUMB)
  Debug.Print "SM_CXHTHUMB = " & GetSystemMetrics(SM_CXHTHUMB)
  Debug.Print "SM_CXICON = " & GetSystemMetrics(SM_CXICON)
  Debug.Print "SM_CYICON = " & GetSystemMetrics(SM_CYICON)
  Debug.Print "SM_CXCURSOR = " & GetSystemMetrics(SM_CXCURSOR)
  Debug.Print "SM_CYCURSOR = " & GetSystemMetrics(SM_CYCURSOR)
  Debug.Print "SM_CYMENU = " & GetSystemMetrics(SM_CYMENU)
  Debug.Print "SM_CXFULLSCREEN = " & GetSystemMetrics(SM_CXFULLSCREEN)
  Debug.Print "SM_CYFULLSCREEN = " & GetSystemMetrics(SM_CYFULLSCREEN)
  Debug.Print "SM_CYKANJIWINDOW = " & GetSystemMetrics(SM_CYKANJIWINDOW)
  Debug.Print "SM_MOUSEPRESENT = " & GetSystemMetrics(SM_MOUSEPRESENT)
  Debug.Print "SM_CYVSCROLL = " & GetSystemMetrics(SM_CYVSCROLL)
  Debug.Print "SM_CXHSCROLL = " & GetSystemMetrics(SM_CXHSCROLL)
  Debug.Print "SM_DEBUG = " & GetSystemMetrics(SM_DEBUG)
  Debug.Print "SM_SWAPBUTTON = " & GetSystemMetrics(SM_SWAPBUTTON)
  Debug.Print "SM_RESERVED1 = " & GetSystemMetrics(SM_RESERVED1)
  Debug.Print "SM_RESERVED2 = " & GetSystemMetrics(SM_RESERVED2)
  Debug.Print "SM_RESERVED3 = " & GetSystemMetrics(SM_RESERVED3)
  Debug.Print "SM_RESERVED4 = " & GetSystemMetrics(SM_RESERVED4)
  Debug.Print "SM_CXMIN = " & GetSystemMetrics(SM_CXMIN)
  Debug.Print "SM_CYMIN = " & GetSystemMetrics(SM_CYMIN)
  Debug.Print "SM_CXSIZE = " & GetSystemMetrics(SM_CXSIZE)
  Debug.Print "SM_CYSIZE = " & GetSystemMetrics(SM_CYSIZE)
  Debug.Print "SM_CXFRAME = " & GetSystemMetrics(SM_CXFRAME)
  Debug.Print "SM_CYFRAME = " & GetSystemMetrics(SM_CYFRAME)
  Debug.Print "SM_CXMINTRACK = " & GetSystemMetrics(SM_CXMINTRACK)
  Debug.Print "SM_CYMINTRACK = " & GetSystemMetrics(SM_CYMINTRACK)
  Debug.Print "SM_CXDOUBLECLK = " & GetSystemMetrics(SM_CXDOUBLECLK)
  Debug.Print "SM_CYDOUBLECLK = " & GetSystemMetrics(SM_CYDOUBLECLK)
  Debug.Print "SM_CXICONSPACING = " & GetSystemMetrics(SM_CXICONSPACING)
  Debug.Print "SM_CYICONSPACING = " & GetSystemMetrics(SM_CYICONSPACING)
  Debug.Print "SM_MENUDROPALIGNMENT = " & GetSystemMetrics(SM_MENUDROPALIGNMENT)
  Debug.Print "SM_PENWINDOWS = " & GetSystemMetrics(SM_PENWINDOWS)
  Debug.Print "SM_DBCSENABLED = " & GetSystemMetrics(SM_DBCSENABLED)
  Debug.Print "SM_CMOUSEBUTTONS = " & GetSystemMetrics(SM_CMOUSEBUTTONS)
  Debug.Print "SM_CXFIXEDFRAME = " & GetSystemMetrics(SM_CXFIXEDFRAME)
  Debug.Print "SM_CYFIXEDFRAME = " & GetSystemMetrics(SM_CYFIXEDFRAME)
  Debug.Print "SM_CXSIZEFRAME = " & GetSystemMetrics(SM_CXSIZEFRAME)
  Debug.Print "SM_CYSIZEFRAME = " & GetSystemMetrics(SM_CYSIZEFRAME)
  Debug.Print "SM_SECURE = " & GetSystemMetrics(SM_SECURE)
  Debug.Print "SM_CXEDGE = " & GetSystemMetrics(SM_CXEDGE)
  Debug.Print "SM_CYEDGE = " & GetSystemMetrics(SM_CYEDGE)
  Debug.Print "SM_CXMINSPACING = " & GetSystemMetrics(SM_CXMINSPACING)
  Debug.Print "SM_CYMINSPACING = " & GetSystemMetrics(SM_CYMINSPACING)
  Debug.Print "SM_CXSMICON = " & GetSystemMetrics(SM_CXSMICON)
  Debug.Print "SM_CYSMICON = " & GetSystemMetrics(SM_CYSMICON)
  Debug.Print "SM_CYSMCAPTION = " & GetSystemMetrics(SM_CYSMCAPTION)
  Debug.Print "SM_CXSMSIZE = " & GetSystemMetrics(SM_CXSMSIZE)
  Debug.Print "SM_CYSMSIZE = " & GetSystemMetrics(SM_CYSMSIZE)
  Debug.Print "SM_CXMENUSIZE = " & GetSystemMetrics(SM_CXMENUSIZE)
  Debug.Print "SM_CYMENUSIZE = " & GetSystemMetrics(SM_CYMENUSIZE)
  Debug.Print "SM_ARRANGE = " & GetSystemMetrics(SM_ARRANGE)
  Debug.Print "SM_CXMINIMIZED = " & GetSystemMetrics(SM_CXMINIMIZED)
  Debug.Print "SM_CYMINIMIZED = " & GetSystemMetrics(SM_CYMINIMIZED)
  Debug.Print "SM_CXMAXTRACK = " & GetSystemMetrics(SM_CXMAXTRACK)
  Debug.Print "SM_CYMAXTRACK = " & GetSystemMetrics(SM_CYMAXTRACK)
  Debug.Print "SM_CXMAXIMIZED = " & GetSystemMetrics(SM_CXMAXIMIZED)
  Debug.Print "SM_CYMAXIMIZED = " & GetSystemMetrics(SM_CYMAXIMIZED)
  Debug.Print "SM_NETWORK = " & GetSystemMetrics(SM_NETWORK)
  Debug.Print "SM_CLEANBOOT = " & GetSystemMetrics(SM_CLEANBOOT)
  Debug.Print "SM_CXDRAG = " & GetSystemMetrics(SM_CXDRAG)
  Debug.Print "SM_CYDRAG = " & GetSystemMetrics(SM_CYDRAG)
  Debug.Print "SM_SHOWSOUNDS = " & GetSystemMetrics(SM_SHOWSOUNDS)
  Debug.Print "SM_CXMENUCHECK = " & GetSystemMetrics(SM_CXMENUCHECK)
  Debug.Print "SM_CYMENUCHECK = " & GetSystemMetrics(SM_CYMENUCHECK)
  Debug.Print "SM_SLOWMACHINE = " & GetSystemMetrics(SM_SLOWMACHINE)
  Debug.Print "SM_MIDEASTENABLED = " & GetSystemMetrics(SM_MIDEASTENABLED)
  Debug.Print "SM_MOUSEWHEELPRESENT = " & GetSystemMetrics(SM_MOUSEWHEELPRESENT)
  Debug.Print "SM_XVIRTUALSCREEN = " & GetSystemMetrics(SM_XVIRTUALSCREEN)
  Debug.Print "SM_YVIRTUALSCREEN = " & GetSystemMetrics(SM_YVIRTUALSCREEN)
  Debug.Print "SM_CXVIRTUALSCREEN = " & GetSystemMetrics(SM_CXVIRTUALSCREEN)
  Debug.Print "SM_CYVIRTUALSCREEN = " & GetSystemMetrics(SM_CYVIRTUALSCREEN)
  Debug.Print "SM_CMONITORS = " & GetSystemMetrics(SM_CMONITORS)
  Debug.Print "SM_SAMEDISPLAYFORMAT = " & GetSystemMetrics(SM_SAMEDISPLAYFORMAT)
  Debug.Print "SM_IMMENABLED = " & GetSystemMetrics(SM_IMMENABLED)
  Debug.Print "SM_CXFOCUSBORDER = " & GetSystemMetrics(SM_CXFOCUSBORDER)
  Debug.Print "SM_CYFOCUSBORDER = " & GetSystemMetrics(SM_CYFOCUSBORDER)
  Debug.Print "SM_TABLETPC = " & GetSystemMetrics(SM_TABLETPC)
  Debug.Print "SM_MEDIACENTER = " & GetSystemMetrics(SM_MEDIACENTER)
  Debug.Print "SM_STARTER = " & GetSystemMetrics(SM_STARTER)
  Debug.Print "SM_SERVERR2 = " & GetSystemMetrics(SM_SERVERR2)
  Debug.Print "SM_MOUSEHORIZONTALWHEELPRESENT = " & GetSystemMetrics(SM_MOUSEHORIZONTALWHEELPRESENT)
  Debug.Print "SM_CXPADDEDBORDER = " & GetSystemMetrics(SM_CXPADDEDBORDER)
  Debug.Print "SM_DIGITIZER = " & GetSystemMetrics(SM_DIGITIZER)
  Debug.Print "SM_MAXIMUMTOUCHES = " & GetSystemMetrics(SM_MAXIMUMTOUCHES)
  Debug.Print "SM_CMETRICS = " & GetSystemMetrics(SM_CMETRICS)
  Debug.Print "SM_REMOTESESSION = " & GetSystemMetrics(SM_REMOTESESSION)
  Debug.Print "SM_SHUTTINGDOWN = " & GetSystemMetrics(SM_SHUTTINGDOWN)
  Debug.Print "SM_REMOTECONTROL = " & GetSystemMetrics(SM_REMOTECONTROL)
  Debug.Print "SM_CARETBLINKINGENABLED = " & GetSystemMetrics(SM_CARETBLINKINGENABLED)
  Debug.Print "SM_CONVERTIBLESLATEMODE = " & GetSystemMetrics(SM_CONVERTIBLESLATEMODE)
  Debug.Print "SM_SYSTEMDOCKED = " & GetSystemMetrics(SM_SYSTEMDOCKED)

  SendKeys "^g"
End Sub
このページの上

GetSystemMetricsCodeModule
' GetSystemMetrics()=codes

Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1
Public Const SM_CXVSCROLL = 2
Public Const SM_CYHSCROLL = 3
Public Const SM_CYCAPTION = 4
Public Const SM_CXBORDER = 5
Public Const SM_CYBORDER = 6
Public Const SM_CXDLGFRAME = 7
Public Const SM_CYDLGFRAME = 8
Public Const SM_CYVTHUMB = 9
Public Const SM_CXHTHUMB = 10
Public Const SM_CXICON = 11
Public Const SM_CYICON = 12
Public Const SM_CXCURSOR = 13
Public Const SM_CYCURSOR = 14
Public Const SM_CYMENU = 15
Public Const SM_CXFULLSCREEN = 16
Public Const SM_CYFULLSCREEN = 17
Public Const SM_CYKANJIWINDOW = 18
Public Const SM_MOUSEPRESENT = 19
Public Const SM_CYVSCROLL = 20
Public Const SM_CXHSCROLL = 21
Public Const SM_DEBUG = 22
Public Const SM_SWAPBUTTON = 23
Public Const SM_RESERVED1 = 24
Public Const SM_RESERVED2 = 25
Public Const SM_RESERVED3 = 26
Public Const SM_RESERVED4 = 27
Public Const SM_CXMIN = 28
Public Const SM_CYMIN = 29
Public Const SM_CXSIZE = 30
Public Const SM_CYSIZE = 31
Public Const SM_CXFRAME = 32
Public Const SM_CYFRAME = 33
Public Const SM_CXMINTRACK = 34
Public Const SM_CYMINTRACK = 35
Public Const SM_CXDOUBLECLK = 36
Public Const SM_CYDOUBLECLK = 37
Public Const SM_CXICONSPACING = 38
Public Const SM_CYICONSPACING = 39
Public Const SM_MENUDROPALIGNMENT = 40
Public Const SM_PENWINDOWS = 41
Public Const SM_DBCSENABLED = 42
Public Const SM_CMOUSEBUTTONS = 43
Public Const SM_CXFIXEDFRAME = SM_CXDLGFRAME
Public Const SM_CYFIXEDFRAME = SM_CYDLGFRAME
Public Const SM_CXSIZEFRAME = SM_CXFRAME
Public Const SM_CYSIZEFRAME = SM_CYFRAME
Public Const SM_SECURE = 44
Public Const SM_CXEDGE = 45
Public Const SM_CYEDGE = 46
Public Const SM_CXMINSPACING = 47
Public Const SM_CYMINSPACING = 48
Public Const SM_CXSMICON = 49
Public Const SM_CYSMICON = 50
Public Const SM_CYSMCAPTION = 51
Public Const SM_CXSMSIZE = 52
Public Const SM_CYSMSIZE = 53
Public Const SM_CXMENUSIZE = 54
Public Const SM_CYMENUSIZE = 55
Public Const SM_ARRANGE = 56
Public Const SM_CXMINIMIZED = 57
Public Const SM_CYMINIMIZED = 58
Public Const SM_CXMAXTRACK = 59
Public Const SM_CYMAXTRACK = 60
Public Const SM_CXMAXIMIZED = 61
Public Const SM_CYMAXIMIZED = 62
Public Const SM_NETWORK = 63
Public Const SM_CLEANBOOT = 67
Public Const SM_CXDRAG = 68
Public Const SM_CYDRAG = 69
Public Const SM_SHOWSOUNDS = 70
Public Const SM_CXMENUCHECK = 71
Public Const SM_CYMENUCHECK = 72
Public Const SM_SLOWMACHINE = 73
Public Const SM_MIDEASTENABLED = 74
Public Const SM_MOUSEWHEELPRESENT = 75
Public Const SM_XVIRTUALSCREEN = 76
Public Const SM_YVIRTUALSCREEN = 77
Public Const SM_CXVIRTUALSCREEN = 78
Public Const SM_CYVIRTUALSCREEN = 79
Public Const SM_CMONITORS = 80
Public Const SM_SAMEDISPLAYFORMAT = 81
Public Const SM_IMMENABLED = 82
Public Const SM_CXFOCUSBORDER = 83
Public Const SM_CYFOCUSBORDER = 84
Public Const SM_TABLETPC = 86
Public Const SM_MEDIACENTER = 87
Public Const SM_STARTER = 88
Public Const SM_SERVERR2 = 89
Public Const SM_MOUSEHORIZONTALWHEELPRESENT = 91
Public Const SM_CXPADDEDBORDER = 92
Public Const SM_DIGITIZER = 94
Public Const SM_MAXIMUMTOUCHES = 95
Public Const SM_CMETRICS = 97
Public Const SM_REMOTESESSION = &H1000
Public Const SM_SHUTTINGDOWN = &H2000
Public Const SM_REMOTECONTROL = &H2001
Public Const SM_CARETBLINKINGENABLED = &H2002
Public Const SM_CONVERTIBLESLATEMODE = &H2003
Public Const SM_SYSTEMDOCKED = &H2004
このページの上