📄 customdlg.cpp
字号:
// CustomDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BmpFile.h"
#include "CustomDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCustomDlg
IMPLEMENT_DYNAMIC(CCustomDlg, CFileDialog)
CCustomDlg::CCustomDlg(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
m_ofn.Flags = (OFN_EXPLORER| OFN_ENABLETEMPLATE| OFN_ENABLEHOOK);
m_ofn.lpTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);
}
BEGIN_MESSAGE_MAP(CCustomDlg, CFileDialog)
//{{AFX_MSG_MAP(CCustomDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CCustomDlg::OnFileNameChange()
{
CFileDialog::OnFileNameChange();
CString exp;
exp=GetFileExt();
exp.MakeUpper(); //在比较扩展名时不区分大小写
if(exp == "BMP") //显示位图
{
m_bitmap.SetIcon(NULL);
m_bitmap.ModifyStyle(SS_ICON,SS_BITMAP);
m_bitmap.SetBitmap((HBITMAP)LoadImage(NULL,GetPathName(),
IMAGE_BITMAP,100,100,LR_LOADFROMFILE));
CFile file;
if(!file.Open(GetPathName(),CFile::modeRead) )
return;
BITMAPFILEHEADER bmfHeader;
//读位图文件头信息
if(file.Read((LPSTR)&bmfHeader,sizeof(bmfHeader)) != sizeof(bmfHeader))
return;
//读位图头信息
BITMAPINFOHEADER bmiHeader;
if (file.Read((LPSTR)&bmiHeader, sizeof(bmiHeader)) !=sizeof(bmiHeader))
return ;
//获得大小信息,并显示
int bmWidth = bmiHeader.biWidth;
int bmHeight = bmiHeader.biHeight;
CString swidth,sheight;
swidth.Format("宽度:%d",bmWidth);
sheight.Format("高度:%d",bmWidth);
m_width.SetWindowText(swidth);
m_height.SetWindowText(sheight);
}
}
BOOL CCustomDlg::OnInitDialog()
{
CFileDialog::OnInitDialog();
// TODO: Add extra initialization here
m_bitmap.SubclassDlgItem(IDC_STATIC1,this);
m_width.SubclassDlgItem(IDC_STATIC2,this);
m_height.SubclassDlgItem(IDC_STATIC3,this);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -