rodrigocfd / windigo

Windows API and GUI in idiomatic Go.
https://pkg.go.dev/github.com/rodrigocfd/windigo
MIT License
405 stars 22 forks source link

Fix modal loop stuck at GetMessage #21

Closed Hoto-Cocoa closed 1 year ago

Hoto-Cocoa commented 1 year ago

In Windows 11, Loop stucks at GetMessage If hWnd.IsWindow() is false.

This commit resolves that issue.

Your patch 8e110a3 works in Windows 10 but not in Windows 11. I tried dig down into windigo and I addressed that is modal loop stucks at GetMessage.

After adding that lines, program works as expected.

Related to #20.

rodrigocfd commented 1 year ago

Are you sure of this?

I just tested my example in a fresh installed Windows 11 machine, and it works perfectly, no need for any changes.

Hoto-Cocoa commented 1 year ago

I tried that but no luck. I know it sounds weird, but after changing order of lines it works perfectly.

But here is my code:

func ShowTextInputBox(title, msg string) string {
    text := ""

    modal := ui.NewWindowModal(ui.WindowModalOpts().
        Title(title).
        ClientArea(win.SIZE{Cx: 300, Cy: 105}),
    )

    createStatic(modal, msg, win.POINT{X: 10, Y: 10}, win.SIZE{Cx: 280, Cy: 15})

    edit := createEdit(modal, win.POINT{X: 10, Y: 35}, win.SIZE{Cx: 280, Cy: 20})

    button := createButton(modal, "OK", win.POINT{X: 10, Y: 65}, win.SIZE{Cx: 280, Cy: 30})
    button.On().BnClicked(func() {
        text = edit.Text()

        modal.Hwnd().SendMessage(co.WM_CLOSE, 0, 0)
    })

    modal.On().WmCreate(func(_ wm.Create) int {
        edit.Hwnd().SetFocus()

        return 0
    })

    modal.ShowModal(globalWindow)

    return text
}

In Windows 10 works perfectly, but not in my all of Windows 11 machines using same build. I'm using latest version(installed all available updates) of Windows 11.

I'm not used goroutine and locked OS thread. Maybe this is Windows or my fault, feel free to close this PR.

Thanks.

Hoto-Cocoa commented 1 year ago

I figured out this issue.

It is not fault of windigo, Windows, and also me.

In my country, banks and governments forced to install their security agents, such as TouchEn nxKey, and that installed to all of my Windows 11 machines. My all of Windows 11 machines are shared PC, so I think other person installed it as I using isolated virtual machine to use bank/government sites.

Anyway, one of that security agents made GetMessage weird. After uninstalling all of their security agents, my build works perfectly.

Sorry for opening invalid PR, maybe I need to found that agent and complain to company...

I'm closing this PR now.

Thanks.

rodrigocfd commented 1 year ago

No problem. In my country, if we want to access bank websites we're also required to install some crap to supposedly protect the computer. But I've never seen a program so intrusive as yours... messing with the message loop probably means a DLL injection gone wrong. Or maybe it's the Go runtime making its detection confused... who knows.