예제 #1
0
파일: main.go 프로젝트: mattn/gyagowin
func MyRegisterClass(hInstance winapi.HINSTANCE) winapi.ATOM {
	var wc winapi.WNDCLASSEX

	wc.CbSize = uint32(unsafe.Sizeof(winapi.WNDCLASSEX{}))
	wc.Style = 0
	wc.LpfnWndProc = syscall.NewCallback(WndProc)
	wc.CbClsExtra = 0
	wc.CbWndExtra = 0
	wc.HInstance = hInstance
	wc.HIcon = winapi.LoadIcon(hInstance, winapi.MAKEINTRESOURCE(132))
	wc.HCursor = winapi.LoadCursor(0, winapi.MAKEINTRESOURCE(winapi.IDC_CROSS))
	wc.HbrBackground = 0
	wc.LpszMenuName = nil
	wc.LpszClassName, _ = syscall.UTF16PtrFromString("GYAZOWIN")

	winapi.RegisterClassEx(&wc)

	var lwc winapi.WNDCLASSEX
	lwc.CbSize = uint32(unsafe.Sizeof(winapi.WNDCLASSEX{}))
	lwc.Style = winapi.CS_HREDRAW | winapi.CS_VREDRAW
	lwc.LpfnWndProc = syscall.NewCallback(LayerWndProc)
	lwc.CbClsExtra = 0
	lwc.CbWndExtra = 0
	lwc.HInstance = hInstance
	lwc.HIcon = winapi.LoadIcon(hInstance, winapi.MAKEINTRESOURCE(132))
	lwc.HCursor = winapi.LoadCursor(0, winapi.MAKEINTRESOURCE(winapi.IDC_CROSS))
	lwc.HbrBackground = winapi.HBRUSH(winapi.GetStockObject(winapi.WHITE_BRUSH))
	lwc.LpszMenuName = nil
	lwc.LpszClassName, _ = syscall.UTF16PtrFromString("GYAZOWINL")

	return winapi.RegisterClassEx(&lwc)
}
예제 #2
0
파일: uitask_windows.go 프로젝트: UIKit0/ui
func makeMessageHandler() (hwnd _HWND, err error) {
	wc := &_WNDCLASS{
		lpszClassName: utf16ToArg(msghandlerclass),
		lpfnWndProc:   syscall.NewCallback(messageHandlerWndProc),
		hInstance:     hInstance,
		hIcon:         icon,
		hCursor:       cursor,
		hbrBackground: _HBRUSH(_COLOR_BTNFACE + 1),
	}

	r1, _, err := _registerClass.Call(uintptr(unsafe.Pointer(wc)))
	if r1 == 0 { // failure
		return _HWND(_NULL), fmt.Errorf("error registering the class of the invisible window for handling events: %v", err)
	}

	r1, _, err = _createWindowEx.Call(
		uintptr(0),
		utf16ToArg(msghandlerclass),
		utf16ToArg(msghandlertitle),
		uintptr(0),
		negConst(_CW_USEDEFAULT),
		negConst(_CW_USEDEFAULT),
		negConst(_CW_USEDEFAULT),
		negConst(_CW_USEDEFAULT),
		// don't negConst() HWND_MESSAGE; windowsconstgen was given a pointer by windows.h, and pointers are unsigned, so converting it back to signed doesn't work
		uintptr(_HWND_MESSAGE),
		uintptr(_NULL),
		uintptr(hInstance),
		uintptr(_NULL))
	if r1 == 0 { // failure
		return _HWND(_NULL), fmt.Errorf("error actually creating invisible window for handling events: %v", err)
	}

	return _HWND(r1), nil
}
예제 #3
0
func RegisterWindow(name string, proc WindowProc) error {
	hinst, _, _ := GetModuleHandle.Call(0)
	if hinst == 0 {
		return errors.New("get module handle failed")
	}
	hicon, _, _ := LoadIcon.Call(0, uintptr(IDI_APPLICATION))
	if hicon == 0 {
		return errors.New("load icon failed")
	}
	hcursor, _, _ := LoadCursor.Call(0, uintptr(IDC_ARROW))
	if hcursor == 0 {
		return errors.New("load cursor failed")
	}

	var wc WNDCLASSEX
	wc.CbSize = uint32(unsafe.Sizeof(wc))
	wc.LpfnWndProc = syscall.NewCallback(proc)
	wc.HInstance = HINSTANCE(hinst)
	wc.HIcon = HICON(hicon)
	wc.HCursor = HCURSOR(hcursor)
	wc.HbrBackground = COLOR_BTNFACE + 1
	wc.LpszClassName = syscall.StringToUTF16Ptr(name)

	atom, _, _ := RegisterClassEx.Call(uintptr(unsafe.Pointer(&wc)))
	if atom == 0 {
		return errors.New("register class failed")
	}
	return nil
}
예제 #4
0
func (m *DWebBrowserEvents2) New() {
	m.IDispatch.New()
	m.AddInterface(&DIID_DWebBrowserEvents2, m)
	m.AddMethod("DocumentComplete", DISPID_DOCUMENTCOMPLETE, syscall.NewCallback(func() HRESULT {
		return m.DocumentComplete()
	}))
}
예제 #5
0
파일: hello.go 프로젝트: henrylee2cn/xcgui
func main() {
	xcgui.XInitXCGUI()
	hwnd := xcgui.XWndCreate(400, 200, 300, 200, "标题",
		xcgui.NULL, xcgui.XC_WINDOW_STYLE_DEFAULT)

	parent := xcgui.HXCGUI(hwnd)
	//button
	btn := xcgui.XBtnCreate(10, 5, 80, 22, "关闭", parent)
	xcgui.XBtnSetType(btn, xcgui.BUTTON_TYPE_CLOSE)
	//监听btn事件
	xcgui.XEleRegEventC(btn, xcgui.XE_BNCLICK, syscall.NewCallback(OnBtnClick))
	//label
	lb := xcgui.XShapeTextCreate(50, 100, 100, 22, "hello world!", parent)
	xcgui.XShapeTextSetText(lb, "hello 世界!")
	xcgui.XShapeTextSetTextColor(lb, 0xff0000, 255)

	//取text及长度
	str := xcgui.XShapeTextGetTextGo(lb)
	fmt.Println(str)
	fmt.Println(xcgui.XShapeTextGetTextLength(lb))

	xcgui.XWndShowWindow(hwnd, xcgui.SW_SHOW)
	xcgui.XRunXCGUI()
	xcgui.XExitXCGUI()
}
예제 #6
0
func init() {
	wc = &wndclassex{
		style:         cs_dblclks,
		hInstance:     hProcess,
		hIcon:         hiApp,
		hIconSm:       hiLogo,
		hCursor:       hcArrow,
		hbrBackground: 15 + 1,
		lpszClassName: uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("oswnd"))),
		lpfnWndProc: syscall.NewCallback(func(hWnd, uMsg, wParam, lParam uintptr) uintptr {
			wnd, ok := wndMap[hWnd]
			if ok {
				mh, ok := wnd.msgHandlers[uMsg]
				if ok {
					ret := mh(wParam, lParam)
					if !ret {
						return 0
					}
				}
			}
			ret, _, _ := syscall.Syscall6(defWindowProc, 4, hWnd, uMsg, wParam, lParam, 0, 0)
			return ret
		}),
	}
	wc.cbSize = uint32(unsafe.Sizeof(*wc))
	syscall.Syscall(registerClassEx, 1, uintptr(unsafe.Pointer(wc)), 0, 0)
}
예제 #7
0
func TestReturnAfterStackGrowInCallback(t *testing.T) {

	const src = `
#include <stdint.h>
#include <windows.h>

typedef uintptr_t __stdcall (*callback)(uintptr_t);

uintptr_t cfunc(callback f, uintptr_t n) {
   uintptr_t r;
   r = f(n);
   SetLastError(333);
   return r;
}
`
	tmpdir, err := ioutil.TempDir("", "TestReturnAfterStackGrowInCallback")
	if err != nil {
		t.Fatal("TempDir failed: ", err)
	}
	defer os.RemoveAll(tmpdir)

	srcname := "mydll.c"
	err = ioutil.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0)
	if err != nil {
		t.Fatal(err)
	}
	outname := "mydll.dll"
	cmd := exec.Command("gcc", "-shared", "-s", "-Werror", "-o", outname, srcname)
	cmd.Dir = tmpdir
	out, err := cmd.CombinedOutput()
	if err != nil {
		t.Fatalf("failed to build dll: %v - %v", err, string(out))
	}
	dllpath := filepath.Join(tmpdir, outname)

	dll := syscall.MustLoadDLL(dllpath)
	defer dll.Release()

	proc := dll.MustFindProc("cfunc")

	cb := syscall.NewCallback(func(n uintptr) uintptr {
		forceStackCopy()
		return n
	})

	// Use a new goroutine so that we get a small stack.
	type result struct {
		r   uintptr
		err syscall.Errno
	}
	c := make(chan result)
	go func() {
		r, _, err := proc.Call(cb, 100)
		c <- result{r, err.(syscall.Errno)}
	}()
	want := result{r: 100, err: 333}
	if got := <-c; got != want {
		t.Errorf("got %d want %d", got, want)
	}
}
func OnCreate(hwnd HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
	// TODO:
	// compilecallback: function must have one output parameter
	// any idea?
	SetTimer(hwnd, ID_TIMER, 1000, syscall.NewCallback(TimerProc))
	return 0
}
예제 #9
0
func NewLineEdit(parent IContainer) (*LineEdit, os.Error) {
	if parent == nil {
		return nil, newError("parent cannot be nil")
	}

	if lineEditSubclassWndProcCallback == nil {
		lineEditSubclassWndProcCallback = syscall.NewCallback(lineEditSubclassWndProc, 4+4+4+4)
		lineEditSubclassWndProcPtr = uintptr(lineEditSubclassWndProcCallback.ExtFnEntry())
	}

	hWnd := CreateWindowEx(
		WS_EX_CLIENTEDGE, syscall.StringToUTF16Ptr("EDIT"), nil,
		ES_AUTOHSCROLL|WS_CHILD|WS_TABSTOP|WS_VISIBLE,
		0, 0, 120, 24, parent.Handle(), 0, 0, nil)
	if hWnd == 0 {
		return nil, lastError("CreateWindowEx")
	}

	lineEditOrigWndProcPtr = uintptr(SetWindowLong(hWnd, GWL_WNDPROC, int(lineEditSubclassWndProcPtr)))
	if lineEditOrigWndProcPtr == 0 {
		return nil, lastError("SetWindowLong")
	}

	le := &LineEdit{Widget: Widget{hWnd: hWnd, parent: parent}}
	le.SetFont(defaultFont)

	widgetsByHWnd[hWnd] = le

	parent.Children().Add(le)

	return le, nil
}
예제 #10
0
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_CREATE] = OnCreate
	table[WM_DESTROY] = OnDestroy

	initWindow("Beeper2", "Beeper2 Timer Demo", syscall.NewCallback(WndProc))
}
예제 #11
0
//Register WndClass
func RegisterClass() {
	var wndProcPtr uintptr = syscall.NewCallback(formProc)
	hInst := GetModuleHandle(nil)
	if hInst == 0 {
		println("error")
		panic("GetModuleHandle")
	}
	hIcon := LoadIcon(0, (*uint16)(unsafe.Pointer(uintptr(IDI_APPLICATION))))
	if hIcon == 0 {
		println("error")
		panic("LoadIcon")
	}
	hCursor := LoadCursor(0, (*uint16)(unsafe.Pointer(uintptr(IDC_ARROW))))
	if hCursor == 0 {
		println("error")
		panic("LoadCursor")
	}
	var wc WNDCLASSEX
	wc.CbSize = uint32(unsafe.Sizeof(wc))
	wc.LpfnWndProc = wndProcPtr
	wc.HInstance = hInst
	wc.HIcon = hIcon
	wc.HCursor = hCursor
	wc.HbrBackground = COLOR_BTNFACE + 1
	wc.LpszClassName = toTEXT(f.name)
	if atom := RegisterClassEx(&wc); atom == 0 {
		println("error")
		panic("RegisterClassEx")
	}
	hProc = HWND(SetWindowLong(f.hWnd, GWL_WNDPROC, int32(wndProcPtr)))
}
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_SIZE] = OnSize
	table[WM_DESTROY] = OnDestroy

	initWindow("RandRect", "Random Rectangles", syscall.NewCallback(WndProc))
}
예제 #13
0
func main() {

	app, _ := NewApp()
	app.On(WM_COMMAND, func(hwnd HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
		switch int32((LOWORD(uint32(wParam)))) {
		case IDM_APP_ABOUT:
			DialogBox(app.HInstance, _T("AboutBox"), hwnd, syscall.NewCallback(func(hDlg HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
				switch msg {
				case WM_INITDIALOG:
					return TRUE

				case WM_COMMAND:
					switch int32(LOWORD(uint32(wParam))) {
					case IDCANCEL, IDOK:
						EndDialog(hDlg, 0)
						return TRUE
					}
				}
				return 0
			}))
		}
		return 0
	})

	app.On(WM_DESTROY, func(hwnd HWND, msg uint32, wParam, lParam uintptr) (result uintptr) {
		PostQuitMessage(0)
		return 0
	})

	app.MenuName = _T("About1")
	app.Init("About1", "About Box Demo Program")
	app.Run()
}
예제 #14
0
func main() {
	hInstance, e := wingui.GetModuleHandle(nil)
	if e != nil {
		wingui.AbortErrNo("GetModuleHandle", e)
	}

	cef.ExecuteProcess(unsafe.Pointer(hInstance))

	settings := cef.Settings{}
	settings.CachePath = "webcache"                // Set to empty to disable
	settings.LogSeverity = cef.LOGSEVERITY_DEFAULT // LOGSEVERITY_VERBOSE
	cef.Initialize(settings)

	wndproc := syscall.NewCallback(WndProc)
	Logger.Println("CreateWindow")
	hwnd := wingui.CreateWindow("cef2go example", wndproc)

	browserSettings := cef.BrowserSettings{}
	// TODO: It should be executable's directory used
	// rather than working directory.
	url, _ := os.Getwd()
	url = "file://" + url + "/example.html"
	cef.CreateBrowser(unsafe.Pointer(hwnd), browserSettings, url)

	// 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(hwnd))
	})

	cef.RunMessageLoop()
	cef.Shutdown()
	os.Exit(0)
}
func TestCallbackWithNoInputParameters(t *testing.T) {
	// Test that NewCallback and NewCallbackCDecl can accept functions without
	// input parameters, see issue 9871.
	cb := func() uintptr { return 0 }
	_ = syscall.NewCallback(cb)
	_ = syscall.NewCallbackCDecl(cb)
}
예제 #16
0
파일: screen.go 프로젝트: rdterner/exp
func initScreenWindow() (err error) {
	swc, err := syscall.UTF16PtrFromString(screenWindowClass)
	if err != nil {
		return err
	}
	emptyString, err := syscall.UTF16PtrFromString("")
	if err != nil {
		return err
	}
	wc := _WNDCLASS{
		LpszClassName: swc,
		LpfnWndProc:   syscall.NewCallback(screenWindowWndProc),
		HIcon:         hDefaultIcon,
		HCursor:       hDefaultCursor,
		HInstance:     hThisInstance,
		HbrBackground: syscall.Handle(_COLOR_BTNFACE + 1),
	}
	_, err = _RegisterClass(&wc)
	if err != nil {
		return err
	}
	screenHWND, err = _CreateWindowEx(0,
		swc, emptyString,
		_WS_OVERLAPPEDWINDOW,
		_CW_USEDEFAULT, _CW_USEDEFAULT,
		_CW_USEDEFAULT, _CW_USEDEFAULT,
		_HWND_MESSAGE, 0, hThisInstance, 0)
	if err != nil {
		return err
	}
	return nil
}
예제 #17
0
func init() {
	webViewIOleClientSiteVtbl = &IOleClientSiteVtbl{
		syscall.NewCallback(webView_IOleClientSite_QueryInterface),
		syscall.NewCallback(webView_IOleClientSite_AddRef),
		syscall.NewCallback(webView_IOleClientSite_Release),
		syscall.NewCallback(webView_IOleClientSite_SaveObject),
		syscall.NewCallback(webView_IOleClientSite_GetMoniker),
		syscall.NewCallback(webView_IOleClientSite_GetContainer),
		syscall.NewCallback(webView_IOleClientSite_ShowObject),
		syscall.NewCallback(webView_IOleClientSite_OnShowWindow),
		syscall.NewCallback(webView_IOleClientSite_RequestNewObjectLayout),
	}
}
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_CREATE] = OnCreate
	table[WM_PAINT] = OnPaint
	table[WM_DESTROY] = OnDestroy

	initWindow("WhatSize", "What Size is the Window?", syscall.NewCallback(WndProc))
}
예제 #19
0
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_SIZE] = OnSize
	table[WM_PAINT] = OnPaint
	table[WM_DESTROY] = OnDestroy

	initWindow("AltWind", "Alternate and Winding Fill Modes", syscall.NewCallback(WndProc))
}
예제 #20
0
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_SIZE] = OnSize
	table[WM_PAINT] = OnPaint
	table[WM_DESTROY] = OnDestroy

	initWindow("Clover", "Draw a Clover", syscall.NewCallback(WndProc))
}
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_CREATE] = OnCreate
	table[WM_PAINT] = OnPaint
	table[WM_DESTROY] = OnDestroy

	initWindow("DevCaps1", "Device Capabilities", syscall.NewCallback(WndProc))
}
예제 #22
0
func main() {
	ole.CoInitialize(0)

	unknown, _ := oleutil.CreateObject("{248DD896-BB45-11CF-9ABC-0080C7E7B78D}")
	winsock, _ := unknown.QueryInterface(ole.IID_IDispatch)
	iid, _ := ole.CLSIDFromString("{248DD893-BB45-11CF-9ABC-0080C7E7B78D}")

	dest := &EventReceiver{}
	dest.lpVtbl = &EventReceiverVtbl{}
	dest.lpVtbl.pQueryInterface = syscall.NewCallback(QueryInterface)
	dest.lpVtbl.pAddRef = syscall.NewCallback(AddRef)
	dest.lpVtbl.pRelease = syscall.NewCallback(Release)
	dest.lpVtbl.pGetTypeInfoCount = syscall.NewCallback(GetTypeInfoCount)
	dest.lpVtbl.pGetTypeInfo = syscall.NewCallback(GetTypeInfo)
	dest.lpVtbl.pGetIDsOfNames = syscall.NewCallback(GetIDsOfNames)
	dest.lpVtbl.pInvoke = syscall.NewCallback(Invoke)
	dest.host = winsock

	oleutil.ConnectObject(winsock, iid, (*ole.IUnknown)(unsafe.Pointer(dest)))
	_, err := oleutil.CallMethod(winsock, "Connect", "127.0.0.1", 80)
	if err != nil {
		log.Fatal(err)
	}

	var m ole.Msg
	for dest.ref != 0 {
		ole.GetMessage(&m, 0, 0, 0)
		ole.DispatchMessage(&m)
	}
}
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_LBUTTONDOWN] = OnLeftButtonDown
	table[WM_SIZE] = OnSize
	table[WM_PAINT] = OnPaint
	table[WM_DESTROY] = OnDestroy

	initWindow("Checker1", "Checker1 Mouse Hit-Test Demo", syscall.NewCallback(WndProc))
}
예제 #24
0
파일: aapi.go 프로젝트: CodyGuo/xcgui
func CallBackGo(pFunc func()) uintptr {
	var pfunc = func() int {
		pFunc()

		return 0
	}

	return syscall.NewCallback(pfunc)
}
예제 #25
0
파일: user32.go 프로젝트: Xustyx/w32
func SetWindowsHookEx(idHook int, lpfn HOOKPROC, hMod HINSTANCE, dwThreadId DWORD) HHOOK {
	ret, _, _ := procSetWindowsHookEx.Call(
		uintptr(idHook),
		uintptr(syscall.NewCallback(lpfn)),
		uintptr(hMod),
		uintptr(dwThreadId),
	)
	return HHOOK(ret)
}
예제 #26
0
func init() {
	gWindows = make(map[w32.HWND]*Window)
	gClasses = make([]string, 0)
	gGeneralCallback = syscall.NewCallback(WndProc)
	gAppInstance = w32.GetModuleHandle("")
	if gAppInstance == 0 {
		panic("could not get app instance")
	}
}
예제 #27
0
func registerServiceCtrlHandlerEx(serviceName string, handler interface{}) SERVICE_STATUS_HANDLE {
	ret, _, _ := procRegisterServiceCtrlHandlerEx.Call(
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(serviceName))),
		syscall.NewCallback(handler),
		0,
	)

	return SERVICE_STATUS_HANDLE(ret)
}
예제 #28
0
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_LBUTTONDOWN] = OnLeftButtonDown
	table[WM_LBUTTONUP] = OnLeftButtonUp
	table[WM_MOUSEMOVE] = OnMouseMove
	table[WM_PAINT] = OnPaint
	table[WM_DESTROY] = OnDestroy

	initWindow("Connect", "Connect-the-Points Mouse Demo", syscall.NewCallback(WndProc))
}
예제 #29
0
func (test *cbTest) run(t *testing.T, dllpath string) {
	dll := syscall.MustLoadDLL(dllpath)
	defer dll.Release()
	cb := cbFuncs[test.n]
	stdcall := syscall.NewCallback(cb)
	f := cbDLLFunc(test.n)
	test.runOne(t, dll, f.stdcallName(), stdcall)
	cdecl := syscall.NewCallbackCDecl(cb)
	test.runOne(t, dll, f.cdeclName(), cdecl)
}
예제 #30
0
func main() {
	table = make(map[uint32]EventHandler)
	table[WM_CREATE] = OnCreate
	table[WM_SIZE] = OnSize
	table[WM_TIMER] = OnTimer
	table[WM_PAINT] = OnPaint
	table[WM_DESTROY] = OnDestroy

	initWindow("Clock", "Analog Clock", syscall.NewCallback(WndProc))
}