Exemplo n.º 1
0
// Creates a hidden window, required for capturing the mouse interaction with the
// notify icon. Windows will call the WndProc of this window, whenever something happens
// on the notify icon (e.g. mouse click).
func (t *_NotifyIcon) createCallbackWindow() (err error) {
	className := "KeyFwdWindowClass"

	err = registerWindowClass(className, t.iconCallback)
	if err != nil {
		return
	}

	classNamePtr, _ := syscall.UTF16PtrFromString(className)
	t.hwnd = w32.CreateWindowEx(
		uint(w32.WS_EX_LEFT|w32.WS_EX_LTRREADING|w32.WS_EX_WINDOWEDGE),
		classNamePtr,
		nil,
		uint(w32.WS_OVERLAPPED|w32.WS_MINIMIZEBOX|w32.WS_SYSMENU|w32.WS_CLIPSIBLINGS|w32.WS_CAPTION),
		w32.CW_USEDEFAULT,
		w32.CW_USEDEFAULT,
		10,
		10,
		w32.HWND_DESKTOP,
		w32.HMENU(0),
		w32.GetModuleHandle(""),
		unsafe.Pointer(uintptr(0)),
	)
	if t.hwnd == 0 {
		return syscall.GetLastError()
	}

	return nil
}
Exemplo n.º 2
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.º 3
0
func init() {
	gWindows = make(map[w32.HWND]*Window)
	gClasses = make([]string, 0)
	gGeneralCallback = syscall.NewCallback(WndProc)
	gAppInstance = w32.GetModuleHandle("")
	if gAppInstance == 0 {
		panic("could not get app instance")
	}
}
Exemplo n.º 4
0
// Register a new window class for the current process. A window with the specified
// class name will use the given WndProc callback function.
func registerWindowClass(className string, callback _WindowProc) error {
	classNamePtr, _ := syscall.UTF16PtrFromString(className)
	var winClass w32.WNDCLASSEX
	winClass.Size = uint32(unsafe.Sizeof(winClass))
	winClass.Instance = w32.GetModuleHandle("")
	winClass.ClassName = classNamePtr
	winClass.WndProc = syscall.NewCallback(callback)

	if w32.RegisterClassEx(&winClass) == 0 {
		return syscall.GetLastError()
	}
	return nil
}
Exemplo n.º 5
0
func Init() {
	gAppInstance = w32.GetModuleHandle("")
	if gAppInstance == 0 {
		panic("Error occurred in App.Init")
	}

	// Initialize the common controls
	var initCtrls w32.INITCOMMONCONTROLSEX
	initCtrls.DwSize = uint32(unsafe.Sizeof(initCtrls))
	initCtrls.DwICC =
		w32.ICC_LISTVIEW_CLASSES | w32.ICC_PROGRESS_CLASS | w32.ICC_TAB_CLASSES |
			w32.ICC_TREEVIEW_CLASSES | w32.ICC_BAR_CLASSES

	w32.InitCommonControlsEx(&initCtrls)
}
Exemplo n.º 6
0
func (app *DemoApp) Initialize() {
	app.CreateDeviceIndependentResources()
	hInstance := w32.GetModuleHandle("")
	icon := w32.LoadIcon(0, w32.MakeIntResource(w32.IDI_APPLICATION))
	wndProc := func(hwnd w32.HWND, msg uint, wParam, lParam uintptr) uintptr {
		return app.WndProc(hwnd, msg, wParam, lParam)
	}
	wndClass := w32.WNDCLASSEX{
		Size:       uint(unsafe.Sizeof(w32.WNDCLASSEX{})),
		Style:      w32.CS_HREDRAW | w32.CS_VREDRAW,
		WndProc:    syscall.NewCallback(wndProc),
		ClsExtra:   0,
		WndExtra:   0,
		Instance:   hInstance,
		Icon:       icon,
		Cursor:     w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_ARROW)),
		Background: 0,
		MenuName:   nil,
		ClassName:  syscall.StringToUTF16Ptr("D2DDemoApp"),
		IconSm:     icon,
	}
	w32.RegisterClassEx(&wndClass)

	dpiX, dpiY := app.factory.GetDesktopDpi(app.factory)

	app.hwnd = w32.CreateWindowEx(
		0,
		syscall.StringToUTF16Ptr("D2DDemoApp"),
		syscall.StringToUTF16Ptr("Hello Windows"),
		w32.WS_OVERLAPPEDWINDOW,
		w32.CW_USEDEFAULT,
		w32.CW_USEDEFAULT,
		int(math.Ceil(float64(640*dpiX/96))),
		int(math.Ceil(float64(640*dpiY/96))),
		0,
		0,
		hInstance,
		nil)
	w32.ShowWindow(app.hwnd, w32.SW_SHOW)
	w32.UpdateWindow(app.hwnd)
}