summaryrefslogtreecommitdiff
path: root/stdfont_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-11 13:06:12 -0500
committerPietro Gagliardi <[email protected]>2014-02-11 13:06:12 -0500
commit42229820d2a47594f68d92356f8e8a86133a29f5 (patch)
tree3cd5deef283b4540bae2f75c049a5e69d4e9db20 /stdfont_windows.go
parenta488e3ab36de1d6a329110fbaae44cd5747c854b (diff)
Added _windows.go extensions to all the files in preparation for the library writing.
Diffstat (limited to 'stdfont_windows.go')
-rw-r--r--stdfont_windows.go74
1 files changed, 74 insertions, 0 deletions
diff --git a/stdfont_windows.go b/stdfont_windows.go
new file mode 100644
index 0000000..8dcba9f
--- /dev/null
+++ b/stdfont_windows.go
@@ -0,0 +1,74 @@
+// 10 february 2014
+package main
+
+import (
+// "syscall"
+ "unsafe"
+)
+
+const (
+ SPI_GETNONCLIENTMETRICS = 0x0029
+ LF_FACESIZE = 32 // from wingdi.h
+)
+
+type LOGFONT struct {
+ lfHeight int32
+ lfWidth int32
+ lfEscapement int32
+ lfOrientation int32
+ lfWeight int32
+ lfItalic byte
+ lfUnderline byte
+ lfStrikeOut byte
+ lfCharSet byte
+ lfOutPrecision byte
+ lfClipPrecision byte
+ lfQuality byte
+ lfPitchAndFamily byte
+ lfFaceName [LF_FACESIZE]uint16
+}
+
+type NONCLIENTMETRICS struct {
+ cbSize uint32
+ iBorderWidth int
+ iScrollWidth int
+ iScrollHeight int
+ iCaptionWidth int
+ iCaptionHeight int
+ lfCaptionFont LOGFONT
+ iSmCaptionWidth int
+ iSmCaptionHeight int
+ lfSmCaptionFont LOGFONT
+ iMenuWidth int
+ iMenuHeight int
+ lfMenuFont LOGFONT
+ lfStatusFont LOGFONT
+ lfMessageFont LOGFONT
+}
+
+var (
+ systemParametersInfo = user32.NewProc("SystemParametersInfoW")
+ createFontIndirect = gdi32.NewProc("CreateFontIndirectW")
+)
+
+// TODO adorn errors with which step failed?
+// TODO this specific font doesn't seem like the right one but that's all I could find for what people actually use; also I need to return the other ones and check HWND types to make sure I apply the right font to the right thing...
+func getStandardWindowFont() (hfont HANDLE, err error) {
+ var ncm NONCLIENTMETRICS
+
+ ncm.cbSize = uint32(unsafe.Sizeof(ncm))
+ r1, _, err := systemParametersInfo.Call(
+ uintptr(SPI_GETNONCLIENTMETRICS),
+ uintptr(unsafe.Sizeof(ncm)),
+ uintptr(unsafe.Pointer(&ncm)),
+ 0)
+ if r1 == 0 { // failure
+ return NULL, err
+ }
+ // TODO does this specify an error?
+ r1, _, err = createFontIndirect.Call(uintptr(unsafe.Pointer(&ncm.lfMessageFont)))
+ if r1 == 0 { // failure
+ return NULL, err
+ }
+ return HANDLE(r1), nil
+}