MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey-v1.0 / InputBoxProc

Function InputBoxProc

Source/script2.cpp:5406–5666  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5404
5405
5406BOOL CALLBACK InputBoxProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
5407// MSDN:
5408// Typically, the dialog box procedure should return TRUE if it processed the message,
5409// and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog
5410// manager performs the default dialog operation in response to the message.
5411{
5412 HWND hControl;
5413
5414 // Set default array index for g_InputBox[]. Caller has ensured that g_nInputBoxes > 0:
5415 int target_index = g_nInputBoxes - 1;
5416 #define CURR_INPUTBOX g_InputBox[target_index]
5417
5418 switch(uMsg)
5419 {
5420 case WM_INITDIALOG:
5421 {
5422 // Clipboard may be open if its contents were used to build the text or title
5423 // of this dialog (e.g. "InputBox, out, %clipboard%"). It's best to do this before
5424 // anything that might take a relatively long time (e.g. SetForegroundWindowEx()):
5425 CLOSE_CLIPBOARD_IF_OPEN;
5426
5427 CURR_INPUTBOX.hwnd = hWndDlg;
5428
5429 if (CURR_INPUTBOX.password_char)
5430 SendDlgItemMessage(hWndDlg, IDC_INPUTEDIT, EM_SETPASSWORDCHAR, CURR_INPUTBOX.password_char, 0);
5431
5432 SetWindowText(hWndDlg, CURR_INPUTBOX.title);
5433 if (hControl = GetDlgItem(hWndDlg, IDC_INPUTPROMPT))
5434 SetWindowText(hControl, CURR_INPUTBOX.text);
5435
5436 // Don't do this check; instead allow the MoveWindow() to occur unconditionally so that
5437 // the new button positions and such will override those set in the dialog's resource
5438 // properties:
5439 //if (CURR_INPUTBOX.width != INPUTBOX_DEFAULT || CURR_INPUTBOX.height != INPUTBOX_DEFAULT
5440 // || CURR_INPUTBOX.xpos != INPUTBOX_DEFAULT || CURR_INPUTBOX.ypos != INPUTBOX_DEFAULT)
5441 RECT rect;
5442 GetWindowRect(hWndDlg, &rect);
5443 int new_width = (CURR_INPUTBOX.width == INPUTBOX_DEFAULT) ? rect.right - rect.left : CURR_INPUTBOX.width;
5444 int new_height = (CURR_INPUTBOX.height == INPUTBOX_DEFAULT) ? rect.bottom - rect.top : CURR_INPUTBOX.height;
5445
5446 // If a non-default size was specified, the box will need to be recentered; thus, we can't rely on
5447 // the dialog's DS_CENTER style in its template. The exception is when an explicit xpos or ypos is
5448 // specified, in which case centering is disabled for that dimension.
5449 int new_xpos, new_ypos;
5450 if (CURR_INPUTBOX.xpos != INPUTBOX_DEFAULT && CURR_INPUTBOX.ypos != INPUTBOX_DEFAULT)
5451 {
5452 new_xpos = CURR_INPUTBOX.xpos;
5453 new_ypos = CURR_INPUTBOX.ypos;
5454 }
5455 else
5456 {
5457 POINT pt = CenterWindow(new_width, new_height);
5458 if (CURR_INPUTBOX.xpos == INPUTBOX_DEFAULT) // Center horizontally.
5459 new_xpos = pt.x;
5460 else
5461 new_xpos = CURR_INPUTBOX.xpos;
5462 if (CURR_INPUTBOX.ypos == INPUTBOX_DEFAULT) // Center vertically.
5463 new_ypos = pt.y;

Callers

nothing calls this directly

Calls 6

CenterWindowFunction · 0.85
SetForegroundWindowExFunction · 0.85
swapFunction · 0.85
AssignMethod · 0.80
ContentsMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected