tatane

External child windows crash my GUI / Intercepting their WM_CLOSE Message

3 posts in this topic

#1 ·  Posted (edited)

Hi,

I've got a problem with external windows (ultravnc gui) that I integrate in my GUI as child. When one of them crashes, my parent GUI crashes too.

How could I prevent this ?

Thanks.

Here is a snippet with notepad instead of vncviewer.exe :

#include <WinAPIProc.au3>
#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <APISysConstants.au3>


$gui = GUICreate("test", 1024, 768, 0, 0, BitOR($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_EX_COMPOSITED))
$pos_x = 0

GUISetState(@SW_SHOW, $gui)


For $i = 1 To 3
    $run = Run("notepad.exe")
    $hwnd_array = _WinAPI_EnumProcessWindows($run, False)

    If Not @error Then
        _WinAPI_SetWindowLong($hwnd_array[1][0], $GWL_EXSTYLE , $WS_EX_MDICHILD)
        _WinAPI_SetParent($hwnd_array[1][0],$gui)
        _WinAPI_SetWindowLong($hwnd_array[1][0], $GWL_HWNDPARENT, $gui)
        _WinAPI_SetWindowPos($hwnd_array[1][0], $HWND_TOP, $pos_x, 0, 200, 200, $SWP_FRAMECHANGED)
        $pos_x = 210 * $i
    EndIf
Next

Run("notepad.exe")


While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            
            Exit
    EndSelect

    Sleep(100)
WEnd

EDIT : No solution ? Do you need some details ?

Edited by tatane

Share this post


Link to post
Share on other sites



Finally, It seems I found the solution !
Just add $WS_EX_NOPARENTNOTIFY Ex Style to the external child :

_WinAPI_SetWindowLong($hwnd_array[1][0], $GWL_EXSTYLE , BitOr($WS_EX_MDICHILD, $WS_EX_NOPARENTNOTIFY))

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I have a new question :
I would like to intercept the WM_CLOSE message from the child GUIs (external executables like above). It seems the only way is to subclass the child windows :
http://stackoverflow.com/questions/6671675/win32-capturing-child-window-messages-in-parent-window
https://msdn.microsoft.com/en-us/library/ms633570(v=VS.85).aspx#subclassing_window
 
I'm not able to do this alone and I don't even know if it's possible with Autoit, so I rely on your expertise.
 
Thanks.
 
 
EDIT : I tried this code but it's not working ($g_hProcOld = 0  / Winapi_LastErrorMessage says "Access Denied")

#include <WinAPIProc.au3>
#include <WinAPI.au3>
#include <GUIConstants.au3>
#include <Constants.au3>

$gui = GUICreate("test", 1024, 768, 0, 0, BitOR($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, $WS_EX_COMPOSITED))
$pos_x = 0

$hProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")

GUISetState(@SW_SHOW)

For $i = 1 To 1
    $run = Run("notepad.exe")
    $hwnd_array = _WinAPI_EnumProcessWindows($run, False)

    If Not @error Then
        $g_hProcOld = _WinAPI_SetWindowLong($hwnd_array[1][0], $GWL_WNDPROC, DllCallbackGetPtr($hProcNew))
        ConsoleWrite("$g_hProcOld="&$g_hProcOld&@CRLF)
        _WinAPI_SetWindowLong($hwnd_array[1][0], $GWL_EXSTYLE , $WS_EX_MDICHILD)
        _WinAPI_SetParent($hwnd_array[1][0],$gui)
        _WinAPI_SetWindowPos($hwnd_array[1][0], $HWND_TOP, $pos_x, 0, 200, 200, $SWP_FRAMECHANGED)
        $pos_x = 210 * $i
    EndIf
Next

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE

            Exit
    EndSelect

    Sleep(100)
WEnd

Func _MyWindowProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_CLOSE
            ConsoleWrite("fermée"&@CRLF)
            Return 0
        Case $WM_DESTROY
            ConsoleWrite("détruite"&@CRLF)
            Return 0
    EndSwitch

    ;pass the unhandled messages to default WindowProc
    Return _WinAPI_CallWindowProc($g_hProcOld, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_MyWindowProc

EDIT 2 : I found this Post with external dll : '?do=embed' frameborder='0' data-embedContent>>
It works but it is pretty slow like WideBoyDixon said in his post.

No way to make it works without a dll injection ?

Edited by tatane

Share this post


Link to post
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