12Dlg.cpp
资源名称:121.rar [点击查看]
上传用户:dzxhhx
上传日期:2022-06-05
资源大小:3604k
文件大小:5k
源码类别:
图片显示
开发平台:
Visual C++
- // 12Dlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "12.h"
- #include "12Dlg.h"
- //#include <atlimage.h>
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMy12Dlg dialog
- CMy12Dlg::CMy12Dlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMy12Dlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMy12Dlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- for(int i = 0 ;i <=1 ;i ++)
- {
- myicon[i] = AfxGetApp()->LoadIcon(128+i*2);
- m_hIcon = myicon[i];
- }
- num = 0 ;
- }
- void CMy12Dlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMy12Dlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMy12Dlg, CDialog)
- //{{AFX_MSG_MAP(CMy12Dlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMy12Dlg message handlers
- BOOL CMy12Dlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 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
- //WriteProfileString("c:\my.ini","usename","xiaoshuaihu158");
- WritePrivateProfileString ("Section1", "FirstKey",
- "It all worked out okay.", "c:\appname.ini");
- SetTimer(1,500,NULL);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- // 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 CMy12Dlg::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- if (IsIconic())
- {
- 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
- {
- drawmainpic(&dc);
- // Draw(&dc); //用来显示jpg图片的
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CMy12Dlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CMy12Dlg::OnOK()
- {
- // TODO: Add extra validation here
- int size = strlen("It all worked out okay.") + 1;
- char * pstring = new char[size];
- GetPrivateProfileString("Section1","FirstKey","sfsd",pstring,size,"c:\appname.ini");
- AfxMessageBox(pstring);
- CDialog::OnOK();
- }
- void CMy12Dlg::drawmainpic(CDC *dc)
- {
- RECT rect;
- GetClientRect(&rect);
- CBitmap bmp;
- bmp.LoadBitmap(IDB_BITMAP1);
- BITMAP sbmp;
- bmp.GetBitmap(&sbmp);
- CDC pdc;
- pdc.CreateCompatibleDC(dc);
- pdc.SelectObject(&bmp);
- dc->BitBlt(0,0,rect.right-rect.left,rect.bottom-rect.top,&pdc,0,0,SRCCOPY);
- }
- void CMy12Dlg::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- num = (num+1)%2 ;
- m_hIcon = myicon[num];
- SendMessage(WM_SETICON,0,(LPARAM)m_hIcon);
- CDialog::OnTimer(nIDEvent);
- }
- void CMy12Dlg::Draw(CDC* pDC)
- {
- IPicture *pPic;
- IStream *pStm;
- CFileStatus fstatus;
- CFile file;
- LONG cb;
- if (file.Open("D:\mmp\0b5d1a3c348744ae98d128963a23f713.jpg",CFile::modeRead)&&file.GetStatus("D:\mmp\0b5d1a3c348744ae98d128963a23f713.jpg",
- fstatus)&&
- ((cb = fstatus.m_size) != -1))
- {
- HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
- LPVOID pvData = NULL;
- if (hGlobal != NULL)
- {
- if ((pvData = GlobalLock(hGlobal)) != NULL)
- {
- file.ReadHuge(pvData, cb);
- GlobalUnlock(hGlobal);
- CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
- if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*
- )&pPic)))
- {
- OLE_XSIZE_HIMETRIC hmWidth;
- OLE_YSIZE_HIMETRIC hmHeight;
- pPic->get_Width(&hmWidth);
- pPic->get_Height(&hmHeight);
- double fX,fY;
- fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);
- fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);
- if(FAILED(pPic->Render(*pDC,0,0,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
- AfxMessageBox("Failed To Render The picture!");
- pPic->Release();
- }
- else
- AfxMessageBox("Error Loading Picture From Stream!");
- }
- }
- }
- else
- AfxMessageBox("Can't Open Image File!");
- }