AutoPlay Media Studio Çıkıştan Önce Kullanıcıdan Onay Alma

guclusat

Tanınmış Üye
Süper Moderatör
Ask the User for Confirmation Before Exiting
In AutoPlay Media Studio, it is possible to stop closing your application based on user input, even after the close button has been pressed, or the Application.Exit action has been used. This is useful if, for example, you are worried that the user will accidentally close your application, or if you want to allow the user to save their changes before they exit.

To accomplish this, you must include a function (QueryAllowProjectClose) in your Global Functions (Project > Global Functions) that returns true if the program should close, and false if it should not:

Kod:
function QueryAllowProjectClose()  --this function will be called when the program is exiting
    confirmation = Dialog.Message("Are you sure?", "Are you sure that you want to exit?", MB_YESNO, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    if confirmation == 6 then
        -- The yes button was pressed, allow program to close (return true)
       return true;
   else
       -- The yes button was NOT pressed, do NOT allow the program to close (Return false)
        return false;
    end
end

Note: This function is called internally by your application when it is told to exit. If true is returned, your application will exit. If false is returned, your program will not exit.

To use this function, you would use script similar to this:

Kod:
if QueryAllowProjectClose() then
   Application.Exit();
end
 

AutoPlay Media Studio Çıkıştan Önce Kullanıcıdan Onay Alma​

AutoPlay Media Studio'da program kapatılmak istendiğinde kullanıcıya "Programdan çıkmak istediğinize emin misiniz?" şeklinde bir onay penceresi gösterebiliriz.

Bu yöntem, kullanıcının yanlışlıkla programı kapatmasını önlemek veya çıkıştan önce kayıt işlemi gibi kontroller yapmak istediğimiz durumlarda kullanılabilir.

Global Functions​

Öncelikle:

Project > Global Functions

bölümüne aşağıdaki fonksiyonu ekliyoruz:

Kod:
function QueryAllowProjectClose()
local confirmation = Dialog.Message(
"Emin misiniz?",
"Programdan çıkmak istediğinize emin misiniz?",
MB_YESNO,
MB_ICONEXCLAMATION,
MB_DEFBUTTON1
)

if confirmation == 6 then
    -- Evet seçildi, programın kapanmasına izin ver
    return true
else
    -- Hayır seçildi, programın kapanmasını engelle
    return false
end

end

Buradaki QueryAllowProjectClose() fonksiyonu program kapatılmak istendiğinde kontrol amacıyla kullanılabilir.

Kullanımı​

Programı kapatmak istediğimiz yerde:

Kod:
if QueryAllowProjectClose() then
Application.Exit();
end

şeklinde kullanabiliriz.

Çalışma Mantığı​

  • Kullanıcı Evet seçerse → true döner ve program kapanır.
  • Kullanıcı Hayır seçerse → false döner ve program açık kalır.
  • Böylece yanlışlıkla Çıkış butonuna basıldığında uygulamanın hemen kapanması engellenmiş olur.
Bu yöntem özellikle AIO uygulamalarında, teknik arşiv programlarında ve kullanıcının yaptığı değişikliklerin kaybolmasını önlemek istediğimiz projelerde kullanılabilir.
 
Geri
Yukarı