BOOL CNetClient::OnAllVideoTypes() { //CMainFrame *pWnd=(CMainFrame*)AfxGetMainWnd(); //CTypeManager typeMgr(&pWnd->m_adoConnection); CTypeManager typeMgr(&g_pWnd->m_adoConnection); CList<CType,CType> lstType; typeMgr.GetAllType(&lstType); CType type; CString strData; //发送的字符串的格式:"战争片,1,喜剧片,2,古装片,3 " for (int i=0;i<lstType.GetCount();i++) { type=lstType.GetAt(lstType.FindIndex(i)); strData+=type.strTypeName; strData+=","; CString strID; strID.Format("%d,",type.nTypeID); strData+=strID; } //首先发送数据长度,然后发送数据 int nLen=strData.GetLength(); LPSTR pData=(LPSTR)malloc(nLen+1); memset(pData,0,nLen+1); strcpy(pData,strData); SendData(VODNETCMD_TYPES_RET,pData,strData.GetLength()); free(pData); return TRUE; }
int CDlgParamSet::GetDelParamlst(vector<ZTreeParam*> &vecParams,int &nGroupCount) { int ncount =0; ZTreeParam* pParam = NULL; CBCGPGridItem*pItem = NULL; CZGridRow *pRow = NULL; CList <CBCGPGridItem*, CBCGPGridItem*> lstSelected; m_wndGridTree.GetSelectedItems (lstSelected); for (POSITION pos = lstSelected.GetHeadPosition(); pos != NULL; ) { pItem = lstSelected.GetAt(pos); lstSelected.GetNext(pos); pRow = (CZGridRow*)pItem->GetParentRow(); pParam = (ZTreeParam*)pRow->GetData(); if (pParam==NULL) continue; if (pParam->m_bIsGroup) nGroupCount++; ncount++; vecParams.push_back(pParam); } return ncount; }
CZGridRow* CDlgParamSet::GetNextRowAfterDel( CZGridRow*pCurItem) { CZGridRow* pParaentItem=NULL; CZGridRow* pNextItem=NULL; CList<CBCGPGridRow*, CBCGPGridRow*> lst; //要删除的pRow //pCurItem = (CZGridRow*)m_wndGridTree.GetRow(nIndex); //if (pCurItem==NULL) return n; pParaentItem = (CZGridRow*)pCurItem->GetParent(); pParaentItem->GetSubItems(lst); POSITION pos =lst.Find(pCurItem); lst.GetNext (pos); if (pos==NULL) pNextItem=pParaentItem; else pNextItem=(CZGridRow*)lst.GetAt(pos); return pNextItem; }
//**************************************************************************************** int CBCGPGridSerializeManager::InsertNewSelection (int nInsertPos, CList<CBCGPGridRow*, CBCGPGridRow*> & lst) { ASSERT (m_pOwnerGrid != NULL); int nCount = 0; for (POSITION pos = lst.GetHeadPosition (); pos != NULL; ) { POSITION posSave = pos; CBCGPGridRow* pRow = lst.GetNext (pos); if (pRow != NULL) { ASSERT_VALID (pRow); //----------------------------------------- // Insert new row at the specified position //----------------------------------------- int nRowIndex = -1; if (m_pOwnerGrid->GetRowCount () <= nInsertPos + nCount) { nRowIndex = m_pOwnerGrid->InsertRowAfter (nInsertPos + nCount, pRow, FALSE); } else { nRowIndex = m_pOwnerGrid->InsertRowBefore (nInsertPos + nCount, pRow, FALSE); } if (nRowIndex >= 0) { nCount++; lst.GetAt (posSave) = NULL; ASSERT (nRowIndex >= nInsertPos); ASSERT (nRowIndex <= nInsertPos + nCount); } } } if (nCount > 0) { // Save inserted range m_InsertRange.SetRows (nInsertPos, nCount, TRUE); // Shift marked ranges for (int j = 0; j < m_arrCutRanges.GetSize (); j++) { m_arrCutRanges [j].OnInsertRange (nInsertPos, nCount); } } return nCount; }
//碰撞检测 void GameManager::CheckCollision() { for (int i = Index_Player; i <= Index_Tool; ++i)//Index_Bomb { if (i == Index_Explosion)continue; CList<GameObject*, GameObject*> *listA = GetList(i); POSITION posA = listA->GetHeadPosition(); while (posA != NULL) { FlyObject* objectA = static_cast<FlyObject*>(listA->GetAt(posA)); for (int j = Index_Player; j <= Index_Tool; ++j)//Index_Bomb { if (j == Index_Explosion)continue; CList<GameObject*, GameObject*> *listB = GetList(j); POSITION posB = listB->GetHeadPosition(); while (posB != NULL) { FlyObject* objectB = static_cast<FlyObject*>(listB->GetAt(posB)); //碰撞检测 if (objectA->Group() == objectB->Group()) { listB->GetNext(posB); continue; } CPoint leftTop = CPoint(objectA->X() - objectB->Width() / 2, objectA->Y() - objectB->Height() / 2); CPoint rightBottom = CPoint(objectA->X() + objectA->Width() + objectB->Width() / 2, objectA->Y() + objectA->Height() + objectB->Height() / 2); CPoint objectCenter = CPoint(objectB->X() + objectB->Width()/2, objectB->Position()->Y() + objectB->Height() / 2); if (objectCenter.x <= rightBottom.x && objectCenter.y <= rightBottom.y && objectCenter.x >= leftTop.x && objectCenter.y >= leftTop.y) { Collision(objectA, objectB); } listB->GetNext(posB); } } listA->GetNext(posA); } } }
~tScriptState() { int i; for (i = 0; i < Commands.GetCount(); ++i) { tCommand *pCmd = Commands.GetAt(i); delete pCmd; } POSITION pos = Labels.GetHeadPosition(); while (pos) { tLabel *pLabel = Labels.GetAt(pos); delete pLabel; Labels.GetNext(pos); } }
bool tScriptState::FindLabelByName(const tParameter& param, ULONG *pStep) { if (param._type != ptString) return FALSE; if (!param.IsString()) return FALSE; if (!Labels.GetCount()) return FALSE; POSITION pos = Labels.GetHeadPosition(); while (pos) { tLabel *pLabel = Labels.GetAt(pos); if (!pLabel->name.CompareNoCase(param.String())) { if (pStep) *pStep = pLabel->index; return TRUE; } Labels.GetNext(pos); } return FALSE; }
BOOL CNetClient::OnVideosByTypeID() { //接收客户端的数据 GETVIDEOS getVideo; if (!RecvData(&getVideo,sizeof(getVideo))) { return FALSE; } //数据库查询指定类型ID的所有视频 //CMainFrame *pWnd=(CMainFrame*)AfxGetMainWnd(); //CVideoManager videoMgr(&pWnd->m_adoConnection); CVideoManager videoMgr(&g_pWnd->m_adoConnection); CList<CVideo,CVideo> lstVideo; videoMgr.GetVideosByTypeID(getVideo.typdID,&lstVideo); //返回给客户端数据,返回的视频信息的格式, //"敢死队,1,泰囧,22,西游记,31 " CVideo v; CString strData; for (int i=0;i<lstVideo.GetCount();i++) { v=lstVideo.GetAt(lstVideo.FindIndex(i)); strData+=v.strVideoName; strData+=","; CString strID; strID.Format("%d,",v.nVideoID); strData+=strID; } //首先发送数据长度,然后发送数据 int nLen=strData.GetLength(); LPSTR pData=(LPSTR)malloc(nLen+1); memset(pData,0,nLen+1); strcpy(pData,strData); SendData(VODNETCMD_TYPES_RET,pData,strData.GetLength()); free(pData); return TRUE; }
void CHello2Dlg::OnProcessSel(int id) { int curch = m_chlist.GetCurSel(); if(m_cmdbase == ID_32773) //data operation { CList<double,double> *data = &m_ridlgs[curch]->m_data; if(m_ridlgs[curch]->show_type == SHOW_ORGDATA) data = &m_ridlgs[curch]->m_output; if(id == 1) //show converted result { m_ridlgs[curch]->show_type = SHOW_MAINDATA; } if(id == 2) //show raw result { m_ridlgs[curch]->show_type = SHOW_ORGDATA; } if(id == 3) //delete the current record { int pos = m_history.GetCurSel(); if((pos >= 0) && (data)) { POSITION p = data->GetHeadPosition(); while(pos-- > 0 ) data->GetNext(p); data->RemoveAt(p); } } if(id == 4) //delete all the record { data->RemoveAll(); } if(id == 5) //export all the record { CFile cf; if(!cf.Open(DATAOUT_NAME,CFile::modeCreate|CFile::modeWrite)) return; //write to txt and open with notepad if(data && (data->GetCount() > 0)) { POSITION pos = data->GetHeadPosition(); char r[50]; do{ double v = data->GetAt(pos); sprintf(r,"%8f\r\n",v); cf.Write(r,strlen(r)); if(pos == data->GetTailPosition()) break; data->GetNext(pos); }while(1); } cf.Close(); SHELLEXECUTEINFO execInf; ZeroMemory (&execInf, sizeof (execInf)); execInf.cbSize = sizeof (SHELLEXECUTEINFO); execInf.fMask = SEE_MASK_NOCLOSEPROCESS; execInf.nShow = SW_SHOWNORMAL; execInf.lpFile = _T("\\windows\\pword.exe"); execInf.lpVerb = _T("open"); execInf.lpParameters = DATAOUT_NAME; ShellExecuteEx (&execInf); } } if(m_cmdbase == ID_32772) { if(id == 1) { m_ridlgs[curview]->sidedata = NULL; }else{ m_ridlgs[curview]->sidedata = &m_ridlgs[id-2]->m_data; m_ridlgs[curview]->side_ch = id-2; } m_ridlgs[curview]->SaveLastConfig(); } if(m_cmdbase == ID_32771) //channel config { if(m_cfgtype == CFGTYPE_BORE) { CSetting<PROBECFG> prbset; prbset.InstallFromFile(PRB_DEFINFO); if(id == 1)//just close it { m_ridlgs[curch]->cfg_now = CFGTYPE_NONE; for(int i=0;i<sizeof(m_ridlgs)/sizeof(CRunitemDialog*);i++){ if((m_ridlgs[i]->cfg_now == CFGTYPE_BORE) && (i != curch) && (m_ridlgs[i]->side_ch == curch)) { m_ridlgs[i]->sidedata = NULL; } } }else{ m_ridlgs[curch]->m_prbid = prbset.GetNameAt(id-2); m_ridlgs[curch]->cfg_now = CFGTYPE_BORE; } m_ridlgs[curch]->SaveLastConfig(); } if(m_cfgtype == CFGTYPE_THMO) { if(m_ridlgs[curch]->IsValid() && (id == 1)) //just close it { m_ridlgs[curch]->cfg_now = CFGTYPE_NONE; for(int i=0;i<sizeof(m_ridlgs)/sizeof(CRunitemDialog*);i++){ if((m_ridlgs[i]->cfg_now == CFGTYPE_THMO) && (i != curch) && (m_ridlgs[i]->side_ch == curch)) { m_ridlgs[i]->sidedata = NULL; } } }else{ if(id != 1){ m_ridlgs[curch]->cfg_now = CFGTYPE_THMO; CString types(_T("TBEJKNRS")); m_ridlgs[curch]->m_prbid = types.GetAt(id-2); } } m_ridlgs[curch]->SaveLastConfig(); } } LoadCurrentView(); }
void CHello2Dlg::Refresh() { int curch = m_chlist.GetCurSel(); if(curch < 0) return; int curcfg = m_cfgtype; //clear the history and graph while(m_history.GetCount() > 0) m_history.DeleteString(0); if(m_ridlgs[curch]->cfg_now != m_cfgtype) { m_graph.AssignMainData(NULL); m_graph.AssignSideData(NULL); m_graph.Invalidate(); return; } //update data shown in graph, (data and text) m_graph.AssignMainData(&m_ridlgs[curch]->m_data); m_graph.ch = curch; m_graph.AssignSideData(m_ridlgs[curch]->sidedata); m_graph.side_ch = m_ridlgs[curch]->side_ch; CString dat; if(m_ridlgs[curch]->cfg_now == CFGTYPE_THMO) { m_graph.smalltext.Format(_T("%.4f mV"),CGraph::GetAverage(&m_ridlgs[curch]->m_output)); m_graph.bigtext.Format(_T("%.4f ℃"),CGraph::GetAverage(&m_ridlgs[curch]->m_data)); }else{ if(m_ridlgs[curch]->cfg_now == CFGTYPE_RESI) { m_graph.smalltext.Format(_T("%.4f Ω"),CGraph::GetAverage(&m_ridlgs[curch]->m_output)); m_graph.bigtext.Format(_T("%.4f ℃"),CGraph::GetAverage(&m_ridlgs[curch]->m_data)); }else{ m_graph.smalltext = m_ridlgs[curch]->m_smalltxt; m_graph.bigtext = m_ridlgs[curch]->m_bigtxt; } } m_graph.ch = curview; m_graph.Invalidate(); //add data to history listbox CList<double,double> *data = &m_ridlgs[curch]->m_data; if(m_ridlgs[curch]->show_type == SHOW_ORGDATA) data = &m_ridlgs[curch]->m_output; if(data && (data->GetCount() > 0)) { POSITION pos = data->GetHeadPosition(); do{ double v = data->GetAt(pos); CString r; r.Format(_T("%8f"),v); m_history.AddString(r); if(pos == data->GetTailPosition()) break; data->GetNext(pos); }while(1); if(m_history.GetCount() > 0) m_history.SetCaretIndex(m_history.GetCount()-1,0); } }
uint32_t CKademlia::CalculateKadUsersNew(){ // the idea of calculating the user count with this method is simple: // whenever we do search for any NodeID (except in certain cases were the result is not usable), // we remember the distance of the closest node we found. Because we assume all NodeIDs are distributed // equally, we can calcualte based on this distance how "filled" the possible NodesID room is and by this // calculate how many users there are. Of course this only works if we have enough samples, because // each single sample will be wrong, but the average of them should produce a usable number. To avoid // drifts caused by a a single (or more) really close or really far away hits, we do use median-average instead through // doesnt works well if we have no files to index and nothing to download and the numbers seems to be a bit too low // compared to out other method. So lets stay with the old one for now, but keeps this here as alternative if (m_liStatsEstUsersProbes.GetCount() < 10) return 0; uint32_t nMedian = 0; CList<uint32_t, uint32_t> liMedian; for (POSITION pos1 = m_liStatsEstUsersProbes.GetHeadPosition(); pos1 != NULL; ) { uint32_t nProbe = m_liStatsEstUsersProbes.GetNext(pos1); bool bInserted = false; for (POSITION pos2 = liMedian.GetHeadPosition(); pos2 != NULL; liMedian.GetNext(pos2)){ if (liMedian.GetAt(pos2) > nProbe){ liMedian.InsertBefore(pos2, nProbe); bInserted = true; break; } } if (!bInserted) liMedian.AddTail(nProbe); } // cut away 1/3 of the values - 1/6 of the top and 1/6 of the bottom to avoid spikes having too much influence, build the average of the rest int32_t nCut = liMedian.GetCount() / 6; for (int i = 0; i != nCut; i++){ liMedian.RemoveHead(); liMedian.RemoveTail(); } uint64_t nAverage = 0; for (POSITION pos1 = liMedian.GetHeadPosition(); pos1 != NULL; ) nAverage += liMedian.GetNext(pos1); nMedian = (uint32_t)(nAverage / liMedian.GetCount()); // LowIDModififier // Modify count by assuming 20% of the users are firewalled and can't be a contact for < 0.49b nodes // Modify count by actual statistics of Firewalled ratio for >= 0.49b if we are not firewalled ourself // Modify count by 40% for >= 0.49b if we are firewalled outself (the actual Firewalled count at this date on kad is 35-55%) const float fFirewalledModifyOld = 1.20F; float fFirewalledModifyNew = 0; if (CUDPFirewallTester::IsFirewalledUDP(true)) fFirewalledModifyNew = 1.40F; // we are firewalled and get get the real statistic, assume 40% firewalled >=0.49b nodes else if (GetPrefs()->StatsGetFirewalledRatio(true) > 0) { fFirewalledModifyNew = 1.0F + (CKademlia::GetPrefs()->StatsGetFirewalledRatio(true)); // apply the firewalled ratio to the modify ASSERT( fFirewalledModifyNew > 1.0F && fFirewalledModifyNew < 1.90F ); } float fNewRatio = CKademlia::GetPrefs()->StatsGetKadV8Ratio(); float fFirewalledModifyTotal = 0; if (fNewRatio > 0 && fFirewalledModifyNew > 0) // weigth the old and the new modifier based on how many new contacts we have fFirewalledModifyTotal = (fNewRatio * fFirewalledModifyNew) + ((1 - fNewRatio) * fFirewalledModifyOld); else fFirewalledModifyTotal = fFirewalledModifyOld; ASSERT( fFirewalledModifyTotal > 1.0F && fFirewalledModifyTotal < 1.90F ); return (uint32_t)((float)nMedian*fFirewalledModifyTotal); }
void CPopulation::AssignRankAndCrowdingDistance() { ASSERT(individuals != NULL); ASSERT(pProblem != NULL); int front_size = 0; int rank = 1; int orig_index, cur_index; POSITION pos1, pos2, tmp_pos; CList<int, int> orig; CList<int, int> cur; for (int i=0; i<pProblem->popsize; i++) orig.AddTail(i); while (!orig.IsEmpty()) { pos1 = orig.GetHeadPosition(); orig_index = orig.GetNext(pos1); if (pos1 == NULL) { individuals[orig_index].rank = rank; individuals[orig_index].crowd_dist = INF; break; } cur.AddHead(orig_index); front_size = 1; orig.RemoveHead(); pos1 = orig.GetHeadPosition(); while (pos1 != NULL) { int flag = -1; orig_index = orig.GetAt(pos1); pos2 = cur.GetHeadPosition(); while (pos2 != NULL) { cur_index = cur.GetAt(pos2); flag = individuals[orig_index].CheckDominance(individuals[cur_index]); if (flag == 1) { orig.AddHead(cur_index); front_size--; tmp_pos = pos2; cur.GetNext(pos2); cur.RemoveAt(tmp_pos); } else if (flag == 0) { cur.GetNext(pos2); } else if (flag == -1) { break; } } if (flag != -1) { cur.AddHead(orig_index); front_size++; tmp_pos = pos1; orig.GetNext(pos1); orig.RemoveAt(tmp_pos); } else { orig.GetNext(pos1); } } pos2 = cur.GetHeadPosition(); while (pos2 != NULL) { cur_index = cur.GetNext(pos2); individuals[cur_index].rank = rank; } AssignCrowdingDistanceList((void*) &cur, front_size); cur.RemoveAll(); rank++; } }
int CFileSizeFilter::FilterDuplicateList( CList<CFileInfo*,CFileInfo*> & FileList) { int Count = 0; bool FilterIt = false; int Iteration = 0; POSITION xPos; // update status and log g_DupeFileFind.m_DuffStatus.Lock(); g_DupeFileFind.m_DuffStatus.CurrentTaskInfo = m_sName; g_DupeFileFind.m_DuffStatus.SubProgress2.Min = 0; g_DupeFileFind.m_DuffStatus.SubProgress2.Max = FileList.GetCount(); g_DupeFileFind.m_DuffStatus.Unlock(); // //for (i = 0; i < FileList.GetSize(); i++) xPos = FileList.GetHeadPosition(); while (xPos) { switch(m_FilterType) { case FT_NOT_EQUAL: // not equal FilterIt = ( FileList.GetAt(xPos)->Size == m_Value1 ); break; case FT_EQUAL: // equal FilterIt = ( FileList.GetAt(xPos)->Size != m_Value1 ); break; case FT_GREATER_THAN: // greater FilterIt = ( FileList.GetAt(xPos)->Size <= m_Value1 ); break; case FT_LESS_THAN: // less FilterIt = ( FileList.GetAt(xPos)->Size >= m_Value1 ); break; case FT_BETWEEN: // between FilterIt = ( FileList.GetAt(xPos)->Size < m_Value1 || FileList.GetAt(xPos)->Size > m_Value2 ); break; case FT_NOT_BETWEEN: // not between FilterIt = ( FileList.GetAt(xPos)->Size >= m_Value1 && FileList.GetAt(xPos)->Size <= m_Value2 ); break; default: return 0; } if (FilterIt) { //FileList.ElementAt(i)->Unaccessible = true; POSITION Pos2 = xPos; FileList.GetNext(Pos2); delete FileList.GetAt(xPos); FileList.RemoveAt(xPos); //i--; xPos = Pos2; Count++; } else { FileList.GetNext(xPos); } Iteration ++; // update status and log if ( g_DupeFileFind.m_DuffStatus.LockIfUnlocked() ) { g_DupeFileFind.m_DuffStatus.SubProgress2.Pos = Iteration; g_DupeFileFind.m_DuffStatus.Unlock(); } // } return Count; }
void CFileMoveProcess::ProcessFiles ( CList<CFileInfo *, CFileInfo *> & FileList) { CString Msg; SHFILEOPSTRUCT fos; TCHAR pDirBuffer[MAX_PATH]; TCHAR pFilenameBuffer[MAX_PATH]; CFileInfo * pFileInfo; POSITION ListPos; // setup to directory buffer // pDirBuffer = new TCHAR[m_Dir.GetLength()+2]; strcpy( pDirBuffer, (LPCSTR) m_Dir); pDirBuffer[m_Dir.GetLength()] = '\0'; pDirBuffer[m_Dir.GetLength()+1] = '\0'; // // setup struct fos.hwnd = AfxGetMainWnd()->m_hWnd; fos.wFunc= FO_MOVE; fos.pTo = pDirBuffer; fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI; fos.lpszProgressTitle = "NULL"; // // set confirmation flag if ( m_YesToAll ) fos.fFlags |= FOF_NOCONFIRMATION; // /* for ( int i = 0; i < FileList.GetSize(); i++) { //if ( ((CDuffDlg*)GetParent()->GetParent())->m_DuplicatePage.m_DupeList.GetCheck(i) == BST_CHECKED ) //{ Temp = FileList.ElementAt(i).m_Filename; //TotalLength += Temp.GetLength() +1; FilesToDelete.Add(Temp); //} } */ // update progress information pDuffStatus->Lock(); pDuffStatus->CurrentTaskStr = "Moving selected duplicate files..."; pDuffStatus->CurrentTaskInfo = ""; pDuffStatus->SubProgress1.Min = 0; pDuffStatus->SubProgress1.Pos = 0; pDuffStatus->SubProgress1.Max = FileList.GetCount(); pDuffStatus->Unlock(); // ListPos = FileList.GetHeadPosition(); while (ListPos) { pFileInfo = FileList.GetAt(ListPos); // process only the selected files if ( pFileInfo->Selected) { if ( ! (pFileInfo->Attributes & FILE_ATTRIBUTE_READONLY) || m_MoveReadOnly ) { /* // remove read-only attribute if ( FileList.ElementAt(i)->ReadOnly ) { DWORD FileAttributes; FileAttributes = GetFileAttributes( FileList.ElementAt(i)->Filename ) FileAttributes ^= FILE_ATTRIBUTE_READONLY; SetFileAttributes(FileList.ElementAt(i)->Filename,FileAttributes ); }*/ _tcscpy(pFilenameBuffer, pFileInfo->GetFullName() ); UINT Length = _tcslen( pFilenameBuffer ); // for (int x = 0; x < FileList.ElementAt(i)->Filename.GetLength(); x++) // { // pFilenameBuffer[x] = FileList.ElementAt(i)->Filename.GetAt(x); // } pFilenameBuffer[Length] = 0; pFilenameBuffer[Length+1] = 0; fos.pFrom = pFilenameBuffer; // g_DupeFileFind.GetDuffDlg()->m_CurrentTaskInfoText.SetWindowText(FileList.ElementAt(i)->GetFullName()); // g_DupeFileFind.GetDuffDlg()->m_CurrentTaskInfoText.RedrawWindow(); // update progress information pDuffStatus->Lock(); pDuffStatus->CurrentTaskInfo = pFileInfo->GetFullName(); pDuffStatus->SubProgress1.Pos++; pDuffStatus->Unlock(); // /* Msg.Format("Moving:\n%s\nto:\n%s",FileList.ElementAt(i)->m_Filename,fos.pTo); MessageBox(NULL,Msg,"FYI",MB_OK); */ if ( SHFileOperation(&fos) ) { Msg.Format("ERROR moving file: %s to %s",pFileInfo->GetFullName(),m_Dir); // g_DupeFileFind.GetDuffDlg()->Log(Msg); } else { Msg.Format("Moved file: %s to %s",pFileInfo->GetFullName(),m_Dir); // g_DupeFileFind.GetDuffDlg()->Log(Msg); } // g_DupeFileFind.GetDuffDlg()->m_ProgressEntire.StepIt(); // delete []pFilenameBuffer; } } FileList.GetNext(ListPos); } // delete[] pDirBuffer; }
//current 变化后,以上没有问题了。 void Genetic::crossoveroperator() { //非均匀算术线性交叉,浮点数适用,alpha ,beta是(0,1)之间的随机数 //对种群中两两交叉的个体选择也是随机选择的。也可取beta=1-alpha; //current的变化会有一些改变。 int i,j; double alpha,beta; CList <int,int> index; int point,temp; double p; // srand( (unsigned)time( NULL ) ); for (i=0;i<popsize;i++)//生成序号 { index.InsertAfter (index.FindIndex(i),i); } for (i=0;i<popsize;i++)//打乱序号 { point=rand()%(popsize-1); temp=index.GetAt(index.FindIndex(i)); index.SetAt(index.FindIndex(i), index.GetAt(index.FindIndex(point))); index.SetAt(index.FindIndex(point),temp); } for (i=0;i<popsize-1;i+=2) { //按顺序序号,按序号选择两个母体进行交叉操作。 p=double(rand()%10000)/10000.0; if (p<crossoverrate) { alpha=double(rand()%10000)/10000.0; beta=double(rand()%10000)/10000.0; current=population.GetAt(population.FindIndex(index.GetAt(index.FindIndex(i)))); current1=population.GetAt(population.FindIndex(index.GetAt(index.FindIndex(i+1))));//临时使用 current1代替 for(j=0;j<variablenum;j++) { //交叉 double sign; sign=rand()%2; if(sign) { current.chromosome[j]=(1-alpha)*current.chromosome[j]+ beta*current1.chromosome[j]; } else { current.chromosome[j]=(1-alpha)*current.chromosome[j]- beta*current1.chromosome[j]; } if (current.chromosome[j]>variabletop[j]) //判断是否超界. { current.chromosome[j]=double(rand()%10000)/10000*(variabletop[j]-variablebottom[j])+ variablebottom[j]; } if (current.chromosome[j]<variablebottom [j]) { current.chromosome[j]=double(rand()%10000)/10000*(variabletop[j]-variablebottom[j])+ variablebottom[j]; } if(sign) { current1.chromosome[j]=alpha*current.chromosome[j]+ (1- beta)*current1.chromosome[j]; } else { current1.chromosome[j]=alpha*current.chromosome[j]- (1- beta)*current1.chromosome[j]; } if (current1.chromosome[j]>variabletop[j]) { current1.chromosome[j]=double(rand()%10000)/10000*(variabletop[j]-variablebottom[j])+ variablebottom[j]; } if (current1.chromosome[j]<variablebottom [j]) { current1.chromosome[j]=double(rand()%10000)/10000*(variabletop[j]-variablebottom[j])+ variablebottom[j]; } } //回代 } newpopulation.InsertAfter (newpopulation.FindIndex(i),current); newpopulation.InsertAfter (newpopulation.FindIndex(i),current1); }
unsigned int CFileLocationMarker::MakeSelections( CList< CList<CFileInfo *,CFileInfo *> *,CList<CFileInfo *,CFileInfo *> * > & DupeList) { //int x,y; POSITION xPos, yPos; int Count = 0; bool Found; //for (x = 0; x < DupeList.GetSize(); x++) xPos = DupeList.GetHeadPosition(); while (xPos) { Found = false; //y = 0; //while (!Found && y < DupeList.ElementAt(x)->GetSize()) yPos = DupeList.GetAt(xPos)->GetHeadPosition(); while (!Found && yPos) { CFileInfo *pFileInfo= DupeList.GetAt(xPos)->GetAt(yPos); switch(m_Option) { case IDC_IN_DIR: if ( (m_Path.CompareNoCase(pFileInfo->GetDirPath()) == 0) || (m_SubDirs && m_Path.CompareNoCase(CString(pFileInfo->GetDirPath()).Left(m_Path.GetLength() )) == 0 ) ) { Found = true; pFileInfo->Selected = true; Count++; } break; case IDC_NOTIN_DIR: if ( (m_Path.CompareNoCase( CString(pFileInfo->GetDirPath()).Left(m_Path.GetLength())) != 0) ) { Found = true; DupeList.GetAt(xPos)->GetAt(yPos)->Selected = true; Count++; } break; default: // should never get here ASSERT(false); break; } //y++; DupeList.GetAt(xPos)->GetNext(yPos); } // if we never found one and we are supposed to mark at least one, then simply mark the first file in the list if (!Found && CFileMarker::GetMarkAtLeastOne() ) { DupeList.GetAt(xPos)->GetHead()->Selected = true; Count++; } // DupeList.GetNext(xPos); } return Count; }
void CHTMLViewCapView::SaveImages(CList<CHTMLViewCapUrl> &lstUrl) { // POSITION pos = NULL; // 浏览器和图片的宽度和高度 DWORD nWidth = 1024; DWORD nHeight = 2048; IDispatch *pDoc = NULL; IViewObject *pViewObject = NULL; VARIANT vUrl; VARIANT vUrlName; // CTime t; CString csTime, csDate, csMark1; CString csPath; CString csFileName; HRESULT hr; // CBitmap *pBM; Bitmap *gdiBMP; // 用于生成图片的序数 static DWORD nNum = 0; /* 创建字体 */ HFONT hfont; LOGFONT lf; ZeroMemory(&lf, sizeof(lf)); lf.lfHeight = 0; lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfStrikeOut = FALSE; lf.lfCharSet = DEFAULT_CHARSET; lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; lf.lfQuality = ANTIALIASED_QUALITY; lf.lfPitchAndFamily = VARIABLE_PITCH; lstrcpy(lf.lfFaceName, _T("微软雅黑")); hfont = CreateFontIndirect(&lf); // 循环遍历所有URL for (pos = lstUrl.GetHeadPosition(); pos != NULL; lstUrl.GetNext(pos)) { // 获取图片和浏览器分辨率 nWidth = lstUrl.GetAt(pos).m_nWidth; nHeight = lstUrl.GetAt(pos).m_nHeight; CString &csUrl = lstUrl.GetAt(pos).m_csUrl; CBitmapDC destDC(nWidth, nHeight); // 创建 媒体名称目录 csPath = ::theApp.m_csImageDir; csPath.Append(_T("\\")); if (lstUrl.GetAt(pos).m_bHasMediaName) { csPath.Append(lstUrl.GetAt(pos).m_csMediaName); } else { csPath.Append(lstUrl.GetAt(pos).getMediaNameInUrl()); } ::CreateDirectory(csPath, NULL); // 创建输出文件路径 t = CTime::GetCurrentTime(); csTime = t.Format("\\%H时%M分%S秒-"); csMark1 = t.Format("%H:%M"); csDate = t.Format(" %Y/%m/%d"); csPath.Append(csTime); vUrl.vt = ::VT_BSTR; vUrl.bstrVal = (BSTR)csUrl.GetString(); m_pBrowserApp->put_Width(nWidth); m_pBrowserApp->put_Height(nHeight); if (m_pBrowserApp->Navigate2(&vUrl, NULL, NULL, NULL, NULL) == S_OK) { m_tBeforeEnterLoop = CTime::GetCurrentTime(); RunModalLoop(); } else { TRACE(_T("%d Document Navigate Failed!\n"), vUrl); MessageBox(_T("Navi Error"), _T("Error"), MB_OK); return ; } TRACE("Begin Cap!\n"); // wait for document to load m_pBrowserApp->Refresh(); // render to enhanced metafile HDC. hr = m_pBrowserApp->get_Document(&pDoc); if (hr != S_OK) { TRACE(_T("%s get_Document failed!\n"), vUrl.bstrVal); return ; } pDoc->QueryInterface(IID_IViewObject, (void**)&pViewObject); // result is first div of document if (pDoc == NULL) { TRACE(_T("%d query IID_IViewObject failed!\n"), vUrl.bstrVal); return ; } hr = OleDraw(pViewObject, DVASPECT_CONTENT, destDC, NULL); if (hr != S_OK) { TRACE(_T("%s OleDraw failed!\n"), vUrl.bstrVal); return ; } /* 使用字体 */ destDC.SelectObject(hfont); destDC.SetTextColor(RGB(0, 0, 0)); destDC.SetBkColor(RGB(235, 231, 228)); //destDC.SetBkMode(TRANSPARENT); // 输出水印 TextOut(destDC, nWidth - 70, nHeight - 100, (LPCTSTR)csMark1, csMark1.GetLength()); TextOut(destDC, nWidth - 100, nHeight - 70, (LPCTSTR)csDate, csDate.GetLength()); pBM = destDC.Close(); gdiBMP = Bitmap::FromHBITMAP(HBITMAP(pBM->GetSafeHandle()), NULL); csFileName.Format(_T("%u.jpg"), nNum++); csPath.Append(csFileName); // 保存图片 gdiBMP->Save(csPath.GetString(), &m_jpegClsid, NULL); // 清理资源 delete gdiBMP; pBM->DeleteObject(); pViewObject->Release(); pDoc->Release(); } }
/** * 响应鼠标单击按钮;Reverse * @param CBCGPGridCtrl* pGridCtrlEdit 输入行 * @param CBCGPGridCtrl* pGridCtrlList 列表 * @param CList<int, int>* plsNb Nb号队列指针 * @return void */ void CGridCtrlOperation::OnBnClickedButtonReverseA(CBCGPGridCtrl* pGridCtrlEdit, CBCGPGridCtrl* pGridCtrlList) { CList<int, int> ListNb; CList<int, int>* plsNb = &ListNb; // 得到索引队列,修改操作、删除操作、颠倒操作 if(false == GetIndexListForChangeOrDeleteOrReverse(pGridCtrlEdit, pGridCtrlList, plsNb)) { return; } CBCGPGridRow* pRow = NULL; // 行 CBCGPGridRow* pRowMax = NULL; // 排序行 CBCGPGridRow* pRowNew = NULL; // 新行 CList<int, int> olsNb; int iNbStart = -1; int iNbEnd = -1; int iRowIndex = -1; int i, j; POSITION posMax; POSITION pos; int iNbMax; int iNb; // 得到Nb队列 for(i = 0; i < plsNb->GetCount(); i++) { pos = plsNb->FindIndex(i); iRowIndex = plsNb->GetAt(pos); iNb = pGridCtrlList->GetRow(iRowIndex)->GetData(); olsNb.AddTail(iNb); if(0 == i) { iNbStart = iNb; } if((plsNb->GetCount() - 1) == i) { iNbEnd = iNb; } } // 对Nb排序,由小到大 for(i = 0; i < olsNb.GetCount(); i++) { posMax = olsNb.FindIndex(i); iNbMax = olsNb.GetAt(posMax); for(j = i + 1; j < olsNb.GetCount(); j++) { pos = olsNb.FindIndex(j); iNb = olsNb.GetAt(pos); if(iNbStart < iNbEnd) { if(iNbMax > iNb) { iNbMax = iNb; posMax = pos; } } else { if(iNbMax < iNb) { iNbMax = iNb; posMax = pos; } } } olsNb.RemoveAt(posMax); olsNb.AddHead(iNbMax); } for(i = 0; i < plsNb->GetCount(); i++) { pos = plsNb->FindIndex(i); iRowIndex = plsNb->GetAt(pos); pRow = pGridCtrlList->GetRow(iRowIndex); posMax = olsNb.FindIndex(i); iNbMax = olsNb.GetAt(posMax); pRowMax = pGridCtrlList->FindRowByData(iNbMax); pRowNew = pGridCtrlList->CreateRow(pGridCtrlList->GetColumnCount()); pGridCtrlList->AddRow(pRowNew, FALSE); pRowNew->SetData(pRow->GetData()); pRowNew->GetItem(0)->SetValue(pRow->GetItem(0)->GetValue()); for(int j = 1; j < pGridCtrlList->GetColumnCount(); j++) { COleVariant oVariant = pRow->GetItem(j)->GetValue(); pRowNew->GetItem(j)->SetValue(oVariant); } pRow->SetData(pRowMax->GetData()); pRow->GetItem(0)->SetValue(pRowMax->GetItem(0)->GetValue()); for(int j = 1; j < pGridCtrlList->GetColumnCount(); j++) { COleVariant oVariant = pRowMax->GetItem(j)->GetValue(); pRow->GetItem(j)->SetValue(oVariant); } pRowMax->SetData(pRowNew->GetData()); pRowMax->GetItem(0)->SetValue(pRowNew->GetItem(0)->GetValue()); for(int j = 1; j < pGridCtrlList->GetColumnCount(); j++) { COleVariant oVariant = pRowNew->GetItem(j)->GetValue(); pRowMax->GetItem(j)->SetValue(oVariant); } pGridCtrlList->RemoveRow((pGridCtrlList->GetRowCount() - 1), FALSE); } pGridCtrlList->AdjustLayout(); }
void CItem::DoSomeWork(DWORD ticks) { if (IsDone()) return; StartPacman(true); DriveVisualUpdateDuringWork(); DWORD start = GetTickCount(); if (GetType() == IT_DRIVE || GetType() == IT_DIRECTORY) { if (!IsReadJobDone()) { LONGLONG dirCount = 0; LONGLONG fileCount = 0; CList<FILEINFO, FILEINFO> files; CFileFindWDS finder; BOOL b = finder.FindFile(GetFindPattern()); while (b) { DriveVisualUpdateDuringWork(); b = finder.FindNextFile(); if (finder.IsDots()) continue; if (finder.IsDirectory()) { dirCount++; AddDirectory(finder); } else { fileCount++; FILEINFO fi; fi.name = finder.GetFileName(); fi.attributes = finder.GetAttributes(); // Retrieve file size fi.length = finder.GetCompressedLength(); finder.GetLastWriteTime(&fi.lastWriteTime); // (We don't use GetLastWriteTime(CTime&) here, because, if the file has // an invalid timestamp, that function would ASSERT and throw an Exception.) files.AddTail(fi); } } CItem *filesFolder = 0; if (dirCount > 0 && fileCount > 1) { filesFolder = new CItem(IT_FILESFOLDER, LoadString(IDS_FILES_ITEM)); filesFolder->SetReadJobDone(); AddChild(filesFolder); } else if (fileCount > 0) { filesFolder = this; } for (POSITION pos=files.GetHeadPosition(); pos != NULL; files.GetNext(pos)) { const FILEINFO& fi = files.GetAt(pos); filesFolder->AddFile(fi); } if (filesFolder != NULL) { filesFolder->UpwardAddFiles(fileCount); if (dirCount > 0 && fileCount > 1) filesFolder->SetDone(); } UpwardAddSubdirs(dirCount); SetReadJobDone(); AddTicksWorked(GetTickCount() - start); } if (GetType() == IT_DRIVE) UpdateFreeSpaceItem(); if (GetTickCount() - start > ticks) { StartPacman(false); return; } } if (GetType() == IT_DRIVE || GetType() == IT_DIRECTORY || GetType() == IT_MYCOMPUTER) { ASSERT(IsReadJobDone()); if (IsDone()) { StartPacman(false); return; } if (GetChildrenCount() == 0) { SetDone(); StartPacman(false); return; } DWORD startChildren = GetTickCount(); while (GetTickCount() - start < ticks) { DWORD minticks = UINT_MAX; CItem *minchild = NULL; for (int i=0; i < GetChildrenCount(); i++) { CItem *child = GetChild(i); if (child->IsDone()) continue; if (child->GetTicksWorked() < minticks) { minticks = child->GetTicksWorked(); minchild = child; } } if (minchild == NULL) { SetDone(); break; } DWORD tickssofar = GetTickCount() - start; if (ticks > tickssofar) minchild->DoSomeWork(ticks - tickssofar); } AddTicksWorked(GetTickCount() - startChildren); } else { SetDone(); } StartPacman(false); }