Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I rotate the whole screen in VB?

Status
Not open for further replies.

tedsmith

Programmer
Joined
Nov 23, 2000
Messages
1,762
Location
AU
I see there are various APIs that seem to rotate the screen but I can't work out how to tie them all together.
Anybody any ideas?

There is a simple program called IRotate that works with my card but it needs manual intervention.
I would like to make it automatic within the application so when you select a function that requires it, it automatically rotates then returns to normal when finished. (Eg viewing portrait photos full screen - by reading the aspect ratio of the file) My monitor has a swivel.
 
Which APIs are you talking about, Ted? Generally full screen rotation is a feature of your videocard driver, rather than the Windows API (I believe that XP Tablet Edition included some screen rotation APIs, but I don't think they work on any other edition)
 
(oh, and there are APIs options for screen rotation under Windows CE. Again, they don't work on other versions of Windows)
 
I was under the impression that monitors with swivels came with driver software which automatically swivelled the screen image when they are rotated. Have you checked your monitor spec/ docs.
 
I found one example with Google that was written in VB net. It uses declarations and "Marshall" a lot, whatever that is.

The NVidia control panel does it but I have a 4 port card and you cant individually rotate.

The IRotate freeware application rotates individually very easily in 90 degree steps - manually and is supposed to work on "any card that supports rotation".

My stand or monitor doesn't have such a switch.(24" 16 x 9 BenQ for A$300)
 
The BenQ FP241W? Documentations suggests that it is supposed to come bundeled with pivoting software.

But, as I said this is normally down down at the video card driver level (and the fact that iRotate makes the point that it is supppsed to work with "any card that supports rotation" merely confirms that).

So there tends to be no simple API solution. I'm willing to bet that most, if not all of the .NET 'solutions' you have seen involve dmDisplayOrientation setting fro .NETs DEVMODE object or DM_DISPLAYORIENTATION setting for the API's DevMode structure. The former is used with .NETs native ChangeDisplaySettings method, the latter with the API's ChangeDisplaySettingsEx function call. However, these are only supposed to work on XP Tablet Edition
 
(oh, and it looks like Vista supports it - well, Vista Ultimate - as well, since it seems to include tablet functionality even on a non-tablet PC)
 
damn!
OK then how do we get to the video driver level? Surely there must be a common thing here as IRotate works with 2 different cards in the one computer?
 
Thanks for the info on Marshall.
It worries me when I see "explanations" like this. People seemed to have lost the art of being able to explain things in easily understood terms these day.

If I hadn't already had experience with things like streams and propertybags I would have had no chance of understanding a word of it!

Some technical authors fill their explanations with jargon and circular references something like the logic of, A=B because B=A.

No wonder "help" screens on computers generally have got such a bad reputation in the past and usually of little use to someone that really needs help!

I have a lot of old friends struggling to use computers and not one of them can understand the Windows Help pages which is why they often phone me!

John? Marsha? Jon-nn? Marr-rsha? Jon! Jon! Jon! Marsssshhhal^^^\.. zzzzzz
 
This looks close (and may be the NET example you cited Ted); I can only rotate 180 degrees and back to normal though, attempts to rotate 90/ 270 degrees do nothing.

'Adapted to VB6 from .NET code at
Private Const CCDEVICENAME = 32
Private Const CCFORMNAME = 32
Private Const ENUM_CURRENT_SETTINGS = -1
Private Const DMDO_DEFAULT = 0
Private Const DMDO_90 = 1
Private Const DMDO_180 = 2
Private Const DMDO_270 = 3
Private Const DM_ORIENTATION = &H1 ' PRINTER
Private Const DM_PAPERSIZE = &H2 ' PRINTER
Private Const DM_PAPERLENGTH = &H4 ' PRINTER
Private Const DM_PAPERWIDTH = &H8 ' PRINTER
Private Const DM_SCALE = &H10 ' PRINTER
Private Const DM_POSITION = &H20
Private Const DM_NUP = &H40
Private Const DM_DISPLAYORIENTATION = &H80 ' DISPLAY -- XP only
Private Const DM_COPIES = &H100 ' PRINTER
Private Const DM_DEFAULTSOURCE = &H200 ' PRINTER
Private Const DM_PRINTQUALITY = &H400 ' PRINTER
Private Const DM_COLOR = &H800 ' PRINTER
Private Const DM_DUPLEX = &H1000 ' PRINTER
Private Const DM_YRESOLUTION = &H2000 ' PRINTER
Private Const DM_TTOPTION = &H4000 ' PRINTER
Private Const DM_COLLATE = &H8000 ' PRINTER
Private Const DM_FORMNAME = &H10000 ' PRINTER
Private Const DM_LOGPIXELS = &H20000
Private Const DM_BITSPERPEL = &H40000 ' DISPLAY
Private Const DM_PELSWIDTH = &H80000 ' DISPLAY
Private Const DM_PELSHEIGHT = &H100000 ' DISPLAY
Private Const DM_DISPLAYFLAGS = &H200000 ' DISPLAY
Private Const DM_DISPLAYFREQUENCY = &H400000 ' DISPLAY
Private Const DM_ICMMETHOD = &H800000
Private Const DM_ICMINTENT = &H1000000
Private Const DM_MEDIATYPE = &H2000000
Private Const DM_DITHERTYPE = &H4000000
Private Const DM_PANNINGWIDTH = &H8000000
Private Const DM_PANNINGHEIGHT = &H10000000
Private Const DM_DISPLAYFIXEDOUTPUT = &H20000000 ' XP only
Private Const DISP_CHANGE_SUCCESSFUL = 0
Private Const DISP_CHANGE_FAILED = -1
Private Const DISP_CHANGE_BADMODE = -2
Private Const DISP_CHANGE_NOTUPDATED = -3
Private Const DISP_CHANGE_BADFLAGS = -4
Private Const DISP_CHANGE_BADPARAM = -5
Private Const DISP_CHANGE_BADDUALVIEW = -6
Private Const DISP_CHANGE_RESTART = 1
Private Const CDS_UPDATEREGISTRY = &H1
Private Const CDS_FULLSCREEN = &H4
Private Const CDS_GLOBAL = &H8
Private Const CDS_SET_PRIMARY = &H10
Private Const CDS_TEST = &H4
Private Const CDS_RESET = &H40000000
Private Const CDS_SETRECT = &H20000000
Private Const CDS_VIDEOPARAMETERS = &H20
Private Const CDS_NORESET = &H10000000
Private Const CDS_FORCE = &H80000000

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 POINTL
x As Long
y As Long
End Type

Private Type DEVMODE
dmDeviceName As String * CCDEVICENAME
dmSpecVersion As Integer
dmDriverVersion As Integer
dmSize As Integer
dmDriverExtra As Integer
dmFields As Long
dmPosition As POINTL
dmDisplayOrientation As Long
dmDisplayFixedOutput As Long
dmColor As Integer
dmDuplex As Integer
dmYResolution As Integer
dmTTOption As Integer
dmCollate As Integer
dmFormName As String * CCFORMNAME
dmLogPixels As Integer
dmBitsPerPel As Long
dmPelsWidth As Long
dmPelsHeight As Long
dmDisplayFlags As Long
dmDisplayFrequency As Long
End Type

Private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" _
(ByVal lpszDeviceName As String, _
ByRef lpDevMode As DEVMODE, _
ByVal hWnd As Long, _
ByVal dwFlags As Long, _
ByVal lParam As Long) As Long

Private Declare Function EnumDisplayDevices Lib "user32" Alias "EnumDisplayDevicesA" _
(ByVal lpDevice As Long, _
ByVal iDevNum As Long, _
ByRef lpDisplayDevice As DISPLAY_DEVICE, _
ByVal dwFlags As Long) As Boolean

Private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" _
(ByVal lpszDeviceName As String, _
ByVal iModeNum As Long, _
ByRef pDevMode As DEVMODE) As Boolean

Sub RotateDisplay(Angle%) 'Angle is 0, 1, 2, 3

Dim DD As DISPLAY_DEVICE

Dim DM As DEVMODE

Dim R As Boolean

Dim RR As Long

DD.cb = LenB(DD)

R = EnumDisplayDevices(0, 0, DD, 0)

DM.dmSize = LenB(DM)

R = EnumDisplaySettings(DD.DeviceName, ENUM_CURRENT_SETTINGS, DM)

DM.dmDisplayOrientation = Angle 'DMDO_180

DM.dmFields = DM_DISPLAYORIENTATION

RR = ChangeDisplaySettingsEx(DD.DeviceName, DM, 0, CDS_FORCE, 0)

End Sub
 
<John? Marsha? Jon-nn? Marr-rsha? Jon! Jon! Jon! Marsssshhhal^^^\.. zzzzzz

Someone's been watching too much Benny Hill....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top