Skip to main content

How to change PC resolution with VB.NET



Ok, Hi guys, After very long time I back with a surprise a code to change resolution of PC with VB.NET just copy this and past it and Call it with ChangeRes( 1024 , 768 , 32 )

The CODE 



function generate() {
Public Class Form1
    ' change resolution Constants, Types and Declares

    ' Using this option to shutdown windows does not send
    ' the WM_QUERYENDSESSION and WM_ENDSESSION messages to
    ' the open applications. Thus, those apps may loose
    ' any unsaved data.
    '
    Const EWX_FORCE As Short = 4
    Const CCDEVICENAME As Short = 32
    Const CCFORMNAME As Short = 32
    Const DM_BITSPERPEL As Integer = &H40000
    Const DM_PELSWIDTH As Integer = &H80000
    Const DM_PELSHEIGHT As Integer = &H100000
    Const CDS_UPDATEREGISTRY As Short = &H1S
    Const CDS_TEST As Short = &H2S
    Const CDS_FULLSCREEN As Short = &H4S
    Const DISP_CHANGE_SUCCESSFUL As Short = 0
    Const DISP_CHANGE_RESTART As Short = 1

    Const HWND_BROADCAST As Integer = &HFFFF
    Const WM_DISPLAYCHANGE As Integer = &H7E
    Const SPI_SETNONCLIENTMETRICS As Short = 42

    Private Structure DEVMODE
         Public dmDeviceName As String
        Dim dmSpecVersion As Short
        Dim dmDriverVersion As Short
        Dim dmSize As Short
        Dim dmDriverExtra As Short
        Dim dmFields As Integer
        Dim dmOrientation As Short
        Dim dmPaperSize As Short
        Dim dmPaperLength As Short
        Dim dmPaperWidth As Short
        Dim dmScale As Short
        Dim dmCopies As Short
        Dim dmDefaultSource As Short
        Dim dmPrintQuality As Short
        Dim dmColor As Short
        Dim dmDuplex As Short
        Dim dmYResolution As Short
        Dim dmTTOption As Short
        Dim dmCollate As Short
         Public dmFormName As String
        Dim dmUnusedPadding As Short
        Dim dmBitsPerPel As Short
        Dim dmPelsWidth As Integer
        Dim dmPelsHeight As Integer
        Dim dmDisplayFlags As Integer
        Dim dmDisplayFrequency As Integer
    End Structure

    Private Overloads Declare Function EnumDisplaySettings Lib "user32" Alias 
"EnumDisplaySettingsA" (ByVal lpszDeviceName As Integer, ByVal iModeNum As Integer, 
ByRef lpDevMode As DEVMODE) As Boolean
    'Private Overloads Declare Function EnumDisplaySettings Lib "user32" Alias 
"EnumDisplaySettingsA" (ByVal lpszDeviceName As Integer, ByVal iModeNum As Integer, 
ByRef lpDevMode As Long) As Boolean

    Private Overloads Declare Function ChangeDisplaySettings Lib "user32" Alias 
"ChangeDisplaySettingsA" (ByRef lpDevMode As DEVMODE, ByVal dwFlags As Integer) 
As Integer
    'Private Overloads Declare Function ChangeDisplaySettings Lib "user32" Alias 
"ChangeDisplaySettingsA" (ByRef lpDevMode As Long, ByVal dwFlags As Integer) 
As Integer

    Public Function ChangeRes(ByVal width As Integer, ByVal height As Integer,
 ByVal BPP As Short) As Integer
        Dim DevM As Form1.DEVMODE
        Dim lResult As Integer
        Dim iAns As Short
        lResult = EnumDisplaySettings(0, 0, DevM)
        With DevM
            .dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
            .dmPelsWidth = width
            .dmPelsHeight = height
            .dmBitsPerPel = BPP
        End With
        lResult = ChangeDisplaySettings(DevM, CDS_FULLSCREEN)
        Select Case lResult
            Case DISP_CHANGE_SUCCESSFUL
                Call ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
            Case Else
                MsgBox("Mode not supported", MsgBoxStyle.SystemModal, "Error")
        End Select
        Return 0
    End Function

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim x As Integer = Screen.PrimaryScreen.BitsPerPixel
        ChangeRes(1024, 768, x)
    End Sub
End Class
}


Change Form1 to Your Form Name 
And Button1 to Your Control Name

Please Leave Comment !!!

Comments

Post a Comment

Popular posts from this blog

Visual Basic ( Catch Me ) Introduction

Hello guys, Welcome back to Visual Basic Tutorial ( GAME ) Catch me: - It is a simple game that a Picture will appear Random in the Windows Form and the player (user) will try to click on it by mouse that all We have lot of version to Catch me so I will make a list for them 1. Catch me Version 1.0.0  Features : User will play in 800*600 window state  User will play it without any effects The result will not be saved 2. Catch me Version 2.0.0  Features : User will play  in Full Screen When User will press in the picture ( Target ) the black color will be green the back to Default The result will  be saved as long as the game is opened 3. Catch me Version 3.0.0  Features : User will play  in Full Screen User will choose the level of game ( Insane - Extreme - Hard - Normal - Easy - Baby Level ) The result will be saved in Database with Names ------------------------------------------------- Notice The title Catch Me Version X.X.X will be

How Bitcoin Mining Works

In traditional fiat money systems, governments simply print more money when they need to. But in bitcoin, money isn’t printed at all – it is discovered. Computers around the world ‘mine’ for coins by competing with each other. How does mining take place? People are sending bitcoins to each other over the bitcoin network all the time, but unless someone keeps a record of all these transactions, no-one would be able to keep track of who had paid what. The bitcoin network deals with this by collecting all of the transactions made during a set period into a list, called a block. It’s the miners’ job to confirm those transactions, and write them into a general ledger. Making a hash of it This general ledger is a long list of blocks, known as the 'blockchain'. It can be used to explore any transaction made between any bitcoin addresses, at any point on the network. Whenever a new block of transactions is created, it is added to the blockchain, creating an increasingly le