I want not to allow selection on the list control items when I try to select the item using right click and should show the selection if left click on the item.
I tried handling it in NM_RCLICK event to prevent right click selection as follows:
void CTestDlg::OnNMRClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
if((pNMItemActivate->uChanged & LVIF_STATE) &&
(pNMItemActivate->uNewState & LVNI_SELECTED))
{
*pResult = 1;
}
else
{
*pResult = 0;
}
}
Please refer screenshot for more information:

Blue color highlight should not come if I do right click on the item where as that highlight should come only for left click.
But still I am able to select the item if it is right click.
Could anyone please help me to solve this issue.
You are handling the notification for the right-click event; it is too late to prevent anything at that point, as the selection is changed and previous selection is lost.
You should handle the WM_RBUTTONDOWN/UP messages and do whatever you want there, without passing it through to the default window procedure.
Finally solved the issue with the suggestion given by @Vlad Feinstein, I tried handling WM_RBUTTONDOWN as below.
BOOL CTestDlg::PreTranslateMessage(MSG* pMsg)
{
long lFocus = ::GetDlgCtrlID(pMsg->hwnd);
if(IDC_LIST1 == lFocus)
{
if (pMsg->message == WM_RBUTTONDOWN)
{
return true;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With