in WM_KEYDOWN event, unknown hwnd Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

in WM_KEYDOWN event, unknown hwnd

07 Sep 2020, 09:21

In a WM_KEYDOWN event, setted with OnMessage, I get the parameter hwnd.
But it is not Gui.hwnd, neither GuiCtrlFromHwnd(hwnd)
It comes form an ActiveX Shell.Explorer (so from a sub-control in a way)

How could I know which Gui that hwnd comes from ?
Last edited by FredOoo on 08 Sep 2020, 16:11, edited 1 time in total.
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: in WM_KEYDOWN event, unknown hwnd

07 Sep 2020, 12:13

Code: Select all

WM_KEYDOWN( wParam, lParam, msg, hwnd ){
    print
    print "WM_KEYDOWN: " wParam " " hwnd
    CurrentCtrl := GuiCtrlFromHwnd(hwnd)
    if CurrentCtrl {
        ; Before I click on the Gui.ActiveX, we pass here
        print "WM_KEYDOWN from: " type(CurrentCtrl) " name: " CurrentCtrl.name
         ; -> from Gui.ActiveX name:WB
    } else {
        ; ELSE: Here it's a mess. I can't make sure hwnd come from a ctrl in that Gui.
        for i, name in WinGetControls(this.hwnd)
        {
            print "-- Control #" i " is '" name
        }
        wHwnd := ControlGetHwnd(hwnd)
        print "WM_KEYDOWN from: " hwnd " " this.hwnd " " wHwnd   ; ???
    }
    if wParam==116 {
        this.WB.Refresh2(3) ; REFRESH_COMPLETELY = 3
    }
}

(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: in WM_KEYDOWN event, unknown hwnd

07 Sep 2020, 13:42

I have found a way to do it but I am afraid it is not the best.
If anyone who has more experience with Gui has any comments, they are welcome.

Code: Select all

WM_KEYDOWN( wParam, lParam, msg, hwnd ){
    if wParam!=116 ; F5 key
        return
    ok := false
    CurrentCtrl := GuiCtrlFromHwnd(hwnd)
    if CurrentCtrl && CurrentCtrl.gui.hwnd==this.hwnd {
        ; BEFORE I click on the Gui.ActiveX, we pass here
        print "-> WM_KEYDOWN from: " type(CurrentCtrl) " name: " CurrentCtrl.name
        ok := true
    } else {
        for ,name in WinGetControls(this.hwnd){ ; Ctrl.names in this Gui
            try ctrlHwnd := ControlGetHwnd(name)
            catch
                return
            if hwnd==ctrlHwnd {
                ; HERE I know the event comes from a "Internet Explorer_Server1" ctrl, in this Gui.
                print "-> WM_KEYDOWN from: " name
                ok := true
                break
            }
        }
    }
    if ok
        this.WB.Refresh2(3) ; 3=REFRESH_COMPLETELY
}
Last edited by FredOoo on 08 Sep 2020, 17:51, edited 2 times in total.
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: in WM_KEYDOWN event, unknown hwnd  Topic is solved

08 Sep 2020, 03:30

How could I know which Gui that hwnd comes from ?
Call GuiFromHwnd(hwnd, true).
User avatar
FredOoo
Posts: 186
Joined: 07 May 2019, 21:58
Location: Paris

Re: in WM_KEYDOWN event, unknown hwnd

08 Sep 2020, 08:12

Thanks @lexikos. It's much more simple now.

Code: Select all

MyGui := Gui.New()
WB := MyGui.Add("ActiveX", "w980 h640", "Shell.Explorer").Value  ; The last parameter is the name of the ActiveX component.
WB.Silent := true  ; Don't box on html doc errors. (but on devMode, check if any)
WB.Navigate("https://www.autohotkey.com/boards/")  ; This is specific to the web browser control.
MyGui.Show()

onMessage 0x100, 'WM_KEYDOWN'
WM_KEYDOWN( wParam, lParam, msg, hwnd ){
    global MyGui, WB
    if  wParam==116  ; F5 key
        && (from:=GuiFromHwnd(hwnd,true))
        && from.hwnd==MyGui.hwnd ; Event from anywhere in MyGui
    {
        WB.Refresh2(3) ; 3=REFRESH_COMPLETELY
        SoundBeep
    }
    ;(This is just an example. Don't F5 before the page is loaded.)
}
(Alan Turing) « What would be the point of saying that A = B if it was really the same thing? »
(Albert Camus) « Misnaming things is to add to the misfortunes of the world. »

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Descolada, micktg99, songdg and 48 guests