DEV Community

Query Filter
Query Filter

Posted on

intel10

SmartAlert(Title, Message) {
    global intellij_id
    global SmartAlertResult := 0 

    WinGetPos, iX, iY, iW, iH, ahk_id %intellij_id%

    ; 1. Layout Configuration
    BoxWidth := 1000      ; <--- Your new width
    ButtonWidth := 120    ; Slightly larger buttons for a huge box

    ; 2. Centering Math
    PosX := iX + (iW / 2) - (BoxWidth / 2)
    PosY := iY + (iH / 2) - 100

    ; Button Center Math: 
    ; (1000 / 2) - (Total width of 2 buttons + gap / 2)
    ; (500) - (120 + 20 + 120 / 2) = 500 - 130 = 370
    StartBtnX := 370

    ; 3. Build the GUI
    Gui, Alert: Destroy ; Clean up any old instance to prevent "Duplicate ID" errors
    Gui, Alert: +AlwaysOnTop -MinimizeBox +HwndAlertHwnd
    Gui, Alert: Color, White

    Gui, Alert: Font, s14 w700, Segoe UI
    Gui, Alert: Add, Text, Center w%BoxWidth%, %Message%

    Gui, Alert: Font, s11 w400
    Gui, Alert: Add, Button, gAlertOK Default w%ButtonWidth% x%StartBtnX% y+30, OK
    Gui, Alert: Add, Button, gAlertCancel w%ButtonWidth% x+20, Cancel 

    ; 4. THE CRITICAL SHOW LINE
    ; Make sure 'w' is followed immediately by 1000 or %BoxWidth%
    Gui, Alert: Show, x%PosX% y%PosY% w%BoxWidth%, %Title%

    WinWaitClose, ahk_id %AlertHwnd%
    return SmartAlertResult

    AlertOK:
        SmartAlertResult := 1
        Gui, Alert: Destroy
    return

    AlertCancel:
    AlertGuiClose:
        SmartAlertResult := 0
        Gui, Alert: Destroy
    return
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)