示例#1
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)
}
示例#2
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)
}
func (gb *GroupBox) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
	if gb.composite != nil {
		switch msg {
		case win.WM_COMMAND, win.WM_NOTIFY:
			gb.composite.WndProc(hwnd, msg, wParam, lParam)

		case win.WM_SETTEXT:
			gb.titleChangedPublisher.Publish()

		case win.WM_PAINT:
			win.UpdateWindow(gb.checkBox.hWnd)

		case win.WM_SIZE, win.WM_SIZING:
			wbcb := gb.WidgetBase.ClientBounds()
			if !win.MoveWindow(
				gb.hWndGroupBox,
				int32(wbcb.X),
				int32(wbcb.Y),
				int32(wbcb.Width),
				int32(wbcb.Height),
				true) {

				lastError("MoveWindow")
				break
			}

			if gb.Checkable() {
				s := gb.checkBox.SizeHint()
				gb.checkBox.SetBounds(Rectangle{9, 14, s.Width, s.Height})
			}

			gbcb := gb.ClientBounds()
			gb.composite.SetBounds(gbcb)
		}
	}

	return gb.WidgetBase.WndProc(hwnd, msg, wParam, lParam)
}
示例#4
0
文件: window.go 项目: CodyGuo/walk
func setWindowEnabled(hwnd win.HWND, enabled bool) {
	win.EnableWindow(hwnd, enabled)

	win.UpdateWindow(hwnd)
}
示例#5
0
func (s *Window) Show() {
	// message handling
	hwnd := win.HWND(unsafe.Pointer(s.GetHwnd()))
	win.ShowWindow(hwnd, win.SW_SHOW)
	win.UpdateWindow(hwnd)
}