$variable = MsgBox(0, "", "Return value.")
MsgBox(0, "", $variable)
; Always returns 1
Is it possible to do this in the simplest way without using
Win* functions, Au3Info
As you are using the $MB_OK flag, the MsgBox is considered as "for info only" and Window does not distinguish between the various actions. If you look at the returns from MsgBoxes with multiple buttons, you usually find that the [X] returns the same value as the "Cancel" button.
If you really want to distinguish when the user closes the dialog with the [X], try the ExtMsgBox UDF (https://www.autoitscript.com/forum/topic/109096-extended-message-box-new-version-19-nov-21/) - that does give a unique return.