Kirjautuminen

Haku

Tehtävät

Keskustelu: Ohjelmointikysymykset: VB6: Ohjelma mun ohjelman sisälle

Kulma [25.10.2005 21:31:37]

#

Miten saan jonkun ohjelman (esim. Shell "ESIM.exe") tavallisen formin sisälle samalla tavalla kuin MDI-childissä (lapsi-ikkunassa)?
Kiitos etukäteen. =)

Blaze [25.10.2005 21:53:42]

#

Ainakaan helposti et mitenkään.

Meitsi [25.10.2005 22:42:52]

#

Windows apilla kikkailemalla voisi ehkä onnistua. Kuten blaze sanoi, helposti et.

nomic [26.10.2005 04:35:38]

#

Private Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
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 TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long

Dim Pid As Long
Dim retval As Long  ' return value

Const GW_HWNDNEXT = 2
Dim mWnd As Long
Private Const GA_ROOT = 2

Private Type POINTAPI
    x As Long
    y As Long
End Type

Function InstanceToWnd(ByVal target_pid As Long) As Long
    Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
    Do While test_hwnd <> 0
        If GetParent(test_hwnd) = 0 Then
            test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid)
            If test_pid = target_pid Then
                InstanceToWnd = test_hwnd
                Exit Do
            End If
        End If
        test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
    Loop
End Function

Private Sub Command1_Click()
    LockWindowUpdate GetDesktopWindow
    Pid = Shell("OHJELMANPOLKU JA NIMI", vbNormalNoFocus) 'softaa tänne

    If Pid = 0 Then MsgBox "Error starting the app"

    mWnd = InstanceToWnd(Pid)
    SetParent mWnd, Me.hwnd
    Putfocus mWnd
    LockWindowUpdate False
    Timer1 = True
    DoEvents
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    DestroyWindow mWnd
    TerminateProcess GetCurrentProcess, 0
End Sub

Private Sub Form_Terminate()
    DestroyWindow mWnd
    TerminateProcess GetCurrentProcess, 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
    DestroyWindow mWnd
    TerminateProcess GetCurrentProcess, 0
End Sub

Private Sub Timer1_Timer()
    retval = MoveWindow(mWnd, -4, -28, Picture1.Width, Picture1.Height, 1)
End Sub

Tämmöisen viritelmän itse joskus löysin muistaakseni freevbcode:sta, johon lisäilin omat jutut jne... Kommentointi on melko olematonta, mulle oli vain tärkeää että se toimi. :)

Kulma [26.10.2005 15:47:59]

#

Mä kokeilin tota ja toi avas sen uuteen ikkunaan, ei ohjelman sisälle. Toi on melkein sama ku:
Shell "ESIM.exe"

2. kysymys Miten mä saisin että mun ohjelma aktivois jonkun toisen ohjelman (aktivoiminen=että formin otsikko menee harmaasta siniseksi
=P)

Blaze [26.10.2005 16:27:30]

#

AppActivate -funktiolla.

nomic [27.10.2005 01:23:27]

#

Kyllä toi mulla ainaskin pistää ohjelmia oman ikkunan sisälle. se on sitten eri juttu, jos ohjelmassa itsessään on enemmänkin formeja tai muita käytössä, silloin se pistää vain ensimmäisen akkunan tohon sisälle...

Kokeile vaikkapa notepadilla, ihmettelen jos ei mene ;)

Vastaus

Aihe on jo aika vanha, joten et voi enää vastata siihen.

Tietoa sivustosta