API FUNCTION 을 이용하여 모니터의 디스플레이 설정을 맘대로 바꾸는 코드입니다. QuickRes 라는 프로그램 있는데 이것과 같은 역할을 합니다. 윈도우 제어판에서 디스플레이 설정을 바꾼후 적용하기 위해 컴퓨터를 종료했다 다시 부팅하는 그런 수고스러움 (윈도우 95 의 경우) 이 없습니다.
1. 모듈에 다음의 API FUNCTION 과 상수를 선언합니다
Public Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _ (ByVal lpszDeviceName As Long, _ ByVal iModeNum As Long, _ lpDevMode As Any) As Boolean
Public Declare Function GetDeviceCaps Lib "gdi32" _ (ByVal hdc As Long, _ ByVal nIndex As Long) As Long
Public Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" _ (lpDevMode As Any, _ ByVal dwflags As Long) As Long
Public Declare Function SetMenuDefaultItem Lib "user32" _ (ByVal hMenu As Long, _ ByVal uItem As Long, _ ByVal fByPos As Long) As Long
Public Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function GetSubMenu Lib "user32" _ (ByVal hMenu As Long, _ ByVal nPos As Long) As Long
Public Const LOGPIXELSX As Long = 88 Public Const LOGPIXELSY As Long = 90 Public Const BITSPIXEL As Long = 12 Public Const HORZRES As Long = 8 Public Const VERTRES As Long = 10 Public Const CCDEVICENAME As Long = 32 Public Const CCFORMNAME As Long = 32 Public Const DM_GRAYSCALE As Long = &H1 Public Const DM_INTERLACED As Long = &H2 Public Const DM_BITSPERPEL As Long = &H40000 Public Const DM_PELSWIDTH As Long = &H80000 Public Const DM_PELSHEIGHT As Long = &H100000 Public Const DM_DISPLAYFLAGS As Long = &H200000 Public Const CDS_UPDATEREGISTRY As Long = &H1 Public Const CDS_TEST As Long = &H2 Public Const CDS_FULLSCREEN As Long = &H4 Public Const CDS_GLOBAL As Long = &H8 Public Const CDS_SET_PRIMARY As Long = &H10 Public Const CDS_NORESET As Long = &H10000000 Public Const CDS_SETRECT As Long = &H20000000 Public Const CDS_RESET As Long = &H40000000 Public Const CDS_FORCE As Long = &H80000000
Public Type DEVMODE dmDeviceName As String * CCDEVICENAME dmSpecVersion As Integer dmDriverVersion As Integer dmSize As Integer dmDriverExtra As Integer dmFields As Long dmOrientation As Integer dmPaperSize As Integer dmPaperLength As Integer dmPaperWidth As Integer dmScale As Integer dmCopies As Integer dmDefaultSource As Integer dmPrintQuality As Integer dmColor As Integer dmDuplex As Integer dmYResolution As Integer dmTTOption As Integer dmCollate As Integer dmFormName As String * CCFORMNAME dmUnusedPadding As Integer dmBitsPerPel As Integer dmPelsWidth As Long dmPelsHeight As Long dmDisplayFlags As Long dmDisplayFrequency As Long End Type
2. 폼에 메뉴편집기를 이용하여 두개의 메뉴를 생성합니다. 그리고 아래의 코딩을 하십시요 - 메인메뉴 생성 Caption : 디스플레이 Name : mnuDisplayModes
- 메인메뉴 아래 하나의 서브메뉴 생성 Caption : 서브 Name : mnuModes Index : 0
Option Explicit
Dim currHRes As Long Dim currVRes As Long Dim currBPP As Long Dim currMenuItem As Long Dim resArray() As Long
Call SetMenuDefaultItem(hMenu, maxItems - 1, True) End If End Sub
Private Sub InitializeDisplayMenu(maxItems As Long) Dim DM As DEVMODE Dim dMode As Long
ReDim resArray(1 To 3, 0 To 35)
DM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL DM.dmSize = LenB(DM) dMode = 0
Do While EnumDisplaySettings(0&, dMode, DM) > 0 If DM.dmBitsPerPel >= 4 Then Call MenuAdd(DM, resArray(), maxItems) End If dMode = dMode + 1 Loop ReDim Preserve resArray(1 To 3, 0 To maxItems) End Sub
Private Function CompareSettings(DM As DEVMODE) As Long CompareSettings = (DM.dmBitsPerPel = currBPP) And _ DM.dmPelsHeight = currVRes And _ DM.dmPelsWidth = currHRes End Function
Private Sub MenuAdd(DM As DEVMODE, resArray() As Long, mnuCount As Long) Dim mType As String Static lastBitsPerPel As Long
Select Case DM.dmBitsPerPel Case 4: mType = "16 Color" Case 8: mType = "256 Color" Case 16: mType = "High Color" Case 24, 32: mType = "True Color" End Select
If mnuCount > 0 Then Load mnuModes(mnuCount)
If lastBitsPerPel <> DM.dmBitsPerPel Then mnuModes(mnuCount).Caption = "-" mnuCount = mnuCount + 1
첫댓글 ㅎ... ㄳ요 이거로 디스플레이 설정 짝퉁버젼 해야지 ㅎㅎ