Windows各種情報の取得

<システムインフォメーションソフトを作ろう>

宣 言


(Private) Const SM_CXSCREEN = 0
(Private) Const SM_CYSCREEN = 1
(Private) Const SM_CXVSCROLL = 2
(Private) Const SM_CYHSCROLL = 3
(Private) Const SM_CYCAPTION = 4
(Private) Const SM_CXBORDER = 5
(Private) Const SM_CYBORDER = 6
(Private) Const SM_CXDLGFRAME = 7
(Private) Const SM_CYDLGFRAME = 8
(Private) Const SM_CYVTHUMB = 9
(Private) Const SM_CXHTHUMB = 10
(Private) Const SM_CXICON = 11
(Private) Const SM_CYICON = 12
(Private) Const SM_CXCURSOR = 13
(Private) Const SM_CYCURSOR = 14
(Private) Const SM_CYMENU = 15
(Private) Const SM_CXFULLSCREEN = 16
(Private) Const SM_CYFULLSCREEN = 17
(Private) Const SM_CYKANJIWINDOW = 18
(Private) Const SM_MOUSEPRESENT = 19
(Private) Const SM_CYVSCROLL = 20
(Private) Const SM_CXHSCROLL = 21
(Private) Const SM_DEBUG = 22
(Private) Const SM_SWAPBUTTON = 23
(Private) Const SM_RESERVED1 = 24
(Private) Const SM_RESERVED2 = 25
(Private) Const SM_RESERVED3 = 26
(Private) Const SM_RESERVED4 = 27
(Private) Const SM_CXMIN = 28
(Private) Const SM_CYMIN = 29
(Private) Const SM_CXSIZE = 30
(Private) Const SM_CYSIZE = 31
(Private) Const SM_CXFRAME = 32
(Private) Const SM_CYFRAME = 33
(Private) Const SM_CXMINTRACK = 34
(Private) Const SM_CYMINTRACK = 35
(Private) Const SM_CXDOUBLECLK = 36
(Private) Const SM_CYDOUBLECLK = 37
(Private) Const SM_CXICONSPACING = 38
(Private) Const SM_CYICONSPACING = 39
(Private) Const SM_MENUDROPALIGNMENT = 40
(Private) Const SM_PENWINDOWS = 41
(Private) Const SM_DBCSENABLED = 42
(Private) Const SM_CMOUSEBUTTONS = 43
(Private) Const SM_CXFIXEDFRAME = SM_CXDLGFRAME
(Private) Const SM_CYFIXEDFRAME = SM_CYDLGFRAME
(Private) Const SM_CXSIZEFRAME = SM_CXFRAME
(Private) Const SM_CYSIZEFRAME = SM_CYFRAME
(Private) Const SM_SECURE = 44
(Private) Const SM_CXEDGE = 45
(Private) Const SM_CYEDGE = 46
(Private) Const SM_CXMINSPACING = 47
(Private) Const SM_CYMINSPACING = 48
(Private) Const SM_CXSMICON = 49
(Private) Const SM_CYSMICON = 50
(Private) Const SM_CYSMCAPTION = 51
(Private) Const SM_CXSMSIZE = 52
(Private) Const SM_CYSMSIZE = 53
(Private) Const SM_CXMENUSIZE = 54
(Private) Const SM_CYMENUSIZE = 55
(Private) Const SM_ARRANGE = 56
(Private) Const SM_CXMINIMIZED = 57
(Private) Const SM_CYMINIMIZED = 58
(Private) Const SM_CXMAXTRACK = 59
(Private) Const SM_CYMAXTRACK = 60
(Private) Const SM_CXMAXIMIZED = 61
(Private) Const SM_CYMAXIMIZED = 62
(Private) Const SM_NETWORK = 63
(Private) Const SM_CLEANBOOT = 67
(Private) Const SM_CXDRAG = 68
(Private) Const SM_CYDRAG = 69
(Private) Const SM_SHOWSOUNDS = 70
(Private) Const SM_CXMENUCHECK = 71
(Private) Const SM_CYMENUCHECK = 72
(Private) Const SM_SLOWMACHINE = 73
(Private) Const SM_MIDEASTENABLED = 74
(Private) Const SM_CMETRICS = 75
(Private) Declare Function GetSystemMetrics& Lib "user32" (ByVal nIndex As Long)

※Privateは必要に応じて削除またはPublicに変更

引 数 説 明


nIndex

Long

取得する情報番号の指定。戻り値は取得した情報。


引 数 に つ い て の 追 加 説 明

次のコードをnIndexに代入することで次の機能を取得することができます。

引数 機能

SM_CLEANBOOT

Windowsのモード。0=通常、1=セーフブート、2=ネットワークを介してのセーフブート

SM_CMOUSEBUTTON

マウスボタンの数

SM_CXCURSOR
SM_CYCURSOR

カーソルの幅と高さ

SM_CXDOUBLECLK SM_CYDOUBLECLK

ダブルクリック領域の幅と高さ。ダブルクリック領域とは、連続する2回のクリックがダブルクリックとみなされる範囲をいう。

SM_CXICON
SM_CYICON

標準アイコンの幅と高さ

SM_CXICONSPACING
SM_CYICONSPACING

デスクトップアイコンの水平方向と垂直方向の間隔

SM_CXMAXIMIZED SM_CYMAXIMIZED

Windows 95の最大化したウィンドウのデフォルトの幅と高さ

SM_CXSMICON
SM_CYSMICON

Windows 95の「小さいアイコン」の幅と高さ

SM_SLOWMACHINE

システムが低速でWindows 95を効率よく利用できない場合はTRUE

まだまだたくさん命令があるのですが、ここでは説明しきれません。詳しくは「Win32 APIプログラマーズリファレンス」(Visual Basicのプロフェッショナルエディション以上やVisual C++などの開発ソフトに含まれています)などを見てください。

サ ン プ ル プ ロ グ ラ ム

Windowsの各種情報を取得するサンプルです。Visual Basicを起動して、新しいプロジェクトを作成し、次のコードを張りつけ実行してください。各種情報を表示して終了します。

動作確認:Visual Basic 5.0(Visual Basic 4.0でも問題なく動作するはずです),Windows98

'定数の宣言
Private Const SM_CXSCREEN = 0
Private Const SM_CYSCREEN = 1
Private Const SM_CXVSCROLL = 2
Private Const SM_CYHSCROLL = 3
Private Const SM_CYCAPTION = 4
Private Const SM_CXBORDER = 5
Private Const SM_CYBORDER = 6
Private Const SM_CXDLGFRAME = 7
Private Const SM_CYDLGFRAME = 8
Private Const SM_CYVTHUMB = 9
Private Const SM_CXHTHUMB = 10
Private Const SM_CXICON = 11
Private Const SM_CYICON = 12
Private Const SM_CXCURSOR = 13
Private Const SM_CYCURSOR = 14
Private Const SM_CYMENU = 15
Private Const SM_CXFULLSCREEN = 16

Private Const SM_CYFULLSCREEN = 17
Private Const SM_CYKANJIWINDOW = 18
Private Const SM_MOUSEPRESENT = 19
Private Const SM_CYVSCROLL = 20
Private Const SM_CXHSCROLL = 21
Private Const SM_DEBUG = 22
Private Const SM_SWAPBUTTON = 23
Private Const SM_RESERVED1 = 24
Private Const SM_RESERVED2 = 25
Private Const SM_RESERVED3 = 26
Private Const SM_RESERVED4 = 27
Private Const SM_CXMIN = 28
Private Const SM_CYMIN = 29
Private Const SM_CXSIZE = 30
Private Const SM_CYSIZE = 31
Private Const SM_CXFRAME = 32
Private Const SM_CYFRAME = 33
Private Const SM_CXMINTRACK = 34

Private Const SM_CYMINTRACK = 35
Private Const SM_CXDOUBLECLK = 36
Private Const SM_CYDOUBLECLK = 37
Private Const SM_CXICONSPACING = 38
Private Const SM_CYICONSPACING = 39
Private Const SM_MENUDROPALIGNMENT = 40
Private Const SM_PENWINDOWS = 41
Private Const SM_DBCSENABLED = 42
Private Const SM_CMOUSEBUTTONS = 43
Private Const SM_CXFIXEDFRAME = SM_CXDLGFRAME
Private Const SM_CYFIXEDFRAME = SM_CYDLGFRAME
Private Const SM_CXSIZEFRAME = SM_CXFRAME
Private Const SM_CYSIZEFRAME = SM_CYFRAME
Private Const SM_SECURE = 44
Private Const SM_CXEDGE = 45
Private Const SM_CYEDGE = 46
Private Const SM_CXMINSPACING = 47
Private Const SM_CYMINSPACING = 48

Private Const SM_CXSMICON = 49
Private Const SM_CYSMICON = 50
Private Const SM_CYSMCAPTION = 51
Private Const SM_CXSMSIZE = 52
Private Const SM_CYSMSIZE = 53
Private Const SM_CXMENUSIZE = 54
Private Const SM_CYMENUSIZE = 55
Private Const SM_ARRANGE = 56
Private Const SM_CXMINIMIZED = 57
Private Const SM_CYMINIMIZED = 58
Private Const SM_CXMAXTRACK = 59
Private Const SM_CYMAXTRACK = 60
Private Const SM_CXMAXIMIZED = 61
Private Const SM_CYMAXIMIZED = 62
Private Const SM_NETWORK = 63
Private Const SM_CLEANBOOT = 67
Private Const SM_CXDRAG = 68
Private Const SM_CYDRAG = 69

Private Const SM_SHOWSOUNDS = 70
Private Const SM_CXMENUCHECK = 71
Private Const SM_CYMENUCHECK = 72
Private Const SM_SLOWMACHINE = 73
Private Const SM_MIDEASTENABLED = 74
Private Const SM_CMETRICS = 75
Private Declare Function GetSystemMetrics& Lib "user32" (ByVal nIndex As Long)'APIの宣言

Private Sub Form_Load()
Dim Str1 As String'変数の宣言
Dim Str2 As String

'各種情報の取得
Select Case GetSystemMetrics(SM_CLEANBOOT)
Case 0
Str1 = "通常のブート"
Case 1
Str1 = "セーフブート"

Case 2
Str1 = "ネットワークを介してのセーフブート"
End Select

If GetSystemMetrics(SM_SLOWMACHINE) = True Then
Str2 = "利用できない"
Else
Str2 = "利用できる"
End If

MsgBox "マウスボタンの数:" + Str(GetSystemMetrics(43)) + Chr(13) + _
"通常のアイコンの大きさ(x,y):" + Str(GetSystemMetrics(SM_CXICON)) + "," + Str(GetSystemMetrics(SM_CYICON)) + Chr(13) + _
"デスクトップアイコンの水平方向と垂直方向の間隔(x,y):" + Str(GetSystemMetrics(SM_CXICONSPACING)) + "," + Str(GetSystemMetrics(SM_CYICONSPACING)) + Chr(13) + _
"Windowsのブートモード:" + Str1 + Chr(13) + _
"システムが低速でWindowsが効率良く利用できないか:" + Str2
End
End Sub

トップに戻る
Visual Basicワンポイントテクニック目次に戻る

テレワークならECナビ Yahoo 楽天 LINEがデータ消費ゼロで月額500円〜!
無料ホームページ 無料のクレジットカード 海外格安航空券 海外旅行保険が無料! 海外ホテル