还在苦苦敲代码开发APP?你out啦! 试试积木搭建APP吧~

GetNextDlgTabItem用法详解,回车替代Tab键切换控件焦点

来源:清泛原创     2016-11-18 13:25:24    人气:     我有话说( 0 人参与)

GetNextDlgTabItem函数按指定方向(第二个参数,TRUE往前,默认FALSE往后)检索对话框中有WS_TABSTOP类型的第一个控件的句柄,即按照对话框...

GetNextDlgTabItem 函数按指定方向(第二个参数,TRUE往前,默认FALSE往后)检索对话框中有WS_TABSTOP类型的第一个控件的句柄,即按照对话框Tab顺序(rc中Ctrl+D查看、点击修改)检索上一个/下一个控件句柄

函数原型:

HWND GetNextDlgTabltem(HWND hDlg,HWND hCtl,BOOL bPrevious);

The GetNextDlgTabItem function retrieves a handle to the first control that has the WS_TABSTOPstyle that precedes (or follows) the specified control.

Syntax

HWND GetNextDlgTabItem(  HWND hDlg, HWND hCtl, BOOL bPrevious );

Parameters

hDlg
[in] Handle to the dialog box to be searched.
hCtl
[in] Handle to the control to be used as the starting point for the search. If this parameter is NULL, the function uses the last (or first) control in the dialog box as the starting point for the search.
bPrevious
[in] Specifies how the function is to search the dialog box. If this parameter is TRUE, the function searches for the previous control in the dialog box. If this parameter is FALSE, the function searches for the next control in the dialog box.

Return Value

If the function succeeds, the return value is the window handle of the previous (or next) control that has the WS_TABSTOP style set.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.
 

Remarks

The GetNextDlgTabItem function searches controls in the order (or reverse order) they were created in the dialog box template. The function returns the first control it locates that is visible, not disabled, and has the WS_TABSTOP style. If no such control exists, the function returns hCtl.

If the search for the next control with the WS_TABSTOP style encounters a window with the WS_EX_CONTROLPARENT style, the system recursively searches the window's children


回车替代Tab键切换控件焦点,部分代码如下:
BOOL Cxxx::PreTranslateMessage(MSG* pMsg)
{
	// TODO: 在此添加专用代码和/或调用基类
	UINT nKeyCode = pMsg->wParam;
	if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
	{
		CWnd *wnd = GetFocus();
		if (wnd != NULL)
		{
			char str[256];
			CString ClassName = _T("Button");
			GetClassName (wnd->m_hWnd, str, 256);
			if (ClassName == str)
			{
				UINT i = wnd->GetDlgCtrlID();
				SendMessage (WM_COMMAND, i, (LPARAM)wnd->m_hWnd);
				CWnd *mwnd = GetNextDlgTabItem (wnd);
				if (mwnd)
					mwnd->SetFocus();
				return TRUE;
			}
		}
		CWnd *mwnd = GetNextDlgTabItem (wnd);
		if (mwnd) 
		{
			mwnd->SetFocus();
			return TRUE;
		}
	}
	return CFormView::PreTranslateMessage(pMsg);
}

(供参考)

GetNextDlgTabItem

注:本文为本站或本站会员原创优质内容,版权属于原作者及清泛网所有,
欢迎转载,转载时须注明版权并添加来源链接,谢谢合作! (编辑:admin)
分享到: