Kan jeg ændre på skærmopløsningen i mit vb projekt ?

Tags:    visual-basic

Kan man ændre en skærmopløsning fra for eks. 1024x768 til 800x600 ved hjælp af vb ?
Jeg har et lille program, som skal ændre skærmopløsningen til 800x600og så kalde et andet program, og når det program så lukkes, skal skærmopløsningen sættes tilbage til det den var, før programet startes.
Jeg håber at der er nogen der kan hjælpe mig.



4 svar postet i denne tråd vises herunder
2 indlæg har modtaget i alt 4 karma
Sorter efter stemmer Sorter efter dato
Hej Majbritt,

Jeg har fundet der her link:
http://www.freevbcode.com/ShowCode.Asp?ID=467
Håber det kan bruges :-)

Med venlig hilsen
Ken Christensen

Jeg kan ikke helt bruge det link, for den genstarter maskinen, og det var ikke meningen...


jeg mener at denne kode ikke genstarter maskinen!



dette skal i et standart modul
<pre>
Declare Function EnumDisplaySettings Lib "user32" _
Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, _
ByVal iModeNum As Long, _
lpDevMode As Any) As Boolean
Declare Function ChangeDisplaySettings Lib "user32" _
Alias "ChangeDisplaySettingsA" _
(lpDevMode As Any, ByVal dwFlags As Long) As Long

Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Public Const CCDEVICENAME = 32
Public Const CCFORMNAME = 32
Public Const DM_BITSPERPEL = &H40000
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H4
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1
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
</pre>


dene del skal tilføjes f.eks. en knap. Tallene 640, 480 og 16 i koden kan ændres til f.eks.
text1.text, text2.text og text3.text, så skal tallene bare indtastes i disse textboxe.

<pre>
private sub oplosning
Dim DevM As DEVMODE
erg& = EnumDisplaySettings(0&, 0&, DevM)

DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
DevM.dmPelsWidth = 640 'bredde
DevM.dmPelsHeight = 480 'højde
DevM.dmBitsPerPel = 16 'bit farver

erg& = ChangeDisplaySettings(DevM, CDS_TEST)

Select Case erg&
Case DISP_CHANGE_RESTART
an = MsgBox("Genstart computeren", vbYesNo + vbSystemModal, "Info")
If an = vbYes Then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
MsgBox "Alt er ok", vbOKOnly + vbSystemModal, "Skærmopløsning"
Case Else
MsgBox "Skærmopløsning ikke mulig", vbOKOnly + vbSystemModal, "Fejl"
End Select
End Sub



</pre>

-Thomas


[Redigeret d. 17/07-03 13:03:49 af Thomas Christensen]



Hej Majbritt,

Jeg har fundet der her link:
http://www.freevbcode.com/ShowCode.Asp?ID=467
Håber det kan bruges :-)

Med venlig hilsen
Ken Christensen



Hej Majbritt,

Jeg har fundet der her link:
http://www.freevbcode.com/ShowCode.Asp?ID=467
Håber det kan bruges :-)

Med venlig hilsen
Ken Christensen


Jeg kan ikke helt bruge det link, for den genstarter maskinen, og det var ikke meningen...



Hej Majbritt,

Jeg har fundet der her link:
http://www.freevbcode.com/ShowCode.Asp?ID=467
Håber det kan bruges :-)

Med venlig hilsen
Ken Christensen

Jeg kan ikke helt bruge det link, for den genstarter maskinen, og det var ikke meningen...

jeg mener at denne kode ikke genstarter maskinen!



dette skal i et standart modul
<pre>
Declare Function EnumDisplaySettings Lib "user32" _
Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As Long, _
ByVal iModeNum As Long, _
lpDevMode As Any) As Boolean
Declare Function ChangeDisplaySettings Lib "user32" _
Alias "ChangeDisplaySettingsA" _
(lpDevMode As Any, ByVal dwFlags As Long) As Long

Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1
Public Const EWX_REBOOT = 2
Public Const EWX_FORCE = 4
Public Const CCDEVICENAME = 32
Public Const CCFORMNAME = 32
Public Const DM_BITSPERPEL = &H40000
Public Const DM_PELSWIDTH = &H80000
Public Const DM_PELSHEIGHT = &H100000
Public Const CDS_UPDATEREGISTRY = &H1
Public Const CDS_TEST = &H4
Public Const DISP_CHANGE_SUCCESSFUL = 0
Public Const DISP_CHANGE_RESTART = 1
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
</pre>


dene del skal tilføjes f.eks. en knap. Tallene 640, 480 og 16 i koden kan ændres til f.eks.
text1.text, text2.text og text3.text, så skal tallene bare indtastes i disse textboxe.

<pre>
private sub oplosning
Dim DevM As DEVMODE
erg& = EnumDisplaySettings(0&, 0&, DevM)

DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
DevM.dmPelsWidth = 640 'bredde
DevM.dmPelsHeight = 480 'højde
DevM.dmBitsPerPel = 16 'bit farver

erg& = ChangeDisplaySettings(DevM, CDS_TEST)

Select Case erg&
Case DISP_CHANGE_RESTART
an = MsgBox("Genstart computeren", vbYesNo + vbSystemModal, "Info")
If an = vbYes Then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg& = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
MsgBox "Alt er ok", vbOKOnly + vbSystemModal, "Skærmopløsning"
Case Else
MsgBox "Skærmopløsning ikke mulig", vbOKOnly + vbSystemModal, "Fejl"
End Select
End Sub



</pre>

-Thomas


[Redigeret d. 17/07-03 13:03:49 af Thomas Christensen]


Fjern dette stykke kode:

<pre>
Case DISP_CHANGE_RESTART
an = MsgBox("Genstart computeren", vbYesNo + vbSystemModal, "Info")
If an = vbYes Then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
</pre>

Med Venlig Hilsen
Morten Torndahl Pedersen



t