I'm trying to subclass an edit box in a dialog in VS C++ 2022. I want to intercept any key presses in a particular edit box to do further processing.
Here's my code. The 4th line confuses me because I expected GetDlgItem() to return an HWND, not a CWnd, but this is the only way I could get it to work without an error there. The error I do get is on the SetWindowLongPtrA() function call, 3rd parameter.
The error:
argument of type "void (CDialogControlAndStatus::*)() is incompatable with parameter type "LONG_PTR"
And error:
'&': illegal operation on bound member function expression
If I leave off the "&" in front of param #3, I get the same first error plus I get error:
non-standard syntax; use '&' to create a pointer to member
It seems I'm damned if I do or I don't!
void CDialogControlAndStatus::Edit1ProcInst()
{
HWND DlgHndl = m_hWnd; // get handle of this dialog
CWnd *Edit1CWnd = GetDlgItem(IDC_EDIT1); // get the CWnd to the edit box
HWND Edit1Handl = *Edit1CWnd; // get the HWND to the edit box
m_LongPtrEdit1 =
SetWindowLongPtrA(Edit1Handl, GWLP_WNDPROC, &Edit1Proc); //subclass edit box window
}
void CDialogControlAndStatus::Edit1Proc()
{
// TODO: Add your implementation code here.
}