SW_HIDE

esuliga Messages postés 6 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 26 juin 2007 - 18 juin 2007 à 09:54
esuliga Messages postés 6 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 26 juin 2007 - 26 juin 2007 à 11:34
Bonjour,

et en premier, merci pour toutes les astuces que j'ai pu glaner,
de droite et de gauche sur le site.

voici mon problème:
J'ai besoin de visualiser des documents notamment en .pdf , .rtf ou .jpg avec
leur programme associé dans mon appli.

J'ai utilisé l' Api ShellExecute
pour se faire je jance de fichier par :

Lance = ShellExecute(Me.hwnd, "open", Sélection, 0, 0, SW_HIDE)                         'Exécute le programme associé mode SW_HIDE (invisible)
...
SetParent FenDoc, Me.hwnd                                                                                     ' Lui indique qu'elle est fille de mon programme
                                                                                                                                 ' désactive bordures et supprime barre de titre
Call SetWindowLong(FenDoc, GWL_STYLE, GetWindowLong( _
  FenDoc, GWL_STYLE) _
  Xor WS_SIZEBOX _
  Xor WS_BORDER)
...
Y = CDbl(0)                                                                     ' coordonnées de la fenêtre
X = CDbl(262)
Larg = CDbl(((Ouckilé.Width / 15) - X) - 8)
Haut = CDbl((Ouckilé.Height / 15) - 34)
                                                                                ' applique les nouvelles coordonnées et affiche la fenêtre
SetWindowPos FenDoc, HWND_TOP, X, Y, Larg, Haut, _
  SWP_SHOWWINDOW + SWP_NOACTIVATE + SWP_NOZORDER
...
Cela a très bien fonctionné puis la variable SW_HIDE a cessé d'être prise en compte
ce qui a pour consequence d'afficher la construction de ma fenêtre à l'écran: pas très beau et désagréable.

J'ai essayé d'autres commandes
Shell
ShellExecuteEx
CreateProcess
Rien n'y fait, pas de SW_HIDE

Que faire ?,
merci de vos réponses
à noter que des documents qui s'affichent rapidement notamment .rtf fonctionnent.

9 réponses

jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
18 juin 2007 à 10:07
Salut,
Essaie de remplacer SW_HIDE par 0 (sa valeur)

@+: Ju£i?n
Pensez: Réponse acceptée
0
esuliga Messages postés 6 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 26 juin 2007
18 juin 2007 à 10:11
Merci de ta réponse,
j'avais déjà essayé: même résultat
0
cs_casy Messages postés 7741 Date d'inscription mercredi 1 septembre 2004 Statut Membre Dernière intervention 24 septembre 2014 40
18 juin 2007 à 10:12
A partir de quel moment SW_HIDE a cesser de fonctionner, quelles sont les modifications que tu as fait à ce moement là.

---- Sevyc64  (alias Casy) ---- # LE PARTAGE EST NOTRE FORCE #   
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
18 juin 2007 à 10:50
Quelles sont tes declarations d'APIs  ?

quelques remarques en vrac:

Utilises OR, pas '+'   ici    SWP_NOACTIVATE + SWP_NOZORDER

ton "/ 15" est une abomination égoïste, ce ratio dépend du format de l'ecran (entre autres) et sur un ecran 16:9 tu aurais des soucis

Xor WS_SIZEBOX   à rempalcer par And Not WS_SIZEBOX...
en effet, le "Xor" va définir ce flag s'il n'est pas présent (switch). Le "And Not" l'enlève s'il est définit, et ne fait rien, sinon.

Passer 0 en parametre de ShellExeute pour les parametre et le directory est plus ou moins généna,t se lon la déclaration que tu as de cette fonction.

--------------
Lance = ShellExecute(Me.hwnd, "open", Sélection, vbnullstring, vbnullstring, SW_HIDE)                         'Exécute le programme associé mode SW_HIDE (invisible)
...
SetParent FenDoc, Me.hwnd                                                                                     ' Lui indique qu'elle est fille de mon programme
                                                                                                                                 ' désactive bordures et supprime barre de titre
Call SetWindowLong(FenDoc, GWL_STYLE, GetWindowLong( _
  FenDoc, GWL_STYLE) _
  And Not WS_SIZEBOX _
  And Not WS_BORDER)
...
Y = CDbl(0)                                                                     ' coordonnées de la fenêtre
X = CDbl(262)
Larg = CDbl(((Ouckilé.Width / Screen.TwipsPerPixelX) - X) - 8)
Haut = CDbl((Ouckilé.Height / Screen.TwipsPerPixelY) - 34)
                                                                                ' applique les nouvelles coordonnées et affiche la fenêtre
SetWindowPos FenDoc, 0, X, Y, Larg, Haut, _
  SWP_SHOWWINDOW Or SWP_NOACTIVATE Or SWP_NOZORDER

Renfield
Admin CodeS-SourceS- MVP Visual Basic
0

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

Posez votre question
esuliga Messages postés 6 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 26 juin 2007
18 juin 2007 à 18:07
Merci à tous
vrai pour "abomination égoïste" je suis allé au plus simple.
pour ce qui est du + dans SWP_NOACTIVATE + SWP_NOZORDER cela ne me pose aucun problème

j'avais aussi essayé
Lance = ShellExecute(Me.hwnd, "open", Sélection, vbnullstring, vbnullstring, SW_HIDE)
même résultat

Quant au moment  à partir du quel SW_HIDE a cesser de fonctionner j'avoue que je ne sais pas, mais j'ai repris
les fonctions unniquement shell dans un programme séparé et même résultat

genre:

Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

puis
ShellExecute(Me.hwnd, "open", mondoc.jpg, vbnullstring, vbnullstring, SW_HIDE)
ou
ShellExecute(Me.hwnd, "open", l'appliassociée, " " & mondoc.jpg, vbnullstring, SW_HIDE)
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
18 juin 2007 à 19:55
déclarées en String, tu ne PEUX pas mettre 0, sinon, tu transmets "0" ce qui change la donne

Renfield
Admin CodeS-SourceS- MVP Visual Basic
0
esuliga Messages postés 6 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 26 juin 2007
19 juin 2007 à 16:46
Voici un programme test des différentes api, aucun ne me permet de lancer une appli en mode invisible

Module
Option Explicit


Public Ret As Long


Public Const INFINITE = -1&
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const CREATE_SUSPENDED = 0 * 4


Public Type STARTUPINFO
      cb                                     As Long
      lpReserved                             As String
      lpDesktop                              As String
      lpTitle                                As String
      dwX                                    As Long
      dwY                                    As Long
      dwXSize                                As Long
      dwYSize                                As Long
      dwXCountChars                          As Long
      dwYCountChars                          As Long
      dwFillAttribute                        As Long
      dwFlags                                As Long
      wShowWindow                            As Integer
      cbReserved2                            As Integer
      lpReserved2                            As Long
      hStdInput                              As Long
      hStdOutput                             As Long
      hStdError                              As Long
End Type




Public Type PROCESS_INFORMATION
      hProcess                               As Long
      hThread                                As Long
      dwProcessId                            As Long
      dwThreadID                             As Long
End Type
'------------------------------------------------------------------------------------
Public Declare Function _
CreateProcessA Lib "kernel32" ( _
      ByVal lpApplicationName As Long, _
      ByVal lpCommandLine As String, _
      ByVal lpProcessAttributes As Long, _
      ByVal lpThreadAttributes As Long, _
      ByVal bInheritHandles As Long, _
      ByVal dwCreationFlags As Long, _
      ByVal lpEnvironment As Long, _
      ByVal lpCurrentDirectory As Long, _
      lpStartupInfo As STARTUPINFO, _
      lpProcessInformation As PROCESS_INFORMATION) As Long
'=====================================================================================
Public Declare Function _
            WaitForSingleObject Lib "kernel32" ( _
                                ByVal hHandle As Long, _
                                ByVal dwMilliseconds As Long) As Long
'=====================================================================================
'Constantes ShellExecuteEx
Public Const SEE_MASK_NOCLOSEPROCESS = &H40
Public Const SEE_MASK_FLAG_NO_UI = &H400


'Constantes ERREUR ShellExecuteEx
Public Const SE_ERR_FNF As Byte = 2
Public Const SE_ERR_PNF As Byte = 3
Public Const SE_ERR_ACCESSDENIED As Byte = 5
Public Const SE_ERR_OOM As Byte = 8
Public Const SE_ERR_SHARE As Byte = 26
Public Const SE_ERR_ASSOCINCOMPLETE As Byte = 27
Public Const SE_ERR_DDETIMEOUT As Byte = 28
Public Const SE_ERR_DDEFAIL As Byte = 29
Public Const SE_ERR_DDEBUSY As Byte = 30
Public Const SE_ERR_NOASSOC As Byte = 31
Public Const SE_ERR_DLLNOTFOUND As Byte = 32


'Constantes AFFICHAGE ShellExecuteEx
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_SHOW = 5
Public Const SW_SHOWDEFAULT = 10


Public Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
'------------------------------------------------------------------------------------
Public Declare Function ShellExecuteEx Lib "shell32.dll" _
(SEI As SHELLEXECUTEINFO) As Long'Public Const STARTF_FORCEOFFFEEDBACK &H80
Public Const STARTF_FORCEONFEEDBACK = &H40
Public Const STARTF_RUNFULLSCREEN = &H20            ' ignored For non-x86 platforms
Public Const STARTF_USECOUNTCHARS = &H8
Public Const STARTF_USEFILLATTRIBUTE = &H10
Public Const STARTF_USEPOSITION = &H4
Public Const STARTF_USESHOWWINDOW = &H1
Public Const STARTF_USESIZE = &H2
Public Const STARTF_USESTDHANDLES = &H100
Public Const SW_ERASE = &H4
Public Const SW_INVALIDATE = &H2
Public Const SW_MAX = 10
Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_NORMAL = 1
Public Const SW_OTHERUNZOOM = 4
Public Const SW_OTHERZOOM = 2
Public Const SW_PARENTCLOSING = 1
Public Const SW_PARENTOPENING = 3
Public Const SW_RESTORE = 9
Public Const SW_SCROLLCHILDREN = &H1
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_SHOWNOACTIVATE = 4
'=====================================================================================
Public Declare Function ShellExecuteA Lib "shell32" ( _
    ByVal hwnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long


Public Function lance(ByVal CommandLine As String, ByVal Aspect As Boolean)
'CreateProcess
Dim Start As STARTUPINFO
Dim Process As PROCESS_INFORMATION


' Init de STARTUPINFO
Start.cb = Len(Start)
     
      Start.dwFlags = STARTF_USESHOWWINDOW '& STARTF_USESTDHANDLES
      Start.wShowWindow = Aspect


Ret = CreateProcessA(0&, CommandLine, 0&, 0&, 1&, 0&, 0&, 0&, Start, Process)


Ret = WaitForSingleObject(Process.hProcess, INFINITE)
End Function


Public Function Lance2(ByRef Program As String, ByRef Fichier As String, ByRef OwnerhWnd As Long, Aspect As Long) As Long
'ShellExecuteEx
Dim SEI As SHELLEXECUTEINFO


With SEI
  .cbSize = Len(SEI)
  .fMask = SEE_MASK_NOCLOSEPROCESS Or SEE_MASK_FLAG_NO_UI
  .hwnd = OwnerhWnd
  .lpVerb = "open"
  .lpFile = Program
  .lpParameters = Fichier
  .lpDirectory = vbNullChar
  .nShow = Aspect
  .hInstApp = OwnerhWnd
End With


Lance2 = ShellExecuteEx(SEI)
Lance2 = SEI.hProcess
End Function


Form

Option Explicit
Dim Prog As String
Dim Arg As String
Dim ProgArg As String


Private Sub Command1_Click()
lance ProgArg, SW_SHOWNORMAL
Retour.Caption = Ret
End Sub


Private Sub Command2_Click()
lance ProgArg, SW_HIDE
Retour.Caption = Ret
End Sub


Private Sub Command3_Click()
Ret = ShellExecuteA(0, "open", Prog, " " & Arg, vbNullString, SW_SHOWNORMAL)
Retour = Ret
End Sub


Private Sub Command4_Click()
Ret = ShellExecuteA(Me.hwnd, "Open", Prog, " " & Arg, vbNullString, SW_HIDE)
Retour = Ret
End Sub


Private Sub Command5_Click()
Ret = Lance2(Prog, Arg, Me.hwnd, SW_SHOWNORMAL)
Retour.Caption = Ret
End Sub


Private Sub Command6_Click()
Ret = Lance2(Prog, Arg, Me.hwnd, SW_HIDE)
Retour.Caption = Ret
End Sub


Private Sub Command7_Click()
Ret = Shell(ProgArg, vbNormalFocus)
Retour.Caption = Ret
End Sub


Private Sub Command8_Click()
Ret = Shell(ProgArg, vbHide)
Retour.Caption = Ret
End Sub


Private Sub Form_Activate()
Prog = "C:\Program Files\XnView\xnview.exe"
Arg = " E:\A_moi\Archives\Archivés\Assurances\©41-.jpg"
ProgArg = Prog & " " & Arg
End Sub


Private Sub Form_Load()
Bouton(0).Caption = "CreateProcess visible"
Bouton(1).Caption = "CreateProcess invisible"
Bouton(2).Caption = "ShellExecute visible"
Bouton(3).Caption = "ShellExecute invisible"
Bouton(4).Caption = "ShellExecuteEx visible"
Bouton(5).Caption = "ShellExecuteEx invisible"
Bouton(6).Caption = "Shell visible"
Bouton(7).Caption = "Shell invisible"
End Sub




 
0
esuliga Messages postés 6 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 26 juin 2007
24 juin 2007 à 09:25
Bonjour à tous,
Je reviens à la charge, je suis toujours bloqué.
quelqu'un a-t'il essayé mon code ???
merci de vos réponses.
0
esuliga Messages postés 6 Date d'inscription mercredi 4 juin 2003 Statut Membre Dernière intervention 26 juin 2007
26 juin 2007 à 11:34
Bonjour
PLUS C'EST IDIOT ET PLUS ON CHERCHE
C'est trouvé!
acrobat reader 8 refuse le mode hide 7.07 l'accepte
concernant Xnview s'il a été fermé en maximisé à l'ouverture il refusera le mode hide
sauf à modifier les préférences (mémoriser la position...)
le code est bon
merci à ceux qui ont cherché.
0
Rejoignez-nous