// PoroMediaView.cpp : implementation of the CPoroMediaView class // #include "stdafx.h" #include "MainFrm.h" #include "PoroMedia.h" #include "PoroMediaDoc.h" #include "PoroMediaView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPoroMediaView IMPLEMENT_DYNCREATE(CPoroMediaView, CFormView) BEGIN_MESSAGE_MAP(CPoroMediaView, CFormView) //{{AFX_MSG_MAP(CPoroMediaView) ON_COMMAND(ID_FILE_OPEN, OnFileOpen) ON_WM_PAINT() ON_WM_MOUSEMOVE() ON_WM_CONTEXTMENU() ON_COMMAND(ID_POPUP_OPEN, OnPopupOpen) ON_COMMAND(ID_POPUP_EXIT, OnPopupExit) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPoroMediaView construction/destruction CPoroMediaView::CPoroMediaView() : CFormView(CPoroMediaView::IDD) { //{{AFX_DATA_INIT(CPoroMediaView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // TODO: add construction code here is_bitmap_load=false; } CPoroMediaView::~CPoroMediaView() { } void CPoroMediaView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPoroMediaView) DDX_Control(pDX, IDC_STATIC_IMAGE, m_image); //}}AFX_DATA_MAP } BOOL CPoroMediaView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } void CPoroMediaView::OnInitialUpdate() { CFormView::OnInitialUpdate(); GetParentFrame()->RecalcLayout(); ResizeParentToFit(); } ///////////////////////////////////////////////////////////////////////////// // CPoroMediaView printing BOOL CPoroMediaView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CPoroMediaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CPoroMediaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void CPoroMediaView::OnPrint(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add customized printing code here } ///////////////////////////////////////////////////////////////////////////// // CPoroMediaView diagnostics #ifdef _DEBUG void CPoroMediaView::AssertValid() const { CFormView::AssertValid(); } void CPoroMediaView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CPoroMediaDoc* CPoroMediaView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPoroMediaDoc))); return (CPoroMediaDoc*)m_pDocument; } #endif //_DEBUG void CPoroMediaView::ShowInitBitmap() { m_blank_bitmap.DeleteObject(); m_blank_bitmap.LoadBitmap(IDB_BLANK_BITMAP); BITMAP bm; m_blank_bitmap.GetObject(sizeof(BITMAP),&bm); CDC *pDC=new CDC; CClientDC dc(&m_image); pDC->CreateCompatibleDC(&dc); pDC->SelectObject(m_blank_bitmap); dc.StretchBlt(0,0,1024,1024,pDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY); delete pDC; } void CPoroMediaView::ShowBitmap() { BITMAP bm; m_bitmap.GetObject(sizeof(BITMAP),&bm); CDC *pDC=new CDC; CClientDC dc(&m_image); pDC->CreateCompatibleDC(&dc); pDC->SelectObject(m_bitmap); dc.BitBlt(0,0,bm.bmWidth,bm.bmHeight,pDC,0,0,SRCCOPY); delete pDC; } ///////////////////////////////////////////////////////////////////////////// // CPoroMediaView message handlers void CPoroMediaView::OnFileOpen() { // TODO: Add your command handler code here is_bitmap_load=true; CFileDialog dlg(TRUE,NULL,NULL,NULL,"Paper Sample Picture(*.bmp)|*.bmp|All Files (*.*)|*.*||"); INT_PTR Result=dlg.DoModal(); if(Result==IDOK) { HBITMAP hbitmap; hbitmap=(HBITMAP)::LoadImage(NULL,dlg.GetFileName(),IMAGE_BITMAP,0,0,LR_LOADFROMFILE); BITMAP bm; ::GetObject(hbitmap,sizeof(BITMAP),&bm); m_bitmap.DeleteObject(); m_bitmap.Attach(hbitmap); ShowInitBitmap(); ShowBitmap(); CMainFrame *pMain=(CMainFrame*)AfxGetMainWnd(); char maintitle[100]; sprintf(maintitle,"Porous Media Analysis");//"%s - Porous Media Analysis",dlg.GetFileName()); pMain->SetWindowText(maintitle); } else if(Result==IDCANCEL) return; } void CPoroMediaView::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here if(is_bitmap_load) ShowBitmap(); // Do not call CFormView::OnPaint() for painting messages } void CPoroMediaView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if(is_bitmap_load) { CMainFrame *pMain=(CMainFrame*)AfxGetMainWnd(); char maintitle[10]; sprintf(maintitle,"%d, %d",point.x,point.y); pMain->updatexycoor(maintitle); } CFormView::OnMouseMove(nFlags, point); } void CPoroMediaView::OnContextMenu(CWnd* /*pWnd*/, CPoint point) { // TODO: Add your message handler code here CMenu zooMenu; zooMenu.LoadMenu(IDR_MENU_POPUP); CMenu* pPopup=zooMenu.GetSubMenu(0); pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this); } void CPoroMediaView::OnPopupOpen() { // TODO: Add your command handler code here CPoroMediaView::OnFileOpen(); } void CPoroMediaView::OnPopupExit() { // TODO: Add your command handler code here exit(0); return; }