Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using custom icons with MainWindow? #236

Closed
tmm1 opened this issue Jan 27, 2017 · 6 comments
Closed

Using custom icons with MainWindow? #236

tmm1 opened this issue Jan 27, 2017 · 6 comments

Comments

@tmm1
Copy link
Contributor

tmm1 commented Jan 27, 2017

Apps appear to use the default system icon here:

walk/window.go

Line 334 in c5fab5f

hIcon := win.LoadIcon(0, (*uint16)(unsafe.Pointer(uintptr(win.IDI_APPLICATION))))

Is it possible to specify a custom icon? I am already embedding one with rsrc/goversioninfo but its not being used.

@tmm1
Copy link
Contributor Author

tmm1 commented Jan 27, 2017

Never mind, I misunderstood what IDI_APPLICATION means. Seems like this might be an issue with goversioninfo.

@tmm1 tmm1 closed this as completed Jan 27, 2017
@tmm1
Copy link
Contributor Author

tmm1 commented Jan 30, 2017

The SetIcon method on MainWindow lets you do this.

@tmm1
Copy link
Contributor Author

tmm1 commented Jan 30, 2017

I'm still having a hard time figuring this out.

In #157 (comment), it says:

What works for me is using the rsrc tool to embed an icon into the executable and call walk.NewIconFromResourceId to load it for usage as main window icon.

How do you find the correct resource id to load the icon?

@tmm1 tmm1 reopened this Jan 30, 2017
@lxn
Copy link
Owner

lxn commented Jan 30, 2017

There is an old issue on the rsrc repo, please read the text below the code block:
akavel/rsrc#5 (comment)

@tmm1
Copy link
Contributor Author

tmm1 commented Jan 30, 2017

Thanks. Looks like the ID is printed out when using rsrc now (but not by goversioninfo, but that uses the same code and IDs). You can also use pedump -R to list out the resources for an exe and find the ID that way.

Also remember to create the MainWindow before calling SetIcon on it. Something like:

MainWindow{
  AssignTo: &mainWindow,
}.Create()
mainWindow.SetIcon(icon)
mainWindow.Run()

@cyclamenkde
Copy link

package main

import (
"log"
"strings"

walk "github.com/lxn/walk"
. "github.com/lxn/walk/declarative"

)

func main() {
var inTE, outTE *walk.TextEdit
var mw *walk.MainWindow

icon, _ := walk.NewIconFromFile("favicon.ico")

if _, err := (MainWindow{
	AssignTo: &mw,
	Title:    "SCREAMO",
	MinSize:  Size{600, 400},
	Icon:     icon,
	Layout:   VBox{},
	Children: []Widget{
		HSplitter{
			Children: []Widget{
				TextEdit{AssignTo: &inTE},
				TextEdit{AssignTo: &outTE, ReadOnly: true},
			},
		},
		PushButton{
			Text: "SCREAM",
			OnClicked: func() {
				outTE.SetText(strings.ToUpper(inTE.Text()))
			},
		},
		PushButton{
			Text: "Click",
			OnClicked: func() {
				walk.MsgBox(mw, "hello", inTE.Text(), walk.MsgBoxIconInformation)
			},
		},
	},
}.Run()); err != nil {
	log.Fatal(err)
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants