本文整理汇总了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)
}
示例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
}
示例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
}
示例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()
}))
}
示例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()
}
示例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)
}
示例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)
}
}
示例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
}
示例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
}
示例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))
}
示例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)))
}
示例12: main
func main() {
table = make(map[uint32]EventHandler)
table[WM_SIZE] = OnSize
table[WM_DESTROY] = OnDestroy
initWindow("RandRect", "Random Rectangles", syscall.NewCallback(WndProc))
}
示例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()
}
示例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)
}
示例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)
}