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

Method __New

source/script_gui.cpp:495–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

493
494
495ResultType GuiType::__New(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount)
496{
497 if (mHwnd || mDisposed)
498 _o_throw(ERR_INVALID_USAGE);
499
500 LPTSTR options = ParamIndexToOptionalString(0, _f_number_buf);
501
502 bool set_last_found_window = false;
503 ToggleValueType own_dialogs = TOGGLE_INVALID;
504 if (*options && !ParseOptions(options, set_last_found_window, own_dialogs))
505 _o_return_FAIL; // ParseOptions() already displayed the error.
506
507 mControl = (GuiControlType **)malloc(GUI_CONTROL_BLOCK_SIZE * sizeof(GuiControlType*));
508 if (!mControl)
509 _o_throw_oom;
510 mControlCapacity = GUI_CONTROL_BLOCK_SIZE;
511
512 if (!ParamIndexIsOmittedOrEmpty(2))
513 {
514 if (IObject* obj = TokenToObject(*aParam[2]))
515 {
516 // The caller specified an object to use as event sink.
517 if (obj != this) // Primarily for custom GUI classes: prevent a circular reference.
518 obj->AddRef();
519 mEventSink = obj;
520 }
521 else
522 _o_throw_param(2, _T("object"));
523 }
524
525 LPTSTR title;
526 if (ParamIndexIsOmitted(1)) // Completely omitted, not an empty string.
527 title = g_script.DefaultDialogTitle();
528 else
529 title = ParamIndexToString(1, _f_number_buf);
530
531 // Create the Gui, now that we're past all other failure points.
532 if (!Create(title))
533 return FAIL; // Error already displayed.
534
535 if (set_last_found_window)
536 g->hWndLastUsed = mHwnd;
537 SetOwnDialogs(own_dialogs);
538
539 // Successful creation - add the Gui to the global list of Guis and return it
540 AddGuiToList(this);
541 return OK;
542}
543
544
545BIF_DECL(BIF_GuiFromHwnd)

Callers

nothing calls this directly

Calls 4

TokenToObjectFunction · 0.85
AddGuiToListFunction · 0.85
DefaultDialogTitleMethod · 0.80
AddRefMethod · 0.45

Tested by

no test coverage detected