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;
- p_CurrentImag=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
- {
- this->show();
- 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();
- if(strFilePath.GetLength()>0)
- {
- CFile fsource;
- CFileException fex;
- fsource.Open(strFilePath,CFile::modeRead,&fex);
- int iSize=fsource.GetLength();
- if(this->pBuffer!=NULL)
- {
- delete this->pBuffer;
- this->pBuffer=NULL;
- }
- this->pBuffer=new CHAR[iSize];
- fsource.Read(this->pBuffer,iSize);
- }
- //显示图片;
- this->p_CurrentImag=this->ShowImage();
- }
- HBITMAP CAddressAdminDlg::ShowImage()
- {
- LPSTR pTempBuffer=this->pBuffer;
- BITMAPFILEHEADER bf;
- int leng=sizeof(bf);
- LPSTR pInfor=pTempBuffer+leng;
- BITMAPINFOHEADER& pInfHeader=*(LPBITMAPINFOHEADER)(pInfor);
- BITMAPINFO& pInfo =*(LPBITMAPINFO)(pInfor);
- LPVOID pRGBData =(LPVOID)(pInfo.bmiColors);
- 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像素格式;
- }
- //在OnPaint()中调用,真正的显示图片到Cstatic中
- void CAddressAdminDlg::show()
- {
- if(this->p_CurrentImag!=NULL)//获取图片信息无误
- {
- CStatic* pStc=(CStatic*)this->GetDlgItem(IDC_STATICimg);
- CPaintDC dc(pStc);
- RECT rt;//定义矩形的左上角坐标和右下角坐标
- pStc->GetClientRect(&rt);
- CDC MemDc;
- //用于在向实际的兼容设备表面发送图象之前在内存中作好准备
- MemDc.CreateCompatibleDC(&dc);//该函数仅用于创建与支持光栅操作的设备上下文
- HBITMAP pTemp=(HBITMAP)MemDc.SelectObject(this->p_CurrentImag);
- dc.BitBlt(0,//指定目标矩形左上角的逻辑横坐标
- 0,//指定目标矩形左上角的逻辑纵坐标
- rt.right,//指定目标矩形和源位图的宽度
- rt.bottom,//指定目标矩形和源位图的高度
- &MemDc,//指向CDC对象的指针,标识待拷贝位图的设备上下文
- 0,//指定源位图左上角的逻辑横坐标
- 0,//指定源位图左上角的逻辑纵坐标
- SRCCOPY);//指定要执行的光栅操作
- MemDc.SelectObject(pTemp);//返回被替代的对象的指针
- }
- }