📄 filmdesignview.cpp
字号:
// TODO: Add your command handler code here
CLineParameter dlg;
dlg.m_Title=m_Picture.GetTitle();
dlg.m_Style=m_Picture.GetLine()->style;
dlg.m_Width=m_Picture.GetLine()->width;
dlg.m_Color=m_Picture.GetLine()->color;
if(dlg.DoModal()==IDOK)
{
m_Picture.SetLine(dlg.m_Style,dlg.m_Width,dlg.m_Color);
m_Picture.SetTitle(dlg.m_Title);
}
this->RedrawWindow();
}
void CFilmDesignView::OnDataTable()
{
// TODO: Add your command handler code here
CShowData dlg;
m_Picture.InPutData();
//input data to table
for(int i=0;i<this->m_Picture.m_Reflectance.GetSize();i++)
{
dlg.m_fWaveLength.Add(m_Picture.m_fWaveLength.GetAt(i));
dlg.m_Reflectance.Add(m_Picture.m_Reflectance.GetAt(i));
dlg.m_Transistance.Add(m_Picture.m_Transistance.GetAt(i));
dlg.m_Absorption.Add(m_Picture.m_Absorption.GetAt(i));
}
dlg.DoModal();
}
void CFilmDesignView::OnFileOpen()
{
// TODO: Add your command handler code here
//analyze data structure
CRead read;
BeginWaitCursor();
read.Read();
EndWaitCursor();
}
void CFilmDesignView::OnCopyView()
{
// TODO: Add your command handler code here
CRect rect,Crect;
GetClientRect(&rect);
rect.DeflateRect(10,::GetSystemMetrics(SM_CYCAPTION)*2,10,10);
HWND hWnd=this->GetSafeHwnd();
if(::OpenClipboard(hWnd))
//hWnd为程序窗口句柄
{
//清空剪贴板
EmptyClipboard();
//把屏幕内容粘贴到剪贴板上,
HBITMAP hBitmap=this->CopyScreenToBitmap(&rect);//hbitmap 为刚才的屏幕位图句柄
SetClipboardData(CF_BITMAP, hBitmap);
//关闭剪贴板
CloseClipboard();
}
}
void CFilmDesignView::OnFileSave()
{
// TODO: Add your command handler code here
// TODO: Add your control notification handler code here
CString szPathName="bitmap.bmp";
char szFilter[]="Picture Files (*.bmp|*.bmp||";
CFileDialog fileDialog(false, "BMP","Firstbitmp",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
LPCTSTR lpstrFileName;
BeginWaitCursor();//wait dialog to show
int response=fileDialog.DoModal();
EndWaitCursor(); //dialog is closed
if(response==IDOK)
{
szPathName=fileDialog.GetPathName();
int length=szPathName.GetLength();
lpstrFileName = (LPCTSTR)szPathName.GetBuffer(length);
}
else
{
MessageBox("Cancel Saving File!");
return ;
}
CRect rect,Crect;
GetClientRect(&rect);
rect.DeflateRect(0,::GetSystemMetrics(SM_CYCAPTION)*2,0,0);
//HWND hWnd=this->GetSafeHwnd();
HBITMAP hBitmap=this->CopyScreenToBitmap(&rect);
CBitmap *bitmap;
bitmap=CBitmap::FromHandle(hBitmap);
if(this->SaveBmptoFile(bitmap,lpstrFileName))
MessageBox("Succeed!");
else
MessageBox("Failed!");
}
HBITMAP CFilmDesignView::CopyScreenToBitmap(LPRECT lpRect)
{
HDC hScrDC, hMemDC;
// 屏幕和内存设备描述表
HBITMAP hBitmap, hOldBitmap;
// 位图句柄
int nX, nY, nX2, nY2;
// 选定区域坐标
int nWidth, nHeight;
// 位图宽度和高度
int xScrn, yScrn;
// 屏幕分辨率
// 确保选定区域不为空矩形
if (IsRectEmpty(lpRect))
return NULL;
//为屏幕创建设备描述表
hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
//为屏幕设备描述表创建兼容的内存设备描述表
hMemDC = CreateCompatibleDC(hScrDC);
// 获得选定区域坐标
nX = lpRect->left;
nY = lpRect->top;
nX2 = lpRect->right;
nY2 = lpRect->bottom;
// 获得屏幕分辨率
xScrn = GetDeviceCaps(hScrDC, HORZRES);
yScrn = GetDeviceCaps(hScrDC, VERTRES);
//确保选定区域是可见的
if (nX<0)
nX = 0;
if (nY<0)
nY = 0;
if (nX2>xScrn)
nX2 = xScrn;
if (nY2>yScrn)
nY2 = yScrn;
nWidth = nX2 - nX;
nHeight = nY2 - nY;
// 创建一个与屏幕设备描述表兼容的位图
hBitmap =CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
// 把新位图选到内存设备描述表中
hOldBitmap =(HBITMAP) SelectObject(hMemDC, hBitmap);
// 把屏幕设备描述表拷贝到内存设备描述表中
BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);
//得到屏幕位图的句柄
hBitmap=(HBITMAP)SelectObject(hMemDC, hOldBitmap);
//清除
DeleteDC(hScrDC);
DeleteDC(hMemDC);
// 返回位图句柄
return hBitmap;
}
bool CFilmDesignView::SaveBmptoFile(CBitmap *PBitmap,LPCTSTR m_FileName)
{
BITMAPINFO *m_pBMI;
BYTE *m_pDIBData;
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bi;
BITMAP BM;
PBitmap->GetObject(sizeof(BM),&BM);
CClientDC dc(this);
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = BM.bmWidth;
bi.biHeight = BM.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biCompression = 0;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
bfh.bfType=0x4d42;
bfh.bfOffBits=sizeof(bfh)+sizeof(BITMAPINFOHEADER);
bfh.bfSize=bfh.bfOffBits+BM.bmWidth*BM.bmHeight*3;
bfh.bfReserved1=0;
bfh.bfReserved2=0;
m_pBMI=(BITMAPINFO*)new char[sizeof(BITMAPINFO)];
m_pDIBData=(BYTE*)new char[bfh.bfSize-bfh.bfOffBits];
memcpy(m_pBMI,&bi,sizeof(BITMAPINFOHEADER));
GetDIBits(dc.GetSafeHdc(), (HBITMAP)PBitmap->GetSafeHandle(), 0l, (DWORD)bi.biHeight,
(LPVOID)m_pDIBData,(LPBITMAPINFO)m_pBMI, (DWORD)DIB_RGB_COLORS);
CFile file;
if(!file.Open(m_FileName,CFile::modeCreate|CFile::modeWrite))
{
MessageBox("error!");
return false;
}
file.Write(&bfh,sizeof(bfh));
file.Write(m_pBMI,sizeof(BITMAPINFOHEADER));
file.Write(m_pDIBData,BM.bmWidth*BM.bmHeight*3);
file.Close();
delete m_pBMI;
delete m_pDIBData;
return true;
}
void CFilmDesignView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CView::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CFilmDesignView::OnThickneOtop()
{
// TODO: Add your command handler code here
CFilmDesignApp * app=(CFilmDesignApp*)AfxGetApp();
CData* p=&(app->m_Data[0]);
double pThick;
for(;p->GetUse()==true;p++)
{
pThick=p->GetM()*m_Picture.GetWaveLength()/p->GetN();
p->SetM(pThick);
}
m_Picture.SetThickKind(1);
}
void CFilmDesignView::OnUpdateThickneOtop(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_Picture.GetThickKind()==2)
pCmdUI->Enable(true);
else
pCmdUI->Enable(false);
}
void CFilmDesignView::OnThicknessPtoo()
{
// TODO: Add your command handler code here
CFilmDesignApp * app=(CFilmDesignApp*)AfxGetApp();
CData* p=&(app->m_Data[0]);
double pThick;
for(;p->GetUse()==true;p++)
{
pThick=p->GetM()*p->GetN()/m_Picture.GetWaveLength();
p->SetM(pThick);
}
m_Picture.SetThickKind(2);
}
void CFilmDesignView::OnUpdateThicknessPtoo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if(m_Picture.GetThickKind()==1)
pCmdUI->Enable(true);
else
pCmdUI->Enable(false);
}
void CFilmDesignView::OnSystemNew()
{
// TODO: Add your command handler code here
CFilmDesignApp * app=(CFilmDesignApp*)AfxGetApp();
CShowDataDlg dlg;
int response;
if(response=dlg.DoModal()==IDOK)
{
}
else
{
for(int i=0;i<MAX;i++)
{ app->m_Data[i].SetA(0.0f);
app->m_Data[i].SetK(0.0f);
app->m_Data[i].SetN(0.0f);
app->m_Data[i].SetM(0.0);
app->m_Data[i].SetUse(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -