Ejemplo n.º 1
0
func (this *MainWindow) Show() {
	// Center in the owner window
	w := *this.AssignTo

	//fmt.Printf("aaaa\n")
	sWidth := win.GetSystemMetrics(win.SM_CXFULLSCREEN)
	sHeight := win.GetSystemMetrics(win.SM_CYFULLSCREEN)
	if sWidth != 0 && sHeight != 0 {
		rect := w.Bounds()
		rect.X = (int(sWidth) / 2) - (rect.Width / 2)
		rect.Y = (int(sHeight) / 2) - (rect.Height / 2)
		w.SetBounds(rect)
	}

	w.Show()
}
Ejemplo n.º 2
0
Archivo: main.go Proyecto: CodyGuo/gapp
func createWindow() win.HWND {
	var dwExStyle, dwStyle uint32 = 0, 0

	dwStyle = win.WS_OVERLAPPEDWINDOW

	if !manifest.FormFixed() {
		dwStyle |= win.WS_SIZEBOX
	}

	// 获取屏幕宽度和高度
	var x, y int32
	var width, height int32

	width = manifest.Width()
	height = manifest.Height()
	x = (win.GetSystemMetrics(win.SM_CXSCREEN) - width) / 2
	y = (win.GetSystemMetrics(win.SM_CYSCREEN)-height)/2 - 2

	renderWindow := win.CreateWindowEx(
		dwExStyle,
		syscall.StringToUTF16Ptr(nguiWindowClass),
		nil,
		dwStyle, //|win.WS_CLIPSIBLINGS,
		x,       //win.CW_USEDEFAULT,
		y,       //win.CW_USEDEFAULT,
		width,   //win.CW_USEDEFAULT,
		height,  //win.CW_USEDEFAULT,
		0,       //hwndParent
		0,
		0, //hInstance
		nil)
	if renderWindow == 0 {
		//err := errors.New("CreateWindowEx")
		return win.HWND(0)
	}

	fmt.Printf("CreateWindow x=%v y=%v width=%v height=%v renderWindow=%v renderWindow=%v\n", x, y, width, height, renderWindow, unsafe.Pointer(renderWindow))

	win.ShowWindow(renderWindow, win.SW_SHOW) //win.SW_SHOW
	win.UpdateWindow(renderWindow)

	return renderWindow
}
Ejemplo n.º 3
0
Archivo: ngui.go Proyecto: CodyGuo/ngui
// 创建浏览器窗口
func (a *Application) CreateBrowserWindow(url string, captionless bool) (err error) {
	var dwExStyle, dwStyle uint32 = 0, 0
	var captionlessFlag uintptr = 0
	fmt.Printf("CreateBrowserWindow url=%v captionless=%v\n", url, captionless)

	if captionless {
		captionlessFlag = 1
		//dwExStyle = 0//win.WS_EX_LAYERED

		// 无边框效果不错。但是不能移动
		//dwStyle = win.WS_POPUP //& ^ (win.WS_CAPTION | win.WS_BORDER)

		dwStyle = win.WS_MINIMIZEBOX | win.WS_MAXIMIZEBOX | win.WS_CAPTION | win.WS_CLIPCHILDREN |
			win.WS_SYSMENU | win.WS_POPUP

	} else {
		dwStyle = win.WS_OVERLAPPEDWINDOW
	}

	if !manifest.FormFixed() {
		dwStyle |= win.WS_SIZEBOX
	}

	// 获取屏幕宽度和高度
	var x, y int32
	var width, height int32

	width = manifest.Width()
	height = manifest.Height()
	x = (win.GetSystemMetrics(win.SM_CXSCREEN) - width) / 2
	y = (win.GetSystemMetrics(win.SM_CYSCREEN)-height)/2 - 2

	renderWindow := win.CreateWindowEx(
		dwExStyle,
		syscall.StringToUTF16Ptr(nguiTransparentWindowClass),
		nil,
		dwStyle, //|win.WS_CLIPSIBLINGS,
		x,       //win.CW_USEDEFAULT,
		y,       //win.CW_USEDEFAULT,
		width,   //win.CW_USEDEFAULT,
		height,  //win.CW_USEDEFAULT,
		0,       //hwndParent
		0,
		0, //hInstance
		nil)
	if renderWindow == 0 {
		err = errors.New("CreateWindowEx")
		return
	}

	// 设置captionless标记
	win.SetProp(renderWindow, WindowProp_CaptionLess, win.HANDLE(captionlessFlag))

	if captionless {
		/*
					SetWindowLong(hWnd, GWL_STYLE,
			        GetWindowLong(hWnd, GWL_STYLE) & ~(WS_BORDER));
		*/

		// WS_BORDER Creates a window that has a border.创建一个有边界的窗口。
		// WS_EX_CLIENTEDGE Specifies that a window has a 3D look — that is, a border with a sunken edge.指定窗口具有3D外观,也即是一个下层的边缘。
		//gwlStyle := win.GetWindowLong(renderWindow, win.GWL_STYLE)
		//gwlStyle &= ^(win.WS_BORDER)
		//gwlStyle &= ^(win.WS_EX_CLIENTEDGE)
		//win.SetWindowLong(renderWindow, win.GWL_STYLE, gwlStyle)

		//gwlExStyle := win.GetWindowLong(renderWindow, win.GWL_EXSTYLE)
		//gwlExStyle |= win.WS_EX_LAYERED;
		//win.SetWindowLong(renderWindow, win.GWL_EXSTYLE, gwlExStyle)

		// HWND hWnd: 窗口句柄
		// COLORREF col: 透明化颜色
		// byte bAlpha: =0:整个窗口透明, =255 完全不透明
		// uint32 dwFlags: =1:仅颜色 col 透明, =2 :窗口按照bAlpha变量进行透明处理。
		//win.SetLayeredWindowAttributes(renderWindow, win.BS_SOLID, 0, 2)
		//win.UpdateWindow(renderWindow)
	}

	if captionless {
		//win.MoveWindow(renderWindow, x, y, width, height, false)
		//win.SetWindowPos(renderWindow, 0, x, y, width, height, win.SWP_NOZORDER|win.SWP_NOACTIVATE|win.SWP_NOSIZE)
		win.SetWindowPos(renderWindow, 0, x, y, width, height, win.SWP_FRAMECHANGED)
	} else {
		win.MoveWindow(renderWindow, x, y, width, height, false)
	}

	fmt.Printf("CreateBrowserWindow x=%v, y=%v, width=%v, height=%v\n", x, y, width, height)

	go func() {

		//browser := cef.CreateBrowser(unsafe.Pointer(hwnd), &browserSettings, url, false)
		browserSettings := cef.BrowserSettings{}
		cef.CreateBrowser(unsafe.Pointer(renderWindow), &browserSettings, url, false)

		//m_dwStyle = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP |
		//		WS_VISIBLE;
		cef.WindowResized(unsafe.Pointer(renderWindow))

		win.ShowWindow(renderWindow, win.SW_SHOW) //win.SW_SHOW
		win.UpdateWindow(renderWindow)

		//cef.WindowResized(unsafe.Pointer(renderWindow))
		// It should be enough to call WindowResized after 10ms,
		// though to be sure let's extend it to 100ms.
		//time.AfterFunc(time.Millisecond*100, func() {
		//	cef.WindowResized(unsafe.Pointer(renderWindow))
		//})
	}()

	return
}
Ejemplo n.º 4
0
// 模拟点击
func win_emuClick(browser *cef.Browser, message *cef.CefProcessMessage) interface{} {
	fmt.Printf("win_emuClick\n")
	handle := browser.GetWindowHandle()
	openerHandle := browser.GetOpenerWindowHandle()
	rootHandle := browser.GetRootWindowHandle()
	fmt.Printf("win_start_browser handle=%v openerHandle=%v rootHandle=%v\n", handle, openerHandle, rootHandle)
	//win.ShowWindow(win.HWND(rootHandle), win.SW_MAXIMIZE)
	// 模拟点击
	// 查找窗口
	url := message.GetArgumentList().GetString(1)
	fmt.Printf("url=%v\n", url)
	w, ok := windowHolders[url]
	if ok {
		fmt.Printf("找到窗口\n")
		b, o := cef.BrowserByHandle(unsafe.Pointer(w))
		if o {
			x := message.GetArgumentList().GetInt(2)
			y := message.GetArgumentList().GetInt(3)
			buttonType := message.GetArgumentList().GetBool(4)
			fmt.Printf("X=%v Y=%v ButtonType=%v\n", x, y, buttonType)
			rootHandle = b.GetRootWindowHandle()
			//win.ShowWindow(win.HWND(rootHandle), win.SW_MAXIMIZE)
			// 模拟鼠标
			var pt win.POINT
			pt.X = int32(x) // This is your click coordinates
			pt.Y = int32(y)

			hWnd := win.HWND(rootHandle)

			go func() {
				win.SetForegroundWindow(hWnd)
				time.Sleep(3 * time.Second)

				win.ClientToScreen(hWnd, &pt)

				fmt.Printf("ClientToScreen X=%v Y=%v\n", pt.X, pt.Y)

				cx_screen := win.GetSystemMetrics(win.SM_CXSCREEN) //屏幕 宽
				cy_screen := win.GetSystemMetrics(win.SM_CYSCREEN) //     高

				real_x := 65535 * pt.X / cx_screen //转换后的 x
				real_y := 65535 * pt.Y / cy_screen //         y

				var input win.MOUSE_INPUT
				input.Type = win.INPUT_MOUSE
				input.Mi.Dx = real_x
				input.Mi.Dy = real_y
				if buttonType {
					input.Mi.DwFlags = (win.MOUSEEVENTF_ABSOLUTE | win.MOUSEEVENTF_MOVE | win.MOUSEEVENTF_RIGHTDOWN | win.MOUSEEVENTF_RIGHTUP)
				} else {
					input.Mi.DwFlags = (win.MOUSEEVENTF_ABSOLUTE | win.MOUSEEVENTF_MOVE | win.MOUSEEVENTF_LEFTDOWN | win.MOUSEEVENTF_LEFTUP)
				}
				input.Mi.MouseData = 0
				input.Mi.DwExtraInfo = 0
				input.Mi.Time = 0
				win.SendInput(2, unsafe.Pointer(&input), int32(unsafe.Sizeof(input)))

				fmt.Printf("点击")
			}()
			//hWnd = win.WindowFromPoint(pt)
		}
	} else {
		fmt.Printf("找不到窗口\n")
	}
	return 0
}