Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am writing a game which should be displayed in 1024x768.

 

Is there a way to test the users screen resolution and automatically change it to 1024x768 if it is not already at this resolution?

My website
  • *Experts*
Posted

You can get the screen size using this:

Dim scren As Rectangle = Screen.PrimaryScreen.Bounds() 'get the size
MessageBox.Show(scren.Width) 'display the width
MessageBox.Show(scren.Height) 'display the height

 

ANd you need the ChangeDisplaySettings API to change it.

Posted

Hi,

 

all I get is an error saying cannot convert to rectangle on the line using primaryscreen??

My website
Posted
Did anyone else have trouble trying to code that stuff with? I was having trouble figuring out what DEVMODE gets replaced with. I'm pretty interested in getting this code to run in .net.

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Posted

Thanks for pointing that thread out, mutant. I'm trying to convert the code in that thread from C# to VB.NET. As I've been learning VB.NET, it's been hard not to pick up a little C# along the way, since all the good code samples seem to be in C#, but API calls are a little over my head. So I ran the code through a C# --> VB.NET parser . Would anyone mind telling me what needs to get fixed here?

 

Imports System
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Runtime.InteropServices


Namespace ScreenResolution
   _
  
  Public Class Form1
     Inherits System.Windows.Forms.Form
      _
     
     
     
     Public Enum DMDO
        [DEFAULT] = 0
        D90 = 1
        D180 = 2
        D270 = 3
     End Enum 'DMDO
     <StructLayout(LayoutKind.Sequential, CharSet := CharSet.Auto)>  _
     
     Structure DEVMODE
        Public DM_PELSWIDTH As Integer = &H80000
        Public DM_PELSHEIGHT As Integer = &H100000
        Private CCHDEVICENAME As Integer = 32
        Private CCHFORMNAME As Integer = 32<MarshalAs(UnmanagedType.ByValTStr, SizeConst := CCHDEVICENAME)> 
        
        Public dmDeviceName As String
        Public dmSpecVersion As Short
        Public dmDriverVersion As Short
        Public dmSize As Short
        Public dmDriverExtra As Short
        Public dmFields As Integer
        
        Public dmPositionX As Integer
        Public dmPositionY As Integer
        Public dmDisplayOrientation As DMDO
        Public dmDisplayFixedOutput As Integer
        
        Public dmColor As Short
        Public dmDuplex As Short
        Public dmYResolution As Short
        Public dmTTOption As Short
        Public dmCollate As Short<MarshalAs(UnmanagedType.ByValTStr, SizeConst := CCHFORMNAME)> 
        Public dmFormName As String
        Public dmLogPixels As Short
        Public dmBitsPerPel As Integer
        Public dmPelsWidth As Integer
        Public dmPelsHeight As Integer
        Public dmDisplayFlags As Integer
        Public dmDisplayFrequency As Integer
        Public dmICMMethod As Integer
        Public dmICMIntent As Integer
        Public dmMediaType As Integer
        Public dmDitherType As Integer
        Public dmReserved1 As Integer
        Public dmReserved2 As Integer
        Public dmPanningWidth As Integer
        Public dmPanningHeight As Integer
     End Structure 'DEVMODE
     
     
     '--------------------------------\
     
     
     Shared Declare Auto Function ChangeDisplaySettings Lib "user32.dll" (ByRef<[in]()> lpDevMode As DEVMODE, dwFlags As Integer) As Integer
     'static extern int ChangeDisplaySettings( DEVMODE lpDevMode,  int dwFlags);
     ' should I use this line?
     
     '/ <summary>
     '/ Required designer variable.
     '/ </summary>
     Private components As System.ComponentModel.Container = Nothing
     
     
     Public Sub New()
        '
        ' Required for Windows Form Designer support
        '
        InitializeComponent()
     End Sub 'New
      
     '
     ' TODO: Add any constructor code after InitializeComponent call
     '
     
     
     Protected Overrides Sub Dispose(disposing As Boolean)
        If disposing Then
           If Not (components Is Nothing) Then
              components.Dispose()
           End If
        End If
        MyBase.Dispose(disposing)
     End Sub 'Dispose
     
     
     '
     'ToDo: Error processing original source shown below
     '
     '
     '-----------^--- Pre-processor directives not translated
     '/ <summary>
     '
     'ToDo: Error processing original source shown below
     '
     '
     '--^--- Unexpected pre-processor directive
     '/ Required method for Designer support - do not modify
     '/ the contents of this method with the code editor.
     '/ </summary>
     Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.Size = New System.Drawing.Size(300, 300)
        Me.Text = "Form1"
     End Sub 'InitializeComponent
     
     '
     'ToDo: Error processing original source shown below
     '
     '
     '-----------^--- Pre-processor directives not translated
     '
     'ToDo: Error processing original source shown below
     '
     '
     '--^--- Unexpected pre-processor directive
     
     Shared Sub Main()
        Dim r As New Form1()
        r.ChangeRes()
        Application.Run(New Form1())
     End Sub 'Main
     
     
     Sub ChangeRes()
        
        Dim t As New Form1()
        
        Dim RetVal As Long = 0
        
        Dim dm As New DEVMODE()
        
        dm.dmSize = CShort(Marshal.SizeOf(GetType(DEVMODE)))
        
        dm.dmPelsWidth = 1024
        dm.dmPelsHeight = 768
        
        dm.dmFields = DEVMODE.DM_PELSWIDTH Or DEVMODE.DM_PELSHEIGHT
        
        
        RetVal = ChangeDisplaySettings(dm, 0)
     End Sub 'ChangeRes 
  End Class 'Form1 
End Namespace 'ScreenResolution

 

My goal here is to make something similar to QuickRes, just a statusbar icon with a popup menu containing the available screen resolutions, color depths, and refresh rates.

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Posted
edit

"It may be roundly asserted that human ingenuity cannot concoct a cipher which human ingenuity cannot resolve."

 

- Edgar Allan Poe, 1841

 

I long to accomplish great and noble tasks, but it is my chief duty to accomplish humble tasks as though they were great and noble. The world is moved along, not only by the mighty shoves of its heroes, but also by the aggregate of the tiny pushes of each honest worker.

 

- Helen Keller

Posted
edit

 

what do u mean by "edit" lol?

 

btw

the converter doesnt always work, you have to learn a little bit of C# before you do this

but, try doing this:

 

instead of giving all the code to the converter(parser) at once, give it line by line, i hope this helps

 

and try other converters too,

My VB.NET Game Programming Tutorial Site (GDI+, Direct3D, Tetris [coming soon], a full RPG.... you name it!)

vbprogramming.8k.com

My Project (Need VB.NET Programmers)

http://workspaces.gotdotnet.com/ResolutionRPG

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...