void CGumpControlListDlg::OnBnClickedOrderChange() { CDEditor& editor = m_pView->GetDEditor(); CSortListCtrl& ctrl = m_lsControl; CUIntArray arOrder; arOrder.SetSize(ctrl.GetItemCount()); for (int i =0; i < ctrl.GetItemCount(); i++) arOrder[ctrl.GetItemData(i)] = atoi(ctrl.GetItemText(i, ORDER_COLUMN)); editor.Reorder(arOrder); editor.SetModified(TRUE); editor.RedrawWindow(); OnOK(); }
void CGenPropertyPage::OnDeleteItem() { CUIntArray arySelected; int iCount = m_ctlList->GetSelectedCount (); int nItem, i, iIncluded = 0, iExecuting = 0; arySelected.SetSize (iCount); // first, remember selected items for (nItem = -1, i = 0; (nItem = m_ctlList->GetNextItem(nItem, LVNI_SELECTED)) != -1;) arySelected [i++] = nItem; if (iCount == 0) return; if (App.m_bTriggerRemoveCheck) { // mucking around to make it plural properly CString sName = m_strObjectType; if (iCount > 1) if (sName == "alias") sName += "es"; else sName += "s"; if (::UMessageBox (TFormat ("Delete %i %s - are you sure?", iCount, sName), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) != IDYES ) return; } // end of wanting to confirm // we do it this way because deleting items buggers up the position in the array for (i = iCount - 1; i >= 0; i--) { nItem = arySelected [i]; // get the lower-case name of this item's object CString * pstrObjectName = (CString *) m_ctlList->GetItemData (nItem); ASSERT (pstrObjectName != NULL); CObject * pItem; // see if in the map if (!m_ObjectMap->Lookup (*pstrObjectName, pItem)) continue; // already deleted! ASSERT_VALID (pItem); ASSERT( pItem->IsKindOf( RUNTIME_CLASS( CObject ) ) ); if (CheckIfIncluded (pItem)) { iIncluded++; // don't do message here in case hundreds of them continue; } if (CheckIfExecuting (pItem)) { iExecuting++; // don't do message here in case hundreds of them continue; } // They can no longer cancel the property sheet, the document has changed CancelToClose (); if (!CheckIfTemporary (pItem)) m_doc->SetModifiedFlag (TRUE); // delete from the map m_ObjectMap->RemoveKey (*pstrObjectName); // delete the item itself delete pItem; // and remove from the dialog list control m_ctlList->DeleteItem (nItem); // delete its item string delete pstrObjectName; } // end of dealing with each selected item if (iIncluded) { CString strMsg; strMsg = TFormat ("%i item%s %s included from an include file. You cannot delete %s here.", PLURAL (iIncluded), iIncluded == 1 ? "was" : "were", iIncluded == 1 ? "it" : "them"); ::UMessageBox (strMsg); } if (iExecuting) { CString strMsg; strMsg = TFormat ("%i item%s %s currently executing a script. You cannot delete %s now.", PLURAL (iExecuting), iExecuting == 1 ? "is" : "are", iExecuting == 1 ? "it" : "them"); ::UMessageBox (strMsg); } } // end of CGenPropertyPage::OnDeleteItem
void CPlayerSubresyncBar::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult) { NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR); *pResult = CDRF_DODEFAULT; if (CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage) { m_itemGroups.SetSize(m_list.GetItemCount()); m_totalGroups = 0; for (int i = 0, j = m_list.GetItemCount(); i < j; i++) { if (m_list.GetItemData(i)&TSEP) { m_totalGroups++; } m_itemGroups[i] = m_totalGroups; } *pResult = CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW; } else if (CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage) { pLVCD->nmcd.uItemState &= ~CDIS_FOCUS; *pResult = CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW; } else if ((CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage) { COLORREF clrText; COLORREF clrTextBk; if ((pLVCD->iSubItem == COL_START || pLVCD->iSubItem == COL_END || pLVCD->iSubItem == COL_TEXT || pLVCD->iSubItem == COL_STYLE || pLVCD->iSubItem == COL_LAYER || pLVCD->iSubItem == COL_ACTOR || pLVCD->iSubItem == COL_EFFECT) && m_mode == TEXTSUB) { clrText = 0; } else if ((pLVCD->iSubItem == COL_START) && m_mode == VOBSUB) { clrText = 0; } else { clrText = 0x606060; } clrTextBk = 0xffffff; // if (m_totalGroups > 0) clrTextBk -= ((m_itemGroups[pLVCD->nmcd.dwItemSpec] & 1) ? 0x100010 : 0x200020); if (m_sts[pLVCD->nmcd.dwItemSpec].start <= m_rt / 10000 && m_rt / 10000 < m_sts[pLVCD->nmcd.dwItemSpec].end) { clrText |= 0xFF; } int nCheck = (int)m_list.GetItemData((int)pLVCD->nmcd.dwItemSpec); if ((nCheck & 1) && (pLVCD->iSubItem == COL_START || pLVCD->iSubItem == COL_PREVSTART)) { clrTextBk = 0xffddbb; } else if ((nCheck & 4) && (/*pLVCD->iSubItem == COL_START ||*/ pLVCD->iSubItem == COL_PREVSTART)) { clrTextBk = 0xffeedd; } if ((nCheck & 2) && (pLVCD->iSubItem == COL_END || pLVCD->iSubItem == COL_PREVEND)) { clrTextBk = 0xffddbb; } else if ((nCheck & 8) && (/*pLVCD->iSubItem == COL_END ||*/ pLVCD->iSubItem == COL_PREVEND)) { clrTextBk = 0xffeedd; } pLVCD->clrText = clrText; pLVCD->clrTextBk = clrTextBk; *pResult = CDRF_NOTIFYPOSTPAINT; } else if ((CDDS_ITEMPOSTPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage) { // *pResult = CDRF_DODEFAULT; } else if (CDDS_ITEMPOSTPAINT == pLVCD->nmcd.dwDrawStage) { int nItem = static_cast<int>(pLVCD->nmcd.dwItemSpec); LVITEM rItem; ZeroMemory(&rItem, sizeof(LVITEM)); rItem.mask = LVIF_IMAGE | LVIF_STATE; rItem.iItem = nItem; rItem.stateMask = LVIS_SELECTED; m_list.GetItem(&rItem); { CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc); CRect rcItem; m_list.GetItemRect(nItem, &rcItem, LVIR_BOUNDS); { bool fSeparator = nItem < m_list.GetItemCount() - 1 && (m_list.GetItemData(nItem + 1)&TSEP); CPen p(PS_INSIDEFRAME, 1, fSeparator ? 0x404040 : 0xe0e0e0); CPen* old = pDC->SelectObject(&p); pDC->MoveTo(CPoint(rcItem.left, rcItem.bottom - 1)); pDC->LineTo(CPoint(rcItem.right, rcItem.bottom - 1)); pDC->SelectObject(old); } { CPen p(PS_INSIDEFRAME, 1, 0xe0e0e0); CPen* old = pDC->SelectObject(&p); CHeaderCtrl* pHeader = (CHeaderCtrl*)m_list.GetDlgItem(0); int nColumnCount = pHeader->GetItemCount(); // Get the column offset int offset = rcItem.left; for (int i = 0; i < nColumnCount; i++) { offset += m_list.GetColumnWidth(i); pDC->MoveTo(CPoint(offset, rcItem.top)); pDC->LineTo(CPoint(offset, rcItem.bottom)); } pDC->SelectObject(old); } *pResult = CDRF_SKIPDEFAULT; } } else if (CDDS_POSTPAINT == pLVCD->nmcd.dwDrawStage) { } }
void CSListView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { // TODO: Add your specialized code here and/or call the base class if( UPDATE_HINT_SLISTVIEW != lHint ) return; if( IsWindowVisible() ) SetFocus( ); int nColumnCount = m_Grid.GetColumnCount(); if( nColumnCount <= 0 ) return; if( GetParentFrame()->GetSafeHwnd() != AfxGetMainFrame()->GetActiveFrame()->GetSafeHwnd() ) { m_bShouldUpdate = TRUE; return; } m_bShouldUpdate = FALSE; CStockContainer & container = AfxGetSListStockContainer(); container.Lock(); m_Grid.DeleteNonFixedRows(); // Progress CUIntArray anParams; anParams.SetSize( 0, nColumnCount ); for( int nCol=0; nCol < nColumnCount; nCol ++ ) { LPARAM lParam = m_Grid.GetItemData( 0, nCol ); anParams.Add( lParam ); } CRect rectClient; GetClientRect( &rectClient ); int nPageCount = 1 + rectClient.Height() / abs(m_Grid.GetFixedRowHeight()) + 1; /** disabled for( int i=0; i<container.GetSize(); i++ ) { CStockInfo & info = container.GetStockInfoByID(i); int nRow = m_Grid.InsertRow( info.GetStockName() ); m_Grid.SetItemData( nRow, 0, i ); for( int nCol=0; nCol<anParams.GetSize(); nCol++ ) { m_Grid.SetItemFormat( nRow, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE ); m_Grid.SetItemText( nRow, nCol, AfxGetVariantDispString( anParams[nCol], info, &container ) ); m_Grid.SetItemBkColour( nRow, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); m_Grid.SetItemFgColour( nRow, nCol, AfxGetVariantColor( anParams[nCol], info ) ); if( anParams[nCol] == SLH_DATE ) m_Grid.SetColumnWidth( nCol, 80 ); } if( i == nPageCount+5 ) { m_Grid.Invalidate( ); MSG msg; while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) ) AfxGetApp()->PumpMessage(); } if( pMainFrame ) pMainFrame->SetProgress( 100*i/container.GetSize() ); } // Set Average and Weight Average SetAverageItem( m_Grid, container, FALSE ); // Sort If Needed if( -1 != m_nColSort ) { LPARAM lParam = m_Grid.GetItemData( 0, m_nColSort ); if( lParam >= 0 ) { CStockContainer::m_pSortContainer = &container; container.m_nSortVariantID = lParam; container.m_bSortAscend = m_bSortAscend; m_Grid.SortItems( ItemCompareFunc, 0, TRUE ); } } */ for(int i= 0;i<1;i++) { int nRow = m_Grid.InsertRow( "sz002376"); m_Grid.SetItemData( nRow, 0, i ); const char * paramValues [] = {"新北洋","sz002376","1000","1000","1000","17.74","19.08","17740","-1340.0"}; for( int nCol=0; nCol<9; nCol++ ) { m_Grid.SetItemFormat( nRow, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE ); m_Grid.SetItemText( nRow, nCol, paramValues[nCol] ); m_Grid.SetItemBkColour( nRow, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); //m_Grid.SetItemFgColour( nRow, nCol, ); if( anParams[nCol] == SLH_DATE ) m_Grid.SetColumnWidth( nCol, 80 ); } } int nRow = m_Grid.InsertRow( "summary"); //m_Grid.SetItemData( nRow, 0, 1 ); const char * sumValues [] = {"","","","","","","合计(人民币)","17740","-1340.0"}; for( int ic=0; ic<9; ic++ ) { m_Grid.SetItemFormat( nRow, ic, DT_CENTER|DT_VCENTER|DT_SINGLELINE ); m_Grid.SetItemText( nRow, ic, sumValues[ic] ); m_Grid.SetItemBkColour( nRow, 0, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); } nRow = m_Grid.InsertRow( "blank"); m_Grid.SetItemText( nRow, 0, "" ); m_Grid.SetItemBkColour( nRow, 0, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); //m_Grid.SetItemData( nRow, 0, 1 ); nRow = m_Grid.InsertRow( "allheader"); const char * allValues [] = {"币种","资金余额","可用资金","可取资金","证券市值","资产总值","","",""}; for( ic=0; ic<9; ic++ ) { m_Grid.SetItemFormat( nRow, ic, DT_CENTER|DT_VCENTER|DT_SINGLELINE ); m_Grid.SetItemText( nRow, ic, allValues[ic] ); m_Grid.SetItemBkColour( nRow, ic, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); m_Grid.SetItemFgColour( nRow, ic, 0x00ff0000 ); LOGFONT *pfont = m_Grid.GetItemFont(nRow,ic); pfont->lfWeight = 700; m_Grid.SetItemFont(nRow,ic,pfont); } nRow = m_Grid.InsertRow( "alldata"); const char * alldataValues [] = {"人民币","2163.99","2163.99","2163.99","17740","19903.99","","",""}; for( ic=0; ic<9; ic++ ) { m_Grid.SetItemFormat( nRow, ic, DT_CENTER|DT_VCENTER|DT_SINGLELINE ); m_Grid.SetItemText( nRow, ic, alldataValues[ic] ); m_Grid.SetItemBkColour( nRow, ic, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); } if( m_bFirstUpdate ) m_Grid.AutoSizeColumns( ); else m_Grid.SetColumnWidth( 0, 80 ); m_bFirstUpdate = FALSE; m_Grid.Invalidate( ); //SendRequestQuote(TRUE); container.UnLock(); }
BOOL CSListView::SetAverageItem( CGridCtrl &grid, CStockContainer & container, BOOL bRedraw ) { if( grid.GetColumnCount() <= 0 ) return FALSE; container.Lock(); // Get LPARAM CUIntArray anParams; anParams.SetSize( 0, grid.GetColumnCount() ); for( int nCol=0; nCol < grid.GetColumnCount(); nCol ++ ) { LPARAM lParam = grid.GetItemData( 0, nCol ); anParams.Add( lParam ); } // Set Average CStockInfo & infoAve = container.GetAverage( ); CStockInfo & infoWAve = container.GetWeightAverage( ); int iRowAve=0, iRowWAve=0; if( grid.GetRowCount() >= 3 && grid.GetItemData(grid.GetRowCount()-2,0) == (LPARAM)ID_STOCKCNTN_AVERAGE && grid.GetItemData(grid.GetRowCount()-1,0) == (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE ) { // get item id iRowAve = grid.GetRowCount()-2; iRowWAve = grid.GetRowCount()-1; } else { // Insert item iRowAve = grid.InsertRow( infoAve.GetStockName() ); grid.SetItemData( iRowAve, 0, (LPARAM)ID_STOCKCNTN_AVERAGE ); iRowWAve = grid.InsertRow( infoWAve.GetStockName() ); grid.SetItemData( iRowWAve, 0, (LPARAM)ID_STOCKCNTN_WEIGHTAVERAGE ); } // Set Average for( nCol=0; nCol<anParams.GetSize(); nCol++ ) { grid.SetItemText( iRowAve, nCol, AfxGetVariantDispString(anParams[nCol], infoAve, NULL) ); grid.SetItemBkColour( iRowAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); grid.SetItemFgColour( iRowAve, nCol, AfxGetVariantColor( anParams[nCol], infoAve ) ); } // Set Weight Average for( nCol=0; nCol<anParams.GetSize(); nCol++ ) { grid.SetItemText( iRowWAve, nCol, AfxGetVariantDispString(anParams[nCol], infoWAve, NULL) ); grid.SetItemBkColour( iRowWAve, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); grid.SetItemFgColour( iRowWAve, nCol, AfxGetVariantColor( anParams[nCol], infoWAve ) ); } // Set Param which is // SLH_MARKETVALUE, SLH_MARKETVALUEA, SLH_MARKETVALUEB and etc, and more than SLH_USERDEFINE_BEGIN for( nCol=0; nCol < anParams.GetSize(); nCol ++ ) { UINT lParam = anParams[nCol]; if( SLH_DIFF == lParam || SLH_DIFFPERCENT == lParam || SLH_SCOPE == lParam || SLH_DIFFPERCENT_MIN5 == lParam || SLH_PE == lParam || SLH_PMAININCOME == lParam || SLH_RATIO_PCASH == lParam || SLH_RATIO_CURRENCY == lParam || SLH_RATIO_CHANGEHAND == lParam || SLH_RATIO_VOLUME == lParam || SLH_RS == lParam || SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam || lParam >= SLH_USERDEFINE_BEGIN ) { double dc = 0., average = 0.; double wsum = 0.0001, waverage = 0., w = 0.; for( int iRow=1; iRow<grid.GetRowCount(); iRow++ ) { if( iRow == iRowAve || iRow == iRowWAve ) continue; int id = grid.GetItemData(iRow,0); if( id < 0 || id > container.GetSize() ) continue; CStockInfo & info = container.ElementAt(id); w = info.m_fShare_count_total; double dValue = 0.; if( !AfxGetVariantValue( lParam, info, &dValue, &container ) ) continue; average = (average * dc + dValue)/(dc+1); waverage = (waverage * wsum + dValue * w)/(wsum+w); dc += 1; wsum += w; } CString strText; if( SLH_MARKETVALUE == lParam || SLH_MARKETVALUEA == lParam || SLH_MARKETVALUEB == lParam ) { strText.Format( "%u", (DWORD)average ); grid.SetItemText( iRowAve, nCol, strText ); grid.SetItemText( iRowWAve, nCol, "-" ); } else { strText.Format( "%.2f", average ); grid.SetItemText( iRowAve, nCol, strText ); strText.Format( "%.2f", waverage ); grid.SetItemText( iRowWAve, nCol, strText ); } } } container.UnLock(); if( bRedraw ) { grid.RedrawRow( iRowAve ); grid.RedrawRow( iRowWAve ); } return TRUE; }
void CSListView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { // TODO: Add your specialized code here and/or call the base class if( UPDATE_HINT_SLISTVIEW != lHint ) return; if( IsWindowVisible() ) SetFocus( ); int nColumnCount = m_Grid.GetColumnCount(); if( nColumnCount <= 0 ) return; if( GetParentFrame()->GetSafeHwnd() != AfxGetMainFrame()->GetActiveFrame()->GetSafeHwnd() ) { m_bShouldUpdate = TRUE; return; } m_bShouldUpdate = FALSE; CStockContainer & container = AfxGetSListStockContainer(); container.Lock(); m_Grid.DeleteNonFixedRows(); // Progress CMainFrame * pMainFrame = AfxGetMainFrame(); if( pMainFrame ) { pMainFrame->ShowProgressBar( ); pMainFrame->SetProgress( 0 ); pMainFrame->SetMessageText( IDS_MAINFRAME_WAITING ); } CUIntArray anParams; anParams.SetSize( 0, nColumnCount ); for( int nCol=0; nCol < nColumnCount; nCol ++ ) { LPARAM lParam = m_Grid.GetItemData( 0, nCol ); anParams.Add( lParam ); } CRect rectClient; GetClientRect( &rectClient ); int nPageCount = 1 + rectClient.Height() / abs(m_Grid.GetFixedRowHeight()) + 1; for( int i=0; i<container.GetSize(); i++ ) { CStockInfo & info = container.GetStockInfoByID(i); int nRow = m_Grid.InsertRow( info.GetStockName() ); m_Grid.SetItemData( nRow, 0, i ); for( int nCol=0; nCol<anParams.GetSize(); nCol++ ) { m_Grid.SetItemFormat( nRow, nCol, DT_CENTER|DT_VCENTER|DT_SINGLELINE ); m_Grid.SetItemText( nRow, nCol, AfxGetVariantDispString( anParams[nCol], info, &container ) ); m_Grid.SetItemBkColour( nRow, nCol, AfxGetProfile().GetColor(CColorClass::clrSListBK) ); m_Grid.SetItemFgColour( nRow, nCol, AfxGetVariantColor( anParams[nCol], info ) ); if( anParams[nCol] == SLH_DATE ) m_Grid.SetColumnWidth( nCol, 80 ); if( anParams[nCol] == SLH_CODE ) m_Grid.SetColumnWidth( nCol, 60 ); } if( i == nPageCount+5 ) { m_Grid.Invalidate( ); MSG msg; while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) ) AfxGetApp()->PumpMessage(); } if( pMainFrame ) pMainFrame->SetProgress( 100*i/container.GetSize() ); } // Set Average and Weight Average // SetAverageItem( m_Grid, container, FALSE ); // Sort If Needed if( -1 != m_nColSort ) { LPARAM lParam = m_Grid.GetItemData( 0, m_nColSort ); if( lParam >= 0 ) { CStockContainer::m_pSortContainer = &container; container.m_nSortVariantID = lParam; container.m_bSortAscend = m_bSortAscend; m_Grid.SortItems( ItemCompareFunc, 0, TRUE ); } } if( pMainFrame ) { pMainFrame->SetProgress( 100 ); pMainFrame->HideProgressBar( ); pMainFrame->SetMessageText( IDS_MAINFRAME_FINISHED ); pMainFrame->SetMessageText( IDS_HELPTIP_SLIST ); } if( m_bFirstUpdate ) m_Grid.AutoSizeColumns( ); else m_Grid.SetColumnWidth( 0, 80 ); m_bFirstUpdate = FALSE; m_Grid.Invalidate( ); SendRequestQuote(TRUE); container.UnLock(); }