Click here to Skip to main content
15,911,762 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Changing text on button in MessageBox Pin
koolprasad200313-Jun-07 19:39
professionalkoolprasad200313-Jun-07 19:39 
Questionunknown problem. please help. Pin
manni_n13-Jun-07 5:51
manni_n13-Jun-07 5:51 
AnswerRe: unknown problem. please help. Pin
vbnetnoowb13-Jun-07 6:03
vbnetnoowb13-Jun-07 6:03 
GeneralRe: unknown problem. please help. Pin
manni_n13-Jun-07 20:11
manni_n13-Jun-07 20:11 
GeneralHelp with string comparison Pin
Psycho-*Coder*-Extreme13-Jun-07 5:25
Psycho-*Coder*-Extreme13-Jun-07 5:25 
GeneralRe: Help with string comparison Pin
nlarson1113-Jun-07 5:29
nlarson1113-Jun-07 5:29 
GeneralRe: Help with string comparison [Resolved] Pin
Psycho-*Coder*-Extreme13-Jun-07 6:34
Psycho-*Coder*-Extreme13-Jun-07 6:34 
QuestionRetrieving and restoring extended desktop settings with EnumDisplaySettingsEx [modified] Pin
vbnetnoowb13-Jun-07 4:49
vbnetnoowb13-Jun-07 4:49 
Hi all.

I've been trying in vein for days to figure this out. I use extended desktop to extend my display to the left, not the right, and when I hibernate and come back, the desktop is extended to the right. So I'm writing an app that will retrieve the extended desktop settings on hibernate and set them again on resume.

I've seen a few examples of using EnumDisplaySettingsEx in C and C#, but nothing in vb.net that helps. I just need to figure out how to determine "This monitor is primary, that one is secondary and is positioned on the left." And then "Set this monitor to primary, set that one to be on the left."

I already have the rest of the app written (detecting hibernate, etc.), but I'm super new to the Windows API and all these structs and translations from C to vb.net are way out of my league.

I'm desperate D'Oh! | :doh: . Help!


----
P.S. I've pieced together the following, and it gets devicename and resolution successfully, but I'm still stuck on the aforementioned stuff:

Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form

Const ENUM_CURRENT_SETTINGS As Integer = -1
Const CDS_UPDATEREGISTRY As Integer = &H1
Const CDS_TEST As Long = &H2

Const CCDEVICENAME As Integer = 32
Const CCFORMNAME As Integer = 32

Const DISP_CHANGE_SUCCESSFUL As Integer = 0
Const DISP_CHANGE_RESTART As Integer = 1
Const DISP_CHANGE_FAILED As Integer = -1

Private Declare Function EnumDisplaySettingsEx Lib "user32" Alias "EnumDisplaySettingsExA" (ByVal lpszDeviceName As Integer, ByVal iModeNum As Integer, ByRef lpDevMode As DEVMODE, ByVal dwFlags As Integer) As Integer
Private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (ByRef DEVMODE As DEVMODE, ByVal flags As Long) As Integer

<structlayout(layoutkind.sequential)> Public Structure DEVMODE
<marshalasattribute(unmanagedtype.byvaltstr, sizeconst:="CCDEVICENAME)"> _
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 dmOrientation As Short
Public dmPaperSize As Short
Public dmPaperLength As Short
Public dmPaperWidth As Short
Public dmScale As Short
Public dmCopies As Short
Public dmDefaultSource As Short
Public dmPrintQuality As Short
Public dmColor As Short
Public dmDuplex As Short
Public dmYResolution As Short
Public dmTTOption As Short
Public dmCollate As Short
<marshalasattribute(unmanagedtype.byvaltstr, sizeconst:="CCFORMNAME)"> _
Public dmFormName As String
Public dmUnusedPadding As Short
Public dmBitsPerPel As Short
Public dmPelsWidth As Integer
Public dmPelsHeight As Integer
Public dmDisplayFlags As Integer
Public dmDisplayFrequency As Integer

End Structure

Public Sub getScreenInfo(ByVal theWidth As Integer, ByVal theHeight As Integer)
Dim ascreen As Screen

Dim DevM As DEVMODE

DevM.dmDeviceName = New [String](New Char(32) {})
DevM.dmFormName = New [String](New Char(32) {})
DevM.dmSize = CShort(Marshal.SizeOf(GetType(DEVMODE)))


If 0 <> EnumDisplaySettingsEx(Nothing, ENUM_CURRENT_SETTINGS, DevM, 0) Then
Dim lResult As Integer

DevM.dmPelsWidth = theWidth
DevM.dmPelsHeight = theHeight
DevM.dmPelsWidth = 1280
DevM.dmPelsHeight = 1024

lResult = ChangeDisplaySettings(DevM, CDS_TEST)

If lResult = DISP_CHANGE_FAILED Then
MsgBox("Display Change Failed.", MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "Screen Resolution Change Failed")
Else

lResult = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)

Select Case lResult
Case DISP_CHANGE_RESTART
MsgBox("You must restart your computer to apply these changes.", MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "Screen Resolution Has Changed")
Case DISP_CHANGE_SUCCESSFUL
MsgBox("Display Change Successful.", MsgBoxStyle.OKOnly + MsgBoxStyle.Information, "Screen Resolution Successful")
Case Else
MsgBox("Display Change Failed.", MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "Screen Resolution Change Failed")
End Select
End If


End If
End Sub


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
getScreenInfo(1024, 768)
End Sub


-- modified at 13:28 Wednesday 13th June, 2007
AnswerRe: Retrieving and restoring extended desktop settings with EnumDisplaySettingsEx Pin
Dave Kreskowiak13-Jun-07 7:16
mveDave Kreskowiak13-Jun-07 7:16 
GeneralRe: Retrieving and restoring extended desktop settings with EnumDisplaySettingsEx Pin
vbnetnoowb13-Jun-07 7:31
vbnetnoowb13-Jun-07 7:31 
GeneralRe: Retrieving and restoring extended desktop settings with EnumDisplaySettingsEx Pin
Dave Kreskowiak13-Jun-07 15:44
mveDave Kreskowiak13-Jun-07 15:44 
QuestionVB6 - Controls Can't Be Unlocked [SOLVED] [modified] Pin
#realJSOP13-Jun-07 2:45
professional#realJSOP13-Jun-07 2:45 
AnswerRe: VB6 - Controls Can't Be Unlocked Pin
Craster13-Jun-07 3:08
Craster13-Jun-07 3:08 
AnswerRe: VB6 - Controls Can't Be Unlocked [SOLVED] Pin
Dave Kreskowiak13-Jun-07 4:39
mveDave Kreskowiak13-Jun-07 4:39 
QuestionKeyboard and Mouse control Pin
pirogramci13-Jun-07 1:48
pirogramci13-Jun-07 1:48 
AnswerRe: Keyboard and Mouse control Pin
kubben13-Jun-07 3:12
kubben13-Jun-07 3:12 
AnswerRe: Keyboard and Mouse control Pin
Dave Kreskowiak13-Jun-07 3:52
mveDave Kreskowiak13-Jun-07 3:52 
AnswerRe: Keyboard and Mouse control Pin
pirogramci13-Jun-07 21:44
pirogramci13-Jun-07 21:44 
GeneralRe: Keyboard and Mouse control Pin
Dave Kreskowiak14-Jun-07 4:26
mveDave Kreskowiak14-Jun-07 4:26 
Questionhow to create a wizard using VB ? Pin
prashant pissey13-Jun-07 1:01
prashant pissey13-Jun-07 1:01 
AnswerRe: how to create a wizard using VB ? Pin
v1i9n6o7d13-Jun-07 1:46
v1i9n6o7d13-Jun-07 1:46 
QuestionMailmerge with VS2005 ?????????? Pin
nawalage12-Jun-07 23:53
nawalage12-Jun-07 23:53 
AnswerRe: Mailmerge with VS2005 ?????????? Pin
Ajai Chaudhary29-Jun-07 20:03
Ajai Chaudhary29-Jun-07 20:03 
QuestionAn unhandled win32 exception occured in VB6.EX Pin
Dileep_Vickey12-Jun-07 21:29
Dileep_Vickey12-Jun-07 21:29 
AnswerRe: An unhandled win32 exception occured in VB6.EX Pin
Duncan Edwards Jones12-Jun-07 22:36
professionalDuncan Edwards Jones12-Jun-07 22:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.