Exemplo n.º 1
0
Arquivo: main.go Projeto: gonutz/di8
func main() {
	gform.Init()

	form := gform.NewForm(nil)
	form.Show()
	form.OnClose().Bind(func(arg *gform.EventArg) {
		w32.DestroyWindow(form.Handle())
	})

	check(di8.Init())
	defer di8.Close()

	dinput, err := di8.Create(unsafe.Pointer(w32.GetModuleHandle("")))
	defer dinput.Release()
	check(err)

	dinput.EnumDevices(
		di8.DEVCLASS_ALL,
		func(device di8.DeviceInstance) bool {
			fmt.Printf("%v (%v)\n", device.InstanceName, device.ProductName)
			return true
		},
		di8.EDFL_ALLDEVICES,
	)

	gform.RunMainLoop()
}
Exemplo n.º 2
0
func (this *Window) Close() error {
	UnRegMsgHandler(this.hwnd)
	err := w32.DestroyWindow(this.hwnd)
	if err == false {
		return errors.New("Error closing window")
	}
	return nil
}
Exemplo n.º 3
0
func (this *Dialog) Close(result int) {
	this.onClose.Fire(NewEventArg(this, nil))

	if this.isModal {
		w32.EndDialog(this.hwnd, uintptr(result))
	} else {
		w32.DestroyWindow(this.hwnd)
	}

	UnRegMsgHandler(this.hwnd)
}
Exemplo n.º 4
0
func (this *Form) WndProc(msg uint, wparam, lparam uintptr) uintptr {
	switch msg {
	case w32.WM_LBUTTONDOWN:
		if this.isDragMove {
			w32.ReleaseCapture()
			w32.SendMessage(this.hwnd, w32.WM_NCLBUTTONDOWN, w32.HTCAPTION, 0)
		}
	case w32.WM_CLOSE:
		w32.DestroyWindow(this.hwnd)
	case w32.WM_DESTROY:
		w32.PostQuitMessage(0)
	}

	return w32.DefWindowProc(this.hwnd, msg, wparam, lparam)
}
Exemplo n.º 5
0
// Close closes the window.
func (win *window) Close() {
	// close the childs
	vc := win.w.Property(sparta.Childs)
	if vc != nil {
		for _, c := range vc.([]sparta.Widget) {
			c.Window().Close()
		}
	}
	delete(widgetTable, win.id)

	if win.w.Property(sparta.Parent) != nil {
		win.w.SetProperty(sparta.Parent, nil)
	}
	win.w.SetProperty(sparta.Childs, nil)
	win.w.RemoveWindow()
	win.w = nil

	w32.DestroyWindow(win.id)

	// if there are no more windows, close the app
	if len(widgetTable) == 0 {
		closeApp()
	}
}
Exemplo n.º 6
0
func WndProc(hwnd w32.HWND, msg uint, wparam, lparam uintptr) uintptr {
	wnd := GetMsgHandler(hwnd)
	if wnd == nil {
		return uintptr(w32.DefWindowProc(hwnd, msg, wparam, lparam))
	}

	var rc uintptr
	switch msg {
	case w32.WM_LBUTTONDOWN, w32.WM_RBUTTONDOWN, w32.WM_MBUTTONDOWN:
		wnd.button = wnd.button | buttonForDetail(msg)
		var bpe wde.MouseDownEvent
		bpe.Which = buttonForDetail(msg)
		bpe.Where.X = int(lparam) & 0xFFFF
		bpe.Where.Y = int(lparam>>16) & 0xFFFF
		wnd.lastX = bpe.Where.X
		wnd.lastY = bpe.Where.Y
		wnd.events <- bpe

	case w32.WM_LBUTTONUP, w32.WM_RBUTTONUP, w32.WM_MBUTTONUP:
		wnd.button = wnd.button & ^buttonForDetail(msg)
		var bpe wde.MouseUpEvent
		bpe.Which = buttonForDetail(msg)
		bpe.Where.X = int(lparam) & 0xFFFF
		bpe.Where.Y = int(lparam>>16) & 0xFFFF
		wnd.lastX = bpe.Where.X
		wnd.lastY = bpe.Where.Y
		wnd.events <- bpe

	case w32.WM_MOUSEMOVE:
		var mme wde.MouseMovedEvent
		mme.Where.X = int(lparam) & 0xFFFF
		mme.Where.Y = int(lparam>>16) & 0xFFFF
		if wnd.lastX != wnd.noX {
			mme.From.X = int(wnd.lastX)
			mme.From.Y = int(wnd.lastY)
		} else {
			mme.From.X = mme.Where.X
			mme.From.Y = mme.Where.Y
		}
		wnd.lastX = mme.Where.X
		wnd.lastY = mme.Where.Y

		if !wnd.trackMouse {
			var tme w32.TRACKMOUSEEVENT
			tme.CbSize = uint(unsafe.Sizeof(tme))
			tme.DwFlags = w32.TME_LEAVE
			tme.HwndTrack = hwnd
			tme.DwHoverTime = w32.HOVER_DEFAULT
			w32.TrackMouseEvent(&tme)
			wnd.trackMouse = true
			wnd.events <- wde.MouseEnteredEvent(mme)
		} else {
			if wnd.button == 0 {
				wnd.events <- mme
			} else {
				var mde wde.MouseDraggedEvent
				mde.MouseMovedEvent = mme
				mde.Which = wnd.button
				wnd.events <- mde
			}
		}

	case w32.WM_MOUSELEAVE:
		wnd.trackMouse = false

		var wee wde.MouseExitedEvent
		// TODO: get real position
		wee.Where.Y = wnd.lastX
		wee.Where.X = wnd.lastY
		wnd.events <- wee

	case w32.WM_KEYDOWN:
		// TODO: letter
		ke := wde.KeyEvent{
			fmt.Sprintf("%d", wparam),
		}
		wnd.events <- wde.KeyDownEvent(ke)
		kpe := wde.KeyTypedEvent{
			KeyEvent: ke,
		}
		wnd.events <- kpe

	case w32.WM_KEYUP:
		// TODO: letter
		wnd.events <- wde.KeyUpEvent{
			fmt.Sprintf("%d", wparam),
		}

	case w32.WM_SIZE:
		width := int(lparam) & 0xFFFF
		height := int(lparam>>16) & 0xFFFF
		wnd.buffer = NewDIB(image.Rect(0, 0, width, height))
		wnd.events <- wde.ResizeEvent{width, height}
		rc = w32.DefWindowProc(hwnd, msg, wparam, lparam)

	case w32.WM_PAINT:
		var paint w32.PAINTSTRUCT
		hdc := w32.BeginPaint(hwnd, &paint)
		wnd.blitImage(hdc)
		w32.EndPaint(hwnd, &paint)
		rc = w32.DefWindowProc(hwnd, msg, wparam, lparam)

	case w32.WM_CLOSE:
		UnRegMsgHandler(hwnd)
		w32.DestroyWindow(hwnd)
		wnd.events <- wde.CloseEvent{}

	case w32.WM_DESTROY:
		w32.PostQuitMessage(0)

	default:
		rc = w32.DefWindowProc(hwnd, msg, wparam, lparam)
	}

	return rc
}
Exemplo n.º 7
0
func (this *ControlBase) Close() {
	UnRegMsgHandler(this.hwnd)
	w32.DestroyWindow(this.hwnd)
}
Exemplo n.º 8
0
func WndProc(hwnd w32.HWND, msg uint, wparam, lparam uintptr) uintptr {
	wnd := GetMsgHandler(hwnd)
	if wnd == nil {
		return uintptr(w32.DefWindowProc(hwnd, msg, wparam, lparam))
	}

	var rc uintptr
	switch msg {
	case w32.WM_SHOWWINDOW:
		w32.SetFocus(hwnd)
	case w32.WM_LBUTTONDOWN, w32.WM_RBUTTONDOWN, w32.WM_MBUTTONDOWN:
		wnd.button = wnd.button | buttonForDetail(msg)
		var bpe wde.MouseDownEvent
		bpe.Which = buttonForDetail(msg)
		bpe.Where.X = int(lparam) & 0xFFFF
		bpe.Where.Y = int(lparam>>16) & 0xFFFF
		wnd.lastX = bpe.Where.X
		wnd.lastY = bpe.Where.Y
		wnd.events <- bpe

	case w32.WM_LBUTTONUP, w32.WM_RBUTTONUP, w32.WM_MBUTTONUP:
		wnd.button = wnd.button & ^buttonForDetail(msg)
		var bpe wde.MouseUpEvent
		bpe.Which = buttonForDetail(msg)
		bpe.Where.X = int(lparam) & 0xFFFF
		bpe.Where.Y = int(lparam>>16) & 0xFFFF
		wnd.lastX = bpe.Where.X
		wnd.lastY = bpe.Where.Y
		wnd.events <- bpe

	case w32.WM_MOUSEMOVE:
		var mme wde.MouseMovedEvent
		mme.Where.X = int(lparam) & 0xFFFF
		mme.Where.Y = int(lparam>>16) & 0xFFFF
		if wnd.lastX != wnd.noX {
			mme.From.X = int(wnd.lastX)
			mme.From.Y = int(wnd.lastY)
		} else {
			mme.From.X = mme.Where.X
			mme.From.Y = mme.Where.Y
		}
		wnd.lastX = mme.Where.X
		wnd.lastY = mme.Where.Y

		if !wnd.trackMouse {
			var tme w32.TRACKMOUSEEVENT
			tme.CbSize = uint(unsafe.Sizeof(tme))
			tme.DwFlags = w32.TME_LEAVE
			tme.HwndTrack = hwnd
			tme.DwHoverTime = w32.HOVER_DEFAULT
			w32.TrackMouseEvent(&tme)
			wnd.trackMouse = true
			wnd.events <- wde.MouseEnteredEvent(mme)
		} else {
			if wnd.button == 0 {
				wnd.events <- mme
			} else {
				var mde wde.MouseDraggedEvent
				mde.MouseMovedEvent = mme
				mde.Which = wnd.button
				wnd.events <- mde
			}
		}

	case w32.WM_MOUSELEAVE:
		wnd.trackMouse = false

		var wee wde.MouseExitedEvent
		// TODO: get real position
		wee.Where.Y = wnd.lastX
		wee.Where.X = wnd.lastY
		wnd.events <- wee

	case w32.WM_SYSKEYDOWN:
		keyDown = keyFromVirtualKeyCode(wparam)
		keysDown[wde.KeyLeftAlt] = true
		keysDown[keyDown] = true
		ke := wde.KeyEvent{
			keyDown,
		}
		wnd.events <- wde.KeyDownEvent(ke)
	case w32.WM_KEYDOWN:
		keyDown = keyFromVirtualKeyCode(wparam)
		keysDown[keyDown] = true
		ke := wde.KeyEvent{
			keyDown,
		}
		wnd.events <- wde.KeyDownEvent(ke)
	case w32.WM_SYSCHAR:
		glyph := syscall.UTF16ToString([]uint16{uint16(wparam)})
		ke := wde.KeyEvent{
			keyDown,
		}
		kpe := wde.KeyTypedEvent{
			ke,
			glyph,
			wde.ConstructChord(keysDown),
		}
		wnd.events <- kpe
	case w32.WM_CHAR:
		glyph := syscall.UTF16ToString([]uint16{uint16(wparam)})
		ke := wde.KeyEvent{
			keyDown,
		}
		kpe := wde.KeyTypedEvent{
			ke,
			glyph,
			wde.ConstructChord(keysDown),
		}
		wnd.events <- kpe
	case w32.WM_SYSKEYUP:
		keyUp := keyFromVirtualKeyCode(wparam)
		delete(keysDown, wde.KeyLeftAlt)
		delete(keysDown, keyUp)
		wnd.events <- wde.KeyUpEvent{
			keyUp,
		}
	case w32.WM_KEYUP:
		keyUp := keyFromVirtualKeyCode(wparam)
		delete(keysDown, keyUp)
		wnd.events <- wde.KeyUpEvent{
			keyUp,
		}

	case w32.WM_SIZE:
		width := int(lparam) & 0xFFFF
		height := int(lparam>>16) & 0xFFFF
		wnd.buffer = NewDIB(image.Rect(0, 0, width, height))
		wnd.events <- wde.ResizeEvent{width, height}
		rc = w32.DefWindowProc(hwnd, msg, wparam, lparam)

	case w32.WM_PAINT:
		rc = w32.DefWindowProc(hwnd, msg, wparam, lparam)

	case w32.WM_CLOSE:
		UnRegMsgHandler(hwnd)
		w32.DestroyWindow(hwnd)
		wnd.events <- wde.CloseEvent{}

	case w32.WM_DESTROY:
		w32.PostQuitMessage(0)

	default:
		rc = w32.DefWindowProc(hwnd, msg, wparam, lparam)
	}

	return rc
}