Page 1 sur 1

[resolu] Maximiser Firefox avec ShowWindow_ #SW_MAXIMIZE

Publié : ven. 17/août/2012 16:21
par Ar-S
Je suis en train de faire un programme censé maximiser la fenêtre de firefox.



Code corrigé

Code : Tout sélectionner

Procedure.s GetPIDExePath(hwnd.l)
  ;PAPPIP
	PID.l=0
	GetWindowThreadProcessId_(hwnd,@PID)
	hProcess.l=OpenProcess_(#PROCESS_ALL_ACCESS,0,PID);
	Name.s=Space(256)
	
	If OpenLibrary(0,"PSAPI.DLL")
		*F=GetFunction(0,"GetModuleFileNameExA")
		If *F
			CallFunctionFast(*F,hProcess,0,@Name,#MAX_PATH)
    Else
			MessageRequester ("Erreur PSAPI.DLL" ,"Fonction GetModuleFileNameExA non trouvé",0)
			CloseLibrary(0)
			End
    EndIf
  Else
		MessageRequester ("Erreur PSAPI.DLL" ,"Library non ouverte",0)
		End
  EndIf
	ProcedureReturn Str(PID)+"@"+Name
EndProcedure


Procedure IsFirefox()
  
  Shared.s NOM_exe_path, NOM_EXE, nom_WND
  
  hwnd = FindWindow_(0,0)
  While hwnd <> 0
    If GetWindowLong_(hwnd,#GWL_STYLE) & #WS_VISIBLE=#WS_VISIBLE
      If GetWindowLong_(hwnd,#GWL_EXSTYLE) & #WS_EX_TOOLWINDOW <> #WS_EX_TOOLWINDOW
        nom_WND = Space(#MAX_PATH)
        GetWindowText_(hwnd,@nom_WND,#MAX_PATH)
        ; hwndp.l = GetParent_(hwnd)
        
        If nom_WND <> ""
          PID_NOM_EXE_PATH.s = GetPIDExePath(hwnd)
          PID = Val(StringField(PID_NOM_EXE_PATH, 1, "@"))
          NOM_exe_path = StringField(PID_NOM_EXE_PATH, 2, "@")
          Debug NOM_exe_path
          NOM_EXE = GetFilePart(NOM_exe_path)
          
          If NOM_EXE = "firefox.exe"
              
              FEN.l = FindWindow_(#Null,nom_WND)
              Debug ShowWindow_(FEN,#SW_MAXIMIZE)
              
              Debug "Nom fenêtre : " + nom_WND
              Debug "***** "+NOM_exe_path+ " **********"
              
              ProcedureReturn 1
              
          EndIf
          
          
        EndIf
      EndIf
    EndIf
    
    hwnd = GetWindow_(hwnd,#GW_HWNDNEXT)
    
  Wend
  
  ProcedureReturn 0
EndProcedure

If IsFirefox() = 0
  MessageRequester("Erreur","Firefox n'est pas ouvert ! " + Chr(34) + "Vous devez d'abord ouvrir Firefox puis relancer ce logiciel",#MB_OK)
EndIf



Re: Maximiser Firefox avec ShowWindow_ #SW_MAXIMIZE

Publié : ven. 17/août/2012 20:38
par Droopy

Code : Tout sélectionner

FEN.l = FindWindow_(#Null,nom_WND)

Re: Maximiser Firefox avec ShowWindow_ #SW_MAXIMIZE

Publié : ven. 17/août/2012 20:41
par Ar-S
Droopy a écrit :

Code : Tout sélectionner

FEN.l = FindWindow_(#Null,nom_WND)
fichtre !

Merci Droopy.

Re: [resolu] Maximiser Firefox avec ShowWindow_ #SW_MAXIMIZE

Publié : ven. 17/août/2012 21:27
par Backup
si j'ai bien compris ton code est sensé agrandir Firefox .?

ben pas chez moi :? 8O
ça fais rien ...

Re: [resolu] Maximiser Firefox avec ShowWindow_ #SW_MAXIMIZE

Publié : ven. 17/août/2012 22:03
par Droopy
Le code d'ars fonctionne chez moi.
Voici la même chose avec la DroopyLib

Code : Tout sélectionner

Repeat
  titre.s=WindowsEnum() ; Enumération des fenêtres
  If titre="" : Break : EndIf ; Plus de fenêtre à énumérer, on sort de la boucle
  Handle=GetHandle(titre)
  exe.s=LCase(GetFilePart(HandleToFileName(Handle)))
  If exe="firefox.exe" ; Firefox trouvé
    ShowWindow(Handle,#SW_SHOWMAXIMIZED) ; Affiche Firefox en taille maximum
  EndIf
ForEver

Re: [resolu] Maximiser Firefox avec ShowWindow_ #SW_MAXIMIZE

Publié : ven. 17/août/2012 23:10
par Backup
oui j'ai corrigé ce qui n'allait pas ..
Ar-S a écrit : FEN.l = FindWindow_(#Null,NOM_EXE)
Debug ShowWindow_(FEN,#SW_MAXIMIZE)

en fait c'est

Code : Tout sélectionner

FEN.i  = FindWindow_(#Null,nom_WND) 
contrairement a ce que Ar-S a ecrit , son code n'a pas été corrigé :)




me suis permis d'en faire une procedure :

Code : Tout sélectionner

Declare.s GetPIDExePath(hwnd.l)
Declare  Action_fenetre(nom_fenetre.s,Action.l)


; *********** mise en action *******
Action_fenetre("firefox.exe",#SW_SHOWMAXIMIZED)
delay(2000)
Action_fenetre("firefox.exe",#SW_MINIMIZE)
; *******************************








Procedure.s GetPIDExePath(hwnd.l)
	; PAPPIP
	PID.l=0
	GetWindowThreadProcessId_(hwnd,@PID)
	hProcess.l=OpenProcess_(#PROCESS_ALL_ACCESS,0,PID);
	Name.s=Space(256)
	
	If OpenLibrary(0,"PSAPI.DLL")
		*F=GetFunction(0,"GetModuleFileNameExA")
		If *F
			CallFunctionFast(*F,hProcess,0,@Name,#MAX_PATH)
			Else
			MessageRequester ("Erreur PSAPI.DLL" ,"Fonction GetModuleFileNameExA non trouvé",0)
			CloseLibrary(0)
			End
		EndIf
		Else
		MessageRequester ("Erreur PSAPI.DLL" ,"Library non ouverte",0)
		End
	EndIf
	ProcedureReturn Str(PID)+"@"+Name
EndProcedure


procedure Action_fenetre(nom_fenetre.s,Action.l)
	hwnd = FindWindow_(0,0)
	While hwnd <> 0
		If GetWindowLong_(hwnd,#GWL_STYLE) & #WS_VISIBLE=#WS_VISIBLE
			If GetWindowLong_(hwnd,#GWL_EXSTYLE) & #WS_EX_TOOLWINDOW <> #WS_EX_TOOLWINDOW
				nom_WND.s = Space(#MAX_PATH)
				GetWindowText_(hwnd,@nom_WND,#MAX_PATH)
				hwndp.l = GetParent_(hwnd)
				
				If nom_WND <> ""
					PID_NOM_EXE_PATH.s = GetPIDExePath(hwnd)
					PID = Val(StringField(PID_NOM_EXE_PATH, 1, "@"))
					NOM_exe_path.s = StringField(PID_NOM_EXE_PATH, 2, "@")
					NOM_EXE.s = GetFilePart(NOM_exe_path)
					
					Select NOM_EXE
						Case nom_fenetre.s
						
						FEN.i  = FindWindow_(#Null,nom_WND) 
						Debug ShowWindow_(FEN.i,Action.l)
						ProcedureReturn
					EndSelect
					
					
					
				EndIf
			EndIf
		EndIf
		
		hwnd = GetWindow_(hwnd,#GW_HWNDNEXT)
		
	Wend
	
endprocedure




; EPB


Re: [resolu] Maximiser Firefox avec ShowWindow_ #SW_MAXIMIZE

Publié : sam. 18/août/2012 1:04
par Ar-S
J'ai re modifié le code.
Merci pour la "Droopy version"

En fait depuis la version 13, chez de nombreux client firefox apparait parfois non pas en minimisé mais en tout petit en haut à gauche de l'ecran lors de son lancement. Certains ayant déjà du mal à utiliser une souris et débutant sur ordi, ce genre de mésaventure les bloque...
du coup je vais leur filer ce petit code pour remettre automatiquement FF d'aplomb quand ça arrive.

Re: [resolu] Maximiser Firefox avec ShowWindow_ #SW_MAXIMIZE

Publié : sam. 18/août/2012 20:17
par Droopy
Un raccourcis peut spécifier si l'exe doit être lancée en normal/réduit/agrandi, mais Firefox semble ne pas tenir compte de cela :roll: