summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDmitry Bagdanov <dimbo_job@mail.ru>2019-05-02 23:25:42 +0700
committerDmitry Bagdanov <dimbo_job@mail.ru>2019-05-02 23:25:42 +0700
commitee5f647c5093bea60ef7d3cc105a7b896555f315 (patch)
tree741a2255d9e75412347bd7724a0add75435e1501
parentadd FontMemResource type which allows to load fonts from the application's resources (diff)
downloadwireguard-windows-ee5f647c5093bea60ef7d3cc105a7b896555f315.tar.xz
wireguard-windows-ee5f647c5093bea60ef7d3cc105a7b896555f315.zip
Rewrite implementation to much walk's approach
-rw-r--r--fontresource.go27
1 files changed, 21 insertions, 6 deletions
diff --git a/fontresource.go b/fontresource.go
index c50db637..61f90307 100644
--- a/fontresource.go
+++ b/fontresource.go
@@ -8,6 +8,7 @@ package walk
import (
"github.com/lxn/win"
+ "syscall"
)
// FontMemResource represents a font resource loaded into memory from
@@ -16,12 +17,10 @@ type FontMemResource struct {
hFontResource win.HANDLE
}
-// NewFontMemResource function loads a font resource from the executable's resources.
-// The font must be embedded into resources using corresponding operator in the
-// application's RC script.
-func NewFontMemResource(hModule win.HMODULE, resourceName *uint16) (*FontMemResource, error) {
+func newFontMemResource(resourceName *uint16) (*FontMemResource, error) {
+ hModule := win.HMODULE(win.GetModuleHandle(nil))
if hModule == win.HMODULE(0) {
- hModule = win.HMODULE(win.GetModuleHandle(nil))
+ return nil, lastError("GetModuleHandle")
}
hres := win.FindResource(hModule, resourceName, win.MAKEINTRESOURCE(8) /*RT_FONT*/)
@@ -54,10 +53,26 @@ func NewFontMemResource(hModule win.HMODULE, resourceName *uint16) (*FontMemReso
return &FontMemResource { hFontResource: hFontResource }, nil
}
+// NewFontMemResourceByName function loads a font resource from the executable's resources
+// using the resource name.
+// The font must be embedded into resources using corresponding operator in the
+// application's RC script.
+func NewFontMemResourceByName(name string) (*FontMemResource, error) {
+ return newFontMemResource(syscall.StringToUTF16Ptr(name))
+}
+
+// NewFontMemResourceById function loads a font resource from the executable's resources
+// using the resource ID.
+// The font must be embedded into resources using corresponding operator in the
+// application's RC script.
+func NewFontMemResourceById(id int) (*FontMemResource, error) {
+ return newFontMemResource(win.MAKEINTRESOURCE(uintptr(id)))
+}
+
// Dispose removes the font resource from memory
func (fmr *FontMemResource) Dispose() {
if fmr.hFontResource != 0 {
win.RemoveFontMemResourceEx(fmr.hFontResource)
fmr.hFontResource = 0
}
-} \ No newline at end of file
+}