PDA

Visualizza la versione completa : [VB5] Adattare la risoluzione dello schermo


Nico
18-05-2002, 18:37
Ragazzi vorrei finalmente sapere come si fa per modificare la risoluzione dello schermo da un'applicazione fatta in VB (putroppo ho solo il 5).
Mi sembra che fosse possibile con DirectX...qualcuno ne sa qualcosa???

vonkranz
18-05-2002, 19:14
Puoi usare le API di Win.
Ecco un semplice esempio (Nota: l'ho copiato da "Api-Giude 3.6")


Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_TEST = &H4
Private Type DISPLAY_DEVICE
cb As Long
DeviceName As String * 32
DeviceString As String * 128
StateFlags As Long
DeviceID As String * 128
DeviceKey As String * 128
End Type
Private 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
dmICMMethod As Long 'NT 4.0
dmICMIntent As Long 'NT 4.0
dmMediaType As Long 'NT 4.0
dmDitherType As Long 'NT 4.0
dmReserved1 As Long 'NT 4.0
dmReserved2 As Long 'NT 4.0
dmPanningWidth As Long 'Win2000
dmPanningHeight As Long 'Win2000
End Type
Private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" (lpszDeviceName As Any, lpDevMode As Any, ByVal hWnd As Long, ByVal dwFlags As Long, lParam As Any) As Long
Private Declare Function EnumDisplayDevices Lib "user32" Alias "EnumDisplayDevicesA" (Unused As Any, ByVal iDevNum As Long, lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Long) As Boolean
Dim OldX As Long, OldY As Long, T As Long
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim DD As DISPLAY_DEVICE, DevM As DEVMODE
DD.cb = Len(DD)
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
'First retieve some display info
If EnumDisplayDevices(ByVal 0&, 0, DD, ByVal 0&) Then
'and show it
Me.AutoRedraw = True
Me.Print "Device String:" + Left$(DD.DeviceString, InStr(1, DD.DeviceString, Chr$(0)) - 1)
Me.Print "Device Name:" + Left$(DD.DeviceName, InStr(1, DD.DeviceName, Chr$(0)) - 1)
Me.Print "Device Key:" + Left$(DD.DeviceKey, InStr(1, DD.DeviceKey, Chr$(0)) - 1)
Me.Print "Device ID:" + Left$(DD.DeviceID, InStr(1, DD.DeviceID, Chr$(0)) - 1)
Else
Me.Print "Error while retrieving Display Information"
End If
DevM.dmSize = Len(DevM)
'we want to change the horizontal and the vertical resolution
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidth = 640
DevM.dmPelsHeight = 480
'change the display settings
Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
T = Timer
Do: DoEvents: Loop Until Timer > T + 5
DevM.dmPelsWidth = OldX
DevM.dmPelsHeight = OldY
'change the display settings back to the old settings
Call ChangeDisplaySettingsEx(ByVal 0&, DevM, ByVal 0&, CDS_TEST, ByVal 0&)
End Sub

Copialo in un form e lancia il programma.

Spero ti serva.
Ciao.

Nico
18-05-2002, 20:06
Ho provato a eseguire il programma ...
1.- mi imposta la risoluzione a 600x480...!
2.- Non me la rimette a posto alla fine
3.- Non appare nessuna finestra...non devo metterlo in un modulo il codice?
4.-Non capisco dove sono i valori da modificare per ottenre una risoluzione 1024x768

grazie cmq!

Nico
19-05-2002, 21:10
uuuup ....

Nico
19-05-2002, 23:59
Hey....dato che avevo guardato cos abbastanza di sfuggita non avevo visto i paramteri 640 e 480...!
Cmq il form appare, mi ero sbagliato. Bisogna attendere solo qualche secondo!

Funziona!!!
Grazie!!!! :ciauz: :ciauz:

alfionas
29-05-2002, 20:23
Il codice perfetto, grazie!!!
L'unico inconveniente che ho trovato che nn riesco a settare la barra degli strumenti in basso. Infatti passando dalla risoluzione 800*600 a 1024*768 la barra appare in mezzo a desktop e l'unico modo per sistemara spostarla manualmente in fondo al desktop.
Esiste una maniera che mi permette di farlo in automatico?

Nico
29-05-2002, 22:11
...mi sono accorto del problema ma ho ovviato semplicemente mettendo la dimensione del form iniziale a "maximized" e il border "none".
In questo modo la barra rimane sotto...

Loading