Exemplo n.º 1
0
// Change the size of the rendering region of the window
func (wi *windowInternal) setSize(x, y uint) {
	// SetWindowPos wants the total size of the window (including title bar and borders),
	// so we have to compute it
	rect := C.RECT{0, 0, C.LONG(x), C.LONG(y)}
	style := C.GetWindowLong(wi.window.Handle, C.GWL_STYLE)
	C.__AdjustWindowRect(&rect, C.DWORD(style), C.FALSE)
	width := C.int(rect.right - rect.left)
	height := C.int(rect.bottom - rect.top)

	C.SetWindowPos(wi.window.Handle, nil, 0, 0, width, height, C.SWP_NOMOVE|C.SWP_NOZORDER)
}
Exemplo n.º 2
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
}