Détection Rotation de l'écran

petiflamand Messages postés 675 Date d'inscription samedi 31 mai 2003 Statut Membre Dernière intervention 26 mai 2013 - 16 janv. 2012 à 09:56
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 - 16 janv. 2012 à 12:11
Bonjour à tous ,

J'utilise mon programme pour lire des pdf avec un écran en mode portrait a l'aide de la touche
CTRL & SHIFT & +
Je fait ceci
avec un timer qui vérifie toute les 5 secondes
If ecran_largeur <> Screen.Width And ecran_hauteur <> Screen.Height Then Me.WindowState = vbMaximized

et comme ça quand il détecte que la largeur est différente il fait ceci
If (Me.WindowState = 1) Then Exit Sub

For Each ctl In Me.Controls
    If TypeOf ctl Is ComboBox Then
        'Les comboboxes ont leur propriété Height en lecture seule
        ctl.Move ctl.Left * Me.Width / lng, ctl.Top * Me.Height / lar, ctl.Width * Me.Width / lng
    Else
        If ExistProperty(ctl, "Width") And ExistProperty(ctl, "Height") Then
            ctl.Move ctl.Left * Me.Width / lng, ctl.Top * Me.Height / lar, _
               ctl.Width * Me.Width / lng, ctl.Height * Me.Height / lar
        End If
    End If
Next

lng = Me.Width
lar = Me.Height


y a t-il quelque chose de mieux que d'utilisé un timer toute les 5 secondes.

Merci

4 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
16 janv. 2012 à 10:32
Oui, certainement...

ton appli recoit un WM_DISPLAYCHANGE a chaque changement...

(cf ce code)

Renfield - Admin CodeS-SourceS - MVP Visual Basic & Spécialiste des RegExp
0
petiflamand Messages postés 675 Date d'inscription samedi 31 mai 2003 Statut Membre Dernière intervention 26 mai 2013 1
16 janv. 2012 à 10:34
Merci
0
petiflamand Messages postés 675 Date d'inscription samedi 31 mai 2003 Statut Membre Dernière intervention 26 mai 2013 1
16 janv. 2012 à 11:30
Re,
je reçois une erreur
donc j' ai ceci
je reprend la definition de mon écran actuelle
oldWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)

comme ça je fait un
Private Sub Form_Unload(Cancel As Integer)

    'pour remettre mon ecran qui etait au demarage
    SetWindowLong hwnd, GWL_WNDPROC, oldWndProc
   
End Sub


déja j' ai une erreur utilisation incorrecte de l'opérateur pour
adressof


Dans un modul je declare
Public 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 oldWndProc As Long

Private 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
Private Const WM_DISPLAYCHANGE = &H7E




et je place ceci
[code=vb]Public Function WindowProc(ByVal hwnd As Long, ByVal msg As Long, _
                           ByVal wParam As Long, ByVal lParam As Long) As Long

    If msg = WM_DISPLAYCHANGE Then
       msgbox"aie petiflamand ça a changé"
    End If
   
        WindowProc = CallWindowProc(oldWndProc, hwnd, msg, wParam, lParam)

End Function

pourquoi cette erreur
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
16 janv. 2012 à 12:11
Ton code semble bon...
je t'invite a passer par le module que je t'ai indiqué, ca simplifie l'emploi du subclassing et évite de faire planter VB betement.

j'ai testé ton WM_DISPLAYCHANGE ce matin, avec mon module, ca fonctionne...

je viens de faire le test à l'instant avec le code que tu m'a transmis, je n'ai pas le moindre problème...
(j'ai viré le MsgBox au profit d'un Debug.Print, moins problématique)




Renfield - Admin CodeS-SourceS - MVP Visual Basic & Spécialiste des RegExp
0
Rejoignez-nous