From 78c909cc9ba87abc759767c11b34a9cccf8ef34c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 30 May 2014 14:02:57 -0400 Subject: [PATCH] Added GetWindowLongPtr()/SetWindowLongPtr() generation to the windowsconstgen tool and the pregenerated files. This will be needed for when we get rid of creating a new window class for each Window/Area. Also did some minor cleanup to the windowsconstgen tool. --- tools/windowsconstgen.go | 26 ++++++++++++++++++++++++-- zconstants_windows_386.go | 2 ++ zconstants_windows_amd64.go | 2 ++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tools/windowsconstgen.go b/tools/windowsconstgen.go index 0617eb1..6be1b59 100644 --- a/tools/windowsconstgen.go +++ b/tools/windowsconstgen.go @@ -107,12 +107,31 @@ func preamble(pkg string) string { "package " + pkg + "\n" } +// for backwards compatibiilty reasons, Windows defines GetWindowLongPtr()/SetWindowLongPtr() as a macro which expands to GetWindowLong()/SetWindowLong() on 32-bit systems +// we'll just simulate that here +var gwlpNames = map[string]string{ + "386": "etWindowLong", + "amd64": "etWindowLongPtr", +} + +func printConst(f *os.File, goconst string, winconst string) { + fmt.Fprintf(f, " fmt.Println(\"const %s =\", C.%s)\n", goconst, winconst) +} + +func printGWLPName(f *os.File, which string, char string, targetarch string) { + fmt.Fprintf(f, " fmt.Println(\"var %s = user32.NewProc(\\\"%s\\\")\")\n", + which, char + gwlpNames[targetarch]) +} + func main() { if len(os.Args) < 3 { panic("usage: " + os.Args[0] + " path goarch [go-command-options...]") } pkgpath := os.Args[1] targetarch := os.Args[2] + if _, ok := gwlpNames[targetarch]; !ok { + panic("unknown target windows/" + targetarch) + } goopts := os.Args[3:] // valid if len(os.Args) == 3; in that case this will just be a slice of length zero pkg := getPackage(pkgpath) @@ -163,12 +182,15 @@ func main() { for _, ident := range consts { if ident[0] == 'x' { // hack name; strip the leading x (but not the _ after it) from the constant name but keep the value name unchanged - fmt.Fprintf(f, " fmt.Println(\"const %s =\", C.%s)\n", ident[1:], ident) + printConst(f, ident[1:], ident) continue } // not a hack name; strip the leading _ from the value name but keep the constant name unchanged - fmt.Fprintf(f, " fmt.Println(\"const %s =\", C.%s)\n", ident, ident[1:]) + printConst(f, ident, ident[1:]) } + // and now for _getWindowLongPtr/_setWindowLongPtr + printGWLPName(f, "_getWindowLongPtr", "G", targetarch) + printGWLPName(f, "_setWindowLongPtr", "S", targetarch) fmt.Fprintf(f, "}\n") f.Close() diff --git a/zconstants_windows_386.go b/zconstants_windows_386.go index 4427631..c1d88c2 100644 --- a/zconstants_windows_386.go +++ b/zconstants_windows_386.go @@ -162,3 +162,5 @@ const _IDC_ARROW = 32512 const _IDI_APPLICATION = 32512 const _INVALID_HANDLE_VALUE = 4294967295 const _NULL = 0 +var _getWindowLongPtr = user32.NewProc("GetWindowLong") +var _setWindowLongPtr = user32.NewProc("SetWindowLong") diff --git a/zconstants_windows_amd64.go b/zconstants_windows_amd64.go index 0274d3a..4d3c1c3 100644 --- a/zconstants_windows_amd64.go +++ b/zconstants_windows_amd64.go @@ -162,3 +162,5 @@ const _IDC_ARROW = 32512 const _IDI_APPLICATION = 32512 const _INVALID_HANDLE_VALUE = 18446744073709551615 const _NULL = 0 +var _getWindowLongPtr = user32.NewProc("GetWindowLongPtr") +var _setWindowLongPtr = user32.NewProc("SetWindowLongPtr")