当前位置:网站首页>MFC sends left click, double click, and right click messages to list controls

MFC sends left click, double click, and right click messages to list controls

2022-07-06 07:58:00 donghuangliuyun

void CTestsetting::SendClickToList()
{
    
	NMITEMACTIVATE NMItemActive;
	NMHDR thdr;
	thdr.code = NM_CLICK;					//NM_CLICK single click  NM_DBLCKL  double-click  NM_RCLICK Right click 
	thdr.hwndFrom = m_TestsetList.m_hWnd;	//m_TestList Is the variable associated with the list control 
	thdr.idFrom = IDC_TESTSETTING_LIST;		//IDC_TESTSETTING_LIST  List control ID
	NMItemActive.hdr = thdr;
	NMItemActive.iItem = m_TestsetList.GetItemCount();
	NMItemActive.iItem = 0;					// Set the selected row 
	NMItemActive.iSubItem = 1;				// Set the selected column 
	m_TestsetList.SetSelectionMark(0);
	SendMessage(WM_NOTIFY, IDC_TESTSETTING_LIST, (LPARAM)&NMItemActive);	// Send the message to the parent window where the list is located , Forwarded by the parent window , Instead of forwarding directly to the list 
}

Add list left click response function

void CTestsetting::OnNMClickTestsettingList(NMHDR* pNMHDR, LRESULT* pResult)
{
    
	// Because it is a test, it is a variable written casually 
	LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE)pNMHDR;// Convert the incoming message into LPNMITEMACTIVAT
	int nItem = temp->iItem;// Get line number 
	int nSubItem = temp->iSubItem;// Get column number 
	TRACE("%d, %d\n", nItem, nSubItem);
	*pResult = 0;
}
原网站

版权声明
本文为[donghuangliuyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060750323709.html