Página 1 de 1

[SA] Using Windows Message Boxes in Mods for Error-Reporting and More

Enviado: 04 Mai 2021, 01:11
por HzanRsxa2959
Are you tired of users missing your mod's informative warnings and errors just because they were written using the game's janky text-display system? Do you want to level up your error-reporting to match those fancy ASI mods?

Well, despair no longer! Using the built-in exe function MessageBoxA, you too can present your dilemma to the user with a little more elegance.

Really, look at the advantages:
  • The whole game is paused while the message box is displayed: You can effectively inform the user about the issue without fear of the user missing it or it being consumed by other messages.
  • Using the return value, you can make interactive message boxes: e.g., asking the user to open the link to download newOpcodes if it was not found installed- and doing so only if they click "Yes", of course; don't be annoying!

Here is a Sanny Builder code snippet for elite scripters:

Código: Selecionar tudo

{$CLEO .cs}

0000: NOP

while true
    if 0AB0: is_key_pressed 84
    then
        0AA7: call_function_return 0x81E5E6 num_params 4 pop 0 0x000 "Caption" "Text" 0 31@
        0AD1: show_formatted_text_highpriority "%d" time 5000 31@
    end

    wait 0
end

0x000 is an integer hexadecimal value containing the window flags described in the spoiler below:
SpoilerAbrir
First digit (0x000):
  • 0: The first button is the default button.
  • 1: The second button is the default button.
  • 2: The third button is the default button.
  • 3: The fourth button is the default button.
Second digit (0x000):
  • 0: No icon appears in the message box.
  • 1: A stop-sign icon Imagem appears in the message box.
  • 2: A question-mark icon Imagem appears in the message box. The question-mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility.
  • 3: An exclamation-point icon Imagem appears in the message box.
  • 4: An icon consisting of a lowercase letter i in a circle Imagem appears in the message box.

Third digit (0x000):
  • 0: The message box contains one push button: OK.
  • 1: The message box contains two push buttons: OK and Cancel.
  • 2: The message box contains three push buttons: Abort, Retry, and Ignore.
  • 3: The message box contains three push buttons: Yes, No, and Cancel.
  • 4: The message box contains two push buttons: Yes and No.
  • 5: The message box contains two push buttons: Retry and Cancel.
  • 6: The message box contains three push buttons: Cancel, Try Again, Continue. Prefer to use this value instead of 2.
"Caption" is a string value containing the window title: Use the mod name here.
"Text" is a string value containing the window text: Describe the error here.
31@ is an integer variable containing the return value described in the spoiler below: 
SpoilerAbrir
Note: If a message box has a Cancel button, the function returns the value 2 if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC will no have effect - unless an OK button is present. If an OK button is displayed and the user presses ESC, the return value will be 1.
  • 1: The OK button was selected.
  • 2: The Cancel button was selected.
  • 3: The Abort button was selected.
  • 4: The Retry button was selected.
  • 5: The Ignore button was selected.
  • 6: The Yes button was selected.
  • 7: The No button was selected.
  • 10: The Try Again button was selected.
  • 11: The Continue button was selected.

The code snippet above shows a message box with no icon, title "Caption", text "Text", and an OK button as default. After pressing OK, the return value is stored in the variable 31@ which is then displayed for five seconds using subtitled text.

Source: https://docs.microsoft.com/en-us/window ... essageboxa