Detect landscape or portrait mode in MS Surface

I am wondering if it is possible for xojo using declare or monkeybread plugins or something to detect the mode when the user turn the tablet?

I do not have Xojo code, but I do have a VB6 snippet I gotten from Microsoft MSDN website:

https://msdn.microsoft.com/en-us/library/ms812142.aspx

This is tested to work on my Sony VIAO Duo 13 which is a tablet/notebook convertible. The WindowProc function detect the orientation change in realtime and the respective MsgBox will fire. Replace those two MsgBox parts with your own routines. If you can this convert this to Xojo then this may help.

Form:

[code]Option Explicit

Private Sub Form_Load()
Dim theScreenWidth As Integer
Dim theScreenHeight As Integer
Dim iReturn As Integer

gHW = Me.hwnd
Hook

theScreenWidth = Screen.Width
theScreenHeight = Screen.Height
If (theScreenWidth > theScreenHeight) Then
    'Run the application in landscape, as in:
    iReturn = MsgBox("Form load in landscape.", vbOKOnly, "Landscape")
Else
    'Run the application in portrait, as in:
    iReturn = MsgBox("Form load in portrait.", vbOKOnly, "Portrait")
End If

End Sub

Private Sub Form_Terminate()
Unhook
End Sub
[/code]

Module:

[code]Option Explicit

Declare Function CallWindowProc Lib “user32” Alias _
“CallWindowProcA” (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Declare Function SetWindowLong Lib “user32” Alias _
“SetWindowLongA” (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const GWL_WNDPROC = -4
Public Const WM_DISPLAYCHANGE = 126
Global lpPrevWndProc As Long
Global gHW As Long

Public Sub Hook()
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub Unhook()
Dim temp As Long
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub

Function WindowProc(ByVal hw As Long, ByVal uMsg As _
Long, ByVal wParam As Long, ByVal lParam As Long) As _
Long
'Activated when display changes
If uMsg = WM_DISPLAYCHANGE Then
'Separate the width and height and then
'check to see if screen width is greater than screen height
If lParam Mod &H10000 > lParam \ &H10000 Then
'Run the application in landscape, for example:
MsgBox “Orientation changed to landscape.”
Else
'Run the application in portrait, for example:
MsgBox “Orienatation changed to portrait.”
End If
End If
'Pass windows messages on to the default WindowProc
WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam)
End Function
[/code]

No need for declare.

If screen(0).width > screen(0).height then 'landscape else 'portrait end if

I use this in the Resize event.

thanks… i just try the code and it work.