📄 umain.cpp
字号:
//---------------------------------------------------------------------------
// This file is part of Dicom Explorer, see http://www.sourceforge.net/projects/dcmsee
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This software is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// Liu Jie (liucoldstar@yahoo.com)
//
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "uMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "GR32_RangeBars"
#pragma resource "*.dfm"
TfrmMain *frmMain;
//---------------------------------------------------------------------------
__fastcall TfrmMain::TfrmMain(TComponent* Owner)
: TForm(Owner)
{
m_hFile=NULL;
m_pDataSet=new CDataSet;
m_FileName=NULL;
m_bIsNewAnalyse=false;
m_bIsNewDisplay=false;
m_pFrmReport=NULL;
m_pFrmDisplay=NULL;
m_pFrmReport=new TfrmReport(frmMain);
m_pFrmDisplay=new TfrmDisplay(frmMain);
m_pFileHistory=new TFileHistory(ChangeFileExt(Application->ExeName,".INI"),
5,mItemRecent,&OpenFile);
}
//---------------------------------------------------------------------------
__fastcall TfrmMain::~TfrmMain()
{
char szTempPath[250];
AnsiString TempFileName;
AnsiString TempPath;
if(m_pDataSet) delete m_pDataSet;
if(m_hFile) CloseHandle(m_hFile);
if(m_pFrmReport) delete m_pFrmReport;
if(m_pFrmDisplay) delete m_pFrmDisplay;
if(m_pFileHistory) delete m_pFileHistory;
TempFileName=ExtractFilePath(Application->ExeName)+"\\Save.dat";
if (FileExists(TempFileName)) DeleteFile(TempFileName);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemAboutClick(TObject *Sender)
{
TfrmAbout *frmAbout;
frmAbout=new TfrmAbout(frmMain);
frmAbout->ShowModal();
delete frmAbout;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemExitClick(TObject *Sender)
{
int nValue;
nValue=MessageBox(this->Handle,"Are you sure?","Exit",MB_YESNOCANCEL|MB_ICONQUESTION);
if (nValue==IDYES) Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::OpenFile(AnsiString FileName)
{
int nValue;
if (m_FileName==FileName) return;
if (m_pFrmReport->Visible || m_pFrmDisplay->Visible)
{
nValue=MessageBox(this->Handle,"It will close the image just opened. Are you sure?","Close",MB_YESNOCANCEL|MB_ICONQUESTION);
if (nValue==IDYES) mItemCloseClick(NULL);
else return;
}
if (m_hFile) CloseHandle(m_hFile);
m_hFile = CreateFile(FileName.c_str(),
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // no security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (m_hFile == INVALID_HANDLE_VALUE)
{
ShowExceptionMsg("Error in reading the file!");
return;
}
m_pFileHistory->AddToHistory(FileName);
m_pFileHistory->RebuildHistory();
m_FileName=FileName;
StatusBar->Panels->Items[0]->Text=FileName;
EnableItems();
m_bIsNewDisplay=true;
m_bIsNewAnalyse=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemOpenClick(TObject *Sender)
{
int nValue;
if (m_pFrmReport->Visible || m_pFrmDisplay->Visible)
{
nValue=MessageBox(this->Handle,"It will close the image just opened. Are you sure?","Close",MB_YESNOCANCEL|MB_ICONQUESTION);
if (nValue==IDYES) mItemCloseClick(Sender);
else return;
}
if (OpenDialog->Execute())
{
if (m_hFile) CloseHandle(m_hFile);
m_hFile=CreateFile(OpenDialog->FileName.c_str(),
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // no security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (m_hFile==INVALID_HANDLE_VALUE)
{
ShowExceptionMsg("Error in reading the file!");
return;
}
m_pFileHistory->AddToHistory(OpenDialog->FileName);
m_pFileHistory->RebuildHistory();
m_FileName=OpenDialog->FileName;
StatusBar->Panels->Items[0]->Text=OpenDialog->FileName;
EnableItems();
m_bIsNewDisplay=true;
m_bIsNewAnalyse=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCreate(TObject *Sender)
{
DisableItems();
DragAcceptFiles(this->Handle,true);
}
//---------------------------------------------------------------------------
bool __fastcall TfrmMain::IsNew(void)
{
return (m_bIsNewAnalyse||m_bIsNewDisplay);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemShowAnalysisClick(TObject *Sender)
{
if (!m_hFile) return;
if (m_bIsNewAnalyse)
{
if (IsNew())
{
try
{
m_pDataSet->SetFile(m_hFile);
m_pDataSet->Process();
}
catch (const CException &Error)
{
ShowExceptionMsg(Error.Message);
if((Error.ErrorCode==ERROR_NOT_STANDARD)||(Error.ErrorCode==ERROR_DATASET))
{
m_pDataSet->Clear();
}
return;
}
}
m_pFrmReport->SetList(m_pDataSet->m_pList);
m_pFrmReport->SetImageInformation(m_pDataSet->m_pImageInformation);
m_pFrmReport->CreateReport();
m_bIsNewAnalyse=false;
}
ShowForm(m_pFrmReport);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemShowImageClick(TObject *Sender)
{
if (!m_hFile) return;
if(m_bIsNewDisplay)
{
if(IsNew())
{
try
{
m_pDataSet->SetFile(m_hFile);
m_pDataSet->Process();
}
catch (const CException &Error)
{
ShowExceptionMsg(Error.Message);
if((Error.ErrorCode==ERROR_NOT_STANDARD)||(Error.ErrorCode==ERROR_DATASET))
{
m_pDataSet->Clear();
}
return;
}
}
m_pFrmDisplay->SetImageInformation(m_pDataSet->m_pImageInformation);
m_pFrmDisplay->DrawImage();
m_bIsNewDisplay=false;
}
ShowForm(m_pFrmDisplay);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemShowStatusBarClick(TObject *Sender)
{
StatusBar->Visible=!StatusBar->Visible;
mItemShowStatusbar->Checked=!mItemShowStatusbar->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::ShowForm(TForm *pForm)
{
LockWindowUpdate(Handle);
__try
{
pForm->BorderStyle=bsNone;
pForm->Parent=Panel;
pForm->Align=alClient;
pForm->Show();
}
__finally
{
//Refresh the main window
LockWindowUpdate(0);
RedrawWindow(Handle,NULL, 0, RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemCloseClick(TObject *Sender)
{
m_pFrmReport->Hide();
m_pFrmDisplay->Hide();
m_pFrmReport->Clear();
m_pFrmDisplay->Clear();
m_pDataSet->Clear();
DisableItems();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::ShowExceptionMsg(AnsiString Msg)
{
MessageBox(this->Handle,Msg.c_str(),"Error",MB_OK|MB_ICONWARNING);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::DisableItems(void)
{
mItemShowAnalysis->Enabled=false;
mItemShowImage->Enabled=false;
mItemClose->Enabled=false;
mItemSaveAs->Enabled=false;
mItemCopy->Enabled=false;
mItemZoom->Enabled=false;
mItemRotate->Enabled=false;
mItemFlip->Enabled=false;
ToolBtnAnalysis->Enabled=false;
ToolBtnImage->Enabled=false;
ToolBtnClose->Enabled=false;
ToolBtnSaveAs->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::EnableItems(void)
{
mItemShowAnalysis->Enabled=true;
mItemShowImage->Enabled=true;
mItemClose->Enabled=true;
mItemCopy->Enabled=true;
mItemSaveAs->Enabled=true;
mItemZoom->Enabled=true;
mItemRotate->Enabled=true;
mItemFlip->Enabled=true;
ToolBtnAnalysis->Enabled=true;
ToolBtnImage->Enabled=true;
ToolBtnClose->Enabled=true;
ToolBtnSaveAs->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::FormCloseQuery(TObject *Sender, bool &CanClose)
{
int nValue;
nValue=MessageBox(this->Handle,"Are you sure?","Exit",MB_YESNOCANCEL|MB_ICONQUESTION);
if (nValue!=IDYES) CanClose=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemCopyClick(TObject *Sender)
{
Clipboard()->Assign(m_pFrmDisplay->ImgView32->Bitmap);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemSaveAsClick(TObject *Sender)
{
AnsiString FileName;
if (SaveDialog->Execute())
{
if ((m_pDataSet->m_pImageInformation->nImageBitsAllocated==8)&&
(m_pDataSet->m_pImageInformation->nImageColorType!=COLOR_MONOCHROME1)&&
(m_pDataSet->m_pImageInformation->nImageColorType!=COLOR_MONOCHROME2))
{
switch(SaveDialog->FilterIndex)
{
case 1: //Bitmap(*.bmp)
FileName=ChangeFileExt(SaveDialog->FileName,".bmp");
m_pFrmDisplay->SaveAsColor(FileName,FIF_BMP);
break;
case 2: //JPEG(*.jpg)
FileName=ChangeFileExt(SaveDialog->FileName,".jpg");
m_pFrmDisplay->SaveAsColor(FileName,FIF_JPEG);
break;
case 3: //PNG(*.png)
FileName=ChangeFileExt(SaveDialog->FileName,".png");
m_pFrmDisplay->SaveAsColor(FileName,FIF_PNG);
break;
case 4: //TIFF(*.tif)
FileName=ChangeFileExt(SaveDialog->FileName,".tif");
m_pFrmDisplay->SaveAsColor(FileName,FIF_TIFF);
break;
}
}
else
{
switch(SaveDialog->FilterIndex)
{
case 1: //Bitmap(*.bmp)
FileName=ChangeFileExt(SaveDialog->FileName,".bmp");
m_pFrmDisplay->SaveAsGray(FileName,FIF_BMP);
break;
case 2: //JPEG(*.jpg)
FileName=ChangeFileExt(SaveDialog->FileName,".jpg");
m_pFrmDisplay->SaveAsGray(FileName,FIF_JPEG);
break;
case 3: //PNG(*.png)
FileName=ChangeFileExt(SaveDialog->FileName,".png");
m_pFrmDisplay->SaveAsGray(FileName,FIF_PNG);
break;
case 4: //TIFF(*.tif)
FileName=ChangeFileExt(SaveDialog->FileName,".tif");
m_pFrmDisplay->SaveAsGray(FileName,FIF_TIFF);
break;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::DropFile(TWMDropFiles &Msg)
{
AnsiString FileName;
int nValue;
FileName.SetLength(256);
DragQueryFile((HDROP)Msg.Drop,0,FileName.c_str(),FileName.Length());
OpenFile(FileName);
DragFinish((HDROP)Msg.Drop);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemShowToolbarClick(TObject *Sender)
{
ToolBar->Visible=!ToolBar->Visible;
mItemShowToolbar->Checked=!mItemShowToolbar->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemCleanHistoryClick(TObject *Sender)
{
m_pFileHistory->CleanHistory();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemZoomOutClick(TObject *Sender)
{
m_pFrmDisplay->ZoomOut();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemZoomInClick(TObject *Sender)
{
m_pFrmDisplay->ZoomIn();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemBestFitClick(TObject *Sender)
{
m_pFrmDisplay->BestFit();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemFitToWidthClick(TObject *Sender)
{
m_pFrmDisplay->FitToWidth();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemFitToHeightClick(TObject *Sender)
{
m_pFrmDisplay->FitToHeight();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemActualSizeClick(TObject *Sender)
{
m_pFrmDisplay->ActualSize();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemVerticalClick(TObject *Sender)
{
m_pFrmDisplay->FlipVert();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemHorizontalClick(TObject *Sender)
{
m_pFrmDisplay->FlipHorz();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemRotate90Click(TObject *Sender)
{
m_pFrmDisplay->Rotate90();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemRotate180Click(TObject *Sender)
{
m_pFrmDisplay->Rotate180();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::mItemRotate270Click(TObject *Sender)
{
m_pFrmDisplay->Rotate270();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -