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

📄 picdlg2.cpp

📁 串口程序检测
💻 CPP
字号:
// PICDlg2.cpp : implementation file
//

#include "stdafx.h"
#include "Uart.h"
#include "PICDlg2.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// PICDlg2 dialog


PICDlg2::PICDlg2(CWnd* pParent /*=NULL*/)
	: CDialog(PICDlg2::IDD, pParent)
{
	//{{AFX_DATA_INIT(PICDlg2)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void PICDlg2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(PICDlg2)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(PICDlg2, CDialog)
	//{{AFX_MSG_MAP(PICDlg2)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// PICDlg2 message handlers


//========================================================================
//         图片载入函数
//========================================================================
HBITMAP PICDlg2::LoadALLPIC(CString strFileName)
{
	IPicture* p = NULL;
	IStream*  s = NULL;
	HGLOBAL   hG;
	void * pp;
	FILE * fp;

	fp = fopen(strFileName,"rb");
	if(!fp)
	return NULL;

	fseek(fp ,0,SEEK_END );
	int fs = ftell(fp);
	fseek(fp ,0 ,SEEK_SET );
	hG = GlobalAlloc(GPTR,fs);
	if(!hG)
	{
	fclose(fp);
	return NULL;
	}

	pp = (void*)hG;
	fread(pp,1,fs,fp);
	fclose(fp);
	CreateStreamOnHGlobal(hG,false,&s);
	if(!s)
	{
	GlobalFree(hG);
	return NULL;
	}
	OleLoadPicture(s,0,false,IID_IPicture, (void**)&p);
	if(!p)
	{
	s->Release();
	GlobalFree(hG);
	return NULL;
	}

	s->Release();
	GlobalFree(hG);

	HBITMAP hB = 0;
	p->get_Handle((unsigned int*)&hB);

	HBITMAP hBB = (HBITMAP)CopyImage(hB,IMAGE_BITMAP,0,0,LR_COPYRETURNORG );

	p->Release();
	return hBB;
}

//=================================================================================
//     图片预览
//=================================================================================

void PICDlg2::PicPreview(CString PicPath) 
{
	// TODO: Add your control notification handler code here
   // CString  sPath ="F:\\me.jpg";
	HBITMAP hBitmap=LoadALLPIC(PicPath);  //如sPath="D:\\f.gif"

	BITMAP Bmp;
        ::GetObject(hBitmap,sizeof(BITMAP),&Bmp);  

	PICDlg2 *Pdlg2=new PICDlg2; 
	Pdlg2->Create(IDD_PIC_RX_VIEW); 
	Pdlg2->ShowWindow(SW_SHOW); 
	Pdlg2->SetWindowText("Received Picture");
        
	int with = Bmp.bmWidth+40;
	int height = Bmp.bmHeight+60;
	Pdlg2->MoveWindow(100,100,with,height);
	CStatic   *pStatic   =   (CStatic *)Pdlg2->GetDlgItem(IDC_PIC_RX_VIEW); //显示在CStatic上
	pStatic->ModifyStyle(0xF,SS_BITMAP); 
	pStatic->SetBitmap(hBitmap);
}

⌨️ 快捷键说明

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