Esempio n. 1
0
// Creates the window. This function expects not to be called on a ContextThread
func (wi *windowInternal) initialize(monitor *Monitor, mode VideoMode, title string, style WindowStyle) ThreadError {
	// Compute position and size
	screenDC := C.GetDC(nil)
	width := C.int(mode.Width)
	height := C.int(mode.Height)
	left := (C.GetDeviceCaps(screenDC, C.HORZRES) - width) / 2
	top := (C.GetDeviceCaps(screenDC, C.VERTRES) - height) / 2
	C.ReleaseDC(nil, screenDC)

	// Choose the window style according to the Style parameter
	win32Style := C.DWORD(C.WS_VISIBLE)
	if style == WindowStyleNone {
		win32Style |= C.WS_POPUP
	} else {
		if style&WindowStyleTitlebar != 0 {
			win32Style |= C.WS_CAPTION | C.WS_MINIMIZEBOX
		}
		if style&WindowStyleResize != 0 {
			win32Style |= C.WS_THICKFRAME | C.WS_MAXIMIZEBOX
		}
		if style&WindowStyleClose != 0 {
			win32Style |= C.WS_SYSMENU
		}
	}

	// In windowed mode, adjust width and height so that window will have the requested client area
	fullscreen := style&WindowStyleFullscreen != 0
	if !fullscreen {
		rectangle := C.RECT{
			left:   C.LONG(left),
			top:    C.LONG(top),
			right:  C.LONG(left + width),
			bottom: C.LONG(top + height),
		}
		C.__AdjustWindowRect(&rectangle, win32Style, C.FALSE)
		left = C.int(rectangle.left)
		top = C.int(rectangle.top)
		width = C.int(rectangle.right - rectangle.left)
		height = C.int(rectangle.bottom - rectangle.top)
	}
	wTitle, _ := utf16Convert(title)
	wi.window.Handle = C.CreateWindowExW(0, className, wTitle, win32Style, left, top, width, height, nil, nil, windowClass.hInstance, C.LPVOID(wi))

	// Switch to fullscreen if requested
	if fullscreen {
		wi.switchToFullscreen(monitor, mode)
	}

	return nil
}
Esempio n. 2
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
}