Bug in ProcessSetPriority Example #2 ahk v2 Topic is solved

Share your ideas as to how the documentation can be improved.
User avatar
xypha
Posts: 24
Joined: 24 Apr 2020, 04:14

Bug in ProcessSetPriority Example #2 ahk v2

04 Jan 2024, 03:55

Bug in ProcessSetPriority Example #2 in AHK Docs v2 - Link

Code: Select all

#z:: ; Win+Z hotkey
{
    active_pid := WinGetPID("A")
    active_title := WinGetTitle("A")
    MyGui := Gui(, "Set Priority")
    MyGui.Add("Text",, "
    (
        Press ESCAPE to cancel, or double-click a new
        priority level for the following window:
    )")
    MyGui.Add("Text", "wp", active_title)
    LB := MyGui.Add("ListBox", "r5 Choose1", ["Normal","High","Low","BelowNormal","AboveNormal"])
    LB.OnEvent("DoubleClick", SetPriority)
    MyGui.Add("Button", "default", "OK").OnEvent("Click", SetPriority)
    MyGui.OnEvent("Escape", (*) => MyGui.Destroy())
    MyGui.OnEvent("Close", (*) => MyGui.Destroy())
    MyGui.Show()

    SetPriority(*)
    {
        MyGui.Destroy()
        if ProcessSetPriority(LB.Text, active_pid)
            MsgBox "Success: Its priority was changed to " LB.Text
        else
            MsgBox "Error: Its priority could not be changed to " LB.Text
    }
}
Spoiler

Script works after making the following changes:

Change Line 21 to: MyGui.Hide()
Add new line after line 25: MyGui.Destroy()
User avatar
Ragnar
Posts: 614
Joined: 30 Sep 2013, 15:25

Re: Bug in ProcessSetPriority Example #2 ahk v2

04 Jan 2024, 04:39

I've moved this topic from "Bug Reports" to "Suggestions on Documentation Improvements".
User avatar
Ragnar
Posts: 614
Joined: 30 Sep 2013, 15:25

Re: Bug in ProcessSetPriority Example #2 ahk v2  Topic is solved

04 Jan 2024, 05:15

Thanks for reporting. I've fixed the example as follows (unlike your fix suggestion, which would also work):

Code: Select all

SetPriority(*)
{
    new_prio := LB.Text
    MyGui.Destroy()
    if ProcessSetPriority(new_prio, active_pid)
        MsgBox "Success: Its priority was changed to " new_prio
    else
        MsgBox "Error: Its priority could not be changed to " new_prio
}

Return to “Suggestions on Documentation Improvements”

Who is online

Users browsing this forum: No registered users and 46 guests