Jump to content

Embedding GUI in foreign app


jaja714
 Share

Recommended Posts

For some reason, the following code works when running in SciTE:

DllCall("user32.dll", "int", "SetParent", "hwnd", $gui, "hwnd", $xh)

However, when I build it into an EXE, it does not work! The GUI window stays in its current position and does not become part of the foreign app window.

Any ideas?

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>

#include <WinAPI.au3>



$hMain = GUICreate('Main GUI', 600, 500)

$nButton = GUICtrlCreateButton('button', 20, 470, 70, 20)

GUISetState(@SW_SHOW, $hMain)

$hChild = GUICreate("Child GUI", 300, 250, (600 - 300) / 2, (500 - 250) / 2)

_WinAPI_SetParent($hChild, $hMain)

While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE

            Exit

        Case $nButton

            GUISetState(@SW_SHOW, $hChild)

    EndSwitch

WEnd

Link to comment
Share on other sites

Try to remember that I am making a new gui part of a foreign app. Your example does not cover that. Still, replacing DLLCall with _WinAPI_SetParent was worth a try but ... it still only works when invoked from within SciTE. It does not work when built into an EXE.

Any other ideas?

Edited by jaja714
Link to comment
Share on other sites

  • Moderators

jaja714,

If you run Vista+ then I believe that the OS prevents you from embedding a GUI in another process.

All I have been able to do is get the "embedded" GUI to follow the other app as it moves. Here is some code taken from a script I wrote to add a further toolbar to SciTE. I have stripped it down to a minimum and it now just places the GUI at 100, 100 in the SciTE GUI but it should give you the idea. You obviously need SciTE running: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "On_Exit")

Global $hToolBar, $iToolBar_Add_X, $iToolBar_Add_Y, $iSciTE_Last_X, $iSciTE_Last_Y

Global $hSciTE_Wnd = WinGetHandle("[CLASS:SciTEWindow]")

_Toolbar_Create()
_Toolbar_Follow()

While 1
    ; Check SciTE is running
    If ProcessExists("SciTE.exe") Then
        ; Move toolbar as required
        _Toolbar_Follow()
    Else
        Exit
    EndIf
    Sleep(10)
WEnd

Func _Toolbar_Create()

    ; Locate SciTE window
    Local $aSciTE_Pos = WinGetPos($hSciTE_Wnd)
    ; Determine relative offset fron SciTE position for repositioning code
    $iToolBar_Add_X = 100
    $iToolBar_Add_Y = 100

    ; Create ToolBar GUI
    $hToolBar = GUICreate("SciTE ToolBar", 400, 18, -1, -1, $WS_POPUP, $WS_EX_TOOLWINDOW, $hSciTE_Wnd)
    GUISetBkColor(0xFFCCCC)
    ; Set toolbar in z-order just above SciTE
    DllCall("user32.dll", "bool", "SetWindowPos", "hwnd", $hToolBar, "hwnd", $hSciTE_Wnd, "int", $aSciTE_Pos[0] + 100, "int", $aSciTE_Pos[1] + 100, "int", 400, "int", 18, "uint", 0x0010) ; $SWP_NOACTIVATE

    GUISetState(@SW_SHOW, $hToolBar)

    ; Reset SciTE window focus
    WinActivate($hSciTE_Wnd)

EndFunc   ;==>_Toolbar_Create

Func _Toolbar_Follow()

    ; Check if SciTE exists - or error on IDE exit
    Local $aSciTE_Pos = WinGetPos($hSciTE_Wnd)
    If @error Then Return
    ; Check SciTE position
    If $aSciTE_Pos[0] <> $iSciTE_Last_X Or $aSciTE_Pos[1] <> $iSciTE_Last_Y Then
        $iSciTE_Last_X = $aSciTE_Pos[0]
        $iSciTE_Last_Y = $aSciTE_Pos[1]
        ; Move toolbar to follow
        WinMove($hToolBar, '', $aSciTE_Pos[0] + $iToolBar_Add_X, $aSciTE_Pos[1] + $iToolBar_Add_Y, 400)
    EndIf

EndFunc   ;==>_Toolbar_Follow

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

I hope this is useful. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I'm on Windows 7 and, I must emphasize, this is truly working. However, it is only working from within SciTE. So I am not ready to give up and try something completely different like a watcher/follower.

What really bothers me is that the calls are succeeding as @error and @extended are zero. How in the world can I debug or code around that? I'm looking to see if anyone knows what is happening deep inside these DLLCall /_WinAPI_SetParent functions to cause them to fail and not report it.

One thing I've always wondered is, once you succeed in getting the gui attached to the foreign app, how do you control it's position within that foreign app?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...