github.com/ckxng/wakeup@v0.0.0-20190105202853-90356a5f5a15/src/main_windows.go (about) 1 // Copyright (c) 2014 The cef2go authors. All rights reserved. 2 // License: BSD 3-clause. 3 // Website: https://github.com/CzarekTomczak/cef2go 4 5 package main 6 7 import ( 8 "cef" 9 "wingui" 10 "os" 11 "syscall" 12 "unsafe" 13 "log" 14 "time" 15 ) 16 17 var Logger *log.Logger = log.New(os.Stdout, "[main] ", log.Lshortfile) 18 19 func main() { 20 hInstance, e := wingui.GetModuleHandle(nil) 21 if e != nil { wingui.AbortErrNo("GetModuleHandle", e) } 22 23 cef.ExecuteProcess(unsafe.Pointer(hInstance)) 24 25 settings := cef.Settings{} 26 settings.CachePath = "webcache" // Set to empty to disable 27 settings.LogSeverity = cef.LOGSEVERITY_DEFAULT // LOGSEVERITY_VERBOSE 28 cef.Initialize(settings) 29 30 wndproc := syscall.NewCallback(WndProc) 31 Logger.Println("CreateWindow") 32 hwnd := wingui.CreateWindow("cef2go example", wndproc) 33 34 browserSettings := cef.BrowserSettings{} 35 // TODO: It should be executable's directory used 36 // rather than working directory. 37 url, _ := os.Getwd() 38 url = "file://" + url + "/example.html" 39 cef.CreateBrowser(unsafe.Pointer(hwnd), browserSettings, url) 40 41 // It should be enough to call WindowResized after 10ms, 42 // though to be sure let's extend it to 100ms. 43 time.AfterFunc(time.Millisecond * 100, func(){ 44 cef.WindowResized(unsafe.Pointer(hwnd)) 45 }) 46 47 cef.RunMessageLoop() 48 cef.Shutdown() 49 os.Exit(0) 50 } 51 52 func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintptr) { 53 switch msg { 54 case wingui.WM_CREATE: 55 rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam) 56 case wingui.WM_SIZE: 57 cef.WindowResized(unsafe.Pointer(hwnd)) 58 case wingui.WM_CLOSE: 59 wingui.DestroyWindow(hwnd) 60 case wingui.WM_DESTROY: 61 cef.QuitMessageLoop() 62 default: 63 rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam) 64 } 65 return 66 }