コード例 #1
0
ファイル: SortListCtrl.cpp プロジェクト: myswirl/myworkspace
void CSortListCtrl::LoadColumnInfo()
{
	// you must call this after setting the column headings.
	ASSERT( m_iNumColumns > 0 );

	CString strKey;
	strKey.Format( _T("%d"), GetDlgCtrlID() );

	UINT nBytes = 0;
	BYTE* buf = NULL;
	if( AfxGetApp()->GetProfileBinary( g_pszSection, strKey, &buf, &nBytes ) )
	{
		if( nBytes > 0 )
		{
			CMemFile memFile( buf, nBytes );
			CArchive ar( &memFile, CArchive::load );
			m_ctlHeader.Serialize( ar );
			ar.Close();

			m_ctlHeader.Invalidate();
		}

		delete[] buf;
	}
}
コード例 #2
0
ファイル: SimpleReport.cpp プロジェクト: tlogger/TMon
void CSimpleReport::LayoutLoad(const char* id, const char* tag)
{
	UINT nBytes = 0;
	LPBYTE pData = 0;

	if (!AfxGetApp()->GetProfileBinary(id, tag, &pData, &nBytes))
		return;

	CMemFile memFile(pData, nBytes);
	CArchive ar (&memFile,CArchive::load);

	try {
		SerializeState(ar);
	}
	catch (COleException* pEx) {
		pEx->Delete ();
	}
	catch (CArchiveException* pEx) {
		pEx->Delete ();
	}

	ar.Close();
	memFile.Close();
	delete[] pData;
}
コード例 #3
0
ファイル: BeginGame.cpp プロジェクト: IcyX/bote
	void CBeginGame::DeserializeToDoc(CPeerData *pDoc)
	{
		CMemFile memFile(m_pData, m_nSize);
		CArchive ar(&memFile, CArchive::load);
		pDoc->SerializeBeginGameData(ar);
		ar.Flush();
		memFile.Detach();
	}
コード例 #4
0
void CRichEditCtrlX::SetRTFText(const CStringA& rstrTextA)
{
	CMemFile memFile((BYTE*)(LPCSTR)rstrTextA, rstrTextA.GetLength());
	EDITSTREAM es = {0};
	es.pfnCallback = StreamInCallback;
	es.dwCookie = (DWORD_PTR)&memFile;
	StreamIn(SF_RTF, es);
}
コード例 #5
0
ファイル: File_Resource.cpp プロジェクト: Yetta1/OpenTechBFG
/*
========================
idResourceContainer::Init
========================
*/
bool idResourceContainer::Init( const char* _fileName, uint8 containerIndex )
{

	if( idStr::Icmp( _fileName, "_ordered.resources" ) == 0 )
	{
		resourceFile = fileSystem->OpenFileReadMemory( _fileName );
	}
	else
	{
		resourceFile = fileSystem->OpenFileRead( _fileName );
	}
	
	if( resourceFile == NULL )
	{
		idLib::Warning( "Unable to open resource file %s", _fileName );
		return false;
	}
	
	resourceFile->ReadBig( resourceMagic );
	if( resourceMagic != RESOURCE_FILE_MAGIC )
	{
		idLib::FatalError( "resourceFileMagic != RESOURCE_FILE_MAGIC" );
	}
	
	fileName = _fileName;
	
	resourceFile->ReadBig( tableOffset );
	resourceFile->ReadBig( tableLength );
	// read this into a memory buffer with a single read
	char* const buf = ( char* )Mem_Alloc( tableLength, TAG_RESOURCE );
	resourceFile->Seek( tableOffset, FS_SEEK_SET );
	resourceFile->Read( buf, tableLength );
	idFile_Memory memFile( "resourceHeader", ( const char* )buf, tableLength );
	
	// Parse the resourceFile header, which includes every resource used
	// by the game.
	memFile.ReadBig( numFileResources );
	
	cacheTable.SetNum( numFileResources );
	
	for( int i = 0; i < numFileResources; i++ )
	{
		idResourceCacheEntry& rt = cacheTable[ i ];
		rt.Read( &memFile );
		rt.filename.BackSlashesToSlashes();
		rt.filename.ToLower();
		rt.containerIndex = containerIndex;
		
		const int key = cacheHash.GenerateKey( rt.filename, false );
		bool found = false;
		//for ( int index = cacheHash.GetFirst( key ); index != idHashIndex::NULL_INDEX; index = cacheHash.GetNext( index ) ) {
		//	idResourceCacheEntry & rtc = cacheTable[ index ];
		//	if ( idStr::Icmp( rtc.filename, rt.filename ) == 0 ) {
		//		found = true;
		//		break;
		//	}
		//}
		if( !found )
		{
			//idLib::Printf( "rez file name: %s\n", rt.filename.c_str() );
			cacheHash.Add( key, i );
		}
	}
	Mem_Free( buf );
	
	return true;
}
コード例 #6
0
ファイル: File_Resource.cpp プロジェクト: Yetta1/OpenTechBFG
/*
========================
idResourceContainer::ExtractResourceFile
========================
*/
void idResourceContainer::ExtractResourceFile( const char* _fileName, const char* _outPath, bool _copyWavs )
{
	idFile* inFile = fileSystem->OpenFileRead( _fileName );
	
	if( inFile == NULL )
	{
		idLib::Warning( "Unable to open resource file %s", _fileName );
		return;
	}
	
	uint32 magic;
	inFile->ReadBig( magic );
	if( magic != RESOURCE_FILE_MAGIC )
	{
		delete inFile;
		return;
	}
	
	int _tableOffset;
	int _tableLength;
	inFile->ReadBig( _tableOffset );
	inFile->ReadBig( _tableLength );
	// read this into a memory buffer with a single read
	char* const buf = ( char* )Mem_Alloc( _tableLength, TAG_RESOURCE );
	inFile->Seek( _tableOffset, FS_SEEK_SET );
	inFile->Read( buf, _tableLength );
	idFile_Memory memFile( "resourceHeader", ( const char* )buf, _tableLength );
	
	int _numFileResources;
	memFile.ReadBig( _numFileResources );
	
	for( int i = 0; i < _numFileResources; i++ )
	{
		idResourceCacheEntry rt;
		rt.Read( &memFile );
		rt.filename.BackSlashesToSlashes();
		rt.filename.ToLower();
		byte* fbuf = NULL;
		if( _copyWavs && ( rt.filename.Find( ".idwav" ) >= 0 ||  rt.filename.Find( ".idxma" ) >= 0 ||  rt.filename.Find( ".idmsf" ) >= 0 ) )
		{
			rt.filename.SetFileExtension( "wav" );
			rt.filename.Replace( "generated/", "" );
			int len = fileSystem->GetFileLength( rt.filename );
			fbuf = ( byte* )Mem_Alloc( len, TAG_RESOURCE );
			fileSystem->ReadFile( rt.filename, ( void** )&fbuf, NULL );
		}
		else
		{
			inFile->Seek( rt.offset, FS_SEEK_SET );
			fbuf = ( byte* )Mem_Alloc( rt.length, TAG_RESOURCE );
			inFile->Read( fbuf, rt.length );
		}
		idStr outName = _outPath;
		outName.AppendPath( rt.filename );
		idFile* outFile = fileSystem->OpenExplicitFileWrite( outName );
		if( outFile != NULL )
		{
			outFile->Write( ( byte* )fbuf, rt.length );
			delete outFile;
		}
		Mem_Free( fbuf );
	}
	delete inFile;
	Mem_Free( buf );
}
コード例 #7
0
ファイル: File_Resource.cpp プロジェクト: Yetta1/OpenTechBFG
/*
========================
idResourceContainer::UpdateResourceFile
========================
*/
void idResourceContainer::UpdateResourceFile( const char* _filename, const idStrList& _filesToUpdate )
{
	idFile* outFile = fileSystem->OpenFileWrite( va( "%s.new", _filename ) );
	if( outFile == NULL )
	{
		idLib::Warning( "Unable to open resource file %s or new output file", _filename );
		return;
	}
	
	uint32 magic = 0;
	int _tableOffset = 0;
	int _tableLength = 0;
	idList< idResourceCacheEntry > entries;
	idStrList filesToUpdate = _filesToUpdate;
	
	idFile* inFile = fileSystem->OpenFileRead( _filename );
	if( inFile == NULL )
	{
		magic = RESOURCE_FILE_MAGIC;
		
		outFile->WriteBig( magic );
		outFile->WriteBig( _tableOffset );
		outFile->WriteBig( _tableLength );
		
	}
	else
	{
		inFile->ReadBig( magic );
		if( magic != RESOURCE_FILE_MAGIC )
		{
			delete inFile;
			return;
		}
		
		inFile->ReadBig( _tableOffset );
		inFile->ReadBig( _tableLength );
		// read this into a memory buffer with a single read
		char* const buf = ( char* )Mem_Alloc( _tableLength, TAG_RESOURCE );
		inFile->Seek( _tableOffset, FS_SEEK_SET );
		inFile->Read( buf, _tableLength );
		idFile_Memory memFile( "resourceHeader", ( const char* )buf, _tableLength );
		
		int _numFileResources = 0;
		memFile.ReadBig( _numFileResources );
		
		outFile->WriteBig( magic );
		outFile->WriteBig( _tableOffset );
		outFile->WriteBig( _tableLength );
		
		entries.SetNum( _numFileResources );
		
		for( int i = 0; i < _numFileResources; i++ )
		{
			entries[ i ].Read( &memFile );
			
			
			idLib::Printf( "examining %s\n", entries[ i ].filename.c_str() );
			byte* fileData = NULL;
			
			for( int j = filesToUpdate.Num() - 1; j >= 0; j-- )
			{
				if( filesToUpdate[ j ].Icmp( entries[ i ].filename ) == 0 )
				{
					idFile* newFile = fileSystem->OpenFileReadMemory( filesToUpdate[ j ] );
					if( newFile != NULL )
					{
						idLib::Printf( "Updating %s\n", filesToUpdate[ j ].c_str() );
						entries[ i ].length = newFile->Length();
						fileData = ( byte* )Mem_Alloc( entries[ i ].length, TAG_TEMP );
						newFile->Read( fileData, newFile->Length() );
						delete newFile;
					}
					filesToUpdate.RemoveIndex( j );
				}
			}
			
			if( fileData == NULL )
			{
				inFile->Seek( entries[ i ].offset, FS_SEEK_SET );
				fileData = ( byte* )Mem_Alloc( entries[ i ].length, TAG_TEMP );
				inFile->Read( fileData, entries[ i ].length );
			}
			
			entries[ i ].offset = outFile->Tell();
			outFile->Write( ( void* )fileData, entries[ i ].length );
			
			Mem_Free( fileData );
		}
		
		Mem_Free( buf );
	}
	
	while( filesToUpdate.Num() > 0 )
	{
		idFile* newFile = fileSystem->OpenFileReadMemory( filesToUpdate[ 0 ] );
		if( newFile != NULL )
		{
			idLib::Printf( "Appending %s\n", filesToUpdate[ 0 ].c_str() );
			idResourceCacheEntry rt;
			rt.filename = filesToUpdate[ 0 ];
			rt.length = newFile->Length();
			byte* fileData = ( byte* )Mem_Alloc( rt.length, TAG_TEMP );
			newFile->Read( fileData, rt.length );
			int idx = entries.Append( rt );
			if( idx >= 0 )
			{
				entries[ idx ].offset = outFile->Tell();
				outFile->Write( ( void* )fileData, entries[ idx ].length );
			}
			delete newFile;
			Mem_Free( fileData );
		}
		filesToUpdate.RemoveIndex( 0 );
	}
	
	_tableOffset = outFile->Tell();
	outFile->WriteBig( entries.Num() );
	
	// write the individual resource entries
	for( int i = 0; i < entries.Num(); i++ )
	{
		entries[ i ].Write( outFile );
	}
	
	// go back and write the header offsets again, now that we have file offsets and lengths
	_tableLength = outFile->Tell() - _tableOffset;
	outFile->Seek( 0, FS_SEEK_SET );
	outFile->WriteBig( magic );
	outFile->WriteBig( _tableOffset );
	outFile->WriteBig( _tableLength );
	
	delete outFile;
	delete inFile;
}
コード例 #8
0
ファイル: lanconnection.cpp プロジェクト: IcyX/bote
	void CLANConnection::Run()
	{
		VERIFY(AfxSocketInit());

		// Socket erzeugen, falls noch nicht geschehen
		int nError;
		if (!CreateSocket(nError))
		{
			if (m_pListener)
			{
				m_pListener->OnSocketError(nError, this);
				m_pListener->OnConnectionLost(this);
			}
			return;
		}

		CAsyncSocket socket;
		ASSERT(m_hSocket != INVALID_SOCKET);
		socket.Attach(m_hSocket);

		// IP-Adresse und tatsächlichen Port ermitteln
		SOCKADDR_IN sockaddr;
		memset(&sockaddr, 0, sizeof(sockaddr));
		int nSockAddrLen = sizeof(SOCKADDR_IN);
		if (!socket.GetSockName((SOCKADDR *)&sockaddr, &nSockAddrLen)) goto error;

		m_nPort = ntohs(sockaddr.sin_port);
		m_dwIP = ntohl(sockaddr.sin_addr.S_un.S_addr);

		// main thread loop
		BYTE buf[LAN_BUFSIZE];
		while (!IsInterrupted())
		{
			// Senden
			{
			CReference<CLANMessage> message;
			if (message = GetNextMessage())
			{
				// Magic Number
				memcpy(buf, "BotE", 4);

				// Nachricht serialisieren
				CMemFile memFile(&buf[4], LAN_BUFSIZE - 4);
				CArchive ar(&memFile, CArchive::store);
				message->Serialize(ar);
				ar.Close();
				UINT nSize = memFile.GetPosition() + 4;
				memFile.Detach();

				// Empfänger setzen
				memset(&sockaddr, 0, sizeof(sockaddr));
				sockaddr.sin_family = AF_INET;
				sockaddr.sin_addr.S_un.S_addr = htonl(message->GetReceiverIP());
				sockaddr.sin_port = htons(message->GetReceiverPort());

				// Nachricht versenden, setzt bei Fehler m_bInterrupted
				if (!SendMessageTo(socket, message, buf, nSize, &sockaddr)) break;

				// Broadcast-Nachricht auch an den lokalen Host senden
				if (message->GetReceiverIP() == INADDR_BROADCAST)
				{
					sockaddr.sin_addr.S_un.S_addr = htonl(INADDR_LOOPBACK);
					if (!SendMessageTo(socket, message, buf, nSize, &sockaddr))
						break;
				}
			}
			}

			// Empfangen
			memset(&sockaddr, 0, sizeof(sockaddr));
			int nSockAddrLen = sizeof(sockaddr);
			int nCount = socket.ReceiveFrom(&buf, LAN_BUFSIZE, (SOCKADDR *)&sockaddr, &nSockAddrLen);
			if (nCount > 0)
			{
				// Magic Number prüfen
				if (memcmp(&buf, "BotE", 4) != 0) continue;

				// Nachricht deserialisieren
				CMemFile memFile(&buf[4], nCount - 4);
				CArchive ar(&memFile, CArchive::load);
				CReference<CLANMessage> message(new CLANMessage());
				message->Serialize(ar);
				ar.Close();
				memFile.Detach();

				// IP und Port des Absenders
				DWORD dwIP = ntohl(sockaddr.sin_addr.S_un.S_addr);
				UINT nPort = ntohs(sockaddr.sin_port);
				message->SetSenderIP(dwIP);
				message->SetSenderPort(nPort);

				// Ankunft einer Nachricht melden
				if (m_pListener) m_pListener->OnMessageReceived(message, this);
			}
			else if (nCount == 0)
			{
				// "Verbindung" wurde getrennt
				ASSERT(FALSE);
				break;
			}
			else if (nCount == SOCKET_ERROR)
			{
				int nError = socket.GetLastError();
				if (nError != WSAEWOULDBLOCK)
				{
					if (m_pListener) m_pListener->OnSocketError(nError, this);
					// WSAECONNRESET tritt auf, wenn wir zuvor eine Nachricht an eine Adresse gesendet
					// haben, an der kein Server läuft; Thread dann nicht abbrechen
					if (nError != WSAECONNRESET)
					{
						__super::Interrupt();
						break;
					}
				}
			}

			Sleep(50);
		}

		// verbleibende Nachrichten löschen
		{
			CReference<CLANMessage> message;
			while (message = GetNextMessage())
			{
				if (m_pListener) m_pListener->OnMessageDiscarded(message, this);
			}
		}

		// socket schließen, Thread beenden
		socket.Close();
		m_hSocket = INVALID_SOCKET;
		if (m_bSendLost && m_pListener) m_pListener->OnConnectionLost(this);
		return;

error:
		if (m_pListener) m_pListener->OnSocketError(socket.GetLastError(), this);
		m_hSocket = INVALID_SOCKET;
		if (m_pListener) m_pListener->OnConnectionLost(this);
	}
コード例 #9
0
ファイル: ChatBkDlg.cpp プロジェクト: zhangyongproject/VC
LRESULT CChatBkDlg::OnPreSendMsg(WPARAM wParam, LPARAM lParam)
{

	switch (wParam)
	{
		case 0:
			if (m_pMsgEdit->GetRichEditCtrl().GetSafeHwnd() && m_pMsgEdit->GetRichEditCtrl().GetTextLength())
			{
				clock_t clr0 = clock();


				//将字符串插入到整个内容的最前面

				m_pMsgEdit->GetRichEditCtrl().HideSelection(TRUE, FALSE);
				m_pMsgEdit->GetRichEditCtrl().SetSel(0, -1);
				m_pMsgEdit->GetRichEditCtrl().SetSelectionCharFormat(m_defaultCharFormat);
				

				CMemFile memFile(m_pBuf, BUFLEN);
				memFile.SeekToBegin();
				///////////////////////将整个 RichView中的内容写到内存文件中
				EDITSTREAM es;
				es.dwCookie = (DWORD_PTR)&memFile;
				es.pfnCallback = RichEditStreamOutCallback;
				m_pMsgEdit->GetRichEditCtrl().SetSel(0, -1);
				m_pMsgEdit->GetRichEditCtrl().StreamOut(SF_RTF | SFF_SELECTION, es);
				m_pMsgEdit->GetRichEditCtrl().Clear();
				m_pMsgEdit->GetRichEditCtrl().HideSelection(FALSE, FALSE);


				TRACE(_T("写入内存 用时:%d ms 时间:%d\n"), clock() - clr0, clock()); clr0 = clock();


				//IRichEditOle* pRichEditOleMsg = pChatFrame->m_pMsgView->GetRichEditCtrl().GetIRichEditOle();
				//int count = pRichEditOleMsg->GetObjectCount();     
				//for(int i = 0 ; i < count ; i++) //遍历位图
				//{
				//	REOBJECT object;  //位图信息存在这里
				//	memset(&object,0,sizeof(REOBJECT));
				//	object.cbStruct = sizeof(REOBJECT);
				//	pRichEditOleMsg->GetObject(i, &object, REO_GETOBJ_ALL_INTERFACES);

				//	int pos = object.cp ; //位图的位置信息
				//	DWORD dwUSer  =object.dwUser; //位图的信息,之前应用程序设置的,应有程序当然知道什么意思了
				//}

				//IRichEditOle* pRichEditOleRecord = pChatFrame->m_pRecordView->GetRichEditCtrl().GetIRichEditOle();

				if (m_pCurrentUser->state == USERINFO::USER_STATE_ONLINE)
				{
					CNetData *pChatNetData = new CNetData();
					pChatNetData->MakeNETBuffer(CNetData::TCP_CHATMSG, RIMConfig::GetInstance()->m_pLogonUser, m_pCurrentUser, m_curUserIP, m_pBuf, UINT(memFile.Seek(0, CFile::current)));
					if (pChatNetData->GetBufferLen())
						RIMConfig::GetInstance()->m_TCPSendQueue.Push(pChatNetData);
					else
						delete pChatNetData;


					//int memFileLen = UINT(memFile.Seek(0, CFile::current));
					//LPBYTE pBufferTemp = new BYTE[memFileLen + 5];

					//////////////////////////////对数据进行压缩
					//if (HZIP hz = CreateZip(pBufferTemp, memFileLen + 5, ""))
					//{
					//	tstring newGuidStr = GetNewGuid() + _T(".txt");
					//	if (ZR_OK == ZipAdd(hz, newGuidStr.c_str(), m_pBuf, UINT(memFile.Seek(0, CFile::current))))
					//	{
					//		LPBYTE	pZipBuffer	= NULL;
					//		DWORD	destlen		= 0;
					//		ZipGetMemory(hz, (void**)&pZipBuffer, &destlen);
					//		if (pZipBuffer && destlen)
					//		{
					//			CNetData *pChatNetData = new CNetData();
					//			pChatNetData->MakeNETBuffer(CNetData::TCP_CHATMSG, RIMConfig::GetInstance()->m_pLogonUser, m_pCurrentUser, pZipBuffer, destlen);
					//			RIMConfig::GetInstance()->m_TCPSendQueue.Push(pChatNetData);
					//		}
					//	}

					//	if (hz != NULL)	{ CloseZip(hz);	hz = NULL; }
					//}
					//if (pBufferTemp)
					//	delete[] pBufferTemp;
				}
				TRACE(_T("写入数据队列 用时:%d ms 时间:%d\n"), clock() - clr0, clock()); clr0 = clock();


				{//////////////// 将内存文件中的内容写到通话记录视图中

					///////////////构造字符串,包括发送的用户,及发送时间
					SYSTEMTIME systemtime;
					GetLocalTime(&systemtime);
					TCHAR ch[MAX_PATH] ={ 0 };
					_stprintf_s(ch, MAX_PATH, _T("%s (%d/%02d/%02d %02d:%02d:%02d):\n"), 
						RIMConfig::GetInstance()->m_pLogonUser->UserName.c_str(), 
						systemtime.wYear, 
						systemtime.wMonth, 
						systemtime.wDay, 
						systemtime.wHour, 
						systemtime.wMinute, 
						systemtime.wSecond);

					memFile.SeekToBegin();
					m_pRecordView->GetRichEditCtrl().SetReadOnly(FALSE);

					m_pRecordView->GetRichEditCtrl().SetSel(-2, -1);
					m_pRecordView->GetRichEditCtrl().SetWordCharFormat(m_sendUserCharFormat);
					m_pRecordView->GetRichEditCtrl().ReplaceSel(ch, FALSE);					//输入用户发送时间

					EDITSTREAM es;
					es.dwCookie = (DWORD_PTR)&memFile;
					es.pfnCallback = RichEditStreamInCallback;
					m_pRecordView->GetRichEditCtrl().SetSel(-2, -1);
					m_pRecordView->GetRichEditCtrl().StreamIn(SF_RTF | SFF_SELECTION, es);
					//为了解决添加SFF_SELECTION后,自动滚动不显示的问题

					if(!(GetAsyncKeyState(VK_LBUTTON) && 0x8000))	////鼠标没有按下
						m_pRecordView->GetRichEditCtrl().PostMessage(WM_VSCROLL, MAKELONG(SB_BOTTOM, 0), 0);;

					m_pRecordView->GetRichEditCtrl().SetReadOnly(TRUE);
				}

				TRACE(_T("写入上面View 用时:%d ms 时间:%d\n"), clock() - clr0, clock()); clr0 = clock();

			}
			break;
		case 1:
		{
			CFileDialog filedlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_READONLY, _T("All Files (*.*)|*.*||"), this);

			if (IDOK == filedlg.DoModal())
			{
				CString filePath = filedlg.GetPathName();
				SendFileOrDic(filePath);
			}

			InvalidateRect(m_sendFileRc, FALSE);
		}
			break;
		case 2:
		{
			TCHAR szPath[MAX_PATH] ={ 0 }; //存放选择的目录路径

			BROWSEINFO bi;
			bi.hwndOwner		= m_hWnd;
			bi.pidlRoot			= NULL;
			bi.pszDisplayName	= szPath;
			bi.lpszTitle		= _T("请选择需要导出的目录:");
			bi.ulFlags			= BIF_RETURNONLYFSDIRS;
			bi.lpfn				= BrowseCallbackProc; //设置CALLBACK函数
			bi.iImage			= 0;
			bi.lParam			= long(m_oldDic.GetBuffer());

			//弹出选择目录对话框
			LPITEMIDLIST lp = SHBrowseForFolder(&bi);
			if (lp && SHGetPathFromIDList(lp, szPath))
			{
				m_oldDic = szPath;
				SendFileOrDic(szPath);
			}

			InvalidateRect(m_sendDicRc, FALSE);
		}
			break;
		case 3:
		{
			CString sFilter = _T("All image file|*.bmp;*.jpg;|Bitmap Files (*.bmp)|*.bmp|JPEG Files (*.jpg)|*.jpg|");
			//CString sFilter = _T("All image file|*.bmp;*.jpg;*.gif|Bitmap Files (*.bmp)|*.bmp|JPEG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|");

			CFileDialog filedlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_READONLY, sFilter, this);

			if (IDOK == filedlg.DoModal())
			{
				CTapBitmap bmp;
				if (bmp.Load(filedlg.GetPathName()) == FALSE)
				{
					AfxMessageBox(_T("Could not load image."));
					return TRUE;
				}
				CEnBitmap enBitmap;
				CBitmap Bitmap;
				if (enBitmap.Attach(bmp.GetBMP(), 0))
				{
					Bitmap.DeleteObject();
					Bitmap.Attach(enBitmap.Detach());

					IRichEditOle	*pRichEditOle;
					pRichEditOle	= m_pMsgEdit->GetRichEditCtrl().GetIRichEditOle();
					HBITMAP hBitmap = (HBITMAP)Bitmap;
					if (hBitmap)
					{
						ImageDataObject::InsertBitmap(pRichEditOle, hBitmap);
					}
					pRichEditOle->Release();
				}
			}

			InvalidateRect(m_sendPictureRc, FALSE);
		}
			break;
	}


	return TRUE;
}
コード例 #10
0
ファイル: ChatBkDlg.cpp プロジェクト: zhangyongproject/VC
void CChatBkDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO:  在此添加消息处理程序代码和/或调用默认值

	if (m_pCurrentUser)
	{
		while (m_pCurrentUser->receiveMsgQueue.GetQueueCount())
		{
			CNetData *pQueueData = NULL;
			m_pCurrentUser->receiveMsgQueue.Pop((CQueueData**)&pQueueData);
			if (pQueueData)
			{//////////////// 将内存文件中的内容写到通话记录视图中
				CMemFile memFile(pQueueData->GetBuffer(), pQueueData->GetBufferLen());
				memFile.SeekToBegin();


				{//////////////// 将内存文件中的内容写到通话记录视图中

					///////////////接收时间
					int iplistCnt = m_pCurrentUser->ipList.size();
					TCHAR ch[MAX_PATH] ={ 0 };
					_stprintf_s(ch, MAX_PATH, _T("%s (%d/%02d/%02d %02d:%02d:%02d):\n"), 
						iplistCnt > 1 ?pQueueData->GetFromOrToIP().c_str():pQueueData->GetSourceID().c_str(), 
								pQueueData->GetDataCreateTime().wYear, 
								pQueueData->GetDataCreateTime().wMonth,
								pQueueData->GetDataCreateTime().wDay,
								pQueueData->GetDataCreateTime().wHour,
								pQueueData->GetDataCreateTime().wMinute,
								pQueueData->GetDataCreateTime().wSecond);

					memFile.SeekToBegin();
					m_pRecordView->GetRichEditCtrl().SetReadOnly(FALSE);

					m_pRecordView->GetRichEditCtrl().SetSel(-2, -1);
					m_pRecordView->GetRichEditCtrl().SetWordCharFormat(m_recvUserCharFormat);
					m_pRecordView->GetRichEditCtrl().ReplaceSel(ch, FALSE);					//输入用户发送时间

					EDITSTREAM es;
					es.dwCookie = (DWORD_PTR)&memFile;
					es.pfnCallback = RichEditStreamInCallback;
					m_pRecordView->GetRichEditCtrl().SetSel(-2, -1);
					m_pRecordView->GetRichEditCtrl().StreamIn(SF_RTF | SFF_SELECTION, es);
					//为了解决添加SFF_SELECTION后,自动滚动不显示的问题

					if(!(GetAsyncKeyState(VK_LBUTTON) && 0x8000))	////鼠标没有按下
						m_pRecordView->GetRichEditCtrl().PostMessage(WM_VSCROLL, MAKELONG(SB_BOTTOM, 0), 0);
					m_pRecordView->GetRichEditCtrl().SetReadOnly(TRUE);
				}

				memFile.Close();
				delete pQueueData;
			}
		}

		/////将接收队列插入树控件
		while (m_pCurrentUser->receiveFileQueue.GetQueueCount())
		{
			LPTRANSFILEINFO pTransfileInfo = NULL;
			m_pCurrentUser->receiveFileQueue.Pop((CQueueData**)&pTransfileInfo);

			HTREEITEM hItem = m_filleTree.InsertItem(SENDFILELISTTREE_RECVSTR, TVI_ROOT, TVI_FIRST);
			m_filleTree.SetItemData(hItem, (DWORD_PTR)pTransfileInfo);
			pTransfileInfo->SafeModifyTransFlag(TRANSFILEINFO::TRANS_FLAG_TRANSBEGIN);

			BringWindowToTop();
			SetForegroundWindow();
		}
		/////将发送队列插入树控件
		while (m_pCurrentUser->sendFileQueue.GetQueueCount())
		{
			LPTRANSFILEINFO pTransfileInfo = NULL;
			m_pCurrentUser->sendFileQueue.Pop((CQueueData**)&pTransfileInfo);

			HTREEITEM hItem = m_filleTree.InsertItem(SENDFILELISTTREE_SENDSTR, TVI_ROOT, TVI_LAST);
			m_filleTree.SetItemData(hItem, (DWORD_PTR)pTransfileInfo);

			///////构造文件网络传输数据块
			string xmlStr = TRANSFILEINFO::MakeXmlStr(pTransfileInfo);
			if (xmlStr.size())
			{
				CFileNetData *pFileNetData = new CFileNetData(pTransfileInfo);
				pFileNetData->MakeNETBuffer(CNetData::TCP_FILEASKSEND, RIMConfig::GetInstance()->m_pLogonUser, m_pCurrentUser, m_curUserIP, (LPBYTE)xmlStr.c_str(), xmlStr.size());
				RIMConfig::GetInstance()->m_TCPSendQueue.Push(pFileNetData);
			}

			pTransfileInfo->SafeModifyTransFlag(TRANSFILEINFO::TRANS_FLAG_TRANSBEGIN);

			BringWindowToTop();
			SetForegroundWindow();
		}

	}

	if (m_filleTree.GetSafeHwnd())
	{
		LPTRANSFILEINFO pTransfileInfo	= NULL;
		HTREEITEM	hItem				= m_filleTree.GetRootItem();
		while (hItem != NULL)
		{
			if (pTransfileInfo = (LPTRANSFILEINFO)m_filleTree.GetItemData(hItem))
			{
				switch (pTransfileInfo->GetTransFlag())
				{
					case TRANSFILEINFO::TRANS_FLAG_PRETRANS:
					case TRANSFILEINFO::TRANS_FLAG_TRANSBEGIN:
						////该操作由树控件处理是开始接收还是发送
					case TRANSFILEINFO::TRANS_FLAG_TRANSING:
						/////由下面统一刷新
						break;
					case TRANSFILEINFO::TRANS_FLAG_TRANSCANCEL:
					case TRANSFILEINFO::TRANS_FLAG_TRANSPREEND:
						//取消操作不处理等待发送或接收线程处理
						break;
					case TRANSFILEINFO::TRANS_FLAG_TRANSEND:
					{
						CString strTip = _T("");
						strTip.Format(_T("(%s)%s\n"), PathFindFileName(pTransfileInfo->GetApplicationName().c_str()), pTransfileInfo->transError.c_str());
						m_pRecordView->GetRichEditCtrl().SetReadOnly(FALSE);
						m_pRecordView->GetRichEditCtrl().SetSel(-2, -1);
						m_pRecordView->GetRichEditCtrl().ReplaceSel(strTip, FALSE);	//替换首部字符串
						m_pRecordView->GetRichEditCtrl().SetReadOnly(TRUE);

						m_filleTree.DeleteItem(hItem);	hItem = m_filleTree.GetRootItem();	////删除并重新开始遍历
						delete pTransfileInfo;
						TRACE(_T("删除结构时间:%d ms\n"), clock());

					}
						continue;	//receiveFileVec结构发生变化需要重新来
				}
			}
			hItem	= m_filleTree.GetNextItem(hItem, TVGN_NEXT);
		}

		if (m_filleTree.GetCount())
		{
			RepositionSelfDlg(TRUE);
			m_filleTree.Invalidate(FALSE);
		}
		else
			RepositionSelfDlg(FALSE);
	}


	CDialog::OnTimer(nIDEvent);
}
コード例 #11
0
ファイル: USBLogView.cpp プロジェクト: cyphunk/sectk
void CUSBLogView::OnEditPaste(void) 
{
    if(!IsClipboardFormatAvailable(GetApp().m_uClipboardFormat))
    {
        TRACE("OnEditPaste(): no suitable clipboard format available!\n");
        return;
    }

    // we need a focused URB as well...
    int nFocusedURB = m_Log.FindFocusedURB();
    if(-1 == nFocusedURB)
    {
        nFocusedURB = 0;
    }

    if(!AfxGetMainWnd()->OpenClipboard())
    {
        TRACE("Error while opening clipboard!\n");
        return;
    }
    // from here on, we have to close the clipboard
    // before exiting this function, otherwise other
    // applications might not get a chance to copy/paste
    // stuff!
    HANDLE hBinary = NULL;
    PVOID pData = NULL;
    try
    {
        hBinary = GetClipboardData(GetApp().m_uClipboardFormat);
        if(NULL == hBinary)
        {
            AfxThrowNotSupportedException();
        }

        pData = GlobalLock(hBinary);
        {
            CMyMemFile memFile(pData);
            CArchive ar(&memFile, CArchive::load);
            DWORD dwVersion = ar.ReadCount();
            if(_VERSION_DWORD_ != dwVersion)
            {
                AfxThrowNotSupportedException();
            }

            DWORD nURBCnt = ar.ReadCount();
            TRACE("Pasting %d URBs...\n", nURBCnt);
            
            CUSBLogDoc *pDoc = GetDocument();
            int nInsertLocation = nFocusedURB;
            while(0 < nURBCnt)
            {
                CRuntimeClass *pClass = ar.ReadClass();
                if(!pClass->IsDerivedFrom(RUNTIME_CLASS(CURB)))
                {
                    TRACE("unknown runtime class!\n");
                    AfxThrowArchiveException(CArchiveException::badClass);
                }

                CURB *pURB = (CURB*) pClass->CreateObject();
                ASSERT(NULL != pURB);
                pURB->SetChunkAllocator(&pDoc->m_arURB.m_ChunkAllocator);
                pURB->Serialize(ar);
                pDoc->m_arURB.InsertAt(nInsertLocation, pURB);
                nInsertLocation++;
                --nURBCnt;
            }
            pDoc->UpdateAllViews(NULL, 1);
            OnEditSelectNone();
            m_Log.SetFocusedURB(nFocusedURB);            
        }

        GlobalUnlock(hBinary);
        hBinary = NULL;

        CloseClipboard();
    }
    catch(...)
    {
        if((NULL != pData) && (NULL != hBinary))
        {
            GlobalUnlock(hBinary);
        }
        CloseClipboard();
        throw;
    }
}
コード例 #12
0
ファイル: USBLogView.cpp プロジェクト: cyphunk/sectk
void CUSBLogView::OnEditCopyCutDelete(BOOL bPlaceInClipboard, BOOL bDeleteFromThis)
{
    CWaitCursor waitcursor;
    CArrayData arData;
    CMyDWORDArray arURBs;
    if(!m_Log.GetSelectionArrays(arData, arURBs))
    {
        return;
    }

    int nURBCnt = arURBs.GetSize();

    TRACE("URBs marked with selection: %d\n", nURBCnt);
    for(int i = 0; i < nURBCnt; ++i)
    {
        TRACE("  %d: %d\n", i, arURBs[i]);
    }

    GetApp().InitializeWorkTicks((bDeleteFromThis ? nURBCnt : 0) + 2 * (nURBCnt + arData.GetSize()));

    CUSBLogDoc *pDoc = GetDocument();
    if(bPlaceInClipboard)
    {
        CMyMemFile NullFile;
        SerializeURBsToArchive(&NullFile, arURBs);
        UINT nBinaryLength = NullFile.GetLength();
        TRACE("Binary Length: %d bytes\n", nBinaryLength);

        int nDataCnt = arData.GetSize();
        TCHAR sBuffer[MAX_PATH];
        DWORD dwTextLength = 0;
        DWORD dwTextSeparators = 0;
        for(int nIndex = 0; nIndex < nDataCnt; ++nIndex)
        {
            int nURB = arData[nIndex].nURB;
            int nLine = arData[nIndex].nLine;
            CURB *pURB = pDoc->m_arURB[nURB];
            if(0 == nLine)
            {
                // get accumulated length of all header
                // columns
                for(int nCol = 0; nCol < LOGCOL_MAX_COLUMN; ++nCol)
                {
                    if(m_Log.GetURBText(pURB, nLine, nCol, sBuffer))
                    {
                        dwTextLength += _tcslen(sBuffer);
                        dwTextSeparators += 2;
                    }
                }
            }
            else
            {
                if(m_Log.GetURBText(pURB, nLine, 0, sBuffer))
                {
                    dwTextLength += _tcslen(sBuffer);
                    dwTextSeparators += 2;
                }
            }
            GetApp().IncrementWorkTick();
        }
        TRACE("Text Length: %d bytes\n", dwTextLength);
        TRACE("Text Separators: %d bytes\n", dwTextSeparators);

        if(!AfxGetMainWnd()->OpenClipboard())
        {
            TRACE("Error while opening clipboard!\n");
            return;
        }
        // from here on, we have to close the clipboard
        // before exiting this function, otherwise other
        // applications might not get a chance to copy/paste
        // stuff!
        try
        {
            EmptyClipboard();

            DWORD dwTextTotalLength = dwTextLength + dwTextSeparators;
            HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE, (dwTextTotalLength + 1) * sizeof(TCHAR));
            if(NULL == hText)
            {
                AfxThrowMemoryException();
            }
            HGLOBAL hBinary = GlobalAlloc(GMEM_MOVEABLE, nBinaryLength);
            if(NULL == hBinary)
            {
                GlobalFree(hText);
                AfxThrowMemoryException();
            }

            LPTSTR pText = (LPTSTR) GlobalLock(hText);
            for(int nIndex = 0; nIndex < nDataCnt; ++nIndex)
            {
                int nURB = arData[nIndex].nURB;
                int nLine = arData[nIndex].nLine;
                CURB *pURB = pDoc->m_arURB[nURB];
                if(0 == nLine)
                {
                    for(int nCol = 0; nCol < LOGCOL_MAX_COLUMN; ++nCol)
                    {
                        if(m_Log.GetURBText(pURB, nLine, nCol, pText))
                        {
                            pText += _tcslen(pText);
                            if((LOGCOL_MAX_COLUMN - 1) != nCol)
                            {
                                _tcscat(pText, "\t");
                                pText += _tcslen(pText);
                            }
                        }
                    }
                }
                else
                {
                    if(m_Log.GetURBText(pURB, nLine, 0, pText))
                    {
                        pText += _tcslen(pText);
                    }
                }
                _tcscat(pText, "\n");
                pText += _tcslen(pText);
                GetApp().IncrementWorkTick();
            }
            GlobalUnlock(hText);

            PVOID pData = GlobalLock(hBinary);
            CMyMemFile memFile((PBYTE) pData);
            SerializeURBsToArchive(&memFile, arURBs);
            GlobalUnlock(hBinary);

            SetClipboardData(CF_TEXT, hText);
            SetClipboardData(GetApp().m_uClipboardFormat, hBinary);

            CloseClipboard();
        }
        catch(...)
        {
            CloseClipboard();
            throw;
        }
    }

    if(bDeleteFromThis)
    {
        int nFocusedURB = m_Log.FindFocusedURB();
        OnEditSelectNone();
        for(int nIndex = nURBCnt - 1; 0 <= nIndex; --nIndex)
        {
            int nURB = arURBs[nIndex];
            CURB *pURB = pDoc->m_arURB[nURB];
            delete pURB;
            pDoc->m_arURB.RemoveAt(nURB);
            GetApp().IncrementWorkTick();
        }
        pDoc->UpdateAllViews(NULL, 1);
        m_Log.SetFocusedURB(nFocusedURB);
    }

    GetApp().DeinitializeWorkTicks();
}
コード例 #13
0
ファイル: occmgr.cpp プロジェクト: rickerliang/OpenNT
HWND COccManager::CreateDlgControl(CWnd* pWndParent, HWND hwAfter,
	BOOL bDialogEx, LPDLGITEMTEMPLATE pItem, WORD nMsg, BYTE* lpData, DWORD cb)
{
	LPWSTR pszClass = (LPWSTR)(pItem + 1);
	DLGITEMTEMPLATE dlgItemTmp;

	if (bDialogEx)
	{
		// We have an extended dialog template: copy relevant parts into an
		// ordinary dialog template, because their layouts are different
		DLGITEMTEMPLATEEX* pItemEx = (DLGITEMTEMPLATEEX*)pItem;
		dlgItemTmp.style = pItemEx->style;
		dlgItemTmp.dwExtendedStyle = pItemEx->exStyle;
		dlgItemTmp.x = pItemEx->x;
		dlgItemTmp.y = pItemEx->y;
		dlgItemTmp.cx = pItemEx->cx;
		dlgItemTmp.cy = pItemEx->cy;
		dlgItemTmp.id = (WORD)pItemEx->id;
		pItem = &dlgItemTmp;
		pszClass = (LPWSTR)(pItemEx + 1);
	}

	CRect rect(pItem->x, pItem->y, pItem->x + pItem->cx, pItem->y + pItem->cy);
	::MapDialogRect(pWndParent->m_hWnd, &rect);

	BSTR bstrLicKey = NULL;

	// extract license key data, if any
	if (cb >= sizeof(ULONG))
	{
		ULONG cchLicKey = *(UNALIGNED ULONG*)lpData;
		lpData += sizeof(ULONG);
		cb -= sizeof(ULONG);
		if (cchLicKey > 0)
		{
			bstrLicKey = SysAllocStringLen((LPCOLESTR)lpData, cchLicKey);
			lpData += cchLicKey * sizeof(WCHAR);
			cb -= cchLicKey * sizeof(WCHAR);
		}
	}

	// If WM_OCC_INITNEW, we should have exhausted all of the data by now.
	ASSERT((nMsg != WM_OCC_INITNEW) || (cb == 0));

	CDataBoundProperty* pBindings = NULL;
	CString strDataField;
	WORD ctlidRowSource = 0;
	DISPID defdispid = 0;
	UINT dwType = 0;

	if (nMsg == WM_OCC_LOADFROMSTREAM_EX ||
		nMsg == WM_OCC_LOADFROMSTORAGE_EX)
	{
		// Read the size of the section
		ULONG cbOffset = *(UNALIGNED ULONG*)lpData;
		ULONG cbBindInfo = cbOffset - sizeof(DWORD);
		lpData += sizeof(DWORD);

		ULONG dwFlags = *(UNALIGNED ULONG*)lpData;
		cbBindInfo -= sizeof(DWORD);
		lpData += sizeof(DWORD);
		ASSERT(dwFlags == 1);

		ULONG cbBinding = *(UNALIGNED ULONG*)lpData;
		cbBindInfo -= sizeof(DWORD);
		lpData += sizeof(DWORD);

		while(cbBindInfo > 0)
		{
			DISPID dispid;
			UWORD ctlid;

			dispid = *(UNALIGNED DISPID *)lpData;
			lpData += sizeof(DISPID);
			cbBindInfo -= sizeof(DISPID);
			ctlid =  *(UNALIGNED WORD *)lpData;
			lpData += sizeof(WORD);
			cbBindInfo -= sizeof(WORD);

			if(dispid == DISPID_DATASOURCE)
			{
				defdispid = *(UNALIGNED ULONG*)lpData;
				cbBindInfo -= sizeof(DISPID);
				lpData += sizeof(DISPID);
				dwType = *(UNALIGNED ULONG*)lpData;
				cbBindInfo -= sizeof(DWORD);
				lpData += sizeof(DWORD);

				ASSERT(*(UNALIGNED DISPID *)lpData == DISPID_DATAFIELD);
				lpData += sizeof(DISPID);
				cbBindInfo -= sizeof(DISPID);
				// Skip the string length
				lpData += sizeof(DWORD);
				cbBindInfo -= sizeof(DWORD);
				strDataField = (char *)lpData;
				lpData += strDataField.GetLength()+1;
				cbBindInfo -= strDataField.GetLength()+1;
				ctlidRowSource = ctlid;
			} else
				pBindings = new CDataBoundProperty(pBindings, dispid, ctlid);
		}
		cb -= cbOffset;
	}

	// From now on act as a regular type
	nMsg -= (WM_OCC_LOADFROMSTREAM_EX - WM_OCC_LOADFROMSTREAM);

	GUID clsid;
	HRESULT hr;
	if (pszClass[0] == L'{')
		hr = CLSIDFromString(pszClass, &clsid);
	else
		hr = CLSIDFromProgID(pszClass, &clsid);

#ifdef _DEBUG
	if (FAILED(hr))
	{
		TRACE1("Unable to convert \"%ls\" to a class ID.\n", pszClass);
		TRACE1(">>> Result code: 0x%08lx\n", hr);
		if (pszClass[0] != L'{')
			TRACE0(">>> Is the control properly registered?\n");
	}
#endif

	CMemFile memFile(lpData, cb);
	CMemFile* pMemFile = (nMsg == WM_OCC_INITNEW) ? NULL : &memFile;

	CWnd* pWndNew = NULL;
	COleControlSite* pSite = NULL;

	if (SUCCEEDED(hr) &&
		pWndParent->InitControlContainer() &&
		pWndParent->m_pCtrlCont->CreateControl(NULL, clsid, NULL, pItem->style,
			rect, pItem->id, pMemFile, (nMsg == WM_OCC_LOADFROMSTORAGE),
			bstrLicKey, &pSite))
	{
		ASSERT(pSite != NULL);
		// set ZOrder only!
		SetWindowPos(pSite->m_hWnd, hwAfter, 0, 0, 0, 0,
			SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

		pSite->m_pBindings = pBindings;
		pSite->m_strDataField = strDataField;
		pSite->m_ctlidRowSource = ctlidRowSource;
		pSite->m_defdispid = defdispid;
		pSite->m_dwType = dwType;

		// Determine if this is a DataSource by QI for ICursor
		ICursor* pCursor;
		if (SUCCEEDED(pSite->m_pObject->QueryInterface(IID_ICursor,
			(LPVOID *)&pCursor)))
		{
			pCursor->Release();
            pSite->m_pDataSourceControl = new CDataSourceControl(pSite);
		}
	}

	if (bstrLicKey != NULL)
		SysFreeString(bstrLicKey);

	return (pSite != NULL) ? pSite->m_hWnd : NULL;
}