And I noticed that the role of the press the TAB key can respond to the current button, for the same reason I press the enter key can only seem to setfocus, rather than the button "activate",
The following is a snippet, is very simple,
void CCalcDlg: : OnBnClickedOk ()
{
//TODO: add the control notification handler code
//CDialogEx: : OnOK ();
//# define OKflag NULL
//int intRet=OKflag;
//EndDialog (intRet);
//callback functon of the default control box
The CWnd * p1=GetFocus ();
The CWnd * p2=GetNextDlgTabItem (p1);
The CWnd * p3=p2 - & gt; SetFocus ();
Cstrings PTR=__T (" ");
The p2 - & gt; GetWindowTextW (PTR);
//MessageBox (PTR. Get string ());
//GetFocus () - & gt; GetNextWindow () - & gt; SetFocus ();
}
//afx_msg LRESULT CCalcDlg: : OnInitdialog (WPARAM WPARAM, LPARAM LPARAM)
//{
//return 0;
//}
WNDPROC oldWindowproc;
LRESULT a CALLBACK newWindowproc (
The HWND HWND,
UINT uMsg,
WPARAM WPARAM,
LPARAM LPARAM)
{
BOOL ret=false;
If (uMsg==WM_CHAR & amp; & WParam==0 x0d)
{
(: : SetFocus GetNextWindow (HWND, GW_HWNDNEXT));
Ret=true;
return ret;
}
The else
{
Return CallWindowProc (
OldWindowproc,
The HWND,
UMsg,
WParam,
LParam);
}
//oldWindowproc (
//the HWND,
//uMsg,
//wParam,
//lParam);
}
Afx_msg LRESULT CCalcDlg: : OnInitdialog (WPARAM WPARAM, LPARAM LPARAM)
{
CDialogEx: : OnInitDialog ();
Pcombox1=(CComboBox *) GetDlgItem (IDC_COMBO1);
if (! Pcombox1 - & gt; GetCount ())
{
Pcombox1 - & gt; InsertString (0, __T (" add "));
Pcombox1 - & gt; InsertString (1, __T (" cut "));
Pcombox1 - & gt; InsertString (2, __T (" on "));
Pcombox1 - & gt; InsertString (3, __T (" addition "));
}
Pcombox1 - & gt; SetCurSel (0);
GetDlgItem (IDC_EDIT2) - & gt; SetFocus ();
//: : SetFocus (GetDlgItem (IDC_EDIT2) - & gt; M_hWnd);
//oldWindowproc=(WNDPROC) SetWindowLongPtr (GetDlgItem (IDC_EDIT2) - & gt; M_hWnd, GWLP_WNDPROC, (long) newWindowproc);
//it is very inportant here to set the return value FALSE, otherwise we the default focus will always be set
Return FALSE;
}
CodePudding user response:
BOOL CFocus_testDlg: : PreTranslateMessage (MSG * pMsg)
{
//TODO: Add your specialized code here and/or call the base class
If (WM_KEYDOWN==pMsg - & gt; Message)
{
The CWnd * pFocus=GetFocus ();
If (pFocus)
{
If (IDC_BUTTON1==pFocus - & gt; GetDlgCtrlID ())
{
(CButton *) (GetDlgItem (IDC_BUTTON2) - & gt; SetFocus ();
}
Else if (IDC_BUTTON2==pFocus - & gt; GetDlgCtrlID ())
{
(CButton *) (GetDlgItem (IDC_BUTTON3) - & gt; SetFocus ();
}
Else if (IDC_BUTTON3==pFocus - & gt; GetDlgCtrlID ())
{
(CButton *) (GetDlgItem (IDC_BUTTON1) - & gt; SetFocus ();
}
return TRUE;
}
}
Return CDialog: : PreTranslateMessage (pMsg);
}
CodePudding user response:
CodePudding user response:
Press enter button to get the focus should be equivalent button clicks, without OnBnClickedOkCodePudding user response: