Esempio n. 1
0
func main(f func(screen.Screen)) (retErr error) {
	// It does not matter which OS thread we are on.
	// All that matters is that we confine all UI operations
	// to the thread that created the respective window.
	runtime.LockOSThread()

	hr := C.initUtilityWindow()
	if hr != C.S_OK {
		return winerror("failed to create utility window", hr)
	}
	defer func() {
		// TODO(andlabs): log an error if this fails?
		C.DestroyWindow(C.utilityWindow)
		// TODO(andlabs): unregister window class
	}()

	hr = C.initWindowClass()
	if hr != C.S_OK {
		return winerror("failed to create Window window class", hr)
	}
	// TODO(andlabs): uninit

	s := newScreenImpl()
	go f(s)

	C.mainMessagePump()
	return nil
}
Esempio n. 2
0
func (wi *windowInternal) close() ThreadError {
	// Destroy the custom icon, if any
	if wi.icon != nil {
		C.DestroyIcon(wi.icon)
	}

	if wi.callback == nil {
		// Destroy the window
		if wi.window.IsValid() {
			C.DestroyWindow(wi.window.Handle)
		}
	} else {
		// The window is external : remove the hook on its message callback
		C.__SetWindowLongPtr(wi.window.Handle, C.GWLP_WNDPROC, wi.callback)
	}

	return nil
}
Esempio n. 3
0
func (ic *contextInternal) close() ThreadError {
	// start by waiting for deactivation to finish
	<-ic.deactivateSignal

	// Destroy the OpenGL context
	if ic.context != nil {
		C.wglDeleteContext(ic.context)
	}

	// Destroy the device context
	if ic.hdc != nil {
		C.ReleaseDC(ic.window, ic.hdc)
	}

	// Destroy the window if we own it
	if ic.window != nil && ic.ownsWindow {
		C.DestroyWindow(ic.window)
	}

	return nil
}