Ayuda para reservar espacio en la pantalla y recuperarlo

Esta sección es para preguntas sobre programación/scripting usando AutoHotkey.

Moderator: Flipeador

instigator
Posts: 3
Joined: 25 Oct 2023, 14:39

Ayuda para reservar espacio en la pantalla y recuperarlo

27 Oct 2023, 18:39

Usando el siguiente código, puedo reservar un espacio en la pantalla para poder mostrar una ventana en específico.

Code: Select all

#Persistent
#NoEnv  
SendMode Input  
SetWorkingDir %A_ScriptDir%  
SetBatchLines -1
DetectHiddenWindows, On

; dlghwnd := WinExist("ahk_exe dopus.exe ahk_class #32770 ahk_title test_dlg")
dlghwnd := Run("notepad.exe")
if (dlghwnd = 0) {
	MsgBox, "App not running"
	ExitApp
}
; preserve current positioning
WinGetPos, HX,HY,HW,HH, ahk_id %dlghwnd%
uEdge:=2                                 ; left=0,top=1,right=2,bottom=3
uAppWidth:=A_ScreenWidth * 1/3                           ; "ideal" width for a vertical appbar
uAppHeight:=30                          ; "ideal" height when horizontal

if (uEdge = 2) {
  dlgx := A_ScreenWidth - uAppWidth
} else {
  dlgx := 0
}

if (uEdge = 3) {
  dlgy := A_ScreenHeight - uAppHeight
} else {
  dlgy := 0
}

if (uEdge in 0,2) {
  dlgw := uAppWidth
  dlgh := A_ScreenHeight-30
} else {
  dlgw := A_ScreenWidth
  dlgh := uAppHeight
}

GoSub, SetWindow
GoSub, SetAPPBAR
OnExit, QuitScript
Return

SetWindow:
WinSet, Style, -0xC00000, ahk_id %dlghwnd% ; hide title bar
WinSet, ExStyle, +0x80, ahk_id %dlghwnd%    ; Remove it from the alt-tab list
WinSet, ExStyle, -0x00040000, ahk_id %dlghwnd%    ; Turn off WS_EX_APPWINDOW
WinSet, Style, -0x800000, ahk_id %dlghwnd% ; hide thin-line border
WinSet, Style, -0x400000, ahk_id %dlghwnd% ; hide dialog frame
WinSet, Style, -0x40000,ahk_id  %dlghwnd%  ; hide thickframe/sizebox
WinSet, AlwaysOnTop, On, ahk_id %dlghwnd%
WinMove, ahk_id %dlghwnd%,,%dlgx%,%dlgy%,%dlgw%,%dlgh%
Return

SetAPPBAR:
  ABM := DllCall("RegisterWindowMessage", Str,"AppBarMsg", "UInt")
  VarSetCapacity(APPBARDATA , (cbAPPBARDATA := A_PtrSize == 8 ? 48 : 36), 0)
  Off :=  NumPut(cbAPPBARDATA, APPBARDATA, "Ptr")
  Off :=  NumPut(dlghwnd, Off+0, "Ptr")
  Off :=  NumPut(ABM, Off+0, "UInt")
  Off :=  NumPut(uEdge, Off+0, "UInt") 
  Off :=  NumPut(dlgx, Off+0, "Int") 
  Off :=  NumPut(dlgy, Off+0, "Int") 
  Off :=  NumPut(dlgw, Off+0, "Int") 
  Off :=  NumPut(dlgh, Off+0, "Int")
  Off :=  NumPut(1, Off+0, "Ptr")
  DllCall("Shell32.dll\SHAppBarMessage", UInt,(ABM_NEW:=0x0)     , Ptr,&APPBARDATA)
  DllCall("Shell32.dll\SHAppBarMessage", UInt,(ABM_QUERYPOS:=0x2), Ptr,&APPBARDATA)
  DllCall("Shell32.dll\SHAppBarMessage", UInt,(ABM_SETPOS:=0x3)  , Ptr,&APPBARDATA)
Return

Unset_Window:
if (dlghwnd = 0) return
WinSet, Style, +0xC00000, ahk_id %dlghwnd% ; hide title bar
WinSet, ExStyle, -0x80, ahk_id %dlghwnd%    ; Remove it from the alt-tab list
WinSet, ExStyle, +0x00040000, ahk_id %dlghwnd%    ; Turn off WS_EX_APPWINDOW
WinSet, Style, +0x800000, ahk_id %dlghwnd% ; hide thin-line border
WinSet, Style, +0x400000, ahk_id %dlghwnd% ; hide dialog frame
WinSet, Style, +0x40000,ahk_id  %dlghwnd%  ; hide thickframe/sizebox
WinSet, AlwaysOnTop, Off, ahk_id %dlghwnd%
WinMove, ahk_id %dlghwnd%,,%HX%,%HY%,%HW%,%HH%
Return


RemoveAppBar:
  DllCall("Shell32.dll\SHAppBarMessage", UInt,(ABM_REMOVE := 0x1), Ptr,&APPBARDATA )
Return

QuitScript:
GoSub, Unset_Window
GoSub, RemoveAppbar
ExitApp
Return

Run(Target)
{
  Try Run, % Target,,, OutputVarPID
  Catch, 
    Throw, "Couldn't run " Target

  WinWait, % "ahk_pid " OutputVarPID

  Return WinExist("ahk_pid " OutputVarPID)
}
El problema viene a que luego, tras cerrar el script, no consigo recuperar el espacio automáticamente. Si se usa una ventana creada por Autohotkey, si funciona ¿Alguien podría decirme dónde está el error por favor? Muchas gracias.

Return to “Pedir Ayuda”

Who is online

Users browsing this forum: No registered users and 59 guests