Réduire une fenêtre aec l'API Windows ?

Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007 - 12 déc. 2006 à 11:35
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007 - 12 déc. 2006 à 18:06
Bonjour,


Après quelques recherche pas très fructueuse (et devant le nombre de
fonctions de l'API Windows...) je cherche à réduire une fenêtre
exterieur à mon programme grâce à l'API Windows, je m'explique.


En VB6, j'ai une barre en haut de mon écran, je voudrais que, exemple,
si je lance IE, il se réduise pour être en dessous de ma barre (ma
barre est déjà en premier plan, le problème c'est qu'elle est trop
lage, donc cache la barre d'url de IE) donc en fait, réduire la fenêtre
E juste en dessous mon form.


Merci.

56 réponses

drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 11:43
Salut voir avec ces API:

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

Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 12:37
Alors déjà, merci beaucoup de l'aide et de la rapidité de réponse ^^

Mais il me reste une erreur, ainsi qu'une question...

Au niveau de cette ligne  : Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

Il me met Type définit par l'utilisateur non définit...

Et euh, je vois pas pourquoi ^^

Ensuite, pour appeler cette fonction en continue, je la met dans un timer interval 1 qui execute : SetWindowPlacement ?
0
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 12:44
En fait, après un petit test, c'es tle type WINDOWPLACEMENT qui pose problème...

Je suis sous VB6, me manque peut-être une référence/composant ?
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 13:06
Le descriptif de la fonction:



· hWnd
[in] Handle to the window.


· lpwndpl
[in] Pointer to a WINDOWPLACEMENT structure that specifies the new show state and window positions.
Before calling SetWindowPlacement, set the length member of the WINDOWPLACEMENT structure to sizeof(WINDOWPLACEMENT). SetWindowPlacement fails if lpwndpl->length is not set correctly.

Un exemple :


Private Const SW_MINIMIZE = 6


Private Type POINTAPI


x As Long


y As Long


End Type


Private Type RECT


Left As Long


Top As Long


Right As Long


Bottom As Long


End Type


Private Type WINDOWPLACEMENT


Length As Long


flags As Long


showCmd As Long


ptMinPosition As POINTAPI


ptMaxPosition As POINTAPI


rcNormalPosition As RECT


End Type


Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long


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


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


Dim Rectan As RECT


Private Sub Form_Load()


'Tip submitted by pyp99 (pyp99@hotmail.com)


Dim WinEst As WINDOWPLACEMENT


Dim rtn As Long


WinEst.Length = Len(WinEst)


'get the current window placement


rtn = GetWindowPlacement(Me.hwnd, WinEst)


Rectan = WinEst.rcNormalPosition


End Sub


Private Sub Command1_Click()


Dim WinEst As WINDOWPLACEMENT


Dim Punto As POINTAPI


Dim rtn As Long


'set the new min/max positions


Punto.x = 100


Punto.y = 100


'initialize the structure


WinEst.Length = Len(WinEst)


WinEst.showCmd = SW_MINIMIZE


WinEst.ptMinPosition = Punto


WinEst.ptMaxPosition = Punto


WinEst.rcNormalPosition = Rectan


'set the new window placement (minimized)


rtn = SetWindowPlacement(Me.hwnd, WinEst)


End Sub





 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 13:24
Alors, il ne me met aucune erreur, mais lors du command_click il ne fait que réduire ma form dans la barre des tâches, hors, ce ce que je veux c'est que les fenêtres soit tout le temps en dessous de ma barre (niveau taille je parle) un peu à la manière de EuroBarre (si tu connais)
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 13:31
Il faudrai voir pour redimmensionner la fenêtre alors non?

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 13:34
Oui, redimensionner la fenêtre IE dans mon cas (et non ma Form de VB) en gros, VB agit sur la taille de la fenêtre que j'ouvre sur lui, mais c'est vraiment possible ? ^^
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 13:43
Si tu passes avec la fonction GetActiveWindow si le handle retourné est celui de ton appli tu ne fais rien sinon tu passes par SetWindowPos pour la redimmensionner!

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 13:46
Ha oui au fait, enlève toutes les réponses accéptés car ton problème n'est pas encore résolu, accepte seulement la ou les réponse qui aura résolu ou répondu à ton problème, ou qui t'aura aider à trouver la solution! Par ce que là tout le monde crois que le problème est résolu et du coup ils ne lisent pas le topic.

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 13:54
Le problème est que je ne sais pas utiliser les fonctions GetActiveWindow et SetWindowPos, si tu pouvais tout simplement m'écrire l'appel que je mettrais dans un timer dire qu'il le fasse en boucle, merci ^^
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 14:03
Te retourne le handle de la fenêtre active:
Declare Function GetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long

Exemple avec SetWindowPos:
Const HWND_TOPMOST = -1

Const HWND_NOTOPMOST = -2

Const SWP_NOSIZE = &H1

Const SWP_NOMOVE = &H2

Const SWP_NOACTIVATE = &H10

Const SWP_SHOWWINDOW = &H40

Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)

Private Sub Form_Activate()

'KPD-Team 1998

'URL: http://www.allapi.net/

'E-Mail: KPDTeam@Allapi.net

'Set the window position to topmost

SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

End Sub

Paramètre de SetWindowPos:

· hWnd
Identifies the window.· hWndInsertAfter
Identifies the window to precede the positioned window in the Z order. This parameter must be a window handle or one of the following values:
HWND_BOTTOM
 Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows.
HWND_NOTOPMOST
 Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window.
HWND_TOP
 Places the window at the top of the Z order.
HWND_TOPMOST
 Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.

· X
Specifies the new position of the left side of the window.

· Y
Specifies the new position of the top of the window.

· cx
Specifies the new width of the window, in pixels.

· cy
Specifies the new height of the window, in pixels.

· uFlags
Specifies the window sizing and positioning flags. This parameter can be a combination of the following values:
SWP_DRAWFRAME
 Draws a frame (defined in the window’s class description) around the window.
SWP_FRAMECHANGED
 Sends a WM_NCCALCSIZE message to the window, even if the window’s size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window’s size is being changed.
SWP_HIDEWINDOW
 Hides the window.
SWP_NOACTIVATE
 Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
SWP_NOCOPYBITS
 Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
SWP_NOMOVE
 Retains the current position (ignores the X and Y parameters).
SWP_NOOWNERZORDER
 Does not change the owner window’s position in the Z order.
SWP_NOREDRAW
 Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
SWP_NOREPOSITION
 Same as the SWP_NOOWNERZORDER flag.
SWP_NOSENDCHANGING
 Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
SWP_NOSIZE
 Retains the current size (ignores the cx and cy parameters).
SWP_NOZORDER
 Retains the current Z order (ignores the hWndInsertAfter parameter).
SWP_SHOWWINDOW
 Displays the window.

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 14:15
Mmh, voilà ce que j'ai :

Const HWND_TOPMOST = -1


Const HWND_NOTOPMOST = -2


Const SWP_NOSIZE = &H1


Const SWP_NOMOVE = &H2


Const SWP_NOACTIVATE = &H10


Const SWP_SHOWWINDOW = &H40


Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)


Private Declare Function GetActiveWindow Lib "User32" () As Long


Private Sub Timer1_Timer()


SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE


End Sub

Mais il ne me réduit pas mes autres fenêtres, en revanche j'arrive à afficher le Handle de GetActiveWindow, mais je vois pas où m'en servir
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 14:27
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOACTIVATE = &H10
Const SWP_SHOWWINDOW = &H40
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function GetActiveWindow Lib "User32" () As Long

Private Sub Timer1_Timer()

If CetActiveWindow <> Me.Hwnd Then

'El la à la place des 0 tu définis la taille et la position de la fenêtre par rapport aux paramètres cités au-dessus de la fonction
SetWindowPos CetActiveWindow , HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE

End If

End Sub
,

----

(Coloration syntaxique automatique par Kenji)



 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 14:30
Et pareil pour ces paramètres, il faut choisir celui que tu veux!
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE


Autres paramètres:
 uFlags
Specifies the window sizing and positioning flags. This parameter can be a combination of the following values:
SWP_DRAWFRAME
 Draws a frame (defined in the window?s class description) around the window.
SWP_FRAMECHANGED
 Sends a WM_NCCALCSIZE message to the window, even if the window?s size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window?s size is being changed.
SWP_HIDEWINDOW
 Hides the window.
SWP_NOACTIVATE
 Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
SWP_NOCOPYBITS
 Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
SWP_NOMOVE
 Retains the current position (ignores the X and Y parameters).
SWP_NOOWNERZORDER
 Does not change the owner window?s position in the Z order.
SWP_NOREDRAW
 Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
SWP_NOREPOSITION
 Same as the SWP_NOOWNERZORDER flag.
SWP_NOSENDCHANGING
 Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
SWP_NOSIZE
 Retains the current size (ignores the cx and cy parameters).
SWP_NOZORDER
 Retains the current Z order (ignores the hWndInsertAfter parameter).
SWP_SHOWWINDOW
 Displays the window.

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 14:35
'Ce code devrai fonctionner en tout cas chez moi oui:

Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Declare Function GetActiveWindow Lib "User32" () As Long

Private Sub Timer1_Timer()

If CetActiveWindow <> Me.Hwnd Then

SetWindowPos GetActiveWindow, HWND_TOPMOST, 200, 200, 200, 200, SWP_HIDEWINDOW

End If

End Sub,

----

(Coloration syntaxique automatique par Kenji)





 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 14:40
Déjà, merci de continuer de m'aider, j'suis pas facil ^^

Alors, il arrive bien à detecter si ma Form est devant ou derrière une fenêtre, mais il ne redimensionne pas, je ne comprend pas bien la différence des paramètres SWP...
Qu'est-ce que je dois mettre si mon Form fait : Height 2505, Width 5580 en position de ma form j'utilise : Me.Left = (Screen.Width - Me.Width) \ 2
    Me.Top = (Screen.Height - Me.Height) \ 10000

Voilà mon msn, si tu veux m'ajouter pour que ça aille plus vite : Espritofsan@Hotmail.com

Merci !
0
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 14:42
Alors, il marche oui, mais c'est pas ce que j'attend, je veux que toutes les fenêtres qui arrive devant mon programme soit redimensionner pour aparaître en dessous
Comme si il était toujours au premier plan, mais que en fait il redimensionne les autres fenêtres...
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 14:44
Tu as essayé mon dernier bout de code?
Et c'est ton appli ou l'autre fenêtre que tu veux redimensionner?
Mon code du dessus redimensionne la fenêtre que l'utilistaeur aura lancer (IE par exemple)

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
drikce06 Messages postés 2236 Date d'inscription lundi 29 mai 2006 Statut Membre Dernière intervention 29 mai 2008 10
12 déc. 2006 à 14:46
Et ben si j'ai bien compris mon code fais ce que tu veux!

 Drikce 06

Si la réponse vous convient: Réponse acceptée. Si la réponse vous convient pas:
0
Vienyc Messages postés 47 Date d'inscription dimanche 18 décembre 2005 Statut Membre Dernière intervention 28 juin 2007
12 déc. 2006 à 14:51
Le programme est censé redimensionner l'autre fenêtre (IE par exemple)

Je t'ai pris un screen de ce que je voudrais obtenir si on lance une fenêtre IE sur mon programme : http://agenda-mda.ifrance.com/API.JPG
0
Rejoignez-nous