lxn / walk

A Windows GUI toolkit for the Go Programming Language
Other
6.82k stars 886 forks source link

Failed to wrap HTMLayout for walk as external widget #140

Closed Archs closed 9 years ago

Archs commented 9 years ago

HTMLayout is a fast, lightweight and embeddable HTML/CSS renderer and layout manager component. I've modified a binding go-htmlayout (which is workabe using cgo and syscall together) of the original c api.

I then tried to create an easy walk wrapper htmlayout for go-htmlayout using the declarative style. But it doesn't work.

In go-htmlayout I use gohl.ProcNoDefault

func WndProc(hWnd win.HWND, message uint32, wParam uintptr, lParam uintptr) uintptr {
    ret, handled := gohl.ProcNoDefault(hWnd, message, wParam, lParam)
    if handled {
        return uintptr(ret)
    }
    switch message {
    case win.WM_CREATE:
        println("win.WM_CREATE called", win.WM_CREATE)
    }
    return win.DefWindowProc(hWnd, message, wParam, lParam)
}

to embed the HTMLayout window and it works fine(full example here). image

In walk, the following code

func (de *HtmLayout) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
    ret, handled := gohl.ProcNoDefault(hwnd, msg, wParam, lParam)
    if handled {
        return uintptr(ret)
    }
    // begin default message loop
    switch msg {
    case win.WM_CREATE: // this msg never arrive, maybe the result of subclassing, but it doesn't matter here
        if err := gohl.LoadFile(hwnd, "a.html"); err != nil { // this fails other places
            println("gohl.LoadFile failed:", err.Error())  
        }
    }
    return de.WindowBase.WndProc(hwnd, msg, wParam, lParam)
}

(full code here) gohl.LoadFile fails or has no effect. I've tried to do gohl.LoadFile in several other places later or earlier, but never made it work. image

I think this problem relates to the Windows Messaging Mechanism and how walk and HTMLayout responds to it. I searched in the walk source code and only find that subclassing maybe relevant, but I can't find out the key point of the problem.

Can you @lxn help me with this problem, thanks in advance :smile:

Archs commented 9 years ago

Following the documentation for sciter (Upgraded version of HTMLayhout), the HTMLayout control may need WM_CREATE message to behave correctly.

But in walk the external widget's WndProc can't receive WM_CREATE message, can walk handle this?

Archs commented 9 years ago

With pull request https://github.com/lxn/walk/pull/141, One can using walk.MustRegisterWindowClassWithWndProcPtr to do supper classing of the window gui system, and thus can pass WM_CREATE etc to the target control and thus one could wrap more kind of controls as extrenal widgets into walk