lxn / win

A Windows API wrapper package for the Go Programming Language
Other
1.21k stars 315 forks source link

How to kill HWND ? #42

Open wilon opened 6 years ago

wilon commented 6 years ago
hwnd := win.FindWindow(nil, syscall.StringToUTF16Ptr("someApp"))
// I want to kill hwnd, how?
krpors commented 6 years ago

Have you tried

win.SendMessage(hwnd, win.WM_CLOSE, 0, 0)

?

StephanVerbeeck commented 5 years ago

It might be prudent to use the non-blocking variant

win.PostMessage(yourHWND, win.WM_CLOSE, 0, 0)

The program you are trying to close might open a popup dialog (e.g. requesting to save the modified document it was showing) and that will block your program!