📄 dlgdraw.cpp
字号:
// DlgDraw.cpp : implementation file
//
#include "stdafx.h"
#include "SeqProcess.h"
#include "DlgDraw.h"
#include "FnMath.h"
#include "FnBitmap.h"
#include "FnMatrix.h"
#include "FnImage.h"
#include "CDib.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static FnMath fMath;
/////////////////////////////////////////////////////////////////////////////
// CDlgDraw dialog
CDlgDraw::CDlgDraw(CWnd* pParent /*=NULL*/)
: CDialog(CDlgDraw::IDD, pParent)
{
m_scale = 1;
m_posX = 0;
m_posY = 0;
//{{AFX_DATA_INIT(CDlgDraw)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
/////////////////////////////////////////////////////////////////////////////
void CDlgDraw::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgDraw)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgDraw, CDialog)
//{{AFX_MSG_MAP(CDlgDraw)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgDraw message handlers
BOOL CDlgDraw::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_width = m_scale * m_Image.xsize;
m_height = m_scale * m_Image.ysize;
ASSERT( m_width > 0 && m_height > 0);
m_color = 1000 * ones(3, 1);
// Window title text
SetWindowText(m_windowText);
int MinWidth = 32;
int MinHeight = 32;
// Set parent window size to default minimum
SetWindowPos(NULL, m_posX, m_posY, MinWidth, MinHeight, SWP_SHOWWINDOW);
// Make sure the default size setting is successful
CRect rectW; // Parent window (includes the client window)
GetWindowRect(&rectW);
int rectWwidth = ( rectW.right - rectW.left);
int rectWheight = ( rectW.bottom - rectW.top);
ASSERT( rectWwidth == MinWidth && rectWheight == MinHeight);
// Make sure client (display) area does not have zero size
CRect rectC; // Client (display) window
GetClientRect(&rectC);
ASSERT( rectC.right > 0 && rectC.bottom > 0);
// Compute the size of the required window area
int widthWindow = m_width;
int heightWindow = m_height;
//Find the amount the client area (hence the parent window area)
//must be increased to cover the image
int wdiff = widthWindow - rectC.right;
int hdiff = heightWindow - rectC.bottom;
//Increase parent window size to cover the required display area
rectWwidth += (int) fMath.Max(0, wdiff);
rectWheight += (int) fMath.Max(0, hdiff);
SetWindowPos(NULL, m_posX, m_posY, rectWwidth, rectWheight, SWP_SHOWWINDOW);
//CClientDC dc(this);
//dc.FillSolidRect( xPosWindow, yPosWindow, widthDisplay, heightDisplay, RGB(192, 192, 192));
Draw();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//-----------------------------------------------------------------------------
void CDlgDraw::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
Draw();
// Do not call CDialog::OnPaint() for painting messages
}
//-----------------------------------------------------------------------------
void CDlgDraw::Draw()
{
CClientDC dc(this);
CDib tmpDib;
CPoint origin;
origin.x = 0;
origin.y = 0;
CSize size;
size.cx = m_width;
size.cy = m_height;
tmpDib.Create( m_Image.xsize, m_Image.ysize, 8*m_Image.numbands, &dc);
ConvertMat2Dib( tmpDib, m_Image); // convert the matrix to a dib image
tmpDib.Draw( &dc, origin, size);
}
//-----------------------------------------------------------------------------
BOOL CDlgDraw::OpenFile( CString& strFileName, CString& strFileTitle,
CString strFileExtension, CString strInitialDir,
CString strOpenTitle,
char* strFilter, BOOL isReadFile)
{
char FileName[500];
char FileTitle[100];
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = m_hWnd;
ofn.hInstance = NULL;
ofn.lpstrFilter = strFilter;
ofn.lpstrCustomFilter = NULL;
ofn.nMaxCustFilter = 0;
ofn.nFilterIndex = 1;
ofn.lpstrFile = FileName;
ofn.nMaxFile = 500;
ofn.lpstrFileTitle = FileTitle;
ofn.nMaxFileTitle = 99;
ofn.lpstrInitialDir = (LPCTSTR)strInitialDir;
ofn.lpstrTitle = (LPCTSTR)strOpenTitle; //"Open BMP File";
ofn.Flags = OFN_FILEMUSTEXIST;
ofn.lpstrDefExt = (LPCTSTR)strFileExtension;
ofn.lCustData = NULL;
ofn.lpfnHook = NULL;
ofn.lpTemplateName = NULL;
FileName[0] = '\0';
if( isReadFile) GetOpenFileName(&ofn);
else GetSaveFileName(&ofn);
if(FileName[0] == '\0') return FALSE;
strFileName = FileName;
strFileTitle = FileTitle;
return TRUE;
}
//-----------------------------------------------------------------------------
void CDlgDraw::SaveMatrix()
{
// write the CDib image as bitmap, first get the name of the .bmp file
CString strFileTitle; //return value
CString strFileName; //return value
CString strFileExtension = ".bmp";
CString strOpenTitle = "Save image as...";
CString strInitialDir;
char* strFilter;
strFilter = new char[256];
strFilter = TEXT("Bitmap files *.bmp\0 *.bmp\0All Files *\0*\0\0");
if( ! OpenFile( strFileName, strFileTitle, strFileExtension,
strInitialDir, strOpenTitle, strFilter, FALSE)) return;
//strInitialDir = strFileName.Left( strFileName.GetLength() - strFileTitle.GetLength() - 1);
// Convert the matrix to CDib
CDib dib;
CClientDC dc(this);
dib.Create( m_Image.xsize, m_Image.ysize, 8*m_Image.numbands, &dc);
ConvertMat2Dib ( dib, m_Image);
CFile myfile;
myfile.Open(strFileName, CFile::modeCreate | CFile::modeWrite);
// write as bitmap
dib.Write( &myfile);
}
//---------------------------------------------------------------------------------------------
void CDlgDraw::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if ( nFlags & MK_SHIFT)
{
SaveMatrix();
}
CDialog::OnLButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -