1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:04:39 -07:00

exp/wingui: made compatible with windows/amd64

R=golang-dev, alex.brainman
CC=golang-dev, vcc.163
https://golang.org/cl/4974041
This commit is contained in:
Jaroslavas Počepko 2011-08-31 15:39:50 +10:00 committed by Alex Brainman
parent 7349d21f8e
commit 95429d82f1
6 changed files with 52 additions and 54 deletions

View File

@ -25,13 +25,12 @@ func abortErrNo(funcname string, err int) {
// global vars
var (
mh uint32
bh uint32
mh syscall.Handle
bh syscall.Handle
)
// WinProc called by windows to notify us of all windows events we might be interested in.
func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
var rc int32
func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintptr) {
switch msg {
case WM_CREATE:
var e int
@ -49,7 +48,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
fmt.Printf("button handle is %x\n", bh)
rc = DefWindowProc(hwnd, msg, wparam, lparam)
case WM_COMMAND:
switch uint32(lparam) {
switch syscall.Handle(lparam) {
case bh:
e := PostMessage(hwnd, WM_CLOSE, 0, 0)
if e != 0 {
@ -66,7 +65,7 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
rc = DefWindowProc(hwnd, msg, wparam, lparam)
}
//fmt.Printf("WndProc(0x%08x, %d, 0x%08x, 0x%08x) (%d)\n", hwnd, msg, wparam, lparam, rc)
return uintptr(rc)
return
}
func rungui() int {

View File

@ -6,6 +6,7 @@ package main
import (
"unsafe"
"syscall"
)
type Wndclassex struct {
@ -14,25 +15,25 @@ type Wndclassex struct {
WndProc uintptr
ClsExtra int32
WndExtra int32
Instance uint32
Icon uint32
Cursor uint32
Background uint32
Instance syscall.Handle
Icon syscall.Handle
Cursor syscall.Handle
Background syscall.Handle
MenuName *uint16
ClassName *uint16
IconSm uint32
IconSm syscall.Handle
}
type Point struct {
X int32
Y int32
X uintptr
Y uintptr
}
type Msg struct {
Hwnd uint32
Hwnd syscall.Handle
Message uint32
Wparam int32
Lparam int32
Wparam uintptr
Lparam uintptr
Time uint32
Pt Point
}
@ -109,22 +110,22 @@ var (
IDI_INFORMATION = IDI_ASTERISK
)
//sys GetModuleHandle(modname *uint16) (handle uint32, errno int) = GetModuleHandleW
//sys GetModuleHandle(modname *uint16) (handle syscall.Handle, errno int) = GetModuleHandleW
//sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) = user32.RegisterClassExW
//sys CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent uint32, menu uint32, instance uint32, param uintptr) (hwnd uint32, errno int) = user32.CreateWindowExW
//sys DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.DefWindowProcW
//sys DestroyWindow(hwnd uint32) (errno int) = user32.DestroyWindow
//sys CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent syscall.Handle, menu syscall.Handle, instance syscall.Handle, param uintptr) (hwnd syscall.Handle, errno int) = user32.CreateWindowExW
//sys DefWindowProc(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.DefWindowProcW
//sys DestroyWindow(hwnd syscall.Handle) (errno int) = user32.DestroyWindow
//sys PostQuitMessage(exitcode int32) = user32.PostQuitMessage
//sys ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) = user32.ShowWindow
//sys UpdateWindow(hwnd uint32) (errno int) = user32.UpdateWindow
//sys GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) [failretval==-1] = user32.GetMessageW
//sys ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) = user32.ShowWindow
//sys UpdateWindow(hwnd syscall.Handle) (errno int) = user32.UpdateWindow
//sys GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) [failretval==-1] = user32.GetMessageW
//sys TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage
//sys DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
//sys LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) = user32.LoadIconW
//sys LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) = user32.LoadCursorW
//sys SetCursor(cursor uint32) (precursor uint32, errno int) = user32.SetCursor
//sys SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.SendMessageW
//sys PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) = user32.PostMessageW
//sys LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, errno int) = user32.LoadIconW
//sys LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, errno int) = user32.LoadCursorW
//sys SetCursor(cursor syscall.Handle) (precursor syscall.Handle, errno int) = user32.SetCursor
//sys SendMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.SendMessageW
//sys PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (errno int) = user32.PostMessageW
func MakeIntResource(id uint16) *uint16 {
return (*uint16)(unsafe.Pointer(uintptr(id)))

View File

@ -28,9 +28,9 @@ var (
procPostMessageW = moduser32.NewProc("PostMessageW")
)
func GetModuleHandle(modname *uint16) (handle uint32, errno int) {
func GetModuleHandle(modname *uint16) (handle syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(modname)), 0, 0)
handle = uint32(r0)
handle = syscall.Handle(r0)
if handle == 0 {
if e1 != 0 {
errno = int(e1)
@ -58,9 +58,9 @@ func RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) {
return
}
func CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent uint32, menu uint32, instance uint32, param uintptr) (hwnd uint32, errno int) {
func CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style uint32, x int32, y int32, width int32, height int32, wndparent syscall.Handle, menu syscall.Handle, instance syscall.Handle, param uintptr) (hwnd syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall12(procCreateWindowExW.Addr(), 12, uintptr(exstyle), uintptr(unsafe.Pointer(classname)), uintptr(unsafe.Pointer(windowname)), uintptr(style), uintptr(x), uintptr(y), uintptr(width), uintptr(height), uintptr(wndparent), uintptr(menu), uintptr(instance), uintptr(param))
hwnd = uint32(r0)
hwnd = syscall.Handle(r0)
if hwnd == 0 {
if e1 != 0 {
errno = int(e1)
@ -73,13 +73,13 @@ func CreateWindowEx(exstyle uint32, classname *uint16, windowname *uint16, style
return
}
func DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) {
func DefWindowProc(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) {
r0, _, _ := syscall.Syscall6(procDefWindowProcW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
lresult = int32(r0)
lresult = uintptr(r0)
return
}
func DestroyWindow(hwnd uint32) (errno int) {
func DestroyWindow(hwnd syscall.Handle) (errno int) {
r1, _, e1 := syscall.Syscall(procDestroyWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
@ -98,13 +98,13 @@ func PostQuitMessage(exitcode int32) {
return
}
func ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) {
func ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) {
r0, _, _ := syscall.Syscall(procShowWindow.Addr(), 2, uintptr(hwnd), uintptr(cmdshow), 0)
wasvisible = bool(r0 != 0)
return
}
func UpdateWindow(hwnd uint32) (errno int) {
func UpdateWindow(hwnd syscall.Handle) (errno int) {
r1, _, e1 := syscall.Syscall(procUpdateWindow.Addr(), 1, uintptr(hwnd), 0, 0)
if int(r1) == 0 {
if e1 != 0 {
@ -118,7 +118,7 @@ func UpdateWindow(hwnd uint32) (errno int) {
return
}
func GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) {
func GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) {
r0, _, e1 := syscall.Syscall6(procGetMessageW.Addr(), 4, uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax), 0, 0)
ret = int32(r0)
if ret == -1 {
@ -145,9 +145,9 @@ func DispatchMessage(msg *Msg) (ret int32) {
return
}
func LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) {
func LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall(procLoadIconW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(iconname)), 0)
icon = uint32(r0)
icon = syscall.Handle(r0)
if icon == 0 {
if e1 != 0 {
errno = int(e1)
@ -160,9 +160,9 @@ func LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) {
return
}
func LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) {
func LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall(procLoadCursorW.Addr(), 2, uintptr(instance), uintptr(unsafe.Pointer(cursorname)), 0)
cursor = uint32(r0)
cursor = syscall.Handle(r0)
if cursor == 0 {
if e1 != 0 {
errno = int(e1)
@ -175,9 +175,9 @@ func LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int)
return
}
func SetCursor(cursor uint32) (precursor uint32, errno int) {
func SetCursor(cursor syscall.Handle) (precursor syscall.Handle, errno int) {
r0, _, e1 := syscall.Syscall(procSetCursor.Addr(), 1, uintptr(cursor), 0, 0)
precursor = uint32(r0)
precursor = syscall.Handle(r0)
if precursor == 0 {
if e1 != 0 {
errno = int(e1)
@ -190,13 +190,13 @@ func SetCursor(cursor uint32) (precursor uint32, errno int) {
return
}
func SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) {
func SendMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) {
r0, _, _ := syscall.Syscall6(procSendMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
lresult = int32(r0)
lresult = uintptr(r0)
return
}
func PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) {
func PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (errno int) {
r1, _, e1 := syscall.Syscall6(procPostMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
if int(r1) == 0 {
if e1 != 0 {

View File

@ -158,7 +158,7 @@ func NewCallback(fn interface{}) uintptr
//sys GetLastError() (lasterrno int)
//sys LoadLibrary(libname string) (handle Handle, errno int) = LoadLibraryW
//sys FreeLibrary(handle Handle) (errno int)
//sys GetProcAddress(module Handle, procname string) (proc Handle, errno int)
//sys GetProcAddress(module Handle, procname string) (proc uintptr, errno int)
//sys GetVersion() (ver uint32, errno int)
//sys FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, errno int) = FormatMessageW
//sys ExitProcess(exitcode uint32)

View File

@ -141,9 +141,8 @@ func FreeLibrary(handle Handle) (errno int) {
return
}
func GetProcAddress(module Handle, procname string) (proc Handle, errno int) {
r0, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0)
proc = Handle(r0)
func GetProcAddress(module Handle, procname string) (proc uintptr, errno int) {
proc, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0)
if proc == 0 {
if e1 != 0 {
errno = int(e1)

View File

@ -141,9 +141,8 @@ func FreeLibrary(handle Handle) (errno int) {
return
}
func GetProcAddress(module Handle, procname string) (proc Handle, errno int) {
r0, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0)
proc = Handle(r0)
func GetProcAddress(module Handle, procname string) (proc uintptr, errno int) {
proc, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(StringBytePtr(procname))), 0)
if proc == 0 {
if e1 != 0 {
errno = int(e1)