⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transserverdlg.cpp

📁 《医学图象的远程传输系统》
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		m_JpegBuffer[i]=(BYTE*)::GlobalAlloc(GMEM_FIXED,MAX_JPEG_SIZE);
		if (!m_JpegBuffer[i]){
			AddLog("Error to allocate memory for jpeg!");
		}
		//******************************************
		//initialize image sample system
		m_CanSample[i]=FALSE;
		m_TotalTime[i][0]=m_TotalTime[i][1]=m_TotalTime[i][2]=0;
		if (!ISInit(i)){
			AddLog(ISGetLastError(i));
			m_SampleThread[i]=NULL;
		}
		else{
			m_SampleThread[i]=AfxBeginThread(SampleThread,(LPVOID)i,THREAD_PRIORITY_NORMAL);
		}
	}
	//******************************************
	//initialize image transfer system
    ::AfxSocketInit();
	m_ListenSocket=new CListenSocket(this);
    if (!m_ListenSocket->Create(LISTEN_PORT,SOCK_STREAM,FD_ACCEPT)){
        AddLog("Error when create listen socket!");
    }
    else{
		if (!m_ListenSocket->Listen()){
			AddLog("Can not listen to socket!");
		}
		else{
			AddLog("Init network successful.");
		}
	}
	ShowWindow(SW_SHOW);
	OnButton1();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

BOOL CTransServerDlg::DestroyWindow() 
{
	OnButton2();
	Sleep(500);
	for (int i=0;i<4;i++){
		::GlobalFree(m_pDib[i]);
		::GlobalFree(m_pThumb[i]);
		::GlobalFree(m_JpegBuffer[i]);
		ICRelease(i,&m_jcprops[i]);
	}
	return CDialog::DestroyWindow();
}

void CTransServerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	UpdateData(TRUE);
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTransServerDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTransServerDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//add log information into the log box
//2002.05.17
void CTransServerDlg::AddLog(LPCTSTR Msg)
{
	int len=m_EditLog.GetWindowTextLength();
	m_EditLog.SetSel(len,len);
	m_EditLog.ReplaceSel(Msg);
	m_EditLog.ReplaceSel("\n");
}

//remove an connection in the connection list
//2002.05.17
void CTransServerDlg::RemoveConnection(int Channel,CONNECTION* connection)
{
	ASSERT(Channel>=0 && Channel<4);
	CString sResult;
	sResult.Format("Socket [%d] removed from connection list.",connection->pSocket);
	AddLog(sResult);
	//connection->pSocket->Close();//error ??
	for(POSITION pos=m_ConnectionList[Channel].GetHeadPosition();pos!=NULL;){
		POSITION temp=pos;
		CONNECTION* conn=(CONNECTION*)m_ConnectionList[Channel].GetNext(pos);
		if (connection==conn){
			m_ConnectionList[Channel].RemoveAt(temp);
			break;
		}
	}
	//delete connection;//error ??
}

//draw the sampled image, or set the rect to empty if image not exists
//2002.05.17
void CTransServerDlg::DrawImg(int Channel,BOOL bDraw)
{
	CDC* pDC=GetDC();
	if (pDC==NULL)
		return;
	CStatic* pImgWnd;
	switch(Channel){
	case 0:pImgWnd=(CStatic*)GetDlgItem(IDC_STATIC_IMAGE1);break;
	case 1:pImgWnd=(CStatic*)GetDlgItem(IDC_STATIC_IMAGE2);break;
	case 2:pImgWnd=(CStatic*)GetDlgItem(IDC_STATIC_IMAGE3);break;
	case 3:pImgWnd=(CStatic*)GetDlgItem(IDC_STATIC_IMAGE4);break;
	default:return;
	}
	CRect rect;
	pImgWnd->GetWindowRect(&rect);
	ScreenToClient(&rect);
	if (bDraw){//draw
		::SetDIBitsToDevice(pDC->m_hDC,
            rect.left,
            rect.top,
            rect.Width(),
            rect.Height(),
            0,
            0,
            0,
            rect.Height(),
            m_pThumb[Channel],
            &m_bmInfo[Channel],
            DIB_RGB_COLORS);
		pDC->SetTextColor(RGB(0,255,0));
		pDC->SetBkColor(RGB(0,0,0));
		char str[15];
        DWORD TotalTimeTmp=(m_TotalTime[Channel][0]+m_TotalTime[Channel][1]+m_TotalTime[Channel][2])/3;
		sprintf(str,"fps %.2f",TotalTimeTmp>0?(float)1000/TotalTimeTmp:0);
		::TextOut(pDC->m_hDC,rect.left+10,rect.top+10,str,strlen(str));
	}
	else{//erase
        pDC->FillSolidRect(rect.left,rect.top,rect.Width(),rect.Height(),RGB(0,0,0));
	}
	ReleaseDC(pDC);
	return;
}

//enable or disable sample on a channel
//2002.05.24
void CTransServerDlg::EnableSample(int Channel,BOOL Enable)
{
	if (m_SampleThread[Channel]==NULL){
		AfxMessageBox("This channel had not been initialized yet!",MB_ICONWARNING);
		return;
	}
	m_CanSample[Channel]=Enable;
	m_Sample[Channel*2].EnableWindow(!Enable);
	m_Sample[Channel*2+1].EnableWindow(Enable);
	if (!Enable){
		DrawImg(Channel,FALSE);
	}
}

void CTransServerDlg::OnBtnSample1(){EnableSample(0,TRUE);}

void CTransServerDlg::OnBtnSample2(){EnableSample(0,FALSE);}

void CTransServerDlg::OnBtnSample3(){EnableSample(1,TRUE);}

void CTransServerDlg::OnBtnSample4(){EnableSample(1,FALSE);}

void CTransServerDlg::OnBtnSample5(){EnableSample(2,TRUE);}

void CTransServerDlg::OnBtnSample6(){EnableSample(2,FALSE);}

void CTransServerDlg::OnBtnSample7(){EnableSample(3,TRUE);}

void CTransServerDlg::OnBtnSample8(){EnableSample(3,FALSE);}

//start sample in all channels
//2002.05.25
void CTransServerDlg::OnButton1() 
{
	for (int i=0;i<4;i++){
		if (m_SampleThread[i]!=NULL && !m_CanSample[i]){
			EnableSample(i,TRUE);
		}
	}
}

//stop sample in all channels
//2002.05.25
void CTransServerDlg::OnButton2() 
{
	for (int i=0;i<4;i++){
		if (m_SampleThread[i]!=NULL && m_CanSample[i]){
			EnableSample(i,FALSE);
		}
	}
}

//start to save image into database on one channel
//2002.05.25
void CTransServerDlg::OnButton3() 
{
	AfxMessageBox("Not suprot yet!",MB_ICONINFORMATION);
	return;
	CChannelDlg dlg;
	if (dlg.DoModal()==IDOK){
		m_PatientID=ENAddPatient();	
		if (m_PatientID<0){//if ENAddPatient() failed will return -1.
			AddLog("Error to add new patient!");
			m_ChannelToSave=-1;
		}
		else{
			m_ChannelToSave=dlg.m_Channel;
			CString str;
			str.Format("Begin to save image of patient %d on channel %d .",m_PatientID,m_ChannelToSave);
			AddLog(str);
		}
	}
}

//stop save image into database
//2002.05.25
void CTransServerDlg::OnButton4() 
{
	AfxMessageBox("Not suprot yet!",MB_ICONINFORMATION);
	return;
	m_ChannelToSave=-1;
}

//browse the image database
//2002.05.25
void CTransServerDlg::OnButton5() 
{
	AfxMessageBox("Not suprot yet!",MB_ICONINFORMATION);
	return;
	ENBrowse();
}

//image process
//2002.05.25
void CTransServerDlg::OnButton6() 
{
	CChannelDlg dlg;
	if (dlg.DoModal()==IDOK){
		BOOL bChannelOpened=m_CanSample[dlg.m_Channel];
		EnableSample(dlg.m_Channel,FALSE);
		char AppFileName[MAX_PATH]="";
		if (!GetModuleFileName(AfxGetApp()->m_hInstance,AppFileName,MAX_PATH)){
			AfxMessageBox("Error when get application path!",MB_ICONERROR);
			return;
		}
		CString TmpFileName=AppFileName;
		TmpFileName+=".tmp";
		CFile f;
		f.Open(TmpFileName,CFile::modeCreate | CFile::modeWrite);
		BITMAPINFOHEADER* bmih=(BITMAPINFOHEADER*)(m_pDib[dlg.m_Channel]+sizeof(BITMAPFILEHEADER));
		f.WriteHuge(m_pDib[dlg.m_Channel],
			bmih->biWidth*bmih->biHeight*3+
			sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER));
		f.Close();
		EnableSample(dlg.m_Channel,bChannelOpened);
		CString ExeFileName=AppFileName;
		ExeFileName=ExeFileName.Left(ExeFileName.ReverseFind('\\')+1);
		ExeFileName+="ImgGrabProc.exe";
		if ((int)::ShellExecute(GetSafeHwnd(),"open",ExeFileName,"\""+TmpFileName+"\"",NULL,SW_SHOW)<=32){
			AfxMessageBox("Error when start image process application!",MB_ICONWARNING);
		}
	}
}

//options
void CTransServerDlg::OnButton7() 
{
	COptionDlg dlg;
    dlg.m_CompressQuality=m_CompressQuality;
	dlg.m_SampleFrequency=m_SampleFrequency;
	if (dlg.DoModal()==IDOK){
		m_SampleFrequency=dlg.m_SampleFrequency;
        m_CompressQuality=dlg.m_CompressQuality;
	}
}

void CTransServerDlg::OnButton8() 
{
    CAboutDlg dlg;
    dlg.DoModal();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -