PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 9 nov. 2006 à 18:21
salut,
met une picturebox assez grande sur une form assez grande....
Option Explicit
'
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As
Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As
Long
Private Declare Function GetWindowThreadProcessId Lib
"user32" (ByVal hwnd As Long, lpdwProcessId As Long) As
Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As
Long
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Const GW_HWNDNEXT = 2
Dim mWnd As Long
'
Function InstanceToWnd(ByVal target_pid As Long) As
Long
Dim test_hwnd As Long, test_pid As Long, test_thread_id As
Long
'Find the first
window
test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
Do While test_hwnd <> 0
'Check if the window isn't a child
If GetParent(test_hwnd) = 0 Then
'Get the window's thread
test_thread_id = GetWindowThreadProcessId(test_hwnd,
test_pid)
If test_pid = target_pid Then
InstanceToWnd = test_hwnd
Exit Do
End If
End If
'retrieve the next
window
test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
'
'
Private Sub Form_Load()
'KPD-Team 1999
'URL:
http://www.allapi.net/ 'E-Mail:
KPDTeam@Allapi.net
Dim Pid As Long
'Lock the window update
LockWindowUpdate GetDesktopWindow
'Execute notepad.Exe
Pid = Shell("c:\windows\notepad.exe", vbNormalFocus)
If Pid = 0 Then MsgBox "Error starting the app"
'retrieve the handle of the window
mWnd = InstanceToWnd(Pid)
'Set
the notepad's parent
SetParent mWnd, Picture1.hwnd
'Put the focus on notepad
Putfocus mWnd
'Unlock
windowupdate
LockWindowUpdate False
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Unload notepad
DestroyWindow mWnd
End Sub
cboulas
Messages postés2641Date d'inscriptionmercredi 2 juin 2004StatutMembreDernière intervention 8 janvier 201416 9 nov. 2006 à 16:53
Salut, si ton fichier as l'extension EXE mais contient une image, oui c'est faisable, si c'est une image dans un EXE : il faut pouvoir l'extraire, si tu veux ouvrir un exe avec un picturebox : Shell(...)
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 201847 14 nov. 2006 à 15:45
salut,
l'API SetWindowPos est faite aussi pour çà
exemple :
Option Explicit
'
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 Command1_Click()
' on déplace
en
' left 200
'
top 300
' width 640
' height 480
Call SetWindowPos(Me.hWnd, 0&, 200, 300, 640, 480, 0&)
End Sub
là tu n'as plus qu'à remplacer ton Me.hWnd par mWnd à mettre en fin de Form_Load
ps : l'API LockWindowUpdate est ici utilisée que pour l'exemple avec le bloc-note... à adapter donc (t'en a normalement pas besoin)
++
<hr size="2" width="100%" />Prenez un instant pour répondre à ce sondage svp
cs_amita
Messages postés151Date d'inscriptionsamedi 17 juillet 2004StatutMembreDernière intervention11 mai 2012 20 nov. 2006 à 18:16
merci cher ami pour ton effort
mais le pblm que cet commande me ramene mon form parent a une position precise, je veux que mon exe soit ramener a une postion left =0 et top=0 dans le picturebox.
BasicInstinct
Messages postés1470Date d'inscriptionmardi 5 février 2002StatutMembreDernière intervention20 octobre 201412 28 nov. 2006 à 08:14
Bonjour,
Le code ici correspond parfaitement à mes besoins, mais je n'arrive pas a l'adapter a VB.NET.
J'arrive a le faire executer sans probleme, mais mon notepad reste independant de ma picture.
Comment faire fonctionner SetParent en VB.Net avec des application externe ?
SetParent a l'air de pourtant bien fonctionner entre 2 form VB.
j'avouerai que ca fait 2 jours que je suis dessus et que je suis toujours sans reponse.