Tags Archives: snippet

How to find the text column header of a CListCtrl in MFC

  How to find the text column header of a CListCtrl in MFC CString GetColumnName( CListCtrl * list, int nCol ) {     CString strNome;     CHeaderCtrl* pHdr = list->GetHeaderCtrl();     if ( pHdr )         if ( nCol < pHdr->GetItemCount() )         {             HDITEM hdi;             hdi.mask = HDI_TEXT;             hdi.pszText = strNome.GetBuffer( [...]

Dump a CListCtrl

This snippet dumps the content of a CListCtrl in to a file. It also gets the number of columns in the list.   int GetColumnsCount( CListCtrl * list ) {     if( list != NULL )     {         const CHeaderCtrl * pHeaderCtrl = (CHeaderCtrl*) list->GetDlgItem(0);         if( pHeaderCtrl != NULL ) {             return  pHeaderCtrl->GetItemCount() [...]

How to create a menu and submenu on right click in MFC

  void ::OnNMRClickBacnetTree(NMHDR *pNMHDR, LRESULT *pResult) {     CPoint ptScreen;     SendMessage(WM_CONTEXTMENU, (WPARAM) m_hWnd, GetMessagePos() );     if (! GetCursorPos(&ptScreen))     {         return ;     }     // Select an element under the right click     CPoint ptClient(ptScreen);     m_BACnetTree.ScreenToClient(&ptClient);        // Create the right click menu     CMenu rightClickMenu;     rightClickMenu.CreatePopupMenu();     rightClickMenu.AppendMenu(MF_STRING,1021,_T("One")); [...]