MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / MsgBoxParseOptions

Function MsgBoxParseOptions

source/script2.cpp:4809–4898  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4807}
4808
4809ResultType MsgBoxParseOptions(LPTSTR aOptions, int &aType, double &aTimeout, HWND &aOwner)
4810{
4811 aType = 0;
4812 aTimeout = 0;
4813
4814 //int button_option = 0;
4815 //int icon_option = 0;
4816
4817 LPTSTR next_option, option_end;
4818 TCHAR option[1+MAX_NUMBER_SIZE];
4819 for (next_option = omit_leading_whitespace(aOptions); ; next_option = omit_leading_whitespace(option_end))
4820 {
4821 if (!*next_option)
4822 return OK;
4823
4824 // Find the end of this option item:
4825 if ( !(option_end = StrChrAny(next_option, _T(" \t"))) ) // Space or tab.
4826 option_end = next_option + _tcslen(next_option); // Set to position of zero terminator instead.
4827 size_t option_length = option_end - next_option;
4828
4829 // Make a terminated copy for simplicity and to reduce ambiguity:
4830 if (option_length + 1 > _countof(option))
4831 goto invalid_option;
4832 tmemcpy(option, next_option, option_length);
4833 option[option_length] = '\0';
4834
4835 if (option_length <= 5 && !_tcsnicmp(option, _T("Icon"), 4))
4836 {
4837 aType &= ~MB_ICONMASK;
4838 switch (option[4])
4839 {
4840 case 'x': case 'X': aType |= MB_ICONERROR; break;
4841 case '?': aType |= MB_ICONQUESTION; break;
4842 case '!': aType |= MB_ICONEXCLAMATION; break;
4843 case 'i': case 'I': aType |= MB_ICONINFORMATION; break;
4844 case '\0': break;
4845 default:
4846 goto invalid_option;
4847 }
4848 }
4849 else if (!_tcsnicmp(option, _T("Default"), 7) && IsNumeric(option + 7, FALSE, FALSE, FALSE))
4850 {
4851 int default_button = ATOI(option + 7);
4852 if (default_button < 1 || default_button > 0xF) // Currently MsgBox can only have 4 buttons, but MB_DEFMASK may allow for up to this many in future.
4853 goto invalid_option;
4854 aType = (aType & ~MB_DEFMASK) | ((default_button - 1) << 8); // 1=0, 2=0x100, 3=0x200, 4=0x300
4855 }
4856 else if (toupper(*option) == 'T' && IsNumeric(option + 1, FALSE, FALSE, TRUE))
4857 {
4858 aTimeout = ATOF(option + 1);
4859 }
4860 else if (!_tcsnicmp(option, _T("Owner"), 5) && IsNumeric(option + 5, TRUE, TRUE, FALSE))
4861 {
4862 aOwner = (HWND)ATOI64(option + 5); // This should be consistent with the Gui +Owner option.
4863 }
4864 else if (IsNumeric(option, FALSE, FALSE, FALSE))
4865 {
4866 int other_option = ATOI(option);

Callers 1

BIF_DECLFunction · 0.85

Calls 7

omit_leading_whitespaceFunction · 0.85
StrChrAnyFunction · 0.85
IsNumericFunction · 0.85
ATOIFunction · 0.85
ATOFFunction · 0.85
ATOI64Function · 0.85
ValueErrorFunction · 0.85

Tested by

no test coverage detected