extern "C" STEP_API void WINAPI STEPGetFileInfo(int nItem, FILE_INFO* info) { CSuperGridCtrl::CTreeItem *pItem = STEP_List->GetTreeItem(nItem); CItemInfo *pItemInfo = STEP_List->GetData(pItem); FILE_MP3 *fileMP3 = STEP_List->m_pDoc->GetListMP3((int)pItemInfo->GetLParam()); info->pFileMP3 = fileMP3; }
BOOL CMySuperGrid::OnItemLButtonDown(LVHITTESTINFO& ht) { if(ht.iItem!=-1) { #ifdef _WHAT_EVER_ CTreeItem*pSelItem = GetTreeItem(ht.iItem); if(pSelItem!=NULL) { CItemInfo* pInfo = GetData(pSelItem); if((ht.iSubItem==0) && (pInfo->GetItemText()==CString(_T("Hello World")))) { AfxMessageBox("no can do buddy"); return 0; } for(int i=0;i<pInfo->GetItemCount(); i++) { if(i==ht.iSubItem-1) { CString str=pInfo->GetSubItem(i); if(str == CString(_T("Ethan Hunt"))) { AfxMessageBox("Tom Cruise\nliked him in a few good men"); return 0; } } } } #endif } return 1; }
//helper function to copy CItemInfo used when drag/drop you must override this this function to suit your own CItemInfo class CItemInfo* CMySuperGrid::CopyData(CItemInfo* lpSrc) { ASSERT(lpSrc!=NULL); CItemInfo* lpDest = new CItemInfo; //well okay I put all the copy thing in one function, located in CItemInfo class, //so you should check out this function, remember to modify this function each time you add new data to CItemInfo class. lpDest->CopyObjects(lpSrc); return lpDest; }
void CMySuperGrid::HowToLoopThroughAllItems_if_we_wanted_to_print_them_or_what_ever(CDC *pDC) { TEXTMETRIC tm; pDC->GetTextMetrics(&tm); int cy = tm.tmHeight + tm.tmExternalLeading; int nLineY=0; nLineY+=cy; pDC->TextOut(10, nLineY, _T("GIVE ME A BREAK YOU KNOW PRINT PREVIEW IS NOT THE ISSUE HERE")); nLineY+=cy; nLineY+=cy; int nIndex = GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); //print from current node if(nIndex!=-1) { //GetHeadPosition POSITION pos = GetRootHeadPosition(); while(pos != NULL) { CTreeItem *pParent =(CTreeItem*)GetNextRoot(pos); CTreeItem *pItem = pParent; CItemInfo* lp = GetData(pParent); CString strData = lp->GetItemText(); strData+='\t'; nLineY+=cy; for(int nCol=0; nCol < lp->GetItemCount(); nCol++) { CString str = lp->GetSubItem(nCol); strData+=str; strData+='\t'; } pDC->TabbedTextOut(10,nLineY,strData,strData.GetLength(), 0, NULL, 0); nLineY+=cy; //GetNext ....loop through all children for(;;) { CTreeItem *pCur = GetNext(pParent,pItem, TRUE, FALSE/*regardless of the item are hidden or not*/); if(!IsChildOf(pParent, pCur)) break; else if(pCur==pItem) break; CItemInfo* lp = GetData(pCur); CString strData = lp->GetItemText(); strData+='\t'; for(int nCol=0; nCol < lp->GetItemCount(); nCol++) { CString str = lp->GetSubItem(nCol); strData+=str; strData+='\t'; } pDC->TabbedTextOut(10,nLineY,strData,strData.GetLength(), 0, NULL, 0); nLineY+=cy; pItem=pCur; } } } }
//override void CMySuperGrid::OnUpdateListViewItem(CTreeItem* lpItem, LV_ITEM *plvItem) { //put some extra validation here CString str = (CString)plvItem->pszText; if(!str.Compare(_T("Bugs: Impossible"))) { str+=_T(" (selfconfidence allright)");//that's valid enough :§) CItemInfo *lp = GetData(lpItem); if(lp!=NULL) { if(plvItem->iSubItem==0) lp->SetItemText(str); else //subitem data lp->SetSubItemText(plvItem->iSubItem-1, str); UpdateData(lpItem, lp); //update internal nodes } SetItemText(plvItem->iItem, plvItem->iSubItem, str.GetBuffer(1)); } else CSuperGridCtrl::OnUpdateListViewItem(lpItem, plvItem); }
// -----------------------------------------------------------// // Function : Add_MS_DOS_Stub // Param : CHAR* pBuffer // CMySuperGrid& m_ListGrid // CTreeItem_* parentItem // Return : CTreeItem_* // Comment : // -----------------------------------------------------------// CTreeItem_* CPEShowView::Add_MS_DOS_Stub(CHAR* pBuffer, DWORD dwAddressBase, CMySuperGrid& m_ListGrid,CTreeItem_* parentItem) { if(pBuffer == NULL || parentItem == NULL) { return NULL; } CItemInfo* dosStubItem = new CItemInfo(); dosStubItem->SetImage(0); dosStubItem->SetItemText("MS_DOS_Stub"); CString str; str.Format(_T("%08x"), dwAddressBase); dosStubItem->AddSubItemText(str); dosStubItem->AddSubItemText("-"); dosStubItem->AddSubItemText("-"); dosStubItem->AddSubItemText("-"); dosStubItem->AddSubItemText("MS_DOS_Stub"); CTreeItem_* pDosTreeItem = m_ListGrid.InsertItem(parentItem, dosStubItem); if(pDosTreeItem == NULL) { return NULL; } return pDosTreeItem; }
//override called when OnLButtondown void CMySuperGrid::OnControlLButtonDown(UINT nFlags, CPoint point, LVHITTESTINFO& ht) { //now I am sure I added a combobox some where, so check for this control CTreeItem*pSelItem = GetTreeItem(ht.iItem); if(pSelItem!=NULL) { CItemInfo* pInfo = GetData(pSelItem); CItemInfo::CONTROLTYPE ctrlType; if(pInfo->GetControlType(ht.iSubItem-1, ctrlType)) { if(ctrlType==pInfo->CONTROLTYPE::combobox) { CStringList* list=NULL; pInfo->GetListData(ht.iSubItem-1, list); CComboBox * pList = ShowList(ht.iItem, ht.iSubItem, list); } } /* else //activate default edit control CSuperGridCtrl::OnControlLButtonDown(nFlags, point, ht); */ } }
BOOL CMySuperGrid::OnVkReturn() { BOOL bResult=FALSE; int iItem = GetNextItem( -1, LVNI_ALL | LVNI_SELECTED); if( GetCurSubItem() != -1 && iItem != -1) { CTreeItem*pSelItem = GetTreeItem(iItem); if(pSelItem!=NULL) { CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0); int iSubItem = Header_OrderToIndex(pHeader->m_hWnd, GetCurSubItem()); CItemInfo* pInfo = GetData(pSelItem); CItemInfo::CONTROLTYPE ctrlType; if(pInfo->GetControlType(iSubItem-1, ctrlType)) { switch(ctrlType) { /*put in your own control here*/ case pInfo->CONTROLTYPE::datecontrol:break; case pInfo->CONTROLTYPE::spinbutton:break; case pInfo->CONTROLTYPE::dropdownlistviewwhatevercontrol:break; case pInfo->CONTROLTYPE::combobox: { CStringList* list=NULL; pInfo->GetListData(iSubItem-1, list); CComboBox * pList = ShowList(iItem, iSubItem, list); bResult=TRUE; //I'll handle it from here }break; default:break; } } } } return bResult; }
//another search thing CMySuperGrid::CTreeItem* CMySuperGrid::SearchEx(CTreeItem *pStartPosition, CString strItem) { CItemInfo* lp = GetData(pStartPosition); //if(lp->GetCheck()) another condition here maybe CString strData = lp->GetItemText(); if(strData==strItem) { return pStartPosition; } const int nChildren = NumChildren(pStartPosition); if (nChildren > 0) { POSITION pos = GetHeadPosition(pStartPosition); while (pos) { CTreeItem *pChild = GetNextChild(pStartPosition, pos); CItemInfo* lp = GetData(pChild); CString strData = lp->GetItemText(); if(strData==strItem) { return pChild; } } } POSITION pos = GetHeadPosition(pStartPosition); while (pos) { CTreeItem *pChild = GetNextChild(pStartPosition, pos); CItemInfo* lp = GetData(pChild); CString strData = lp->GetItemText(); if(strData==strItem) { return pChild; } pChild = SearchEx(pChild, strItem); if(pChild!=NULL) return pChild; } return NULL; }
CTypeInfo* CStreamPathHookBase::FindType(const CObjectStack& stk) { CItemInfo* item = FindItem(stk); return item ? const_cast<CTypeInfo*>(item->GetTypeInfo()) : 0; }
extern "C" STEP_API const wchar_t* WINAPI STEPGetSubItemText(int nItem, int nColumn) { CSuperGridCtrl::CTreeItem *pItem = STEP_List->GetTreeItem(nItem); CItemInfo *pItemInfo = STEP_List->GetData(pItem); return pItemInfo->GetSubItem(nColumn-1); }
void CMySuperGrid::_DeleteAll() { DeleteAll();//call CSuperGridCtrl::DeleteAll(); //add some new data CItemInfo* lp = new CItemInfo(); lp->SetImage(4); //add item text lp->SetItemText(_T("New data")); //Create root item CTreeItem * pRoot = InsertRootItem(lp);//previous we call CreateTreeCtrl(lp) if( pRoot == NULL ) return; //insert items int nCol = GetNumCol(); for(int i=0; i < nCol; i++) { CItemInfo* lpItemInfo = new CItemInfo(); CString strItem; strItem.Format(_T("Item %d"),i); //add items text lpItemInfo->SetItemText(strItem); //add subitem text for(int y=0;y < nCol-1; y++) { CString str; str.Format(_T("subItem %d of %s"),y,lpItemInfo->GetItemText()); lpItemInfo->AddSubItemText(str); lpItemInfo->AddSubItemText(str); } //insert the iteminfo with ParentPtr CTreeItem* pParent = InsertItem(pRoot, lpItemInfo); //other nodes if(i%nCol) { CTreeItem* pParent1=NULL; CTreeItem* pParent2=NULL; for(int x=0; x < nCol; x++) { CItemInfo* lpItemInfo = new CItemInfo(); CString strItem; strItem.Format(_T("Item %d"),x); lpItemInfo->SetItemText(strItem); for(int z=0; z < nCol-1; z++) { CString str; str.Format(_T("subItem %d of %s"),z, lpItemInfo->GetItemText()); lpItemInfo->AddSubItemText(str); } pParent1 = InsertItem(pParent, lpItemInfo); } } } //expand one level Expand(pRoot, 0 /*listview index 0*/); UINT uflag = LVIS_SELECTED | LVIS_FOCUSED; SetItemState(0, uflag, uflag); }
//HOWTO: Search nodeptr that have a specific item and subitems also shows you how to select the node and delete it void CMySuperGrid::HowToSearch_I_am_using_hardcoded_values_here_cause_I_am_tired_now(void) { //one Item and two Subitems CTreeItem *pNode = Search(__T("Hello World"),_T("Happy"),_T("Programming"),NULL); if(pNode!=NULL) { CItemInfo *pInfo = GetData(pNode); AfxMessageBox(_T("Found Item ") + pInfo->GetItemText()); } else AfxMessageBox(_T("not found")); //one Item and one Subitem CTreeItem *pNode1 = Search(_T("Mission: Impossible"),_T("Allan Nielsen"),NULL); if(pNode1!=NULL) { CItemInfo *pInfo = GetData(pNode1); AfxMessageBox(_T("Found Item ") + pInfo->GetItemText()); } else AfxMessageBox(_T("not found")); //one Item and one Subitem CTreeItem *pNode2 = Search(_T("Training Agent"),_T("Mr. Bean"),NULL); if(pNode2!=NULL) { CItemInfo *pInfo = GetData(pNode2); AfxMessageBox(_T("Found Item") + pInfo->GetItemText()); } else AfxMessageBox(_T("not found")); CTreeItem *pNode3 = Search(_T("BC"),NULL); if(pNode3!=NULL) { CItemInfo *pInfo = GetData(pNode3); AfxMessageBox(_T("Found Item ") + pInfo->GetItemText()); int nIndex = SelectNode(pNode3); if(nIndex!=-1) if(AfxMessageBox(_T("Do you want to delete it"),MB_OKCANCEL)==IDOK) DeleteItemEx(pNode3, nIndex); } else AfxMessageBox(_T("not found")); CTreeItem *pItem = NULL; POSITION pos = GetRootHeadPosition(); while(pos != NULL) { CTreeItem * pRoot = (CTreeItem*)GetNextRoot(pos); pItem = SearchEx(pRoot, "AB"); if(pItem!=NULL) { CItemInfo *pInfo = GetData(pItem); AfxMessageBox(_T("Found Item ") + pInfo->GetItemText()); int nIndex = SelectNode(pItem); if(nIndex!=-1) if(AfxMessageBox(_T("Do you want to delete it"),MB_OKCANCEL)==IDOK) DeleteItemEx(pItem, nIndex); } } if( pItem == NULL ) AfxMessageBox(_T("not found")); }
void CMySuperGrid::HowToLoopThroughAllItems_that_has_a_checkmark_and_print_them_or_what_ever(CDC *pDC) { TEXTMETRIC tm; pDC->GetTextMetrics(&tm); int cy = tm.tmHeight + tm.tmExternalLeading; int nLineY=0; nLineY+=cy; pDC->TextOut(10,nLineY,_T("GIVE ME A BREAK YOU KNOW PRINT PREVIEW IS NOT THE ISSUE HERE")); nLineY+=cy; nLineY+=cy; if(!GetItemCount()) return; int nIndex=0;//has to be the root if(nIndex!=-1) { //do a GetHeadPosition POSITION pos = GetRootHeadPosition(); while(pos != NULL) { CTreeItem *pParent = (CTreeItem*)GetNextRoot(pos); CTreeItem *pItem = pParent; CItemInfo* lp = GetData(pParent); if(lp->GetCheck())//very hard :)= { CString strData=lp->GetItemText(); strData+='\t'; nLineY+=cy; for(int nCol=0; nCol < lp->GetItemCount(); nCol++) { CString str = lp->GetSubItem(nCol); strData+=str; strData+='\t'; } pDC->TabbedTextOut(10,nLineY,strData,strData.GetLength(), 0, NULL, 0); nLineY+=cy; } //GetNext ....loop through all children for(;;) { CTreeItem *pCur = GetNext(pParent, pItem, TRUE, FALSE/*regardless of the item are hidden or not*/); if(!IsChildOf(pParent, pCur)) break; else if(pCur==pItem) break; CItemInfo* lp = GetData(pCur); if(lp->GetCheck()) { CString strData = lp->GetItemText(); strData+='\t'; for(int nCol=0; nCol < lp->GetItemCount(); nCol++) { CString str = lp->GetSubItem(nCol); strData+=str; strData+='\t'; } pDC->TabbedTextOut(10,nLineY,strData,strData.GetLength(), 0, NULL, 0); nLineY+=cy; } pItem=pCur; } }//while }//if }
//HOWTO: void CMySuperGrid::HowToInsertItemsAfterTheGridHasBeenInitialized(int nIndex, const CString& str) { CTreeItem *pSelItem = GetTreeItem(nIndex); if(pSelItem != NULL) { SetRedraw(0); BOOL bUpdate = FALSE; if(!IsCollapsed(pSelItem)) bUpdate = TRUE;//Children are expanded, want to see update right away if not no visual update CItemInfo* lpRelative = new CItemInfo(); lpRelative->SetItemText(str); lpRelative->AddSubItemText(_T("I am")); lpRelative->AddSubItemText(_T("now")); lpRelative->AddSubItemText(_T("going to insert")); lpRelative->AddSubItemText(_T("some items")); CTreeItem* pParent = InsertItem(pSelItem, lpRelative, bUpdate); for(int i=0; i < GetNumCol(); i++) { CItemInfo* lpItemInfo = new CItemInfo(); CString strItem; strItem.Format(_T("Item %d"), i); //add items text lpItemInfo->SetItemText(strItem); //add subitem text for(int y=0;y < GetNumCol()-1; y++) { CString str; str.Format(_T("SubItem %d of %s"), y, lpItemInfo->GetItemText()); lpItemInfo->AddSubItemText(str); } //set combobox in last col lpItemInfo->SetControlType(lpItemInfo->CONTROLTYPE::combobox, GetNumCol()-2); CStringList list; for(int x = 0; x < 3; x++) { CString str; str.Format("ListItem %d",x); list.AddTail(str); } lpItemInfo->SetListData(GetNumCol()-2, &list); InsertItem(pParent, lpItemInfo); } SetRedraw(1); InvalidateRect(NULL); UpdateWindow(); } }
void CPlayer::useItem(int itemID) { std::string machineName = this->getMachineName(); size_t idx = machineName.find("Server"); if(idx != std::string::npos) { // Server端處理 CItemInfo* pItemInfo = CItem::getInfo(itemID); if(pItemInfo == NULL) return; if(pItemInfo->getClassType() == WEAPON) { CWeaponInfo *pWp = (CWeaponInfo*) pItemInfo; if(this->getLevel() >= pWp->getLevel()) { if(ONE_HAND == pWp->getWield()) wearToEquipSlot(MAIN_HAND, itemID); else if(TWO_HAND == pWp->getWield()) wearToEquipSlot(OFF_HAND, itemID); } } else if(pItemInfo->getClassType() == ARMOR) { CArmorInfo *pAm = (CArmorInfo*) pItemInfo; if(this->getLevel() >= pAm->getLevel()) { if(CLOTHES == pAm->getWear()) wearToEquipSlot(CHEST, itemID); else if(BELTS == pAm->getWear()) wearToEquipSlot(BELT, itemID); else if(PANTS == pAm->getWear()) wearToEquipSlot(LEGS, itemID); else if(PAULDRONS == pAm->getWear()) wearToEquipSlot(SHOULDER, itemID); else if(GLOVES == pAm->getWear()) wearToEquipSlot(GLOVE, itemID); else if(BOOTS == pAm->getWear()) wearToEquipSlot(BOOT, itemID); } } else if(pItemInfo->getClassType() == CONSUMABLE) { CConsumableInfo *pConsumableInfo = (CConsumableInfo *)pItemInfo; if(this->getLevel() >= pConsumableInfo->getLevel()) { if(pConsumableInfo->getEffect() == EDIBLE_SKILL) addSkill(pConsumableInfo->getMuch()); // 學習某項技能 else if(pConsumableInfo->getEffect() == EDIBLE_HP) { if(getHPMax() == getHP()) return; addHP(pConsumableInfo->getMuch()); // 補血 // Todo: 藥水是否有CD時間 } else if(pConsumableInfo->getEffect() == EDIBLE_MP) { if(getMP() == getMPMax()) return; addMP(pConsumableInfo->getMuch()); // 補魔 // Todo: 藥水是否有CD時間 } else return; // 背包物品減一 m_pBackpack->removeItem(itemID); } } } else { // Client端處理 } }
//this is just one way to search items...strItem must match and then all subitems must be //a match before returning the node //the search function here search all nodes regardless if collapsed or expanded CMySuperGrid::CTreeItem* CMySuperGrid::Search(CString strItem,...) { if(!GetItemCount()) return NULL; va_list args; va_start(args, strItem); int nCount=0; for(;;) { LPCTSTR lpsz = va_arg(args, LPCTSTR); if(lpsz==NULL) break; nCount++; } POSITION pos = GetRootHeadPosition(); while(pos != NULL) { CTreeItem *pParent = (CTreeItem*)GetNextRoot(pos); CTreeItem *pItem = pParent; CItemInfo* lp = GetData(pParent); CString strData = lp->GetItemText(); if(strData==strItem)//must be a match before going further...suit you self { va_start(args, strItem); int nResult=0; for(int i=0; i<nCount;i++) { LPCTSTR lpsz = va_arg(args, LPCTSTR); for(int nCol=0; nCol < lp->GetItemCount(); nCol++) { CString str = lp->GetSubItem(nCol); if(!str.CompareNoCase(lpsz)) { nResult++; break; } } } va_end(args); if(nCount==nResult)//all args was found return node return pParent; } //GetNext ....loop through all children for(;;) { CTreeItem *pCur = GetNext(pParent, pItem, TRUE, FALSE/*regardless of the item are hidden or not, set to TRUE if only visible items must be included in the search*/); if(!IsChildOf(pParent, pCur)) break; else if(pCur==pItem) break; CItemInfo* lp = GetData(pCur); CString strData = lp->GetItemText(); if(strData==strItem)//must be a match before going further { va_start(args, strItem); int nResult=0; for(int i=0; i<nCount;i++) { LPCTSTR lpsz = va_arg(args, LPCTSTR); for(int nCol=0; nCol < lp->GetItemCount(); nCol++) { CString str = lp->GetSubItem(nCol); if(!str.CompareNoCase(lpsz)) { nResult++; break; } } } va_end(args); if(nCount==nResult)//all args was found return node return pCur; } pItem=pCur;//next; } } return NULL; }