DEV Community

Query Filter
Query Filter

Posted on

intel12

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

    ; --- THE UNIVERSAL TARGET FIX ---
    ; 1. Find the current active IntelliJ window (Project or Welcome screen)
    CurrentIntelliJ := WinExist("ahk_exe idea64.exe")

    if (CurrentIntelliJ) {
        ; Get coordinates of whatever IntelliJ window is currently alive
        WinGetPos, iX, iY, iW, iH, ahk_id %CurrentIntelliJ%
    } else {
        ; FALLBACK: If IntelliJ is completely closed, use the primary monitor center
        iX := 0, iY := 0, iW := A_ScreenWidth, iH := A_ScreenHeight
    }

    ; 2. Layout Configuration
    BoxWidth := 1000
    ButtonWidth := 120
    Margin := 50
    TextWidth := BoxWidth - (Margin * 2)

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

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

    ; Left aligned text with margin
    Gui, Alert: Font, s13 w600, Segoe UI
    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)