AddressAdminDlg.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:6k
源码类别:
ActiveX/DCOM/ATL
开发平台:
Visual C++
- // AddressAdminDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "AddressAdmin.h"
- #include "AddressAdminDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAddressAdminDlg dialog
- CAddressAdminDlg::CAddressAdminDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CAddressAdminDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CAddressAdminDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- this->pBuffer=NULL;
- }
- void CAddressAdminDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAddressAdminDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAddressAdminDlg, CDialog)
- //{{AFX_MSG_MAP(CAddressAdminDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAddressAdminDlg message handlers
- BOOL CAddressAdminDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CAddressAdminDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CAddressAdminDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CAddressAdminDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CAddressAdminDlg::OnButton8()
- {
- // TODO: Add your control notification handler code here
- CFileDialog dlg(TRUE);//打开一个浏览框(选择图片)
- dlg.DoModal();//弹出对话框有效
- CString strFilePath=dlg.GetPathName();//获取该图片的路径(空则为0)
- if(strFilePath.GetLength()>0) //地址有效的时候
- {
- CFile fsource;
- CFileException fex;
- fsource.Open(strFilePath,CFile::modeRead,&fex);//读取的方式打开
- int iSize=fsource.GetLength();//获取图片大小
- if(this->pBuffer!=NULL)//pBuffer在头文件中已定义并在构造函数中初始化了
- {
- delete this->pBuffer;
- this->pBuffer=NULL;
- }
- this->pBuffer=new CHAR[iSize];//连续的字符内存空间
- fsource.Read(this->pBuffer,iSize);
- }
- //显示图片;
- this->ShowImage();
- }
- HBITMAP CAddressAdminDlg::ShowImage()
- {
- LPSTR pTempBuffer=this->pBuffer;//由上面的步骤,pBuffer已获取图片二进制数据
- BITMAPFILEHEADER bf;//要过滤的文件头
- int leng=sizeof(bf);//获取要过滤的文件头的长度
- LPSTR pInfor=pTempBuffer+leng;//指针移动指定的长度即把文件头给过滤掉了
- BITMAPINFOHEADER& pInfHeader=*(LPBITMAPINFOHEADER)(pInfor);//强转成bmp格式类型
- BITMAPINFO& pInfo =*(LPBITMAPINFO)(pInfor);//再转
- LPVOID pRGBData =(LPVOID)(pInfo.bmiColors);//void类型指针
- CClientDC dc(this);//用于在窗口客户区画图
- HBITMAP hResult=CreateDIBitmap(dc.m_hDC,&pInfHeader,CBM_INIT,pRGBData,&pInfo,DIB_RGB_COLORS);
- return hResult;
- //BITMAPFILEHEADER; //*.bmp文件头;
- //BITMAPINFOHEADER; //*.bmp格式的信息头;
- //BITMAPINFO; //*.bmp格式主体;其包含格式的信息头及像素格式
- //RGBQUAD //*.bmp像素格式;
- }