tk2ico: Manipulate icons under Windows

tk2ico.createR Documentation

Manipulate icons under Windows

Description

Create, load and work with Windows icons. Change icons for Windows. These functions are only useful for Windows, but they silently return NULL on other platforms for writing compatible code (Windows icons instructions can be simply ignored).

Usage

tk2ico.create(iconfile, res = 0, size = 16)

tk2ico.destroy(icon)

tk2ico.list(file = "shell32.dll")

tk2ico.sizes(file = "shell32.dll", res = "application")

tk2ico.load(file = "shell32.dll", res = "application", size = 16)

tk2ico.setFromFile(win, iconfile)

tk2ico.set(win, icon)

Arguments

iconfile

A file with a .ico, or .exe extension, containing one or more Windows icons

res

The name of the resource from where the icon should be extracted.

size

Te size of the icon to use. For windows icons, 16 should be fine usually.

icon

A icon object.

file

A file having icon resources (.exe, or .dll).

win

A Tk window, or an integer representing the handle (HWND) of a foreign window whose icon will be changed (take care, the function returns TRUE even if the handle is wrong!

Value

An icon object, which is a reference to an image resource in Tcl. Its classes are c("tclObj", "tclIcon"). Do not forget to destroy it using tk2ico.destroy() when you do not need it any more! If tk2ico.load() fails, it returns NULL instead of a Tcl object.

Note

This is Windows-specific. It is implemented using the ico Tcl package.

Author(s)

Philippe Grosjean

See Also

tk2dde.exec(), tk2reg.get()

Examples

## Not run: 
# These cannot be run by examples() but should be OK when pasted
# into an interactive R session with the tcltk package loaded

### Examples of tk2ico - icon manipulation under Windows
tt2 <- tktoplevel()
# Load a system icon (there are: "application", "asterisk", "error",
# "exclamation", "hand", "question", "information", "warning", and "winlogo".
Warn <- tk2ico.load(res = "warning")
# Change the icon of my window tt2
tk2ico.set(tt2, Warn)
# Do not forget to destroy icon to free resource when not needed any more
tk2ico.destroy(Warn)
rm(Warn)

### Otherwise, the list of icons in a file are:
tk2ico.list()
# and for a given icon, the various sizes are:
tk2ico.sizes(res = 4)

### One can set icon of a window from an .ico or .exe file directly
tk2ico.setFromFile(tt, default = file.path(R.home("bin"), "Rgui.exe"))

tk2ico.setFromFile(tt2, system.file("gui", "SciViews.ico", package = "tcltk2"))

### When done, dispose of the window and clean the workspace
tkdestroy(tt2)
rm(tt2)

## End(Not run)

tcltk2 documentation built on June 8, 2025, 1:04 p.m.