void CShowPalDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { ASSERT(1); // We don't do this. } else { // Get the file from the archive. CFile* fp = ar.GetFile(); ASSERT(fp); ar.Flush(); // Load the DIB from the file. CDIB dib; if (!dib.Load(fp)) { AfxMessageBox("Failed to load DIB file"); return; } // Create the palette from the DIB. if (m_pPal) delete m_pPal; m_pPal = new CDIBPal; ASSERT(m_pPal); if (!m_pPal->Create(&dib)) { AfxMessageBox("Failed to create palette from DIB file"); delete m_pPal; m_pPal = NULL; } } }
void CControlView::OnNMClickPlotdataTree(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: 在此添加控件通知处理程序代码 *pResult = 0; UpdateData(TRUE); clicked_flag = TRUE; CSmartCarDoc * pDoc_temp=(CSmartCarDoc*)m_pDocument; for (int i=0;i<9;i++) { BOOL hehe = m_PlotTree.GetCheck(hPlot[i]); pDoc_temp->plot[i].SetShowFlag(m_PlotTree.GetCheck(hPlot[i])); } //序列化保存配置信息 CFile file (_T ("abc.txt"), CFile::modeCreate | CFile::modeWrite); CArchive ar (&file, CArchive::store); for (int i=0;i<9;i++) { pDoc_temp->plot[i].Serialize(ar); } ar.Flush(); //读完毕,关闭文件流 ar.Close(); file.Close(); *pResult = 0; }
/************************************************************************* * * \函数名称: * Serialize() * * \输入参数: * CArchive& ar - 指向应用程序归档对象 * * \返回值: * 无 * * \说明: * 该函数进行串行化过程,将CDib数据进行读入或者写出 * ************************************************************************ */ void CDib::Serialize(CArchive& ar) { DWORD dwPos; // 获得此归档文件的CFile对象指针 dwPos = ar.GetFile()->GetPosition(); TRACE("CDib::Serialize -- pos = %d\n", dwPos); // 从归档文件缓冲区中冲掉未写入数据 ar.Flush(); // 重新获得此归档文件的CFile对象指针 dwPos = ar.GetFile()->GetPosition(); TRACE("CDib::Serialize -- pos = %d\n", dwPos); // 确定归档文件是否被存储,是则进行存储 if(ar.IsStoring()) { Write(ar.GetFile()); } // 否则进行加载 else { Read(ar.GetFile()); } }
void CDib::Serialize(CArchive& ar) { ar.Flush(); if(ar.IsStoring()) Write(ar.GetFile()); else Read(ar.GetFile()); }
// DIB is stored as a standard Windows bitmap file void CDIB::Serialize(CArchive& ar) { ar.Flush(); CFile *fp = ar.GetFile(); if (ar.IsStoring()) { Save(fp); } else { Load(fp); } }
void CSimpleReport::LayoutSave(const char* id, const char* tag) { CMemFile memFile; CArchive ar (&memFile,CArchive::store); SerializeState(ar); ar.Flush(); DWORD nBytes = (DWORD)memFile.GetPosition(); LPBYTE pData = memFile.Detach(); AfxGetApp()->WriteProfileBinary(id, tag, pData, nBytes); ar.Close(); memFile.Close(); free(pData); }
void CBZDoc::Serialize(CArchive& ar) { MEMORYSTATUS ms; GlobalMemoryStatus(&ms); CFile *pFile = ar.GetFile(); ar.Flush(); if (ar.IsLoading()) { // TODO: add loading code here m_dwTotal = GetFileLength(pFile); #ifdef FILE_MAPPING if(IsFileMapping()) { if(!MapView()) return; } else #endif //FILE_MAPPING { if(!(m_pData = (LPBYTE)MemAlloc(m_dwTotal))) { AfxMessageBox(IDS_ERR_MALLOC); return; } DWORD len = pFile->Read(m_pData, m_dwTotal); if(len < m_dwTotal) { AfxMessageBox(IDS_ERR_READFILE); MemFree(m_pData); // ###1.61 m_pData = NULL; return; } m_bReadOnly = options.bReadOnlyOpen; } } else { // TODO: add storing code here #ifdef FILE_MAPPING if(IsFileMapping()) { BOOL bResult = (m_pMapStart) ? ::FlushViewOfFile(m_pMapStart, m_dwMapSize) : ::FlushViewOfFile(m_pData, m_dwTotal); if(!bResult) { ErrorMessageBox(); } } else #endif //FILE_MAPPING pFile->Write(m_pData, m_dwTotal); m_dwUndoSaved = m_dwUndo; // ###1.54 TouchDoc(); /* if(m_pUndo) { MemFree(m_pUndo); m_pUndo = NULL; } */ } }
//*************************************************************************************** BOOL CBCGPXMLSettings::Write (LPCTSTR pszKey, CWordArray& wcArray) { if (m_bReadOnly) { ASSERT (FALSE); return FALSE; } BOOL bRes = FALSE; try { CMemFile file; { CArchive ar (&file, CArchive::store); ar << (int)wcArray.GetSize (); for (int i = 0; i < wcArray.GetSize (); i ++) { ar << wcArray [i]; } ar.Flush (); } #if _MSC_VER >= 1300 ULONGLONG dwDataSize = file.GetLength (); #else DWORD dwDataSize = file.GetLength (); #endif LPBYTE lpbData = file.Detach (); if (lpbData == NULL) { return FALSE; } bRes = Write (pszKey, lpbData, (UINT) dwDataSize); free (lpbData); } catch (CMemoryException* pEx) { pEx->Delete (); TRACE(_T("Memory exception in CBCGPXMLSettings::Write ()!\n")); return FALSE; } return bRes; }
void CDib::Serialize(CArchive& ar) { DWORD dwPos; dwPos = ar.GetFile()->GetPosition(); TRACE(_T("CDib::Serialize -- pos = %d\n"), dwPos); ar.Flush(); dwPos = ar.GetFile()->GetPosition(); TRACE(_T("CDib::Serialize -- pos = %d\n"), dwPos); if(ar.IsStoring()) { Write(ar.GetFile()); } else { Read(ar.GetFile()); } }
void CSoliDireDoc::Serialize(CArchive& ar) { ar.Flush(); CFile* fp = ar.GetFile( ); if (ar.IsStoring()) { if (is_packed() && IsModified()) pack_added_file(fp); else pack_all_file(fp);// pack the file } else { read_file(fp); } }
void CControlView::OnTvnItemChangedPlotdataTree(NMHDR *pNMHDR, LRESULT *pResult) { NMTVITEMCHANGE *pNMTVItemChange = reinterpret_cast<NMTVITEMCHANGE*>(pNMHDR); // TODO: 在此添加控件通知处理程序代码 //UpdateData(TRUE); if (Initial_flag && clicked_flag)//防止bug { CMainFrame *pMain=(CMainFrame *)AfxGetApp()->m_pMainWnd; CPlotView* pPlotView_tempt=(CPlotView*)pMain->pPlotView; CSmartCarDoc * pDoc_temp=(CSmartCarDoc*)m_pDocument; for (int i=0; i<3; i++) pPlotView_tempt->Window[i].SetShowFlag(m_PlotTree.GetCheck(hWindow[i])); for (int i=0;i<9;i++) pDoc_temp->plot[i].SetShowFlag(m_PlotTree.GetCheck(hPlot[i])); //序列化保存配置信息 CFile file (_T ("abc.txt"), CFile::modeCreate | CFile::modeWrite); CArchive ar (&file, CArchive::store); for (int i=0;i<9;i++) { pDoc_temp->plot[i].Serialize(ar); } ar.Flush(); //读完毕,关闭文件流 ar.Close(); file.Close(); //保存窗口坐标轴信息 CFile file1 (_T ("Axis.txt"), CFile::modeCreate | CFile::modeWrite); CArchive ar1 (&file1, CArchive::store); for (int i=0;i<3;i++) { pPlotView_tempt->Window[i].Serialization(ar1); } ar1.Flush(); //读完毕,关闭文件流 ar1.Close(); file1.Close(); clicked_flag = FALSE; //更新视图 pPlotView_tempt->Invalidate(FALSE); } *pResult = 0; }
//************************************************************************************************ BOOL CBCGPMouseManager::SaveState (LPCTSTR lpszProfileName) { CString strProfileName = ::BCGPGetRegPath (strMouseProfile, lpszProfileName); BOOL bResult = FALSE; try { CMemFile file; { CArchive ar (&file, CArchive::store); Serialize (ar); ar.Flush (); } UINT uiDataSize = (UINT) file.GetLength (); LPBYTE lpbData = file.Detach (); if (lpbData != NULL) { CBCGPRegistrySP regSP; CBCGPRegistry& reg = regSP.Create (FALSE, FALSE); if (reg.CreateKey (strProfileName)) { bResult = reg.Write (strRegEntryName, lpbData, uiDataSize); } free (lpbData); } } catch (CMemoryException* pEx) { pEx->Delete (); TRACE(_T("Memory exception in CBCGPMouseManager::SaveState ()!\n")); } catch (CArchiveException* pEx) { pEx->Delete (); TRACE(_T("CArchiveException exception in CBCGPMouseManager::SaveState ()!\n")); } return bResult; }
void PacketSerialize(long nPackets, CArchive& arData, CArchive& arAck) { BYTE bValue = 0; WORD nCopies = 0; if (arData.IsStoring()) { CString strText; errno_t err; unsigned int number; for(int p = 0; p < nPackets; p++) { err = rand_s(&number); // if (err == 0)... bValue = (BYTE)(number%256); err = rand_s(&number); // if (err == 0)... nCopies = (WORD)(number%32000); // Send header information arData << bValue << nCopies; for(int c = 0; c < nCopies; c++) { // Send data arData << bValue; } strText.Format(_T("Sender sent packet %d of %d (Value = %d, Copies = %d)"), p + 1, nPackets, (int)bValue, nCopies); // Send receipt string arData << strText; arData.Flush(); // Receive acknowledgment arAck >> strText; // display it DisplayMessage(strText); } }
BOOL CRegistry::Write (LPCTSTR pszKey, CDWordArray& dwcArray) { ASSERT (m_hKey != NULL); ASSERT (pszKey != NULL); if (m_bReadOnly) { ASSERT (FALSE); return FALSE; } BOOL bRes = FALSE; try { CMemFile file; { CArchive ar (&file, CArchive::store); dwcArray.Serialize(ar); ar.Flush (); } DWORD dwDataSize = (DWORD) file.GetLength (); LPBYTE lpbData = file.Detach (); if (lpbData == NULL) { return FALSE; } bRes = Write (pszKey, lpbData, (UINT) dwDataSize); free (lpbData); } catch (CMemoryException* pEx) { pEx->Delete (); TRACE(_T("Memory exception in CRegistry::Write ()!\n")); return FALSE; } return bRes; }
LPSTREAM AFXAPI _AfxGetArchiveStream(CArchive& ar, CArchiveStream& stm) { // Obtain direct access to the archive's LPSTREAM. ar.Flush(); CFile* pFile = ar.GetFile(); ASSERT(pFile != NULL); LPSTREAM pstm; if (pFile->IsKindOf(RUNTIME_CLASS(COleStreamFile))) { pstm = ((COleStreamFile*)pFile)->m_lpStream; ASSERT(pstm != NULL); } else { ASSERT(stm.m_pArchive == NULL || stm.m_pArchive == &ar); stm.m_pArchive = &ar; pstm = &stm; } return pstm; }
BOOL CBCGPRegistry::Write(LPCTSTR pszKey, const CRect& rect) { if (m_bReadOnly) { ASSERT (FALSE); return FALSE; } BOOL bRes = FALSE; try { CMemFile file; { CArchive ar (&file, CArchive::store); ar << rect; ar.Flush (); } DWORD dwDataSize = (DWORD) file.GetLength (); LPBYTE lpbData = file.Detach (); if (lpbData == NULL) { return FALSE; } bRes = Write (pszKey, lpbData, (UINT) dwDataSize); free (lpbData); } catch (CMemoryException* pEx) { pEx->Delete (); TRACE(_T("Memory exception in CBCGPRegistry::Write ()!\n")); return FALSE; } return bRes; }
BOOL CEasyBDoc::ExportGameInfo(CArchive& ar) { // export game info // export hands WriteText(ar, "[Dealt Hands]\r\n"); CString strHands = FormatOriginalHands(); WriteText(ar, strHands); // export bidding history WriteText(ar, "\r\n\r\n"); WriteText(ar, "[Bidding History]\r\n"); const CString strBiddingHistory = pMAINFRAME->GetBiddingHistory(); WriteText(ar, strBiddingHistory); if (ISBID(GetContract())) { int nDeclarer = GetDeclarerPosition(); CString strContract = FormString("Contract: %s by %s; %s leads", pDOC->GetContractString(), PositionToString(nDeclarer), PositionToString(GetNextPlayer(nDeclarer))); // WriteText(pFile, strContract); } // export play history WriteText(ar, "\r\n\r\n\r\n"); WriteText(ar, "[Play History]\r\n"); const CString strPlayHistory = pMAINFRAME->GetPlayHistory(); WriteText(ar, strPlayHistory); // export current hands if (GetNumTricksPlayed() > 0) { WriteText(ar, "\r\n\r\n\r\n"); WriteText(ar, "[Current Hands]\r\n"); CString strHands = pDOC->FormatCurrentHands(); WriteText(ar, strHands); } // done ar.Flush(); return TRUE; }
//**************************************************************************************** BOOL CBCGPMenuHash::SaveMenuBar (HMENU hMenu, CBCGPToolBar* pBar) { ASSERT_VALID (pBar); if (pBar->GetCount () == 0) { return FALSE; } HANDLE hFileOld = NULL; if (m_StoredMenues.Lookup (hMenu, hFileOld)) { //-------------------- // Free unused handle: //-------------------- ::CloseHandle (hFileOld); } //--------------------- // Get the temp path... //--------------------- CString strTempPath; GetTempPath (MAX_PATH, strTempPath.GetBuffer (MAX_PATH)); strTempPath.ReleaseBuffer(); //------------------------------------------- // Create a temporary file for the output.... //------------------------------------------- CString strTempName; GetTempFileName (strTempPath, _T("BCG"), 0, strTempName.GetBuffer (MAX_PATH)); strTempName.ReleaseBuffer (); HANDLE hFile = ::CreateFile (strTempName, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE, NULL); if (hFile == INVALID_HANDLE_VALUE) { TRACE(_T("Can't create temporary file!\n")); return FALSE; } try { //--------------------------------- // Write a menubar context to file: //--------------------------------- #if _MSC_VER >= 1300 CFile file (hFile); #else CFile file ((HFILE) hFile); #endif CArchive ar (&file, CArchive::store); m_bIsActive = TRUE; pBar->Serialize (ar); ar.Flush (); m_bIsActive = FALSE; } catch (CArchiveException* pEx) { TRACE(_T("Archive exception in CBCGPMenuHash::SaveMenuBar ()!\n")); pEx->Delete (); ::CloseHandle(hFile); m_bIsActive = FALSE; return FALSE; } catch (CMemoryException* pEx) { TRACE(_T("Memory exception in CBCGPMenuHash::SaveMenuBar ()!\n")); pEx->Delete (); ::CloseHandle(hFile); m_bIsActive = FALSE; return FALSE; } catch (CFileException* pEx) { TRACE(_T("File exception in CBCGPMenuHash::SaveMenuBar ()!\n")); pEx->Delete (); ::CloseHandle(hFile); m_bIsActive = FALSE; return FALSE; } m_StoredMenues.SetAt (hMenu, hFile); return TRUE; }
// //--------------------------------------------------------- // BOOL CEasyBDoc::WriteFile(CArchive& ar) { pFile = ar.GetFile(); ASSERT(pFile != NULL); int i,j,numCards; CString strTemp,strHand; // write the data // //----------------------------------------------------- // // first the file ID // WriteBlockHeader(BLOCK_FILEINFO); WriteString(ITEM_PROGRAM_ID,(LPCTSTR)theApp.GetValue(tstrProgramTitle)); WriteInt(ITEM_MAJOR_VERSIONNO,theApp.GetValue(tnProgramMajorVersion)); WriteInt(ITEM_MINOR_VERSIONNO,theApp.GetValue(tnProgramMinorVersion)); WriteInt(ITEM_INCREMENT_VERSIONNO,theApp.GetValue(tnProgramIncrementVersion)); WriteInt(ITEM_BUILD_NUMBER,theApp.GetValue(tnProgramBuildNumber)); WriteString(ITEM_BUILD_DATE,(LPCTSTR)theApp.GetValue(tstrProgramBuildDate)); CTime time = CTime::GetCurrentTime(); strTemp.Format(" %s",(LPCTSTR)time.Format("%c")); WriteString(ITEM_FILE_DATE,strTemp); SkipLine(); // then the file description WriteBlockHeader(BLOCK_FILEDESC); WriteString(ITEM_NONE,m_strFileDescription); // SkipLine(); // //----------------------------------------------------- // // hand information // WriteBlockHeader(BLOCK_HANDINFO); // first the current hand for(i=0;i<4;i++) { numCards = PLAYER(i).GetNumCards(); strHand.Empty(); for(j=0;j<numCards;j++) { strHand += PLAYER(i).GetCardByPosition(j)->GetName(); strHand += " "; } switch(i) { case NORTH: WriteString(ITEM_CURRHAND_NORTH,strHand); break; case EAST: WriteString(ITEM_CURRHAND_EAST,strHand); break; case SOUTH: WriteString(ITEM_CURRHAND_SOUTH,strHand); break; case WEST: WriteString(ITEM_CURRHAND_WEST,strHand); break; } } // then the original hand for(i=0;i<4;i++) { if (pVIEW->GetCurrentMode() == CEasyBView::MODE_CARDLAYOUT) { numCards = PLAYER(i).GetNumCards(); strHand.Empty(); for(j=0;j<numCards;j++) { strHand += PLAYER(i).GetCardByPosition(j)->GetName(); strHand += " "; } } else { strHand.Empty(); for(j=0;j<13;j++) { strHand += PLAYER(i).GetInitialHandCard(j)->GetName(); strHand += " "; } } switch(i) { case NORTH: WriteString(ITEM_ORIGHAND_NORTH,strHand); break; case EAST: WriteString(ITEM_ORIGHAND_EAST,strHand); break; case SOUTH: WriteString(ITEM_ORIGHAND_SOUTH,strHand); break; case WEST: WriteString(ITEM_ORIGHAND_WEST,strHand); break; } } SkipLine(); // //----------------------------------------------------- // // current round information // WriteBlockHeader(BLOCK_ROUNDINFO); /* WriteString(ITEM_CURR_ROUND_LEAD, PositionToString(m_nRoundLead)); // WriteInt(ITEM_NUM_CARDS_PLAYED_IN_ROUND, m_numCardsPlayedInRound); // tricks in current round for(i=0;i<m_numCardsPlayedInRound;i++) WriteString(ITEM_TRICK_CARD_1+i,m_pCurrTrick[i]->GetName()); */ // SkipLine(); // //----------------------------------------------------- // // game status info // WriteBlockHeader(BLOCK_GAMEINFO); WriteInt(ITEM_VIEW_STATUS_CODE,pVIEW->GetCurrentMode()); WriteBool(ITEM_RUBBER_IN_PROGRESS,theApp.IsRubberInProgress()); WriteBool(ITEM_GAME_IN_PROGRESS,theApp.IsGameInProgress()); WriteBool(ITEM_BIDDING_IN_PROGRESS,theApp.IsBiddingInProgress()); WriteBool(ITEM_HANDS_DEALT,m_bHandsDealt); strTemp.Format("%s",SuitToString(m_nContractSuit)); WriteString(ITEM_CONTRACT_SUIT,strTemp); WriteInt(ITEM_CONTRACT_LEVEL,m_nContractLevel); WriteInt(ITEM_CONTRACT_MODIFIER, m_bRedoubled? 2 : m_bDoubled? 1 : 0); WriteString(ITEM_DEALER,PositionToString(m_nDealer)); WriteInt(ITEM_NUM_BIDS,m_numBidsMade); // declarer & bidding history strTemp.Empty(); int nIndex = 0; for(i=0;i<=m_numBidsMade;i++) { strTemp += BidToShortString(m_nBiddingHistory[i]); strTemp += " "; } WriteString(ITEM_DECLARER,PositionToString(m_nDeclarer)); WriteString(ITEM_BIDDING_HISTORY,strTemp); SkipLine(); // //----------------------------------------------------- // // game play record // WriteBlockHeader(BLOCK_GAMERECORD); if (m_bSaveIntermediatePositions) { // write the # tricks played int numTricks = m_numTricksPlayed; // see if the current trick is incomplete if ((pDOC->GetNumCardsPlayedInRound() > 0) && (numTricks < 13)) numTricks++; WriteInt(ITEM_NUM_TRICKS_PLAYED,numTricks); // # tricks won by each side WriteInt(ITEM_NUM_TRICKS_WON_NS,m_numTricksWon[0]); WriteInt(ITEM_NUM_TRICKS_WON_EW,m_numTricksWon[1]); WriteString(ITEM_GAME_LEAD,PositionToString(m_nGameLead)); // and the record of tricks for(i=0;i<13;i++) { if (i <= m_numTricksPlayed) { strTemp.Empty(); strTemp += PositionToString(m_nTrickLead[i]); strTemp += " "; for(j=0;j<4;j++) { CCard* pCard = NULL; if (i < m_numTricksPlayed) pCard = m_pGameTrick[i][j]; else pCard = m_pCurrTrick[j]; // if (pCard != NULL) { strTemp += pCard->GetName(); strTemp += " "; } else { strTemp += "-- "; } } strTemp += PositionToString(m_nTrickWinner[i]); } else { strTemp = ""; } WriteString(ITEM_GAME_TRICK_1+i,strTemp); } } else { WriteInt(ITEM_NUM_TRICKS_PLAYED, 0); } // SkipLine(); // //----------------------------------------------------- // // match info // if (theApp.IsRubberInProgress()) { // write block header WriteBlockHeader(BLOCK_MATCHINFO); // write out scores WriteInt(ITEM_SCORE_NS_BONUS, m_nBonusScore[NORTH_SOUTH]); WriteInt(ITEM_SCORE_NS_GAME0, m_nGameScore[0][NORTH_SOUTH]); WriteInt(ITEM_SCORE_NS_GAME1, m_nGameScore[1][NORTH_SOUTH]); WriteInt(ITEM_SCORE_NS_GAME2, m_nGameScore[2][NORTH_SOUTH]); WriteInt(ITEM_SCORE_NS_GAMES_WON, m_numGamesWon[NORTH_SOUTH]); // WriteInt(ITEM_SCORE_EW_BONUS, m_nBonusScore[EAST_WEST]); WriteInt(ITEM_SCORE_EW_GAME0, m_nGameScore[0][EAST_WEST]); WriteInt(ITEM_SCORE_EW_GAME1, m_nGameScore[1][EAST_WEST]); WriteInt(ITEM_SCORE_EW_GAME2, m_nGameScore[2][EAST_WEST]); WriteInt(ITEM_SCORE_EW_GAMES_WON, m_numGamesWon[EAST_WEST]); // write out current game WriteInt(ITEM_CURRENT_GAME_INDEX, m_nCurrGame+1); // write out score record int numBonusScoreRecords = m_strArrayBonusPointsRecord.GetSize(); for(int i=0;i<numBonusScoreRecords;i++) WriteString(ITEM_BONUS_SCORE_RECORD, WrapInQuotes(m_strArrayBonusPointsRecord.GetAt(i))); // int numGameScoreRecords = m_strArrayTrickPointsRecord.GetSize(); for(i=0;i<numGameScoreRecords;i++) WriteString(ITEM_GAME_SCORE_RECORD, WrapInQuotes(m_strArrayTrickPointsRecord.GetAt(i))); // SkipLine(); } // //----------------------------------------------------- // // misc info // WriteBlockHeader(BLOCK_MISCINFO); WriteBool(ITEM_AUTOSHOW_COMMENTS,m_bShowCommentsUponOpen); WriteBool(ITEM_AUTOSHOW_BID_HISTORY,m_bShowBidHistoryUponOpen); WriteBool(ITEM_AUTOSHOW_PLAY_HISTORY,m_bShowPlayHistoryUponOpen); WriteBool(ITEM_AUTOSHOW_ANALYSES,m_bShowAnalysesUponOpen); SkipLine(); // //----------------------------------------------------- // // file comments // WriteBlockHeader(BLOCK_COMMENTS); // get the current file comments text if the dialog is open CWnd* pWnd = pMAINFRAME->GetDialog(twFileCommentsDialog); if (pWnd) pWnd->SendMessage(WM_COMMAND, WMS_UPDATE_TEXT, TRUE); WriteString(0,m_strFileComments); SkipLine(); // //----------------------------------------------------- // // PlayerAnalysis, if appropriate // for(i=0;i<4;i++) { if (m_bSavePlayerAnalysis[i]) { // save out the player analysis text WriteBlockHeader(BLOCK_PLAYER_ANALYSIS + i); WriteString(0, m_pPlayer[i]->GetValueString(tszAnalysis)); SkipLine(); } } // //----------------------------------------------------- // // All done // ar.Flush(); return TRUE; }
//********************************************************************************* BOOL CBCGPOutlookBar::SaveState (LPCTSTR lpszProfileName, int nIndex, UINT uiID) { CBCGPBaseTabbedBar::SaveState (lpszProfileName, nIndex, uiID); for (POSITION pos = m_lstCustomPages.GetHeadPosition (); pos != NULL;) { CBCGPOutlookBarPane* pPage = (CBCGPOutlookBarPane*)m_lstCustomPages.GetNext (pos); ASSERT_VALID (pPage); int nID = pPage->GetDlgCtrlID (); pPage->SaveState (lpszProfileName, nID, nID); } CString strProfileName = ::BCGPGetRegPath (strOutlookBarProfile, lpszProfileName); if (nIndex == -1) { nIndex = GetDlgCtrlID (); } CString strSection; if (uiID == (UINT) -1) { strSection.Format (REG_SECTION_FMT, strProfileName, nIndex); } else { strSection.Format (REG_SECTION_FMT_EX, strProfileName, nIndex, uiID); } try { CMemFile file; { CArchive ar (&file, CArchive::store); ar << (int) m_lstCustomPages.GetCount (); for (POSITION pos = m_lstCustomPages.GetHeadPosition (); pos != NULL;) { CBCGPOutlookBarPane* pPage = (CBCGPOutlookBarPane*)m_lstCustomPages.GetNext (pos); ASSERT_VALID (pPage); ar << pPage->GetDlgCtrlID (); CString strName; if (pPage->IsTabbed ()) { pPage->GetWindowText (strName); } else { pPage->GetParent ()->GetWindowText (strName); } ar << strName; } CBCGPOutlookWnd* pOutlookBar = (CBCGPOutlookWnd*) GetUnderlinedWindow (); if (pOutlookBar != NULL) { ar << pOutlookBar->GetVisiblePageButtons (); } else { ar << -1; } ar.Flush (); } UINT uiDataSize = (UINT) file.GetLength (); LPBYTE lpbData = file.Detach (); if (lpbData != NULL) { CBCGPRegistrySP regSP; CBCGPRegistry& reg = regSP.Create (FALSE, FALSE); if (reg.CreateKey (strSection)) { reg.Write (strRegCustomPages, lpbData, uiDataSize); } free (lpbData); } } catch (CMemoryException* pEx) { pEx->Delete (); TRACE(_T("Memory exception in CBCGPOutlookBar::SaveState ()!\n")); } catch (CArchiveException* pEx) { pEx->Delete (); TRACE(_T("Archive exception in CBCGPOutlookBar::SaveState ()!\n")); } return TRUE; }
void CControlView::OnInitialUpdate() { CFormView::OnInitialUpdate(); //加载窗口信息 CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd(); CPlotView *pPlotView_temp=(CPlotView*)pFrame->pPlotView; CFile file ; if(file.Open(_T ("Axis.txt"), CFile::modeRead))//打开了文档 { try { CArchive ar (&file, CArchive::load); for (int i=0;i<3;i++) { pPlotView_temp->Window[i].Serialization(ar); } ar.Flush(); ar.Close(); } catch (CArchiveException*) { //若反序列化失败 AfxMessageBox(_T("未正确读取坐标,将采用默认配置")); IsAxisFailed = TRUE; } file.Close(); } else//文档不存在,创建新文档 { AfxMessageBox(_T("坐标配置文件不存在,创建默认文件")); IsAxisFailed = TRUE; } //若曲线信息文件加载失败,创建默认文件 if (IsAxisFailed) { CAxisConfigDlg dlg_temp; dlg_temp.SaveAxisConfig(); } if (((CSmartCarDoc*)m_pDocument)->IsFailedReadConfig) { CWavePlotDlg tem_dlg; tem_dlg.p_doc = (CSmartCarDoc*)m_pDocument; tem_dlg.saveconfig(); } CString str; for (int i=1;i<25;i++) { str.Format(_T("COM%d"),i); m_ComNum.AddString(str); } str_baudrate.push_back(_T("4800")); str_baudrate.push_back(_T("9600")); str_baudrate.push_back(_T("19200")); str_baudrate.push_back(_T("38400")); str_baudrate.push_back(_T("57600")); str_baudrate.push_back(_T("115200"));//CString类型存储的是string变量的首地址,每个元素占四个字节 for (int i=0;i < static_cast<int>(str_baudrate.size());i++) { m_Baudrate.AddString(str_baudrate[i]); } m_nBaudrate = str_baudrate.size()-1; UpdateData(FALSE); CSmartCarDoc * pDoc_temp=(CSmartCarDoc*)m_pDocument; //创建句柄时将曲线名称信息显示至树状图中 hRoot = m_PlotTree.InsertItem(_T("WavePlot"), 0, 0); hWindow[0] = m_PlotTree.InsertItem(_T("Window1"), hRoot, TVI_LAST); hWindow[1] = m_PlotTree.InsertItem(_T("Window2"), hRoot, TVI_LAST); hWindow[2] = m_PlotTree.InsertItem(_T("Window3"), hRoot, TVI_LAST); hPlot[0]=m_PlotTree.InsertItem(pDoc_temp->plot[0].GetTitle(), hWindow[0], TVI_LAST); hPlot[1]=m_PlotTree.InsertItem(pDoc_temp->plot[1].GetTitle(), hWindow[0], TVI_LAST); hPlot[2]=m_PlotTree.InsertItem(pDoc_temp->plot[2].GetTitle(), hWindow[0], TVI_LAST); hPlot[3]=m_PlotTree.InsertItem(pDoc_temp->plot[3].GetTitle(), hWindow[1], TVI_LAST); hPlot[4]=m_PlotTree.InsertItem(pDoc_temp->plot[4].GetTitle(), hWindow[1], TVI_LAST); hPlot[5]=m_PlotTree.InsertItem(pDoc_temp->plot[5].GetTitle(), hWindow[1], TVI_LAST); hPlot[6]=m_PlotTree.InsertItem(pDoc_temp->plot[6].GetTitle(), hWindow[2], TVI_LAST); hPlot[7]=m_PlotTree.InsertItem(pDoc_temp->plot[7].GetTitle(), hWindow[2], TVI_LAST); hPlot[8]=m_PlotTree.InsertItem(pDoc_temp->plot[8].GetTitle(), hWindow[2], TVI_LAST); m_PlotTree.Expand(hRoot,TVE_EXPAND); m_PlotTree.Expand(hWindow[0],TVE_EXPAND); m_PlotTree.Expand(hWindow[1],TVE_EXPAND); m_PlotTree.Expand(hWindow[2],TVE_EXPAND); m_PlotTree.SetCheck(hRoot); for (int i=0;i<9;i++) { if(pDoc_temp->plot[i].GetShowFlag()) { m_PlotTree.SetCheck(hPlot[i]); } } for (int i=0;i<3;i++) { if(pPlotView_temp->Window[i].GetShowFlag()) m_PlotTree.SetCheck(hWindow[i]); } Initial_flag = TRUE; // OnBnClickedOpencom();//一开始就打开串口 // TODO: 在此添加专用代码和/或调用基类 }
// //--------------------------------------------------------- // // PBN File output routine // BOOL CEasyBDoc::WriteFilePBN(CArchive& ar) { pFile = ar.GetFile(); ASSERT(pFile != NULL); // write header WriteComment(""); WriteComment("EXPORT"); WriteComment("PBN Format 1.0"); WriteComment(FormString("File generated by Easy Bridge version %s", theApp.GetProgramVersionString())); WriteComment(""); // // write the data // // Event tag WriteLine(TAG_EVENT, FormString("%s Game", theApp.GetValue(tstrProgramTitle))); // Site Tag WriteLine(TAG_SITE, "At Home"); // NCR added At Home // Date Tag CTime time = CTime::GetCurrentTime(); WriteLine(TAG_DATE, time.Format("%Y.%m.%d")); /* * skip the round tag -- no longer mandatory in PBN 0.91+ * // Round Tag WriteLine(TAG_ROUND, ""); */ // Board Tag WriteLine(TAG_BOARD, "1"); // NCR added 1 // West/North/East/South Tags WriteLine(TAG_WEST, "Computer"); WriteLine(TAG_NORTH, "Computer"); WriteLine(TAG_EAST, "Computer"); WriteLine(TAG_SOUTH, "Human Player"); // Dealer Tag WriteLine(TAG_DEALER, FormString("%c", PositionToChar(m_nDealer))); // Vulnerable Tag CString strVulnerable; if ((m_bVulnerable[NORTH_SOUTH]) && (m_bVulnerable[EAST_WEST])) strVulnerable = "Both"; else if (m_bVulnerable[NORTH_SOUTH]) strVulnerable = "NS"; else if (m_bVulnerable[EAST_WEST]) strVulnerable = "EW"; else strVulnerable = "None"; WriteLine(TAG_VULNERABLE, strVulnerable); // deal tag CString strDeal = "W:"; int nPos = WEST; int i; // NCR-FFS added here, removed below for(/*int*/ i=0;i<4;i++) { CCardHoldings& cards = m_pPlayer[nPos]->GetHand().GetInitialHand(); strDeal += cards.GetGIBFormatHoldingsString(); nPos = GetNextPlayer(nPos); if (i < 3) strDeal += ' '; } WriteLine(TAG_DEAL, strDeal); // Scoring tag if (theApp.IsRubberInProgress()) WriteLine(TAG_SCORING, _T("Rubber")); else WriteLine(TAG_SCORING, _T("None")); // Declarer Tag if (ISPOSITION(m_nDeclarer)) WriteLine(TAG_DECLARER, FormString("%c", PositionToChar(m_nDeclarer))); else WriteLine(TAG_DECLARER, "?"); // Contract Tag if (ISBID(m_nContract)) { // NCR Include ContractToString() here as PBN file does NOT have space before X CString strBid; strBid.Format("%d%s", BID_LEVEL(m_nContract), szSuitNameShort[BID_SUIT(m_nContract)]); int nModifier = pDOC->GetContractModifier(); if (nModifier > 0) strBid += FormString("%s", ((nModifier == 1)? "X" : "XX")); // w/o space WriteLine(TAG_CONTRACT, strBid); // NCR replaced ContractToString(m_nContract) } else WriteLine(TAG_CONTRACT, "?"); // Result tag if (m_numTricksPlayed == 13) WriteLine(TAG_RESULT, FormString("%d", m_numTricksWon[m_nContractTeam])); // NCR removed extra "s else WriteLine(TAG_RESULT, "?"); // // write out the hands in comment form // CString strHands = "{\r\n" + pDOC->FormatOriginalHands() + "}"; WriteLine(strHands); // // write out auction // CString strBids = FormString("[Auction \"%c\"]", PositionToChar(m_nDealer)); // NCR Lowercased if (m_numBidsMade > 0) strBids += "\r\n"; nPos = m_nDealer; for(i=0;i<m_numBidsMade;i++) { strBids += FormString("%s ", ::BidToPBNString(m_nBiddingHistory[i])); nPos = ::GetNextPlayer(nPos); if ( (((i+1) % 4) == 0) && (i < m_numBidsMade-1) ) strBids += "\r\n"; } // add marker if needed if (!ISBID(m_nContract)) strBids += "\r\n*"; // and write out WriteLine(strBids); // // write out plays // CString strPlays = FormString("[Play \"%c\"]", PositionToChar(m_nGameLead)); // NCR Lowercased if (m_numTricksPlayed> 0) strPlays += "\r\n"; bool bLastRowFnd = false; // NCR added - only output single row with -s for(i=0;i<m_numTricksPlayed;i++) { int nPos = m_nGameLead; for(int j=0;j<4;j++) { CCard* pCard = m_pGameTrick[i][nPos]; if (pCard == NULL) { strPlays += "- "; bLastRowFnd = true; // NCR this row will end the output } else strPlays += FormString("%s ", pCard->GetName()); nPos = ::GetNextPlayer(nPos); } // end for(j) thru poisitions if (i < m_numTricksPlayed-1) strPlays += "\r\n"; if(bLastRowFnd) break; // NCR finished output plays on line with -s } // end for(i) thru tricks // add marker if needed if (m_numTricksPlayed < 13) strPlays += "\r\n*"; // and write out WriteLine(strPlays); // Generator Tag WriteLine(TAG_GENERATOR, FormString("Easy Bridge version %s", theApp.GetProgramVersionString())); // Description Tag WriteLine(TAG_DESCRIPTION, m_strFileDescription); // blank line // SkipLine(); // // write out the auction // // // All done // ar.Flush(); return TRUE; }