当前位置: 首页>>代码示例>>Golang>>正文


Golang syscall.NewCallback函数代码示例

本文整理汇总了Golang中syscall.NewCallback函数的典型用法代码示例。如果您正苦于以下问题:Golang NewCallback函数的具体用法?Golang NewCallback怎么用?Golang NewCallback使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewCallback函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: MyRegisterClass

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)
}
开发者ID:mattn,项目名称:gyagowin,代码行数:32,代码来源:main.go

示例2: makeMessageHandler

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
}
开发者ID:UIKit0,项目名称:ui,代码行数:35,代码来源:uitask_windows.go

示例3: RegisterWindow

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
}
开发者ID:tnhu,项目名称:systray,代码行数:29,代码来源:tray_windows.go

示例4: New

func (m *DWebBrowserEvents2) New() {
	m.IDispatch.New()
	m.AddInterface(&DIID_DWebBrowserEvents2, m)
	m.AddMethod("DocumentComplete", DISPID_DOCUMENTCOMPLETE, syscall.NewCallback(func() HRESULT {
		return m.DocumentComplete()
	}))
}
开发者ID:axet,项目名称:desktop,代码行数:7,代码来源:desktop_win_systraybrowser.go

示例5: main

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()
}
开发者ID:henrylee2cn,项目名称:xcgui,代码行数:25,代码来源:hello.go

示例6: init

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)
}
开发者ID:yulon,项目名称:go-oswnd,代码行数:27,代码来源:window_windows.go

示例7: TestReturnAfterStackGrowInCallback

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)
	}
}
开发者ID:vinodpanicker,项目名称:go,代码行数:60,代码来源:syscall_windows_test.go

示例8: OnCreate

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
}
开发者ID:weimingtom,项目名称:ProgrammingWindowsWithGo,代码行数:7,代码来源:Beeper2.go

示例9: NewLineEdit

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
}
开发者ID:lalitjsraks,项目名称:walk,代码行数:32,代码来源:lineedit.go

示例10: main

func main() {
	table = make(map[uint32]EventHandler)
	table[WM_CREATE] = OnCreate
	table[WM_DESTROY] = OnDestroy

	initWindow("Beeper2", "Beeper2 Timer Demo", syscall.NewCallback(WndProc))
}
开发者ID:weimingtom,项目名称:ProgrammingWindowsWithGo,代码行数:7,代码来源:Beeper2.go

示例11: RegisterClass

//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)))
}
开发者ID:jumbycc,项目名称:GolangOnWindows,代码行数:32,代码来源:form.go

示例12: main

func main() {
	table = make(map[uint32]EventHandler)
	table[WM_SIZE] = OnSize
	table[WM_DESTROY] = OnDestroy

	initWindow("RandRect", "Random Rectangles", syscall.NewCallback(WndProc))
}
开发者ID:weimingtom,项目名称:ProgrammingWindowsWithGo,代码行数:7,代码来源:RandRect.go

示例13: main

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()
}
开发者ID:weimingtom,项目名称:ProgrammingWindowsWithGo,代码行数:33,代码来源:About1.go

示例14: main

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)
}
开发者ID:Doflatango,项目名称:cef2go,代码行数:34,代码来源:main_windows.go

示例15: TestCallbackWithNoInputParameters

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)
}
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:7,代码来源:syscall_windows_test.go


注:本文中的syscall.NewCallback函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。