-
Notifications
You must be signed in to change notification settings - Fork 326
Description
I am preparing to write a dynamic link library file,it contains a winform. The code such as:
`
func init() {
title := "Spark"
hInst := win.GetModuleHandle(nil)
if hInst == 0 {
panic(fmt.Sprintf("GetModuleHandle: %v", win.GetLastError()))
}
wc := win.WNDCLASSEX{}
wc.CbSize = uint32(unsafe.Sizeof(wc))
wc.LpfnWndProc = syscall.NewCallback(wndProc)
wc.HInstance = hInst
wc.HbrBackground = win.COLOR_WINDOW + 1
wc.LpszClassName = syscall.StringToUTF16Ptr(title)
wc.Style = win.CS_HREDRAW | win.CS_VREDRAW
if atom := win.RegisterClassEx(&wc); atom == 0 {
panic(fmt.Sprintf("RegisterClassEx: %v", win.GetLastError()))
}
hwnd = win.CreateWindowEx(
win.WS_EX_TOOLWINDOW,
syscall.StringToUTF16Ptr(title),
syscall.StringToUTF16Ptr(title),
win.WS_VISIBLE | win.WS_POPUP,
0,
0,
0,
0,
0,
0,
hInst,
nil,
)
if hwnd == 0 {
panic(fmt.Sprintf("CreateWindowEx: %v", win.GetLastError()))
}
win.ShowWindow(hwnd, win.SW_HIDE)
win.UpdateWindow(hwnd)
var msg win.MSG
for {
if m := win.GetMessage(&msg, 0, 0, 0); m != 0 {
win.TranslateMessage(&msg)
win.DispatchMessage(&msg)
}
}
}
func wndProc(hwnd win.HWND, msg uint32, wparam, lparam uintptr) (result uintptr) {
switch msg {
case win.WM_DESTROY:
win.PostQuitMessage(0)
case win.WM_DEVICECHANGE:
OnDeviceChange(hwnd, msg, wparam, lparam)
case WM_USB_EVENT: // Customer Message
OnUsbEvent(hwnd, msg, wparam, lparam)
default:
return win.DefWindowProc(hwnd, msg, wparam, lparam)
}
return 0
}
//export DoPausePlay
func DoPausePlay() *C.char {
doPause()
return C.CString("0")
}
`
But when another program calls, it hangs at this code:
for { if m := win.GetMessage(&msg, 0, 0, 0); m != 0 { win.TranslateMessage(&msg) win.DispatchMessage(&msg) } }
Other methods, such as DoPausePlay(), cannot be called. How can I change this?