📄 picdlg.cpp
字号:
// PICDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Uart.h"
#include "PICDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// PICDlg dialog
PICDlg::PICDlg(CWnd* pParent /*=NULL*/)
: CDialog(PICDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(PICDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void PICDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(PICDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(PICDlg, CDialog)
//{{AFX_MSG_MAP(PICDlg)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// PICDlg message handlers
//========================================================================
// 图片载入函数
//========================================================================
HBITMAP PICDlg::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 PICDlg::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);
PICDlg *Pdlg=new PICDlg;
Pdlg->Create(IDD_PIC_PREVIEW);
Pdlg->ShowWindow(SW_SHOW);
Pdlg->SetWindowText("图片预览");
int with = Bmp.bmWidth+40;
int height = Bmp.bmHeight+60;
Pdlg->MoveWindow(0,0,with,height);
CStatic *pStatic = (CStatic *)Pdlg->GetDlgItem(IDC_PIC_PREV); //显示在CStatic上
pStatic->ModifyStyle(0xF,SS_BITMAP);
pStatic->SetBitmap(hBitmap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -