FAQ Visual Basic Routines 
    
Comment Activer une fentre sans Focus 
   
S'applique  : VB4-32, VB5, VB6  

 

 Pr-requis 
  
Rien. 

--------------------------------------------------------------------------------
 

Ce code montre le chargement et l'affichage d'une feuille quand l'on reoit le focus sur la feuille pricipale. 

 

 Code Module BAS 
  
Mettre ce qui suit dans un module BAS. 

--------------------------------------------------------------------------------
 


Option Explicit

Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5

Public Type RECT
    Left    As Long
    Top     As Long
    Right   As Long
    Bottom  As Long
End Type

Public Type POINTAPI
    x       As Long
    y       As Long
End Type

Public Type WINDOWPLACEMENT
    Length            As Long
    flags             As Long
    showCmd           As Long
    ptMinPosition     As POINTAPI
    ptMaxPosition     As POINTAPI
    rcNormalPosition  As RECT
End Type

Public Declare Function GetWindowPlacement Lib "user32" _
   (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Public Declare Function SetWindowPlacement Lib "user32" _
   (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

'--Fin de Bloc--'
   

 Code Feuille 
  
Lancer un nouveau projet, et ajoutez y deux feuilles, en utilisant les noms par dfaut. Sur Feuille1(Form1), placer un bouton Commande (Command1), et ajoutez ce qui suit: 

--------------------------------------------------------------------------------
 


Option Explicit

Private Sub Command1_Click()

    Dim r As Long
    Dim hWndToActivate As Long

    Dim currRect As RECT
    Dim currWinP As WINDOWPLACEMENT
  
    hWndToActivate = Form2.hwnd
  
    currWinP.Length = Len(currWinP)
    r = GetWindowPlacement(hWndToActivate, currWinP)

    currWinP.Length = Len(currWinP)
    currWinP.flags = 0&    currWinP.showCmd = SW_SHOWNOACTIVATE
    r = SetWindowPlacement(hWndToActivate, currWinP)
  
End Sub
'--Fin de Bloc--'
   

 Commentaires 
  
Excuter le projet. Cliquez sur le bouton Commande qui charge et affiche la Feuille2 (Form2), et le focus reste pourtant sur la Feuille1 (Form1). 

--------------------------------------------------------------------------------


Retour  la page prcdente
 
