Example #1
0
func (w *window) Show() {
	if !w.shownbefore {
		C.ShowWindow(w.hwnd, C.nCmdShow)
		C.updateWindow(w.hwnd)
		w.shownbefore = true
	} else {
		C.ShowWindow(w.hwnd, C.SW_SHOW)
	}
}
Example #2
0
func (window *Win32Window) Create(width uint, height uint, title string) bool {

	hInstance := C.GetModuleHandle(nil)

	if hInstance == nil {
		fmt.Println("Error")
		return false
	}

	res := C.RegisterWindow(C.CString("WindowClass"), hInstance, (C.WNDPROC)(unsafe.Pointer(syscall.NewCallback(func(hwnd C.HWND, message C.UINT, wParam C.WPARAM, lparam C.LPARAM) C.LRESULT {
		return window.WndProc(hwnd, message, wParam, lparam)
	}))))

	if res == 0 {
		fmt.Println("ERRRROR")
	}

	hwnd := C.CreateWindowTest(C.CString("WindowClass"), C.CString(title), (C.UINT)(width), (C.UINT)(height), hInstance)

	window.width = width
	window.height = height
	window.hInstance = hInstance
	window.hwnd = hwnd

	C.ShowWindow(hwnd, C.SW_SHOW)

	return true
}
Example #3
0
func (wi *windowInternal) switchToFullscreen(monitor *Monitor, mode VideoMode) error {
	devMode := C.DEVMODEW{
		dmSize:       C.DEVMODEW_size,
		dmPelsWidth:  C.DWORD(mode.Width),
		dmPelsHeight: C.DWORD(mode.Height),
		dmBitsPerPel: C.DWORD(mode.BitsPerPixel),
		dmFields:     C.DM_PELSWIDTH | C.DM_PELSHEIGHT | C.DM_BITSPERPEL,
	}

	// Apply fullscreen mode
	if err := ChangeDisplaySettingsExW(&monitor.internal.info.szDevice[0], &devMode, nil, C.CDS_FULLSCREEN, nil); err != nil {
		return err
	}

	// Make the window flags compatible with fullscreen mode
	C.SetWindowULong(wi.window.Handle, C.GWL_STYLE, C.WS_POPUP|C.WS_CLIPCHILDREN|C.WS_CLIPSIBLINGS)
	C.SetWindowLong(wi.window.Handle, C.GWL_EXSTYLE, C.WS_EX_APPWINDOW)

	// Resize the window so that it fits the entire screen
	C.SetWindowPos(wi.window.Handle, HWND_TOP, 0, 0, C.int(mode.Width), C.int(mode.Height), C.SWP_FRAMECHANGED)
	C.ShowWindow(wi.window.Handle, C.SW_SHOW)

	// Set this as the current fullscreen window
	wi.monitor = monitor
	wi.devMode = &devMode

	return nil
}
Example #4
0
func createHiddenWindow(width, height int) C.HWND {
	window := C.CreateWindowExW(0, contextInternal_className, contextInternal_wTitle, C.WS_POPUP|C.WS_DISABLED, 0, 0, C.int(width), C.int(height), nil, nil, C.GetModuleHandle(nil), nil)
	if window == nil {
		return nil
	}

	C.ShowWindow(window, C.SW_HIDE)
	return window
}
Example #5
0
// Show or hide the window
func (wi *windowInternal) setVisible(visible bool) ThreadError {
	nCmdShow := C.int(C.SW_HIDE)
	if visible {
		nCmdShow = C.SW_SHOW
	}

	C.ShowWindow(wi.window.Handle, nCmdShow)
	return nil
}
Example #6
0
func newControlSingleHWND(hwnd C.HWND) *controlSingleHWND {
	c := new(controlSingleHWND)
	c.controlbase = &controlbase{
		fsetParent: c.xsetParent,
		fresize:    c.xresize,
		fnTabStops: func() int {
			// most controls count as one tab stop
			return 1
		},
		fcontainerShow: func() {
			C.ShowWindow(c.hwnd, C.SW_SHOW)
		},
		fcontainerHide: func() {
			C.ShowWindow(c.hwnd, C.SW_HIDE)
		},
	}
	c.hwnd = hwnd
	return c
}
Example #7
0
// an up-down control will only properly position itself the first time
// stupidly, there are no messages to force a size calculation, nor can I seem to reset the buddy window to force a new position
// alas, we have to make a new up/down control each time :(
// TODO we'll need to store a copy of the current position and range for this
func (s *spinbox) remakeUpDown() {
	// destroying the previous one, setting the parent properly, and subclassing are handled here
	s.hwndUpDown = C.newUpDown(s.hwndUpDown, unsafe.Pointer(s))
	// for this to work, hwndUpDown needs to have rect [0 0 0 0]
	C.moveWindow(s.hwndUpDown, 0, 0, 0, 0)
	C.SendMessageW(s.hwndUpDown, C.UDM_SETBUDDY, C.WPARAM(uintptr(unsafe.Pointer(s.hwndEdit))), 0)
	C.SendMessageW(s.hwndUpDown, C.UDM_SETRANGE32, C.WPARAM(s.min), C.LPARAM(s.max))
	C.SendMessageW(s.hwndUpDown, C.UDM_SETPOS32, 0, C.LPARAM(s.value))
	if s.updownVisible {
		C.ShowWindow(s.hwndUpDown, C.SW_SHOW)
	}
}
Example #8
0
func HideConsoleWindow() (err error) {
	_, err = C.FreeConsole()
	if err != nil {
		return
	}
	_, err = C.AllocConsole()
	if err != nil {
		return
	}
	hwnd, err := C.GetConsoleWindow()
	if err != nil {
		return
	}
	_, err = C.ShowWindow(hwnd, C.SW_HIDE)
	if err != nil {
		return
	}

	return
}
Example #9
0
// TODO be sure to modify this when we add Show()/Hide()
func (s *spinbox) containerHide() {
	C.ShowWindow(s.hwndEdit, C.SW_HIDE)
	C.ShowWindow(s.hwndUpDown, C.SW_HIDE)
	s.updownVisible = false
}
Example #10
0
// TODO be sure to modify this when we add Show()/Hide()
func (s *spinbox) containerShow() {
	C.ShowWindow(s.hwndEdit, C.SW_SHOW)
	C.ShowWindow(s.hwndUpDown, C.SW_SHOW)
	s.updownVisible = true
}
Example #11
0
func (c *container) hide() {
	C.ShowWindow(c.hwnd, C.SW_HIDE)
}
Example #12
0
func (c *container) show() {
	C.ShowWindow(c.hwnd, C.SW_SHOW)
}
Example #13
0
func (wi *windowInternal) processEvent(message C.UINT, wParam C.WPARAM, lParam C.LPARAM) (events []Event, eventErrors []ThreadError) {
	// Don't process any message until window is created
	if wi.window.Handle == nil {
		return
	}

	switch message {
	case C.WM_DESTROY: // Destroy event
		// Here we must cleanup resources !
		wi.cleanup()
	case C.WM_ACTIVATE:
		// TODO fullscreen handling
		if wi.monitor == nil || !wi.monitor.IsValid() {
			break
		}

		// Were we deactivated/iconified?
		wi.inactive = C.__LOWORD(C.DWORD(wParam)) == C.WA_INACTIVE
		minimized := C.__HIWORD(C.DWORD(wParam)) != 0

		if (wi.inactive || minimized) && !wi.minimized {
			// _glfwInputDeactivation();

			// If we are in fullscreen mode we need to iconify
			if wi.monitor != nil && wi.monitor.IsValid() {
				// Do we need to manually iconify?
				if err := ChangeDisplaySettingsExW(&wi.monitor.internal.info.szDevice[0], nil, nil, 0, nil); err != nil {
					// TODO: Error handling
					panic(err)
				}

				if !minimized {
					// Minimize window
					// C.SetWindowULong(wi.window.Handle, C.GWL_STYLE, C.WS_POPUP)
					// C.SetWindowLong(wi.window.Handle, C.GWL_EXSTYLE, 0)
					// C.SetWindowPos(wi.window.Handle, HWND_BOTTOM, 1, 1, 10, 10, C.SWP_HIDEWINDOW)
					C.ShowWindow(wi.window.Handle, C.SW_MINIMIZE)
					minimized = true
				}

				// Restore the original desktop resolution
				if err := ChangeDisplaySettingsExW(&wi.monitor.internal.info.szDevice[0], nil, nil, 0, nil); err != nil {
					// TODO: Error handling
					panic(err)
				}

			}

			// Unlock mouse if locked
			// if !_glfwWin.oldMouseLockValid {
			// 	_glfwWin.oldMouseLock = _glfwWin.mouseLock;
			// 	_glfwWin.oldMouseLockValid = GL_TRUE;
			// 	glfwEnable( GLFW_MOUSE_CURSOR );
			// }
		} else if !wi.inactive || !minimized {
			// If we are in fullscreen mode we need to maximize
			if wi.monitor != nil && wi.monitor.IsValid() && wi.minimized {
				// Change display settings to the user selected mode
				if err := ChangeDisplaySettingsExW(&wi.monitor.internal.info.szDevice[0], wi.devMode, nil, C.CDS_FULLSCREEN, nil); err != nil {
					// TODO error handling
					panic(err)
				}

				// Do we need to manually restore window?
				if minimized {
					// Restore window
					C.ShowWindow(wi.window.Handle, C.SW_RESTORE)
					minimized = false

					// Activate window
					C.ShowWindow(wi.window.Handle, C.SW_SHOW)
					// setForegroundWindow( _glfwWin.window );
					C.SetFocus(wi.window.Handle)
				}

				// Lock mouse, if necessary
				// if _glfwWin.oldMouseLockValid && _glfwWin.oldMouseLock {
				// 	glfwDisable( GLFW_MOUSE_CURSOR );
				// }
				// _glfwWin.oldMouseLockValid = GL_FALSE;
			}
		}

		wi.minimized = minimized

	case C.WM_SETCURSOR: // Set cursor event
		// The mouse has moved, if the cursor is in our window we must refresh the cursor
		if C.__LOWORD(C.DWORD(lParam)) == C.HTCLIENT {
			C.SetCursor(wi.cursor)
		}

	case C.WM_CLOSE: // Close event
		events = append(events, WindowClosedEvent{})

	case C.WM_SIZE: // Resize event
		// Consider only events triggered by a maximize or a un-maximize
		if wParam == C.SIZE_MINIMIZED || wi.resizing {
			break
		}

		// Ignore cases where the window has only been moved
		if x, y := wi.getSize(); wi.lastSizeX == x && wi.lastSizeY == y {
			break
		}

		events = append(events, WindowResizeEvent{
			Width:  wi.lastSizeX,
			Height: wi.lastSizeY,
		})

	case C.WM_ENTERSIZEMOVE: // Start resizing
		wi.resizing = true

	case C.WM_EXITSIZEMOVE: // Stop resizing
		wi.resizing = false
		// Ignore cases where the window has only been moved
		if x, y := wi.getSize(); wi.lastSizeX == x && wi.lastSizeY == y {
			break
		} else {
			wi.lastSizeX, wi.lastSizeY = x, y
		}

		events = append(events, WindowResizeEvent{
			Width:  wi.lastSizeX,
			Height: wi.lastSizeY,
		})

	case C.WM_KILLFOCUS: // Lost focus event
		events = append(events, WindowGainedFocusEvent{})

	case C.WM_SETFOCUS: // Gain focus event
		events = append(events, WindowLostFocusEvent{})

	case C.WM_CHAR: // Text event
		if !wi.keyRepeatEnabled && lParam&(1<<30) != 0 {
			break
		}

		events = append(events, TextEnteredEvent{
			Character: rune(wParam),
		})

	case C.WM_KEYDOWN, C.WM_SYSKEYDOWN: // Keydown event
		if !wi.keyRepeatEnabled && C.__HIWORD(C.DWORD(lParam))&C.KF_REPEAT != 0 {
			break
		}

		events = append(events, KeyPressedEvent{
			Code:    virtualKeyCodeToSF(wParam, lParam),
			Alt:     C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_MENU))) != 0,
			Control: C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_CONTROL))) != 0,
			Shift:   C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_SHIFT))) != 0,
			System:  C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_LWIN))) != 0 || C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_RWIN))) != 0,
		})

	case C.WM_KEYUP, C.WM_SYSKEYUP: // Keyup event
		events = append(events, KeyReleasedEvent{
			Code:    virtualKeyCodeToSF(wParam, lParam),
			Alt:     C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_MENU))) != 0,
			Control: C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_CONTROL))) != 0,
			Shift:   C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_SHIFT))) != 0,
			System:  C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_LWIN))) != 0 || C.__HIWORD(C.DWORD(C.GetAsyncKeyState(C.VK_RWIN))) != 0,
		})

	case C.WM_MOUSEWHEEL: // Mouse wheel event
		// Mouse position is in screen coordinates, convert it to window coordinates
		position := C.POINT{
			x: C.LONG(C.__LOWORD(C.DWORD(lParam))),
			y: C.LONG(C.__HIWORD(C.DWORD(lParam))),
		}
		C.__ScreenToClient(wi.window.Handle, &position)

		events = append(events, MouseWheelEvent{
			Delta: int(int16(C.__HIWORD(C.DWORD(wParam))) / 120),
			X:     int(position.x),
			Y:     int(position.y),
		})

	case C.WM_LBUTTONDOWN, C.WM_RBUTTONDOWN: // Mouse left/right button down event
		button := mouse_vkeys_handed_map[mouseKey{message, C.GetSystemMetrics(C.SM_SWAPBUTTON) == C.TRUE}]
		events = append(events, MouseButtonPressedEvent{
			Button: button,
			X:      int(C.__LOWORD(C.DWORD(lParam))),
			Y:      int(C.__HIWORD(C.DWORD(lParam))),
		})

	case C.WM_LBUTTONUP, C.WM_RBUTTONUP: // Mouse left/right button up event
		button := mouse_vkeys_handed_map[mouseKey{message, C.GetSystemMetrics(C.SM_SWAPBUTTON) == C.TRUE}]
		events = append(events, MouseButtonReleasedEvent{
			Button: button,
			X:      int(C.__LOWORD(C.DWORD(lParam))),
			Y:      int(C.__HIWORD(C.DWORD(lParam))),
		})

	case C.WM_MBUTTONDOWN: // Mouse wheel button down event
		events = append(events, MouseButtonPressedEvent{
			Button: MouseMiddle,
			X:      int(C.__LOWORD(C.DWORD(lParam))),
			Y:      int(C.__HIWORD(C.DWORD(lParam))),
		})

	case C.WM_MBUTTONUP: // Mouse wheel button up event
		events = append(events, MouseButtonReleasedEvent{
			Button: MouseMiddle,
			X:      int(C.__LOWORD(C.DWORD(lParam))),
			Y:      int(C.__HIWORD(C.DWORD(lParam))),
		})

	case C.WM_XBUTTONDOWN: // Mouse X button down event
		event := MouseButtonPressedEvent{
			X: int(C.__LOWORD(C.DWORD(lParam))),
			Y: int(C.__HIWORD(C.DWORD(lParam))),
		}

		switch C.__HIWORD(C.DWORD(wParam)) {
		default:
			fallthrough
		case C.XBUTTON1:
			event.Button = MouseXButton1
		case C.XBUTTON2:
			event.Button = MouseXButton2

		}
		events = append(events, event)

	case C.WM_XBUTTONUP: // Mouse X button up event
		event := MouseButtonPressedEvent{
			X: int(C.__LOWORD(C.DWORD(lParam))),
			Y: int(C.__HIWORD(C.DWORD(lParam))),
		}

		switch C.__HIWORD(C.DWORD(wParam)) {
		default:
			fallthrough
		case C.XBUTTON1:
			event.Button = MouseXButton1
		case C.XBUTTON2:
			event.Button = MouseXButton2

		}
		events = append(events, event)

	case C.WM_MOUSEMOVE: // Mouse move event
		// Check if we need to generate a MouseEntered event
		if !wi.isCursorIn {
			mouseEvent := C.TRACKMOUSEEVENT{
				cbSize:    C.TRACKMOUSEEVENT_size,
				hwndTrack: wi.window.Handle,
				dwFlags:   C.TME_LEAVE,
			}
			C.__TrackMouseEvent(&mouseEvent)

			wi.isCursorIn = true

			events = append(events, MouseEnteredEvent{})
		}

		events = append(events, MouseMoveEvent{
			X: int(C.__LOWORD(C.DWORD(lParam))),
			Y: int(C.__HIWORD(C.DWORD(lParam))),
		})

	case C.WM_MOUSELEAVE: // Mouse leave event
		wi.isCursorIn = false
		events = append(events, MouseLeftEvent{})

	}

	return
}
Example #14
0
func (w *window) Hide() {
	C.ShowWindow(w.hwnd, C.SW_HIDE)
}
Example #15
0
func (s *Window) Show() {
	C.ShowWindow(unsafe.Pointer(s.GetHwnd()))
}