Example #1
0
func setWindowVisible(hwnd win.HWND, visible bool) {
	var cmd int32
	if visible {
		cmd = win.SW_SHOW
	} else {
		cmd = win.SW_HIDE
	}
	win.ShowWindow(hwnd, cmd)
}
Example #2
0
func WinMain(Inst win.HINSTANCE) int32 {
	// 1. 注册窗口类
	atom := MyRegisterClass(Inst)
	if atom == 0 {
		fmt.Println("注册窗口类失败:", win.GetLastError())
		return 0
	}
	fmt.Println("注册窗口类成功", atom)

	// 2. 创建窗口
	wnd := win.CreateWindowEx(win.WS_EX_APPWINDOW,
		syscall.StringToUTF16Ptr("主窗口类"),
		nil,
		win.WS_OVERLAPPEDWINDOW|win.WS_CLIPSIBLINGS,
		win.CW_USEDEFAULT,
		win.CW_USEDEFAULT,
		win.CW_USEDEFAULT,
		win.CW_USEDEFAULT,
		0,
		0,
		Inst,
		nil)
	if wnd == 0 {
		fmt.Println("创建窗口失败", win.GetLastError())
		return 0
	}
	fmt.Println("创建窗口成功", wnd)
	win.ShowWindow(wnd, win.SW_SHOW)
	win.UpdateWindow(wnd)
	// load file
	gohl.EnableDebug()
	if err := gohl.LoadFile(wnd, "a.html"); err != nil {
		println("LoadFile failed", err.Error())
		return 0
	}
	ui(wnd)

	// 3. 主消息循环
	var msg win.MSG
	msg.Message = win.WM_QUIT + 1 // 让它不等于 win.WM_QUIT

	for win.GetMessage(&msg, 0, 0, 0) > 0 {
		win.TranslateMessage(&msg)
		win.DispatchMessage(&msg)
	}

	return int32(msg.WParam)
}
Example #3
0
// SetVisible sets if the *WindowBase is visible.
func (wb *WindowBase) SetVisible(visible bool) {
	var cmd int32
	if visible {
		cmd = win.SW_SHOW
	} else {
		cmd = win.SW_HIDE
	}
	win.ShowWindow(wb.hWnd, cmd)

	wb.visible = visible

	if widget, ok := wb.window.(Widget); ok {
		widget.AsWidgetBase().updateParentLayout()
	}

	wb.visibleChangedPublisher.Publish()
}
Example #4
0
func WinMain(Inst win.HINSTANCE) int32 {
	// RegisterClass
	atom := MyRegisterClass(Inst)
	if atom == 0 {
		fmt.Println("RegisterClass failed:", win.GetLastError())
		return 0
	}
	fmt.Println("RegisterClass ok", atom)

	// CreateWindowEx
	wnd := win.CreateWindowEx(win.WS_EX_APPWINDOW,
		syscall.StringToUTF16Ptr(wndClassName),
		nil,
		win.WS_OVERLAPPEDWINDOW|win.WS_CLIPSIBLINGS,
		win.CW_USEDEFAULT,
		win.CW_USEDEFAULT,
		win.CW_USEDEFAULT,
		win.CW_USEDEFAULT,
		0,
		0,
		Inst,
		nil)
	if wnd == 0 {
		fmt.Println("CreateWindowEx failed:", win.GetLastError())
		return 0
	}
	fmt.Println("CreateWindowEx done", wnd)
	win.ShowWindow(wnd, win.SW_SHOW)
	win.UpdateWindow(wnd)
	// load file
	gohl.EnableDebug()
	if err := gohl.LoadFile(wnd, "a.html"); err != nil {
		println("LoadFile failed", err.Error())
		return 0
	}

	// main message loop
	var msg win.MSG

	for win.GetMessage(&msg, 0, 0, 0) > 0 {
		win.TranslateMessage(&msg)
		win.DispatchMessage(&msg)
	}

	return int32(msg.WParam)
}
Example #5
0
// 该函数将焦点切换指定的窗口,并将其带到前台。
func (wb *WindowBase) SwitchToThisWindow(switchto bool) {
	win.ShowWindow(wb.hWnd, win.SW_RESTORE)
}
Example #6
0
func (s *Window) Show() {
	// message handling
	hwnd := win.HWND(unsafe.Pointer(s.GetHwnd()))
	win.ShowWindow(hwnd, win.SW_SHOW)
	win.UpdateWindow(hwnd)
}