// Register a new window class for the current process. A window with the specified // class name will use the given WndProc callback function. func registerWindowClass(className string, callback _WindowProc) error { classNamePtr, _ := syscall.UTF16PtrFromString(className) var winClass w32.WNDCLASSEX winClass.Size = uint32(unsafe.Sizeof(winClass)) winClass.Instance = w32.GetModuleHandle("") winClass.ClassName = classNamePtr winClass.WndProc = syscall.NewCallback(callback) if w32.RegisterClassEx(&winClass) == 0 { return syscall.GetLastError() } return nil }
func RegisterClass(className string, wndproc uintptr) error { icon := w32.LoadIcon(gAppInstance, w32.MakeIntResource(w32.IDI_APPLICATION)) var wc w32.WNDCLASSEX wc.Size = uint32(unsafe.Sizeof(wc)) wc.Style = w32.CS_HREDRAW | w32.CS_VREDRAW wc.WndProc = wndproc wc.Instance = gAppInstance wc.Background = w32.COLOR_BTNFACE + 1 wc.Icon = icon wc.ClassName = syscall.StringToUTF16Ptr(className) wc.MenuName = nil wc.IconSm = icon if ret := w32.RegisterClassEx(&wc); ret == 0 { return syscall.GetLastError() } return nil }
func RegisterClass(className string, wndproc uintptr) { instance := GetAppInstance() icon := w32.LoadIcon(instance, w32.MakeIntResource(w32.IDI_APPLICATION)) var wc w32.WNDCLASSEX wc.Size = uint(unsafe.Sizeof(wc)) wc.Style = w32.CS_HREDRAW | w32.CS_VREDRAW wc.WndProc = wndproc wc.Instance = instance wc.Background = w32.COLOR_BTNFACE + 1 wc.Icon = icon wc.Cursor = w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_ARROW)) wc.ClassName = syscall.StringToUTF16Ptr(className) wc.MenuName = nil wc.IconSm = icon if ret := w32.RegisterClassEx(&wc); ret == 0 { panic(syscall.GetLastError()) } }
func (app *DemoApp) Initialize() { app.CreateDeviceIndependentResources() hInstance := w32.GetModuleHandle("") icon := w32.LoadIcon(0, w32.MakeIntResource(w32.IDI_APPLICATION)) wndProc := func(hwnd w32.HWND, msg uint, wParam, lParam uintptr) uintptr { return app.WndProc(hwnd, msg, wParam, lParam) } wndClass := w32.WNDCLASSEX{ Size: uint(unsafe.Sizeof(w32.WNDCLASSEX{})), Style: w32.CS_HREDRAW | w32.CS_VREDRAW, WndProc: syscall.NewCallback(wndProc), ClsExtra: 0, WndExtra: 0, Instance: hInstance, Icon: icon, Cursor: w32.LoadCursor(0, w32.MakeIntResource(w32.IDC_ARROW)), Background: 0, MenuName: nil, ClassName: syscall.StringToUTF16Ptr("D2DDemoApp"), IconSm: icon, } w32.RegisterClassEx(&wndClass) dpiX, dpiY := app.factory.GetDesktopDpi(app.factory) app.hwnd = w32.CreateWindowEx( 0, syscall.StringToUTF16Ptr("D2DDemoApp"), syscall.StringToUTF16Ptr("Hello Windows"), w32.WS_OVERLAPPEDWINDOW, w32.CW_USEDEFAULT, w32.CW_USEDEFAULT, int(math.Ceil(float64(640*dpiX/96))), int(math.Ceil(float64(640*dpiY/96))), 0, 0, hInstance, nil) w32.ShowWindow(app.hwnd, w32.SW_SHOW) w32.UpdateWindow(app.hwnd) }