12Dlg.cpp
上传用户:dzxhhx
上传日期:2022-06-05
资源大小:3604k
文件大小:5k
源码类别:

图片显示

开发平台:

Visual C++

  1. // 12Dlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "12.h"
  5. #include "12Dlg.h"
  6. //#include <atlimage.h> 
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMy12Dlg dialog
  14. CMy12Dlg::CMy12Dlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CMy12Dlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CMy12Dlg)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  21. for(int i = 0 ;i <=1 ;i ++)
  22. {
  23. myicon[i] = AfxGetApp()->LoadIcon(128+i*2);
  24. m_hIcon = myicon[i];
  25. }
  26. num = 0 ;
  27. }
  28. void CMy12Dlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CMy12Dlg)
  32. // NOTE: the ClassWizard will add DDX and DDV calls here
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CMy12Dlg, CDialog)
  36. //{{AFX_MSG_MAP(CMy12Dlg)
  37. ON_WM_PAINT()
  38. ON_WM_QUERYDRAGICON()
  39. ON_WM_TIMER()
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CMy12Dlg message handlers
  44. BOOL CMy12Dlg::OnInitDialog()
  45. {
  46. CDialog::OnInitDialog();
  47. // Set the icon for this dialog.  The framework does this automatically
  48. //  when the application's main window is not a dialog
  49. SetIcon(m_hIcon, TRUE); // Set big icon
  50. SetIcon(m_hIcon, FALSE); // Set small icon
  51. // TODO: Add extra initialization here
  52. //WriteProfileString("c:\my.ini","usename","xiaoshuaihu158");
  53. WritePrivateProfileString ("Section1", "FirstKey", 
  54.                              "It all worked out okay.", "c:\appname.ini"); 
  55.     SetTimer(1,500,NULL);
  56.  
  57. return TRUE;  // return TRUE  unless you set the focus to a control
  58. }
  59. // If you add a minimize button to your dialog, you will need the code below
  60. //  to draw the icon.  For MFC applications using the document/view model,
  61. //  this is automatically done for you by the framework.
  62. void CMy12Dlg::OnPaint() 
  63. {
  64. CPaintDC dc(this); // device context for painting
  65. if (IsIconic())
  66. {
  67. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  68. // Center icon in client rectangle
  69. int cxIcon = GetSystemMetrics(SM_CXICON);
  70. int cyIcon = GetSystemMetrics(SM_CYICON);
  71. CRect rect;
  72. GetClientRect(&rect);
  73. int x = (rect.Width() - cxIcon + 1) / 2;
  74. int y = (rect.Height() - cyIcon + 1) / 2;
  75. // Draw the icon
  76. dc.DrawIcon(x, y, m_hIcon);
  77. }
  78. else
  79. {
  80. drawmainpic(&dc);
  81. // Draw(&dc);         //用来显示jpg图片的
  82. CDialog::OnPaint();
  83. }
  84. }
  85. // The system calls this to obtain the cursor to display while the user drags
  86. //  the minimized window.
  87. HCURSOR CMy12Dlg::OnQueryDragIcon()
  88. {
  89. return (HCURSOR) m_hIcon;
  90. }
  91. void CMy12Dlg::OnOK() 
  92. {
  93. // TODO: Add extra validation here
  94. int size = strlen("It all worked out okay.") + 1;
  95. char * pstring = new char[size];
  96. GetPrivateProfileString("Section1","FirstKey","sfsd",pstring,size,"c:\appname.ini");
  97. AfxMessageBox(pstring);
  98. CDialog::OnOK();
  99. }
  100. void CMy12Dlg::drawmainpic(CDC *dc)
  101. {
  102. RECT rect;
  103. GetClientRect(&rect);
  104. CBitmap bmp;
  105. bmp.LoadBitmap(IDB_BITMAP1);
  106. BITMAP sbmp;
  107. bmp.GetBitmap(&sbmp);
  108. CDC pdc;
  109. pdc.CreateCompatibleDC(dc);
  110. pdc.SelectObject(&bmp);
  111. dc->BitBlt(0,0,rect.right-rect.left,rect.bottom-rect.top,&pdc,0,0,SRCCOPY);
  112. }
  113. void CMy12Dlg::OnTimer(UINT nIDEvent) 
  114. {
  115. // TODO: Add your message handler code here and/or call default
  116. num = (num+1)%2 ;
  117. m_hIcon = myicon[num];
  118. SendMessage(WM_SETICON,0,(LPARAM)m_hIcon);
  119. CDialog::OnTimer(nIDEvent);
  120. }
  121. void CMy12Dlg::Draw(CDC*   pDC)   
  122. {     
  123.   
  124.     
  125. IPicture   *pPic;     
  126. IStream   *pStm;     
  127.     
  128. CFileStatus   fstatus;     
  129. CFile   file;     
  130. LONG   cb;     
  131.     
  132. if   (file.Open("D:\mmp\0b5d1a3c348744ae98d128963a23f713.jpg",CFile::modeRead)&&file.GetStatus("D:\mmp\0b5d1a3c348744ae98d128963a23f713.jpg",     
  133. fstatus)&&     
  134. ((cb   =   fstatus.m_size)   !=   -1))     
  135. {     
  136. HGLOBAL   hGlobal   =   GlobalAlloc(GMEM_MOVEABLE,   cb);     
  137. LPVOID   pvData   =   NULL;     
  138. if   (hGlobal   !=   NULL)     
  139. {     
  140. if   ((pvData   =   GlobalLock(hGlobal))   !=   NULL)     
  141. {     
  142. file.ReadHuge(pvData,   cb);     
  143. GlobalUnlock(hGlobal);     
  144. CreateStreamOnHGlobal(hGlobal,   TRUE,   &pStm);     
  145. if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*     
  146. )&pPic)))     
  147. {     
  148. OLE_XSIZE_HIMETRIC   hmWidth;     
  149. OLE_YSIZE_HIMETRIC   hmHeight;     
  150. pPic->get_Width(&hmWidth);     
  151. pPic->get_Height(&hmHeight);     
  152. double   fX,fY;     
  153. fX   =   (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);     
  154. fY   =   (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);     
  155. if(FAILED(pPic->Render(*pDC,0,0,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))     
  156. AfxMessageBox("Failed   To   Render   The   picture!");     
  157. pPic->Release();     
  158. }     
  159. else     
  160. AfxMessageBox("Error   Loading   Picture   From   Stream!");     
  161. }     
  162. }     
  163. }     
  164. else     
  165. AfxMessageBox("Can't   Open   Image   File!");     
  166. }