jaja714 Posted October 26, 2012 Share Posted October 26, 2012 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 More sharing options...
AZJIO Posted October 26, 2012 Share Posted October 26, 2012 #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 My other projects or all Link to comment Share on other sites More sharing options...
jaja714 Posted October 26, 2012 Author Share Posted October 26, 2012 (edited) 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 October 26, 2012 by jaja714 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 26, 2012 Moderators Share Posted October 26, 2012 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: expandcollapse popup#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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jaja714 Posted October 26, 2012 Author Share Posted October 26, 2012 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 More sharing options...
caleb41610 Posted October 26, 2012 Share Posted October 26, 2012 If the GUI is something simple, you could always just embed the controls from the gui themselves in the program. (I think) Multi-Connection TCP Server Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now