画面の色数を取得          <TOP>


画面の色数を取得します。

GetDeviceCaps デバイス固有の情報を取得

GetDC デバイスコンテキストのハンドルを取得

ReleaseDC デバイスコンテキストを解放

 

 

'================================================================
'= 画面の色数を取得
'=    (GetDeviceCaps2.bas)
'================================================================
#include "Windows.bi"

' デバイス固有の情報を取得
Declare Function Api_GetDeviceCaps& Lib "gdi32" Alias "GetDeviceCaps" (ByVal hDC&, ByVal nIndex&)

' 指定されたウィンドウのクライアント領域または画面全体を表すディスプレイデバイスコンテキストのハンドルを取得
Declare Function Api_GetDC& Lib "user32" Alias "GetDC" (ByVal hWnd&)

' デバイスコンテキストを解放
Declare Function Api_ReleaseDC& Lib "user32" Alias "ReleaseDC" (ByVal hWnd&, ByVal hDC&)

#define BITSPIXEL 12         'ピクセルあたりのカラービットの数(プレーンごと)
#define PLANES 14            'カラープレーン数

Var Shared Text1 As Object
Var Shared Button1 As Object

Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

'================================================================
'=
'================================================================
Declare Function ColorDeepness() As String
Function ColorDeepness() As String
    Var hDC As Long
    Var cPixels As Long
    Var Txt As String
    Var Ret As Long
  
    hDC = Api_GetDC(0)
    cPixels = Api_GetDeviceCaps(hDC, BITSPIXEL) * Api_GetDeviceCaps(hDC, PLANES)
    Ret = Api_ReleaseDC(0, hDC)
     
    Select Case cPixels
        Case 1
            Txt = "2 色"
        Case 4
            Txt = "16 色"
        Case 8
            Txt = "256 色"
        Case 16
            Txt = "HighColor: " & Str$(2 ^ cPixels) & " 色"
        Case 32
      Txt = "TrueColor: " & Str$(2 ^ cPixels) & " 色"
    End Select
  
    ColorDeepness = Txt
End Function

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Text1.SetWindowText ColorDeepness
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End