Skip to content

Commit

Permalink
Implemented support for CTRL+A in CInputBox answer text box. #127
Browse files Browse the repository at this point in the history
  • Loading branch information
end2endzone committed Nov 29, 2023
1 parent afda6c9 commit 180587e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/core/InputBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ HFONT CreateInputBoxFont()

CInputBox::CInputBox(HWND hParent) :
m_hInstance(NULL),
m_prevEditProc(NULL),
m_hWindowFont(NULL),
m_hIcon(NULL),
m_hParent(NULL),
Expand Down Expand Up @@ -288,7 +289,7 @@ inline CInputBox* GetInputBoxInstance(HWND hWnd)

LRESULT CALLBACK CInputBox::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//Get the inputbox saved when WM_CREATE message was processed
//Get the CInputBox instance saved when WM_CREATE message was processed.
CInputBox* pInputBox = GetInputBoxInstance(hWnd);

switch (uMsg)
Expand Down Expand Up @@ -343,6 +344,12 @@ LRESULT CALLBACK CInputBox::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
pInputBox->SetCtrl(CInputBox::TEXTBOX_ANSWER, hTextBoxAnswer);
SendMessage(hTextBoxAnswer, WM_SETFONT, (WPARAM)hWindowFont, 0);

// Set our custom message handler function
if (!(pInputBox->m_prevEditProc = (WNDPROC)SetWindowLongPtrW(hTextBoxAnswer, GWLP_WNDPROC, (LONG_PTR)(&EditProc))))
{
return ERROR_NOT_SUPPORTED;
}

//default value for anwser
std::wstring default_text = pInputBox->GetTextUnicode();
if (!default_text.empty())
Expand Down Expand Up @@ -504,6 +511,21 @@ LRESULT CALLBACK CInputBox::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
return 0;
}

LRESULT CALLBACK CInputBox::EditProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
//Get the CInputBox instance saved when WM_CREATE message was processed.
HWND hMainWnd = GetParent(hWnd);
CInputBox* pInputBox = GetInputBoxInstance(hMainWnd);

if (uMsg == WM_CHAR && wParam == 1) // CTRL+A
{
SendMessage(hWnd, EM_SETSEL, 0, -1);
return 1;
}

return CallWindowProc(pInputBox->m_prevEditProc, hWnd, uMsg, wParam, lParam);
}

bool CInputBox::DoModal(const std::string& caption, const std::string& prompt)
{
std::wstring caption_unicode = ra::unicode::AnsiToUnicode(caption);
Expand Down
2 changes: 2 additions & 0 deletions src/core/InputBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ class SHELLANYTHING_EXPORT CInputBox

private:
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK EditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL UpdateWindowStyle(HWND hWnd, LONG new_styles);

HINSTANCE m_hInstance;
WNDPROC m_prevEditProc; // previous edit control message process function
HFONT m_hWindowFont; //main font
HFONT m_hPromptFont;
HICON m_hIcon;
Expand Down

0 comments on commit 180587e

Please sign in to comment.