Golang Directx screenshot ignore CreateWindowEx
Budget: $250 – $750 USD
Eu preciso de um modulo feito em golang que onde depois que eu criei um form com win.CreateWindowEx que ficara na frente de toda tela do usuario, eu consiga capturar com Directx todo o restante do windwos ignorando na captura o form criado pelo teu hWnd.
abaixo esta o exemplo de como estou criando o form que ficara na frente do usuario e que devera ser ignorado na captura
// ShowForm cria e exibe o formulário com a imagem de fundo
func ShowForm(img *image.RGBA, width int, height int) (syscall.Handle, error) {
// Criar janela
hInstance := win.GetModuleHandle(nil)
if hInstance == 0 {
return 0, fmt.Errorf("Failed to get module handle")
}
className, err := windows.UTF16PtrFromString("MyWin32Class")
if err != nil {
return 0, fmt.Errorf("Failed to create window class name")
}
var wc win.WNDCLASSEX
wc.CbSize = uint32(unsafe.Sizeof(win.WNDCLASSEX{}))
wc.LpfnWndProc = syscall.NewCallback(DefWindowProc)
wc.HInstance = hInstance
wc.HCursor = win.LoadCursor(0, win.MAKEINTRESOURCE(win.IDC_ARROW))
wc.HbrBackground = win.HBRUSH(win.COLOR_WINDOW + 1)
wc.LpszClassName = className
if win.RegisterClassEx(&wc) == 0 {
return 0, fmt.Errorf("Failed to register window class")
}
hWnd := win.CreateWindowEx(
0,
className,
syscall.StringToUTF16Ptr("Captured Image"),
win.WS_POPUP|win.WS_VISIBLE|win.WS_EX_TOPMOST,
win.CW_USEDEFAULT, win.CW_USEDEFAULT, int32(width), int32(height),
0,
0,
hInstance,
nil,
)
if hWnd == 0 {
return 0, fmt.Errorf("Failed to create window")
}
win.ShowWindow(hWnd, win.SW_SHOWDEFAULT)
win.UpdateWindow(hWnd)
// Mostrar imagem na janela
go func() {
hdc := win.GetDC(hWnd)
if hdc == 0 {
fmt.Println("Failed to get window DC")
return
}
defer win.ReleaseDC(hWnd, hdc)
hdcMem := win.CreateCompatibleDC(hdc)
if hdcMem == 0 {
fmt.Println("Failed to create compatible DC")
return
}
defer win.DeleteDC(hdcMem)
hBitmap := win.CreateBitmap(int32(img.Bounds().Dx()), int32(img.Bounds().Dy()), 1, 32, unsafe.Pointer(&img.Pix[0]))
if hBitmap == 0 {
fmt.Println("Failed to create bitmap")
return
}
defer win.DeleteObject(win.HGDIOBJ(hBitmap))
oldBitmap := win.SelectObject(hdcMem, win.HGDIOBJ(hBitmap))
if oldBitmap == 0 {
fmt.Println("Failed to select object into DC")
return
}
defer win.SelectObject(hdcMem, oldBitmap)
rect := win.RECT{Left: 0, Top: 0, Right: int32(img.Bounds().Dx()), Bottom: int32(img.Bounds().Dy())}
FillRect(syscall.Handle(hdc), &rect, win.GetSysColorBrush(win.COLOR_WINDOW)) // Convertido HDC para syscall.Handle
win.BitBlt(hdc, 0, 0, int32(img.Bounds().Dx()), int32(img.Bounds().Dy()), hdcMem, 0, 0, win.SRCCOPY)
}()
return syscall.Handle(hWnd), nil
}
abaixo esta o exemplo de como estou criando o form que ficara na frente do usuario e que devera ser ignorado na captura
// ShowForm cria e exibe o formulário com a imagem de fundo
func ShowForm(img *image.RGBA, width int, height int) (syscall.Handle, error) {
// Criar janela
hInstance := win.GetModuleHandle(nil)
if hInstance == 0 {
return 0, fmt.Errorf("Failed to get module handle")
}
className, err := windows.UTF16PtrFromString("MyWin32Class")
if err != nil {
return 0, fmt.Errorf("Failed to create window class name")
}
var wc win.WNDCLASSEX
wc.CbSize = uint32(unsafe.Sizeof(win.WNDCLASSEX{}))
wc.LpfnWndProc = syscall.NewCallback(DefWindowProc)
wc.HInstance = hInstance
wc.HCursor = win.LoadCursor(0, win.MAKEINTRESOURCE(win.IDC_ARROW))
wc.HbrBackground = win.HBRUSH(win.COLOR_WINDOW + 1)
wc.LpszClassName = className
if win.RegisterClassEx(&wc) == 0 {
return 0, fmt.Errorf("Failed to register window class")
}
hWnd := win.CreateWindowEx(
0,
className,
syscall.StringToUTF16Ptr("Captured Image"),
win.WS_POPUP|win.WS_VISIBLE|win.WS_EX_TOPMOST,
win.CW_USEDEFAULT, win.CW_USEDEFAULT, int32(width), int32(height),
0,
0,
hInstance,
nil,
)
if hWnd == 0 {
return 0, fmt.Errorf("Failed to create window")
}
win.ShowWindow(hWnd, win.SW_SHOWDEFAULT)
win.UpdateWindow(hWnd)
// Mostrar imagem na janela
go func() {
hdc := win.GetDC(hWnd)
if hdc == 0 {
fmt.Println("Failed to get window DC")
return
}
defer win.ReleaseDC(hWnd, hdc)
hdcMem := win.CreateCompatibleDC(hdc)
if hdcMem == 0 {
fmt.Println("Failed to create compatible DC")
return
}
defer win.DeleteDC(hdcMem)
hBitmap := win.CreateBitmap(int32(img.Bounds().Dx()), int32(img.Bounds().Dy()), 1, 32, unsafe.Pointer(&img.Pix[0]))
if hBitmap == 0 {
fmt.Println("Failed to create bitmap")
return
}
defer win.DeleteObject(win.HGDIOBJ(hBitmap))
oldBitmap := win.SelectObject(hdcMem, win.HGDIOBJ(hBitmap))
if oldBitmap == 0 {
fmt.Println("Failed to select object into DC")
return
}
defer win.SelectObject(hdcMem, oldBitmap)
rect := win.RECT{Left: 0, Top: 0, Right: int32(img.Bounds().Dx()), Bottom: int32(img.Bounds().Dy())}
FillRect(syscall.Handle(hdc), &rect, win.GetSysColorBrush(win.COLOR_WINDOW)) // Convertido HDC para syscall.Handle
win.BitBlt(hdc, 0, 0, int32(img.Bounds().Dx()), int32(img.Bounds().Dy()), hdcMem, 0, 0, win.SRCCOPY)
}()
return syscall.Handle(hWnd), nil
}