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

📄 mainfrm.cpp

📁 &#61548 1、有9个工件图像
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "MSSB03.h"

#include "MainFrm.h"
#include "MSSB03Doc.h"
#include "MSSB03View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


void CMainFrame::OnFileOpen() 
{
	// TODO: Add your command handler code here
	 CClientDC dc(this);
	CRect clientRect;
	GetClientRect(&clientRect);
	//OnPrepareDC(&dc);
	dc.DPtoLP(&clientRect);
	CPen myPen;
	CRect rectClient(2, 27, 620, 240); 
	CBrush brushBkColor; 
	brushBkColor.CreateSolidBrush(RGB(236,233,216)); 
	dc.DPtoLP(rectClient); 
	dc.FillRect(rectClient, &brushBkColor); 
	CMSSB03Doc * pDoc = (CMSSB03Doc *)GetActiveDocument();
	CString strPath;
    CFileDialog dlg(TRUE,"bmp","*.bmp", 
        OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, 
        "BMP文件(*.bmp)|*.bmp|GIF文件(*.gif)|*.gif|JPEG文件(*.jpg)|*.jpg|所有文件(*.*)|*.*",NULL); 
    if(dlg.DoModal()==IDOK) 
    { 
        strPath=dlg.GetPathName(); 
        //Invalidate(); 
    } 
   // CPaintDC dc(this);
    CDC* pDC=this->GetDC();

    IStream *pStm;  
    CFileStatus fstatus;  
    CFile file;  
    LONG cb;  
    
    HGLOBAL hGlobal;
    if (file.Open(strPath,CFile::modeRead)&&file.GetStatus(strPath,fstatus)&& ((cb = fstatus.m_size) != -1))  
    {  
        hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);  
        LPVOID pvData = NULL;  
        if (hGlobal != NULL)  
        {  
            if ((pvData = GlobalLock(hGlobal)) != NULL)  
            {  
                file.ReadHuge(pvData, cb);  
                GlobalUnlock(hGlobal);  
                CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);  
            }
        }
        file.Close();
    }
    
    
    
    IPicture *pPic;  
    if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic))) 
    { 
        OLE_XSIZE_HIMETRIC hmWidth;  
        OLE_YSIZE_HIMETRIC hmHeight;  
        pPic->get_Width(&hmWidth);  
        pPic->get_Height(&hmHeight);  
         
        
        pDoc->fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);  
        pDoc->fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);  
		if (pDoc->fX>350)
			pDoc->fX = 350;
			
		if (pDoc->fY>350)
			pDoc->fY = 350;
			
        if(FAILED(pPic->Render(*pDC,2,27,(DWORD)pDoc->fX,(DWORD)pDoc->fY,0,hmHeight,hmWidth,-hmHeight,NULL)))  
            AfxMessageBox("渲染图像失败!");  
        pPic->Release();  
    }  
    else  
        AfxMessageBox("从流中装载图像失败!");  
    
    GlobalFree(hGlobal);

	
	pDoc->loadsuccess =TRUE;
}

⌨️ 快捷键说明

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