DEV Community

Query Filter
Query Filter

Posted on

intel11

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

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

    ; 1. Layout Configuration
    BoxWidth := 1000
    ButtonWidth := 120
    Margin := 50 ; Keeps text 50px away from the edges
    TextWidth := BoxWidth - (Margin * 2) ; 900px wide text area

    ; 2. Centering Math
    PosX := iX + (iW / 2) - (BoxWidth / 2)
    PosY := iY + (iH / 2) - 150
    StartBtnX := (BoxWidth / 2) - 130 ; Centering two buttons + gap

    ; 3. Build the GUI
    Gui, Alert: Destroy 
    Gui, Alert: +AlwaysOnTop -MinimizeBox +HwndAlertHwnd
    Gui, Alert: Color, White

    ; --- THE FIX: Change 'Center' to 'Left' ---
    Gui, Alert: Font, s13 w600, Segoe UI
    ; We add x%Margin% to push the text away from the left wall
    Gui, Alert: Add, Text, Left w%TextWidth% x%Margin%, %Message%

    ; Buttons
    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 

    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)