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

Creating a layered Window #52

Open
duysqubix opened this issue Oct 10, 2023 · 1 comment
Open

Creating a layered Window #52

duysqubix opened this issue Oct 10, 2023 · 1 comment

Comments

@duysqubix
Copy link
Contributor

Im trying to create a layered (fully transparent Window) on Windows and I'm facing two issues:

  1. Is there some way to get the Pixel Window hwnd?
  2. If I use the hwnd manually it won't get layered aswell. Are my parameters correct?

Is there maybe something already build in to draw on a transparent Window?

package main

import (
	"github.com/Sann0/w32"
	"github.com/faiface/pixel"
	"github.com/faiface/pixel/pixelgl"
	"golang.org/x/image/colornames"
	"syscall"
)

var (
	moduser32					   = syscall.NewLazyDLL("user32.dll")
	procSetLayeredWindowAttributes = moduser32.NewProc("SetLayeredWindowAttributes")
)

func SetLayeredAttributes(hwnd w32.HWND, cr w32.COLORREF, alpha byte, flags uint32) bool {
	r0, _, _ := syscall.Syscall6(procSetLayeredWindowAttributes.Addr(), 4, uintptr(hwnd), uintptr(cr), uintptr(alpha), uintptr(flags), 0, 0)
	return r0 != 0
}

func initWindow() {
	cfg := pixelgl.WindowConfig{
		Title:  "Pixel",
		Bounds: pixel.R(0, 0, 1024, 768),
		VSync:  true,
		// Undecorated: true,
		// AlwaysOnTop: true,
	}
	win, err := pixelgl.NewWindow(cfg)
	if err != nil {
		panic(err)
	}
	// win.SetCursorDisabled()
	/*
	result := w32.SetWindowLong(w32.HWND(handle), w32.GWL_EXSTYLE, uint32(w32.GetWindowLong(w32.HWND(handle), w32.GWL_EXSTYLE)) | 0x00080000)
	fmt.Println(result)
	// (135, 206, 345) colornames.Skyblue
	result2 := SetLayeredAttributes(w32.HWND(handle), w32.COLORREF(uint32(135) | uint32(206) | uint32(235)), 0, 0x00000001)
	fmt.Println(result2)
	*/
	mainLoop(win)
}

func mainLoop(win *pixelgl.Window) {
	for !win.Closed() {
		win.Clear(colornames.Skyblue)
		win.Update()
	}
}

func main() {
	pixelgl.Run(initWindow)
}

 Original issue: https://github.com/faiface/pixel/issues/232
@dark-steveneq
Copy link

You want a transparent window? Just set TransparentFramebuffer to true in the window config

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

2 participants