Test win32 api
This commit is contained in:
parent
492dcdf86f
commit
041bb7cbbb
8 changed files with 547 additions and 401 deletions
|
@ -44,6 +44,10 @@ func NewDictionary(prealloc int) Dictionary {
|
||||||
return make(Dictionary, prealloc)
|
return make(Dictionary, prealloc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (interpreter *Interpreter) SetGraphicContext(gc draw2d.GraphicContext) {
|
||||||
|
interpreter.gc = gc
|
||||||
|
}
|
||||||
|
|
||||||
func (interpreter *Interpreter) GetGraphicContext() draw2d.GraphicContext {
|
func (interpreter *Interpreter) GetGraphicContext() draw2d.GraphicContext {
|
||||||
return interpreter.gc
|
return interpreter.gc
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ func arc(interpreter *Interpreter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func clippath(interpreter *Interpreter) {
|
func clippath(interpreter *Interpreter) {
|
||||||
log.Printf("clippath not yet implemented")
|
//log.Printf("clippath not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func stroke(interpreter *Interpreter) {
|
func stroke(interpreter *Interpreter) {
|
||||||
|
@ -198,9 +198,9 @@ func setcmybcolor(interpreter *Interpreter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func setdash(interpreter *Interpreter) {
|
func setdash(interpreter *Interpreter) {
|
||||||
offset := interpreter.PopInt()
|
interpreter.PopInt() // offset
|
||||||
dash := interpreter.PopArray()
|
interpreter.PopArray() // dash
|
||||||
log.Printf("setdash not yet implemented dash: %v, offset: %d \n", dash, offset)
|
//log.Printf("setdash not yet implemented dash: %v, offset: %d \n", dash, offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
func setlinejoin(interpreter *Interpreter) {
|
func setlinejoin(interpreter *Interpreter) {
|
||||||
|
@ -229,7 +229,7 @@ func setlinecap(interpreter *Interpreter) {
|
||||||
|
|
||||||
func setmiterlimit(interpreter *Interpreter) {
|
func setmiterlimit(interpreter *Interpreter) {
|
||||||
interpreter.PopInt()
|
interpreter.PopInt()
|
||||||
log.Printf("setmiterlimit not yet implemented")
|
//log.Printf("setmiterlimit not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func setlinewidth(interpreter *Interpreter) {
|
func setlinewidth(interpreter *Interpreter) {
|
||||||
|
@ -237,7 +237,7 @@ func setlinewidth(interpreter *Interpreter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func showpage(interpreter *Interpreter) {
|
func showpage(interpreter *Interpreter) {
|
||||||
log.Printf("showpage may be an implementation specific, override show page to generate multi page images")
|
//log.Printf("showpage may be an implementation specific, override show page to generate multi page images")
|
||||||
}
|
}
|
||||||
|
|
||||||
func show(interpreter *Interpreter) {
|
func show(interpreter *Interpreter) {
|
||||||
|
@ -275,12 +275,12 @@ func stringwidth(interpreter *Interpreter) {
|
||||||
|
|
||||||
func setflat(interpreter *Interpreter) {
|
func setflat(interpreter *Interpreter) {
|
||||||
interpreter.Pop()
|
interpreter.Pop()
|
||||||
log.Printf("setflat not yet implemented")
|
//log.Printf("setflat not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
func currentflat(interpreter *Interpreter) {
|
func currentflat(interpreter *Interpreter) {
|
||||||
interpreter.Push(1.0)
|
interpreter.Push(1.0)
|
||||||
log.Printf("currentflat not yet implemented")
|
//log.Printf("currentflat not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Coordinate System and Matrix operators
|
// Coordinate System and Matrix operators
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
package postscript
|
package postscript
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
//"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
//proc bind proc Replace operator names in proc with operators; perform idiom recognition
|
//proc bind proc Replace operator names in proc with operators; perform idiom recognition
|
||||||
|
@ -19,7 +19,7 @@ func bind(interpreter *Interpreter) {
|
||||||
v, _ := interpreter.FindValueInDictionaries(s)
|
v, _ := interpreter.FindValueInDictionaries(s)
|
||||||
operator, isOperator := v.(Operator)
|
operator, isOperator := v.(Operator)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
log.Printf("Can't find def: %s\n", s)
|
// log.Printf("Can't find def: %s\n", s)
|
||||||
}
|
}
|
||||||
if isOperator {
|
if isOperator {
|
||||||
values[i] = operator
|
values[i] = operator
|
||||||
|
|
|
@ -1,61 +1,41 @@
|
||||||
// Copyright 2011 The Go Authors. All rights reserved.
|
// Copyright 2011 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build windows
|
||||||
|
|
||||||
package wingui
|
package wingui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func abortf(format string, a ...interface{}) {
|
|
||||||
fmt.Fprintf(os.Stdout, format, a...)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadDll(fname string) uint32 {
|
|
||||||
h, e := syscall.LoadLibrary(fname)
|
|
||||||
if e != 0 {
|
|
||||||
abortf("LoadLibrary(%s) failed with err=%d.\n", fname, e)
|
|
||||||
}
|
|
||||||
return h
|
|
||||||
}
|
|
||||||
|
|
||||||
func getSysProcAddr(m uint32, pname string) uintptr {
|
|
||||||
p, e := syscall.GetProcAddress(m, pname)
|
|
||||||
if e != 0 {
|
|
||||||
abortf("GetProcAddress(%s) failed with err=%d.\n", pname, e)
|
|
||||||
}
|
|
||||||
return uintptr(p)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Wndclassex struct {
|
type Wndclassex struct {
|
||||||
Size uint32
|
Size uint32
|
||||||
Style uint32
|
Style uint32
|
||||||
WndProc uintptr
|
WndProc uintptr
|
||||||
ClsExtra int32
|
ClsExtra int32
|
||||||
WndExtra int32
|
WndExtra int32
|
||||||
Instance uint32
|
Instance syscall.Handle
|
||||||
Icon uint32
|
Icon syscall.Handle
|
||||||
Cursor uint32
|
Cursor syscall.Handle
|
||||||
Background uint32
|
Background syscall.Handle
|
||||||
MenuName *uint16
|
MenuName *uint16
|
||||||
ClassName *uint16
|
ClassName *uint16
|
||||||
IconSm uint32
|
IconSm syscall.Handle
|
||||||
}
|
}
|
||||||
|
|
||||||
type Point struct {
|
type Point struct {
|
||||||
X int32
|
X uintptr
|
||||||
Y int32
|
Y uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
type Msg struct {
|
type Msg struct {
|
||||||
Hwnd uint32
|
Hwnd syscall.Handle
|
||||||
Message uint32
|
Message uint32
|
||||||
Wparam int32
|
Wparam uintptr
|
||||||
Lparam int32
|
Lparam uintptr
|
||||||
Time uint32
|
Time uint32
|
||||||
Pt Point
|
Pt Point
|
||||||
}
|
}
|
||||||
|
@ -102,7 +82,7 @@ const (
|
||||||
// Some button control styles
|
// Some button control styles
|
||||||
BS_DEFPUSHBUTTON = 1
|
BS_DEFPUSHBUTTON = 1
|
||||||
|
|
||||||
// Some colour constants
|
// Some color constants
|
||||||
COLOR_WINDOW = 5
|
COLOR_WINDOW = 5
|
||||||
COLOR_BTNFACE = 15
|
COLOR_BTNFACE = 15
|
||||||
|
|
||||||
|
@ -114,13 +94,13 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Some globaly known cusrors
|
// Some globally known cursors
|
||||||
IDC_ARROW = MakeIntResource(32512)
|
IDC_ARROW = MakeIntResource(32512)
|
||||||
IDC_IBEAM = MakeIntResource(32513)
|
IDC_IBEAM = MakeIntResource(32513)
|
||||||
IDC_WAIT = MakeIntResource(32514)
|
IDC_WAIT = MakeIntResource(32514)
|
||||||
IDC_CROSS = MakeIntResource(32515)
|
IDC_CROSS = MakeIntResource(32515)
|
||||||
|
|
||||||
// Some globaly known icons
|
// Some globally known icons
|
||||||
IDI_APPLICATION = MakeIntResource(32512)
|
IDI_APPLICATION = MakeIntResource(32512)
|
||||||
IDI_HAND = MakeIntResource(32513)
|
IDI_HAND = MakeIntResource(32513)
|
||||||
IDI_QUESTION = MakeIntResource(32514)
|
IDI_QUESTION = MakeIntResource(32514)
|
||||||
|
@ -132,22 +112,22 @@ var (
|
||||||
IDI_INFORMATION = IDI_ASTERISK
|
IDI_INFORMATION = IDI_ASTERISK
|
||||||
)
|
)
|
||||||
|
|
||||||
//sys GetModuleHandle(modname *uint16) (handle uint32, errno int) = GetModuleHandleW
|
//sys GetModuleHandle(modname *uint16) (handle syscall.Handle, err error) = GetModuleHandleW
|
||||||
//sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) = user32.RegisterClassExW
|
//sys RegisterClassEx(wndclass *Wndclassex) (atom uint16, err error) = 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 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, err error) = user32.CreateWindowExW
|
||||||
//sys DefWindowProc(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.DefWindowProcW
|
//sys DefWindowProc(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.DefWindowProcW
|
||||||
//sys DestroyWindow(hwnd uint32) (errno int) = user32.DestroyWindow
|
//sys DestroyWindow(hwnd syscall.Handle) (err error) = user32.DestroyWindow
|
||||||
//sys PostQuitMessage(exitcode int32) = user32.PostQuitMessage
|
//sys PostQuitMessage(exitcode int32) = user32.PostQuitMessage
|
||||||
//sys ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) = user32.ShowWindow
|
//sys ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) = user32.ShowWindow
|
||||||
//sys UpdateWindow(hwnd uint32) (errno int) = user32.UpdateWindow
|
//sys UpdateWindow(hwnd syscall.Handle) (err error) = user32.UpdateWindow
|
||||||
//sys GetMessage(msg *Msg, hwnd uint32, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, errno int) [failretval==-1] = user32.GetMessageW
|
//sys GetMessage(msg *Msg, hwnd syscall.Handle, MsgFilterMin uint32, MsgFilterMax uint32) (ret int32, err error) [failretval==-1] = user32.GetMessageW
|
||||||
//sys TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage
|
//sys TranslateMessage(msg *Msg) (done bool) = user32.TranslateMessage
|
||||||
//sys DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
|
//sys DispatchMessage(msg *Msg) (ret int32) = user32.DispatchMessageW
|
||||||
//sys LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) = user32.LoadIconW
|
//sys LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, err error) = user32.LoadIconW
|
||||||
//sys LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) = user32.LoadCursorW
|
//sys LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, err error) = user32.LoadCursorW
|
||||||
//sys SetCursor(cursor uint32) (precursor uint32, errno int) = user32.SetCursor
|
//sys SetCursor(cursor syscall.Handle) (precursor syscall.Handle, err error) = user32.SetCursor
|
||||||
//sys SendMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (lresult int32) = user32.SendMessageW
|
//sys SendMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (lresult uintptr) = user32.SendMessageW
|
||||||
//sys PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) = user32.PostMessageW
|
//sys PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (err error) = user32.PostMessageW
|
||||||
|
|
||||||
func MakeIntResource(id uint16) *uint16 {
|
func MakeIntResource(id uint16) *uint16 {
|
||||||
return (*uint16)(unsafe.Pointer(uintptr(id)))
|
return (*uint16)(unsafe.Pointer(uintptr(id)))
|
||||||
|
|
|
@ -9,11 +9,26 @@ const (
|
||||||
WM_PAINT = 15
|
WM_PAINT = 15
|
||||||
|
|
||||||
BI_RGB = 0
|
BI_RGB = 0
|
||||||
|
BI_BITFIELDS = 3
|
||||||
|
|
||||||
DIB_PAL_COLORS = 1
|
DIB_PAL_COLORS = 1
|
||||||
DIB_RGB_COLORS = 0
|
DIB_RGB_COLORS = 0
|
||||||
|
|
||||||
|
BLACKNESS = 0x42
|
||||||
|
DSTINVERT = 0x550009
|
||||||
|
MERGECOPY = 0xC000CA
|
||||||
|
MERGEPAINT = 0xBB0226
|
||||||
|
NOTSRCCOPY = 0x330008
|
||||||
|
NOTSRCERASE = 0x1100A6
|
||||||
|
PATCOPY = 0xF00021
|
||||||
|
PATINVERT = 0x5A0049
|
||||||
|
PATPAINT = 0xFB0A09
|
||||||
|
SRCAND = 0x8800C6
|
||||||
SRCCOPY = 0xCC0020
|
SRCCOPY = 0xCC0020
|
||||||
|
SRCERASE = 0x440328
|
||||||
|
SRCINVERT = 0x660046
|
||||||
|
SRCPAINT = 0xEE0086
|
||||||
|
WHITENESS = 0xFF0062
|
||||||
)
|
)
|
||||||
|
|
||||||
type RECT struct {
|
type RECT struct {
|
||||||
|
@ -24,7 +39,7 @@ type RECT struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PAINTSTRUCT struct {
|
type PAINTSTRUCT struct {
|
||||||
HDC uint32
|
HDC syscall.Handle
|
||||||
Erase int32 // bool
|
Erase int32 // bool
|
||||||
RcPaint RECT
|
RcPaint RECT
|
||||||
Restore int32 // bool
|
Restore int32 // bool
|
||||||
|
@ -69,64 +84,64 @@ type RGBQUAD struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
modgdi32 = loadDll("gdi32.dll")
|
modgdi32 = syscall.NewLazyDLL("gdi32.dll")
|
||||||
|
|
||||||
procGetDC = getSysProcAddr(moduser32, "GetDC")
|
procGetDC = moduser32.NewProc("GetDC")
|
||||||
procCreateCompatibleDC = getSysProcAddr(modgdi32, "CreateCompatibleDC")
|
procCreateCompatibleDC = modgdi32.NewProc("CreateCompatibleDC")
|
||||||
procGetObject = getSysProcAddr(modgdi32, "GetObjectW")
|
procGetObject = modgdi32.NewProc("GetObjectW")
|
||||||
procSelectObject = getSysProcAddr(modgdi32, "SelectObject")
|
procSelectObject = modgdi32.NewProc("SelectObject")
|
||||||
procBeginPaint = getSysProcAddr(moduser32, "BeginPaint")
|
procBeginPaint = moduser32.NewProc("BeginPaint")
|
||||||
procEndPaint = getSysProcAddr(moduser32, "EndPaint")
|
procEndPaint = moduser32.NewProc("EndPaint")
|
||||||
procCreateCompatibleBitmap = getSysProcAddr(modgdi32, "CreateCompatibleBitmap")
|
procCreateCompatibleBitmap = modgdi32.NewProc("CreateCompatibleBitmap")
|
||||||
procCreateDIBSection = getSysProcAddr(modgdi32, "CreateDIBSection")
|
procCreateDIBSection = modgdi32.NewProc("CreateDIBSection")
|
||||||
procBitBlt = getSysProcAddr(modgdi32, "BitBlt")
|
procBitBlt = modgdi32.NewProc("BitBlt")
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetDC(hwnd uint32) (hdc uint32) {
|
func GetDC(hwnd syscall.Handle) (hdc syscall.Handle) {
|
||||||
r0, _, _ := syscall.Syscall(procGetDC, 1, uintptr(hwnd), 0, 0)
|
r0, _, _ := syscall.Syscall(procGetDC.Addr(), 1, uintptr(hwnd), 0, 0)
|
||||||
hdc = uint32(r0)
|
hdc = syscall.Handle(r0)
|
||||||
return hdc
|
return hdc
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateCompatibleDC(hwnd uint32) (hdc uint32) {
|
func CreateCompatibleDC(hwnd syscall.Handle) (hdc syscall.Handle) {
|
||||||
r0, _, _ := syscall.Syscall(procCreateCompatibleDC, 1, uintptr(hwnd), 0, 0)
|
r0, _, _ := syscall.Syscall(procCreateCompatibleDC.Addr(), 1, uintptr(hwnd), 0, 0)
|
||||||
hdc = uint32(r0)
|
hdc = syscall.Handle(r0)
|
||||||
return hdc
|
return hdc
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetObject(hgdiobj uint32, cbBuffer int, object uintptr) (size uint32) {
|
func GetObject(hgdiobj syscall.Handle, cbBuffer uintptr, object uintptr) (size uint32) {
|
||||||
r0, _, _ := syscall.Syscall(procGetObject, 3, uintptr(hgdiobj), uintptr(cbBuffer), object)
|
r0, _, _ := syscall.Syscall(procGetObject.Addr(), 3, uintptr(hgdiobj), uintptr(cbBuffer), object)
|
||||||
size = uint32(r0)
|
size = uint32(r0)
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
func SelectObject(hdc uint32, hgdiobj uint32) uint32 {
|
func SelectObject(hdc syscall.Handle, hgdiobj syscall.Handle) syscall.Handle {
|
||||||
r0, _, _ := syscall.Syscall(procSelectObject, 2, uintptr(hdc), uintptr(hgdiobj), 0)
|
r0, _, _ := syscall.Syscall(procSelectObject.Addr(), 2, uintptr(hdc), uintptr(hgdiobj), 0)
|
||||||
return uint32(r0)
|
return syscall.Handle(r0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BeginPaint(hwnd uint32, ps *PAINTSTRUCT) (hdc uint32) {
|
func BeginPaint(hwnd syscall.Handle, ps *PAINTSTRUCT) (hdc syscall.Handle){
|
||||||
r0, _, _ := syscall.Syscall(procBeginPaint, 2, uintptr(hwnd), uintptr(unsafe.Pointer(ps)), 0)
|
r0, _, _ := syscall.Syscall(procBeginPaint.Addr(), 2, uintptr(hwnd), uintptr(unsafe.Pointer(ps)), 0)
|
||||||
hdc = uint32(r0)
|
hdc = syscall.Handle(r0)
|
||||||
return hdc
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func EndPaint(hwnd uint32, ps *PAINTSTRUCT) bool {
|
func EndPaint(hwnd syscall.Handle, ps *PAINTSTRUCT) bool {
|
||||||
syscall.Syscall(procEndPaint, 2, uintptr(hwnd), uintptr(unsafe.Pointer(ps)), 0)
|
syscall.Syscall(procEndPaint.Addr(), 2, uintptr(hwnd), uintptr(unsafe.Pointer(ps)), 0)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateCompatibleBitmap(hdc uint32, width, height int) (hbitmap uint32) {
|
func CreateCompatibleBitmap(hdc syscall.Handle, width, height uintptr) (hbitmap syscall.Handle) {
|
||||||
r0, _, _ := syscall.Syscall(procCreateCompatibleBitmap, 3, uintptr(hdc), uintptr(width), uintptr(height))
|
r0, _, _ := syscall.Syscall(procCreateCompatibleBitmap.Addr(), 3, uintptr(hdc), uintptr(width), uintptr(height))
|
||||||
return uint32(r0)
|
return syscall.Handle(r0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDIBSection(hdc uint32, pbmi *BITMAPINFO, iUsage uint, ppvBits uintptr, hSection uint32, dwOffset uint32) (hbitmap uint32) {
|
func CreateDIBSection(hdc syscall.Handle, pbmi *BITMAPINFO, iUsage uint, ppvBits uintptr, hSection uint32, dwOffset uint32) (hbitmap syscall.Handle) {
|
||||||
r0, _, _ := syscall.Syscall6(procCreateDIBSection, 6, uintptr(hdc), uintptr(unsafe.Pointer(pbmi)), uintptr(iUsage), ppvBits, uintptr(hSection), uintptr(dwOffset))
|
r0, _, _ := syscall.Syscall6(procCreateDIBSection.Addr(), 6, uintptr(hdc), uintptr(unsafe.Pointer(pbmi)), uintptr(iUsage), ppvBits, uintptr(hSection), uintptr(dwOffset))
|
||||||
return uint32(r0)
|
return syscall.Handle(r0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BitBlt(hdc uint32, nXDest, nYDest, nWidth, nHeight int, hdcSrc uint32, nXSrc, nYSrc int, dwRop uint32) bool {
|
func BitBlt(hdc syscall.Handle, nXDest, nYDest, nWidth, nHeight int, hdcSrc syscall.Handle, nXSrc, nYSrc int, dwRop uint32) bool {
|
||||||
r0, _, _ := syscall.Syscall9(procBitBlt, 9, uintptr(hdc), uintptr(nXDest), uintptr(nYDest), uintptr(nWidth), uintptr(nHeight), uintptr(hdcSrc), uintptr(nXSrc), uintptr(nYSrc), uintptr(dwRop))
|
r0, _, _ := syscall.Syscall9(procBitBlt.Addr(), 9, uintptr(hdc), uintptr(nXDest), uintptr(nYDest), uintptr(nWidth), uintptr(nHeight), uintptr(hdcSrc), uintptr(nXSrc), uintptr(nYSrc), uintptr(dwRop))
|
||||||
return r0 != 0
|
return r0 != 0
|
||||||
}
|
}
|
||||||
|
|
151
wingui/wintest/wintest.go
Normal file
151
wingui/wintest/wintest.go
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"unsafe"
|
||||||
|
. "code.google.com/p/draw2d/wingui"
|
||||||
|
)
|
||||||
|
|
||||||
|
// some help functions
|
||||||
|
|
||||||
|
func abortf(format string, a ...interface{}) {
|
||||||
|
fmt.Fprintf(os.Stdout, format, a...)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func abortErrNo(funcname string, err error) {
|
||||||
|
errno, _ := err.(syscall.Errno)
|
||||||
|
abortf("%s failed: %d %s\n", funcname, uint32(errno), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// global vars
|
||||||
|
|
||||||
|
var (
|
||||||
|
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 syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintptr) {
|
||||||
|
_ = make([]int, 100000)
|
||||||
|
switch msg {
|
||||||
|
case WM_CREATE:
|
||||||
|
var e error
|
||||||
|
// CreateWindowEx
|
||||||
|
bh, e = CreateWindowEx(
|
||||||
|
0,
|
||||||
|
syscall.StringToUTF16Ptr("button"),
|
||||||
|
syscall.StringToUTF16Ptr("Quit"),
|
||||||
|
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
|
||||||
|
75, 70, 140, 25,
|
||||||
|
hwnd, 1, mh, 0)
|
||||||
|
if e != nil {
|
||||||
|
abortErrNo("CreateWindowEx", e)
|
||||||
|
}
|
||||||
|
fmt.Printf("button handle is %x\n", bh)
|
||||||
|
rc = DefWindowProc(hwnd, msg, wparam, lparam)
|
||||||
|
case WM_COMMAND:
|
||||||
|
switch syscall.Handle(lparam) {
|
||||||
|
case bh:
|
||||||
|
e := PostMessage(hwnd, WM_CLOSE, 0, 0)
|
||||||
|
if e != nil {
|
||||||
|
abortErrNo("PostMessage", e)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
rc = DefWindowProc(hwnd, msg, wparam, lparam)
|
||||||
|
}
|
||||||
|
case WM_CLOSE:
|
||||||
|
DestroyWindow(hwnd)
|
||||||
|
case WM_DESTROY:
|
||||||
|
PostQuitMessage(0)
|
||||||
|
default:
|
||||||
|
rc = DefWindowProc(hwnd, msg, wparam, lparam)
|
||||||
|
}
|
||||||
|
//fmt.Printf("WndProc(0x%08x, %d, 0x%08x, 0x%08x) (%d)\n", hwnd, msg, wparam, lparam, rc)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func rungui() int {
|
||||||
|
var e error
|
||||||
|
|
||||||
|
// GetModuleHandle
|
||||||
|
mh, e = GetModuleHandle(nil)
|
||||||
|
if e != nil {
|
||||||
|
abortErrNo("GetModuleHandle", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get icon we're going to use.
|
||||||
|
myicon, e := LoadIcon(0, IDI_APPLICATION)
|
||||||
|
if e != nil {
|
||||||
|
abortErrNo("LoadIcon", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get cursor we're going to use.
|
||||||
|
mycursor, e := LoadCursor(0, IDC_ARROW)
|
||||||
|
if e != nil {
|
||||||
|
abortErrNo("LoadCursor", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create callback
|
||||||
|
wproc := syscall.NewCallback(WndProc)
|
||||||
|
|
||||||
|
// RegisterClassEx
|
||||||
|
wcname := syscall.StringToUTF16Ptr("myWindowClass")
|
||||||
|
var wc Wndclassex
|
||||||
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
|
wc.WndProc = wproc
|
||||||
|
wc.Instance = mh
|
||||||
|
wc.Icon = myicon
|
||||||
|
wc.Cursor = mycursor
|
||||||
|
wc.Background = COLOR_BTNFACE + 1
|
||||||
|
wc.MenuName = nil
|
||||||
|
wc.ClassName = wcname
|
||||||
|
wc.IconSm = myicon
|
||||||
|
if _, e := RegisterClassEx(&wc); e != nil {
|
||||||
|
abortErrNo("RegisterClassEx", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateWindowEx
|
||||||
|
wh, e := CreateWindowEx(
|
||||||
|
WS_EX_CLIENTEDGE,
|
||||||
|
wcname,
|
||||||
|
syscall.StringToUTF16Ptr("My window"),
|
||||||
|
WS_OVERLAPPEDWINDOW,
|
||||||
|
CW_USEDEFAULT, CW_USEDEFAULT, 300, 200,
|
||||||
|
0, 0, mh, 0)
|
||||||
|
if e != nil {
|
||||||
|
abortErrNo("CreateWindowEx", e)
|
||||||
|
}
|
||||||
|
fmt.Printf("main window handle is %x\n", wh)
|
||||||
|
|
||||||
|
// ShowWindow
|
||||||
|
ShowWindow(wh, SW_SHOWDEFAULT)
|
||||||
|
|
||||||
|
// UpdateWindow
|
||||||
|
if e := UpdateWindow(wh); e != nil {
|
||||||
|
abortErrNo("UpdateWindow", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process all windows messages until WM_QUIT.
|
||||||
|
var m Msg
|
||||||
|
for {
|
||||||
|
r, e := GetMessage(&m, 0, 0, 0)
|
||||||
|
if e != nil {
|
||||||
|
abortErrNo("GetMessage", e)
|
||||||
|
}
|
||||||
|
if r == 0 {
|
||||||
|
// WM_QUIT received -> get out
|
||||||
|
break
|
||||||
|
}
|
||||||
|
TranslateMessage(&m)
|
||||||
|
DispatchMessage(&m)
|
||||||
|
}
|
||||||
|
return int(m.Wparam)
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
rc := rungui()
|
||||||
|
os.Exit(rc)
|
||||||
|
}
|
|
@ -6,14 +6,14 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.google.com/p/draw2d/draw2d"
|
"code.google.com/p/draw2d/draw2d"
|
||||||
"code.google.com/p/draw2d/postscript"
|
|
||||||
"code.google.com/p/draw2d/wingui"
|
"code.google.com/p/draw2d/wingui"
|
||||||
|
"code.google.com/p/draw2d/postscript"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/color"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"image/color"
|
||||||
"strings"
|
"strings"
|
||||||
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
@ -26,8 +26,8 @@ func abortf(format string, a ...interface{}) {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func abortErrNo(funcname string, err int) {
|
func abortErrNo(funcname string, err error) {
|
||||||
abortf("%s failed: %d %s\n", funcname, err, syscall.Errstr(err))
|
abortf("%s failed: %d %s\n", funcname, err, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// global vars
|
// global vars
|
||||||
|
@ -39,13 +39,13 @@ func TestDrawCubicCurve(gc draw2d.GraphicContext) {
|
||||||
x2, y2 := 153.6, 25.6
|
x2, y2 := 153.6, 25.6
|
||||||
x3, y3 := 230.4, 128.0
|
x3, y3 := 230.4, 128.0
|
||||||
|
|
||||||
gc.SetFillColor(color.NRGBA{0xAA, 0xAA, 0xAA, 0xFF})
|
gc.SetStrokeColor(color.NRGBA{0, 0, 0, 0xFF})
|
||||||
gc.SetLineWidth(10)
|
gc.SetLineWidth(10)
|
||||||
gc.MoveTo(x, y)
|
gc.MoveTo(x, y)
|
||||||
gc.CubicCurveTo(x1, y1, x2, y2, x3, y3)
|
gc.CubicCurveTo(x1, y1, x2, y2, x3, y3)
|
||||||
gc.Stroke()
|
gc.Stroke()
|
||||||
|
|
||||||
gc.SetStrokeColor(color.NRGBA{0xFF, 0x33, 0x33, 0x88})
|
gc.SetStrokeColor(color.NRGBA{0xFF, 0, 0, 0xFF})
|
||||||
|
|
||||||
gc.SetLineWidth(6)
|
gc.SetLineWidth(6)
|
||||||
// draw segment of curve
|
// draw segment of curve
|
||||||
|
@ -56,20 +56,35 @@ func TestDrawCubicCurve(gc draw2d.GraphicContext) {
|
||||||
gc.Stroke()
|
gc.Stroke()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DrawTiger(gc draw2d.GraphicContext){
|
||||||
|
if postscriptContent == "" {
|
||||||
|
src, err := os.OpenFile("../../resource/postscript/tiger.ps", 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("can't find postscript file.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer src.Close()
|
||||||
|
bytes, err := ioutil.ReadAll(src)
|
||||||
|
postscriptContent = string(bytes)
|
||||||
|
}
|
||||||
|
interpreter := postscript.NewInterpreter(gc)
|
||||||
|
reader := strings.NewReader(postscriptContent)
|
||||||
|
interpreter.Execute(reader)
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
mh uint32
|
mh syscall.Handle
|
||||||
wndBufferHeader uint32
|
hdcWndBuffer syscall.Handle
|
||||||
|
wndBufferHeader syscall.Handle
|
||||||
wndBuffer wingui.BITMAP
|
wndBuffer wingui.BITMAP
|
||||||
hdcWndBuffer uint32
|
ppvBits *uint8
|
||||||
ppvBits *color.RGBA
|
|
||||||
backBuffer *image.RGBA
|
backBuffer *image.RGBA
|
||||||
postscriptContent string
|
postscriptContent string
|
||||||
)
|
)
|
||||||
|
|
||||||
// WinProc called by windows to notify us of all windows events we might be interested in.
|
// 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 {
|
func WndProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) (rc uintptr) {
|
||||||
var rc int32
|
_ = make([]int, 100000)
|
||||||
|
|
||||||
switch msg {
|
switch msg {
|
||||||
case wingui.WM_CREATE:
|
case wingui.WM_CREATE:
|
||||||
hdc := wingui.GetDC(hwnd)
|
hdc := wingui.GetDC(hwnd)
|
||||||
|
@ -102,35 +117,41 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
|
||||||
hdcWndBuffer = wingui.CreateCompatibleDC(hdc)
|
hdcWndBuffer = wingui.CreateCompatibleDC(hdc)
|
||||||
wingui.SelectObject(hdcWndBuffer, wndBufferHeader)
|
wingui.SelectObject(hdcWndBuffer, wndBufferHeader)
|
||||||
|
|
||||||
pixel := (*[600 * 800]color.RGBA)(unsafe.Pointer(ppvBits))
|
pixel := (*[600 * 800 * 4]uint8)(unsafe.Pointer(ppvBits))
|
||||||
pixelSlice := pixel[:]
|
pixelSlice := pixel[:]
|
||||||
backBuffer = &image.RGBA{pixelSlice, 600, image.Rect(0, 0, 600, 800)}
|
backBuffer = &image.RGBA{pixelSlice, 4*600, image.Rect(0, 0, 600, 800)}
|
||||||
fmt.Println("Create windows")
|
fmt.Println("Create windows")
|
||||||
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
||||||
case wingui.WM_COMMAND:
|
case wingui.WM_COMMAND:
|
||||||
switch uint32(lparam) {
|
switch syscall.Handle(lparam) {
|
||||||
default:
|
default:
|
||||||
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
||||||
}
|
}
|
||||||
case wingui.WM_PAINT:
|
case wingui.WM_PAINT:
|
||||||
var ps wingui.PAINTSTRUCT
|
var ps wingui.PAINTSTRUCT
|
||||||
lastTime := time.Now()
|
|
||||||
hdc := wingui.BeginPaint(hwnd, &ps)
|
hdc := wingui.BeginPaint(hwnd, &ps)
|
||||||
|
t := time.Now()
|
||||||
gc := draw2d.NewGraphicContext(backBuffer)
|
gc := draw2d.NewGraphicContext(backBuffer)
|
||||||
gc.SetFillColor(color.RGBA{0xFF, 0xFF, 0xFF, 0xFF})
|
/*gc.SetFillColor(color.RGBA{0xFF, 0xFF, 0xFF, 0xFF})
|
||||||
// gc.Clear()
|
gc.Clear()*/
|
||||||
|
for i := 0; i < len(backBuffer.Pix); i+=1 {
|
||||||
|
backBuffer.Pix[i] = 0xff
|
||||||
|
}
|
||||||
gc.Save()
|
gc.Save()
|
||||||
//gc.Translate(0, -380)
|
//gc.Translate(0, -380)
|
||||||
interpreter := postscript.NewInterpreter(gc)
|
DrawTiger(gc)
|
||||||
reader := strings.NewReader(postscriptContent)
|
|
||||||
interpreter.Execute(reader)
|
|
||||||
dt := time.Now().Sub(lastTime)
|
|
||||||
gc.Restore()
|
gc.Restore()
|
||||||
// back buf in
|
// back buf in
|
||||||
|
var tmp uint8
|
||||||
|
for i := 0; i < len(backBuffer.Pix); i+=4 {
|
||||||
|
tmp = backBuffer.Pix[i]
|
||||||
|
backBuffer.Pix[i] = backBuffer.Pix[i+2]
|
||||||
|
backBuffer.Pix[i+2] = tmp
|
||||||
|
}
|
||||||
wingui.BitBlt(hdc, 0, 0, int(wndBuffer.Width), int(wndBuffer.Height), hdcWndBuffer, 0, 0, wingui.SRCCOPY)
|
wingui.BitBlt(hdc, 0, 0, int(wndBuffer.Width), int(wndBuffer.Height), hdcWndBuffer, 0, 0, wingui.SRCCOPY)
|
||||||
wingui.EndPaint(hwnd, &ps)
|
wingui.EndPaint(hwnd, &ps)
|
||||||
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
||||||
|
dt := time.Now().Sub(t)
|
||||||
fmt.Printf("Redraw in : %f ms\n", float64(dt)*1e-6)
|
fmt.Printf("Redraw in : %f ms\n", float64(dt)*1e-6)
|
||||||
case wingui.WM_CLOSE:
|
case wingui.WM_CLOSE:
|
||||||
wingui.DestroyWindow(hwnd)
|
wingui.DestroyWindow(hwnd)
|
||||||
|
@ -139,27 +160,27 @@ func WndProc(hwnd, msg uint32, wparam, lparam int32) uintptr {
|
||||||
default:
|
default:
|
||||||
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
rc = wingui.DefWindowProc(hwnd, msg, wparam, lparam)
|
||||||
}
|
}
|
||||||
return uintptr(rc)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func rungui() int {
|
func rungui() int {
|
||||||
var e int
|
var e error
|
||||||
|
|
||||||
// GetModuleHandle
|
// GetModuleHandle
|
||||||
mh, e = wingui.GetModuleHandle(nil)
|
mh, e = wingui.GetModuleHandle(nil)
|
||||||
if e != 0 {
|
if e != nil {
|
||||||
abortErrNo("GetModuleHandle", e)
|
abortErrNo("GetModuleHandle", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get icon we're going to use.
|
// Get icon we're going to use.
|
||||||
myicon, e := wingui.LoadIcon(0, wingui.IDI_APPLICATION)
|
myicon, e := wingui.LoadIcon(0, wingui.IDI_APPLICATION)
|
||||||
if e != 0 {
|
if e != nil {
|
||||||
abortErrNo("LoadIcon", e)
|
abortErrNo("LoadIcon", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get cursor we're going to use.
|
// Get cursor we're going to use.
|
||||||
mycursor, e := wingui.LoadCursor(0, wingui.IDC_ARROW)
|
mycursor, e := wingui.LoadCursor(0, wingui.IDC_ARROW)
|
||||||
if e != 0 {
|
if e != nil {
|
||||||
abortErrNo("LoadCursor", e)
|
abortErrNo("LoadCursor", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,19 +188,18 @@ func rungui() int {
|
||||||
wproc := syscall.NewCallback(WndProc)
|
wproc := syscall.NewCallback(WndProc)
|
||||||
|
|
||||||
// RegisterClassEx
|
// RegisterClassEx
|
||||||
wcname := syscall.StringToUTF16Ptr("Test Draw2d")
|
wcname := syscall.StringToUTF16Ptr("myWindowClass")
|
||||||
var wc wingui.Wndclassex
|
var wc wingui.Wndclassex
|
||||||
wc.Size = uint32(unsafe.Sizeof(wc))
|
wc.Size = uint32(unsafe.Sizeof(wc))
|
||||||
wc.WndProc = wproc
|
wc.WndProc = wproc
|
||||||
//wc.Style = wingui.CS_HREDRAW | wingui.CS_VREDRAW
|
|
||||||
wc.Instance = mh
|
wc.Instance = mh
|
||||||
wc.Icon = myicon
|
wc.Icon = myicon
|
||||||
wc.Cursor = mycursor
|
wc.Cursor = mycursor
|
||||||
wc.Background = 0
|
wc.Background = wingui.COLOR_BTNFACE + 1
|
||||||
wc.MenuName = nil
|
wc.MenuName = nil
|
||||||
wc.ClassName = wcname
|
wc.ClassName = wcname
|
||||||
wc.IconSm = myicon
|
wc.IconSm = myicon
|
||||||
if _, e := wingui.RegisterClassEx(&wc); e != 0 {
|
if _, e := wingui.RegisterClassEx(&wc); e != nil {
|
||||||
abortErrNo("RegisterClassEx", e)
|
abortErrNo("RegisterClassEx", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +211,7 @@ func rungui() int {
|
||||||
wingui.WS_OVERLAPPEDWINDOW,
|
wingui.WS_OVERLAPPEDWINDOW,
|
||||||
wingui.CW_USEDEFAULT, wingui.CW_USEDEFAULT, 600, 800,
|
wingui.CW_USEDEFAULT, wingui.CW_USEDEFAULT, 600, 800,
|
||||||
0, 0, mh, 0)
|
0, 0, mh, 0)
|
||||||
if e != 0 {
|
if e != nil {
|
||||||
abortErrNo("CreateWindowEx", e)
|
abortErrNo("CreateWindowEx", e)
|
||||||
}
|
}
|
||||||
fmt.Printf("main window handle is %x\n", wh)
|
fmt.Printf("main window handle is %x\n", wh)
|
||||||
|
@ -200,7 +220,7 @@ func rungui() int {
|
||||||
wingui.ShowWindow(wh, wingui.SW_SHOWDEFAULT)
|
wingui.ShowWindow(wh, wingui.SW_SHOWDEFAULT)
|
||||||
|
|
||||||
// UpdateWindow
|
// UpdateWindow
|
||||||
if e := wingui.UpdateWindow(wh); e != 0 {
|
if e := wingui.UpdateWindow(wh); e != nil {
|
||||||
abortErrNo("UpdateWindow", e)
|
abortErrNo("UpdateWindow", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +228,7 @@ func rungui() int {
|
||||||
var m wingui.Msg
|
var m wingui.Msg
|
||||||
for {
|
for {
|
||||||
r, e := wingui.GetMessage(&m, 0, 0, 0)
|
r, e := wingui.GetMessage(&m, 0, 0, 0)
|
||||||
if e != 0 {
|
if e != nil {
|
||||||
abortErrNo("GetMessage", e)
|
abortErrNo("GetMessage", e)
|
||||||
}
|
}
|
||||||
if r == 0 {
|
if r == 0 {
|
||||||
|
@ -222,14 +242,6 @@ func rungui() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
src, err := os.OpenFile("../resource/postscript/tiger.ps", 0, 0)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("can't find postscript file.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer src.Close()
|
|
||||||
bytes, err := ioutil.ReadAll(src)
|
|
||||||
postscriptContent = string(bytes)
|
|
||||||
rc := rungui()
|
rc := rungui()
|
||||||
os.Exit(rc)
|
os.Exit(rc)
|
||||||
}
|
}
|
|
@ -1,208 +1,192 @@
|
||||||
|
// +build windows
|
||||||
|
// mksyscall_windows.pl winapi.go
|
||||||
|
// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||||
|
|
||||||
package wingui
|
package wingui
|
||||||
|
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
import "syscall"
|
import "syscall"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
modkernel32 = loadDll("kernel32.dll")
|
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||||
moduser32 = loadDll("user32.dll")
|
moduser32 = syscall.NewLazyDLL("user32.dll")
|
||||||
|
|
||||||
procGetModuleHandleW = getSysProcAddr(modkernel32, "GetModuleHandleW")
|
procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW")
|
||||||
procRegisterClassExW = getSysProcAddr(moduser32, "RegisterClassExW")
|
procRegisterClassExW = moduser32.NewProc("RegisterClassExW")
|
||||||
procCreateWindowExW = getSysProcAddr(moduser32, "CreateWindowExW")
|
procCreateWindowExW = moduser32.NewProc("CreateWindowExW")
|
||||||
procDefWindowProcW = getSysProcAddr(moduser32, "DefWindowProcW")
|
procDefWindowProcW = moduser32.NewProc("DefWindowProcW")
|
||||||
procDestroyWindow = getSysProcAddr(moduser32, "DestroyWindow")
|
procDestroyWindow = moduser32.NewProc("DestroyWindow")
|
||||||
procPostQuitMessage = getSysProcAddr(moduser32, "PostQuitMessage")
|
procPostQuitMessage = moduser32.NewProc("PostQuitMessage")
|
||||||
procShowWindow = getSysProcAddr(moduser32, "ShowWindow")
|
procShowWindow = moduser32.NewProc("ShowWindow")
|
||||||
procUpdateWindow = getSysProcAddr(moduser32, "UpdateWindow")
|
procUpdateWindow = moduser32.NewProc("UpdateWindow")
|
||||||
procGetMessageW = getSysProcAddr(moduser32, "GetMessageW")
|
procGetMessageW = moduser32.NewProc("GetMessageW")
|
||||||
procTranslateMessage = getSysProcAddr(moduser32, "TranslateMessage")
|
procTranslateMessage = moduser32.NewProc("TranslateMessage")
|
||||||
procDispatchMessageW = getSysProcAddr(moduser32, "DispatchMessageW")
|
procDispatchMessageW = moduser32.NewProc("DispatchMessageW")
|
||||||
procLoadIconW = getSysProcAddr(moduser32, "LoadIconW")
|
procLoadIconW = moduser32.NewProc("LoadIconW")
|
||||||
procLoadCursorW = getSysProcAddr(moduser32, "LoadCursorW")
|
procLoadCursorW = moduser32.NewProc("LoadCursorW")
|
||||||
procSetCursor = getSysProcAddr(moduser32, "SetCursor")
|
procSetCursor = moduser32.NewProc("SetCursor")
|
||||||
procSendMessageW = getSysProcAddr(moduser32, "SendMessageW")
|
procSendMessageW = moduser32.NewProc("SendMessageW")
|
||||||
procPostMessageW = getSysProcAddr(moduser32, "PostMessageW")
|
procPostMessageW = moduser32.NewProc("PostMessageW")
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetModuleHandle(modname *uint16) (handle uint32, errno int) {
|
func GetModuleHandle(modname *uint16) (handle syscall.Handle, err error) {
|
||||||
r0, _, e1 := syscall.Syscall(procGetModuleHandleW, 1, uintptr(unsafe.Pointer(modname)), 0, 0)
|
r0, _, e1 := syscall.Syscall(procGetModuleHandleW.Addr(), 1, uintptr(unsafe.Pointer(modname)), 0, 0)
|
||||||
handle = uint32(r0)
|
handle = syscall.Handle(r0)
|
||||||
if handle == 0 {
|
if handle == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterClassEx(wndclass *Wndclassex) (atom uint16, errno int) {
|
func RegisterClassEx(wndclass *Wndclassex) (atom uint16, err error) {
|
||||||
r0, _, e1 := syscall.Syscall(procRegisterClassExW, 1, uintptr(unsafe.Pointer(wndclass)), 0, 0)
|
r0, _, e1 := syscall.Syscall(procRegisterClassExW.Addr(), 1, uintptr(unsafe.Pointer(wndclass)), 0, 0)
|
||||||
atom = uint16(r0)
|
atom = uint16(r0)
|
||||||
if atom == 0 {
|
if atom == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
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, err error) {
|
||||||
r0, _, e1 := syscall.Syscall12(procCreateWindowExW, 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))
|
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 hwnd == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
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, 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
|
r0, _, _ := syscall.Syscall6(procDefWindowProcW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
|
||||||
lresult = int32(r0)
|
lresult = uintptr(r0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DestroyWindow(hwnd uint32) (errno int) {
|
func DestroyWindow(hwnd syscall.Handle) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procDestroyWindow, 1, uintptr(hwnd), 0, 0)
|
r1, _, e1 := syscall.Syscall(procDestroyWindow.Addr(), 1, uintptr(hwnd), 0, 0)
|
||||||
if int(r1) == 0 {
|
if int(r1) == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostQuitMessage(exitcode int32) {
|
func PostQuitMessage(exitcode int32) {
|
||||||
syscall.Syscall(procPostQuitMessage, 1, uintptr(exitcode), 0, 0)
|
syscall.Syscall(procPostQuitMessage.Addr(), 1, uintptr(exitcode), 0, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowWindow(hwnd uint32, cmdshow int32) (wasvisible bool) {
|
func ShowWindow(hwnd syscall.Handle, cmdshow int32) (wasvisible bool) {
|
||||||
r0, _, _ := syscall.Syscall(procShowWindow, 2, uintptr(hwnd), uintptr(cmdshow), 0)
|
r0, _, _ := syscall.Syscall(procShowWindow.Addr(), 2, uintptr(hwnd), uintptr(cmdshow), 0)
|
||||||
wasvisible = bool(r0 != 0)
|
wasvisible = bool(r0 != 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateWindow(hwnd uint32) (errno int) {
|
func UpdateWindow(hwnd syscall.Handle) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall(procUpdateWindow, 1, uintptr(hwnd), 0, 0)
|
r1, _, e1 := syscall.Syscall(procUpdateWindow.Addr(), 1, uintptr(hwnd), 0, 0)
|
||||||
if int(r1) == 0 {
|
if int(r1) == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
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, err error) {
|
||||||
r0, _, e1 := syscall.Syscall6(procGetMessageW, 4, uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax), 0, 0)
|
r0, _, e1 := syscall.Syscall6(procGetMessageW.Addr(), 4, uintptr(unsafe.Pointer(msg)), uintptr(hwnd), uintptr(MsgFilterMin), uintptr(MsgFilterMax), 0, 0)
|
||||||
ret = int32(r0)
|
ret = int32(r0)
|
||||||
if ret == -1 {
|
if ret == -1 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func TranslateMessage(msg *Msg) (done bool) {
|
func TranslateMessage(msg *Msg) (done bool) {
|
||||||
r0, _, _ := syscall.Syscall(procTranslateMessage, 1, uintptr(unsafe.Pointer(msg)), 0, 0)
|
r0, _, _ := syscall.Syscall(procTranslateMessage.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0)
|
||||||
done = bool(r0 != 0)
|
done = bool(r0 != 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func DispatchMessage(msg *Msg) (ret int32) {
|
func DispatchMessage(msg *Msg) (ret int32) {
|
||||||
r0, _, _ := syscall.Syscall(procDispatchMessageW, 1, uintptr(unsafe.Pointer(msg)), 0, 0)
|
r0, _, _ := syscall.Syscall(procDispatchMessageW.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0)
|
||||||
ret = int32(r0)
|
ret = int32(r0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadIcon(instance uint32, iconname *uint16) (icon uint32, errno int) {
|
func LoadIcon(instance syscall.Handle, iconname *uint16) (icon syscall.Handle, err error) {
|
||||||
r0, _, e1 := syscall.Syscall(procLoadIconW, 2, uintptr(instance), uintptr(unsafe.Pointer(iconname)), 0)
|
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 icon == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadCursor(instance uint32, cursorname *uint16) (cursor uint32, errno int) {
|
func LoadCursor(instance syscall.Handle, cursorname *uint16) (cursor syscall.Handle, err error) {
|
||||||
r0, _, e1 := syscall.Syscall(procLoadCursorW, 2, uintptr(instance), uintptr(unsafe.Pointer(cursorname)), 0)
|
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 cursor == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetCursor(cursor uint32) (precursor uint32, errno int) {
|
func SetCursor(cursor syscall.Handle) (precursor syscall.Handle, err error) {
|
||||||
r0, _, e1 := syscall.Syscall(procSetCursor, 1, uintptr(cursor), 0, 0)
|
r0, _, e1 := syscall.Syscall(procSetCursor.Addr(), 1, uintptr(cursor), 0, 0)
|
||||||
precursor = uint32(r0)
|
precursor = syscall.Handle(r0)
|
||||||
if precursor == 0 {
|
if precursor == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
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, 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
|
r0, _, _ := syscall.Syscall6(procSendMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
|
||||||
lresult = int32(r0)
|
lresult = uintptr(r0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func PostMessage(hwnd uint32, msg uint32, wparam int32, lparam int32) (errno int) {
|
func PostMessage(hwnd syscall.Handle, msg uint32, wparam uintptr, lparam uintptr) (err error) {
|
||||||
r1, _, e1 := syscall.Syscall6(procPostMessageW, 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
|
r1, _, e1 := syscall.Syscall6(procPostMessageW.Addr(), 4, uintptr(hwnd), uintptr(msg), uintptr(wparam), uintptr(lparam), 0, 0)
|
||||||
if int(r1) == 0 {
|
if int(r1) == 0 {
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
errno = int(e1)
|
err = error(e1)
|
||||||
} else {
|
} else {
|
||||||
errno = syscall.EINVAL
|
err = syscall.EINVAL
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
errno = 0
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
Loading…
Reference in a new issue