FuPeiJiang / VD.ahk

Windows Virtual Desktop, AutoHotkey, Windows 11 support, Windows Server 2022, switch desktop, move window(wintitle) to current desktop; createDesktop, PinWindow, getCount, getDesktopNumOfWindow -> mute all windows in Virtual Desktop
MIT License
319 stars 45 forks source link

VD PinWindow function doesn't work with ahk_id #17

Closed megamorphg closed 1 year ago

megamorphg commented 1 year ago

As per a Stack Overflow answer: I tried using process ID but I think VD.PinWindow doesn't work with it e.g. VD.PinWindow("ahk_id 0xD3854") or VD.PinWindow("ahk_id %this_id%").

Full code used:

#Persistent
; If the script is not elevated, relaunch as administrator and kill current instance
full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try ; leads to having the script re-launching itself as administrator
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}

#Include lib\VD.ahk-class_VD\_VD.ahk

WinGet, HWiNFO64List, List, ahk_exe HWiNFO64.EXE
VD.init()

Loop, %HWiNFO64List%
{
    this_id := HWiNFO64List%A_Index%
    VD.PinWindow("%this_id%")
    ; MsgBox %this_id%
}
FuPeiJiang commented 1 year ago

try VD.PinWindow("ahk_id " this_id) instead of VD.PinWindow("%this_id%")

this is a scripting error % is not to be used inside quotes


this_id is a variable this is how you'd write it in javascript: string concatenation VD.PinWindow("ahk_id " + this_id) this is how you'd write it in ahk: . is string concatenation operator VD.PinWindow("ahk_id " . this_id) or (concatenation is assumed): VD.PinWindow("ahk_id " this_id)


props to you for putting Full code


you can also 'step into' using a debugger and see that the parameter's value isn't what you want I use https://marketplace.visualstudio.com/items?itemName=zero-plusplus.vscode-autohotkey-debug#installation

megamorphg commented 1 year ago

Thank you! That worked. The parameter is already variabilized so it was failing.

      WinGet, HWiNFO64List, List, ahk_exe HWiNFO64.EXE
      Loop, %HWiNFO64List%
      {
         this_id := HWiNFO64List%A_Index%
         VD.PinWindow("ahk_id " this_id)
      }