Each item of CListCtrl in C++ displays a different message

  • 2020-05-30 20:46:07
  • OfStack

Each item of CListCtrl in C++ displays a different message

Add CToolTipCtrl member variables m_toolTipCtrl,CListCtrl member variables m_ListUser,CImageList member variables m_imageList

Add the following code to the OnInitDialog() function


m_BoradcastEnd.EnableWindow(FALSE); 
  m_imageList.Create(32, 32, ILC_COLOR8, 2, 2); 
  DWORD dwStyle = m_ListUser.GetExtendedStyle();  
  dwStyle |= LVS_EX_INFOTIP;  
  m_ListUser.SetExtendedStyle(dwStyle);  
   
  for (int i=0; i<5; i++) 
  { 
    CBitmap bit; 
    bit.LoadBitmap(IDB_TEA_ONLINE+i); 
    m_imageList.Add(&bit, RGB(0, 0, 0)); 
    bit.DeleteObject(); 
  } 
   
  EnableToolTips(TRUE); 
  m_toolTipCtrl.Create(this); 
  m_toolTipCtrl.SetMaxTipWidth(500);// If you block the format of this prompt message, you may have a problem and cannot wrap  
  m_toolTipCtrl.Activate(TRUE);  
  m_ListUser.SetImageList(&m_imageList, TVSIL_NORMAL); 
  m_ListUser.InsertItem(0, "172.16.30.32.231", 0); 
  m_ListUser.InsertItem(1, "172.16.30.218", 4); 
  CRect rect; 
  m_ListUser.GetItemRect(0, &rect, LVIR_BOUNDS); 
  m_toolTipCtrl.AddTool(&m_ListUser, "MAC:/nHost:/nIP:", &rect, 1);  
  m_ListUser.GetItemRect(1, &rect, LVIR_BOUNDS); 
  m_toolTipCtrl.AddTool(&m_ListUser, "gggggggggg/nggggggggsfgsfgsfg", &rect, 2); 

Add virtual function PreTranslateMessage()

Add the following code to the function


BOOL CMutiScreenDlg::PreTranslateMessage(MSG* pMsg)  
{ 
  // TODO: Add your specialized code here and/or call the base class 
  m_toolTipCtrl.RelayEvent(pMsg); 
   
  return CDialog::PreTranslateMessage(pMsg); 
} 

If you have any questions, please leave a message or come to this site to discuss the community, hope to help you through this article, thank you for your support of this site!


Related articles: