DlgBmp.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // DlgBmp.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "IDE.h"
  5. #include "DlgBmp.h"
  6. #include "mainfrm.h"
  7. #include "IDEView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. extern CString g_strViewName;
  14. extern CString g_strStartPic;
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CDlgBmp dialog
  17. CDlgBmp::CDlgBmp(CWnd* pParent /*=NULL*/)
  18. : CDlgBase(CDlgBmp::IDD, pParent)
  19. {
  20. //{{AFX_DATA_INIT(CDlgBmp)
  21. // m_tHisDate = 0;
  22. //}}AFX_DATA_INIT
  23. }
  24. CDlgBmp::~CDlgBmp()
  25. {
  26. }
  27. void CDlgBmp::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDlgBase::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CDlgBmp)
  31. DDX_DateTimeCtrl(pDX, IDC_HISDATE, m_tHisDate);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(CDlgBmp, CDlgBase)
  35. //{{AFX_MSG_MAP(CDlgBmp)
  36. ON_BN_CLICKED(ID_HISEVENT, OnHisevent)
  37. ON_BN_CLICKED(ID_MAINPAGE, OnMainpage)
  38. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_HISDATE, OnDatetimechangeHisdate)
  39. ON_BN_CLICKED(ID_FRESHVIEW, OnFreshview)
  40. ON_BN_CLICKED(IDC_LASTWEEK, OnLastweek)
  41. ON_BN_CLICKED(IDC_LASTDAY, OnLastday)
  42. ON_BN_CLICKED(IDC_NEXTDAY, OnNextday)
  43. ON_BN_CLICKED(IDC_NEXTWEEK, OnNextweek)
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDlgBmp message handlers
  48. BOOL CDlgBmp::OnInitDialog()
  49. {
  50. CDlgBase::OnInitDialog();
  51. // TODO: Add extra initialization here
  52. CClientDC dc(this);
  53. SetupRegion(&dc,m_bmp,RGB(255,255,255));
  54. VERIFY(m_button[0].AutoLoad(IDC_LASTWEEK,this));
  55. VERIFY(m_button[1].AutoLoad(IDC_LASTDAY,this));
  56. VERIFY(m_button[2].AutoLoad(IDC_NEXTWEEK,this));
  57. VERIFY(m_button[3].AutoLoad(IDC_NEXTDAY,this));
  58. VERIFY(m_button[4].AutoLoad(ID_HISEVENT,this));
  59. VERIFY(m_button[5].AutoLoad(ID_MAINPAGE,this));
  60. VERIFY(m_button[6].AutoLoad(IDOK,this));
  61. VERIFY(m_button[7].AutoLoad(ID_FRESHVIEW,this));
  62. m_tHisDate = CTime::GetCurrentTime();
  63. return TRUE; // return TRUE unless you set the focus to a control
  64. // EXCEPTION: OCX Property Pages should return FALSE
  65. }
  66. void CDlgBmp::SetupRegion(CDC *pDC, CBitmap &cBitmap, COLORREF TransColor)
  67. {
  68. CDC memDC;
  69. //创建与传入DC兼容的临时DC
  70. memDC.CreateCompatibleDC(pDC);
  71. CBitmap *pOldMemBmp=NULL;
  72. //将位图选入临时DC
  73. pOldMemBmp=memDC.SelectObject(&cBitmap);
  74. CRgn wndRgn;
  75. //创建总的窗体区域,初始region为0
  76. wndRgn.CreateRectRgn(0,0,0,0);
  77. BITMAP bit;
  78. cBitmap.GetBitmap (&bit);//取得位图参数,这里要用到位图的长和宽
  79. int y;
  80. for(y=0;y<=bit.bmHeight ;y++)
  81. {
  82. CRgn rgnTemp; //保存临时region
  83. int iX = 0;
  84. do
  85. {
  86. //跳过透明色找到下一个非透明色的点.
  87. while (iX <= bit.bmWidth && memDC.GetPixel(iX, y) == TransColor)
  88. iX++;
  89. //记住这个起始点
  90. int iLeftX = iX;
  91. //寻找下个透明色的点
  92. while (iX <= bit.bmWidth && memDC.GetPixel(iX, y) != TransColor)
  93. ++iX;
  94. //创建一个包含起点与重点间高为1像素的临时“region”
  95. rgnTemp.CreateRectRgn(iLeftX, y, iX, y+1);
  96. //合并到主"region".
  97. wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_OR);
  98. //删除临时"region",否则下次创建时和出错
  99. rgnTemp.DeleteObject();
  100. }while(iX <bit.bmWidth );
  101. iX = 0;
  102. }
  103. if(pOldMemBmp)
  104. memDC.SelectObject(pOldMemBmp);
  105. CWnd * pWnd = pDC->GetWindow();
  106. pWnd->SetWindowRgn(wndRgn,TRUE);
  107. pWnd->SetForegroundWindow();
  108. ReleaseDC( &memDC );
  109. DeleteObject( wndRgn );
  110. }
  111. void CDlgBmp::OnHisevent()
  112. {
  113. int screenx=GetSystemMetrics(SM_CXSCREEN);
  114. int screeny=GetSystemMetrics(SM_CYSCREEN);
  115. }
  116. void CDlgBmp::OnMainpage()
  117. {
  118. UpdateData(true);
  119. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  120. //CIDEView* pView = (CIDEView*)(pFrame->GetActiveView());
  121. //g_strViewName = _PICTUREDIR;
  122. g_strViewName = g_strStartPath + "\\" + g_strStartPic + ".view";
  123. pFrame->AddIDEView(g_strStartPic, g_strViewName);
  124. }
  125. void CDlgBmp::OnDatetimechangeHisdate(NMHDR* pNMHDR, LRESULT* pResult)
  126. {
  127. // 取视图;
  128. UpdateData(true);
  129. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  130. CIDEView* pView = (CIDEView*)(pFrame->GetActiveView());
  131. pView->SetHisTime( m_tHisDate );
  132. *pResult = 0;
  133. }
  134. void CDlgBmp::OnFreshview()
  135. {
  136. UpdateData(true);
  137. CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
  138. CIDEView* pView = (CIDEView*)(pFrame->GetActiveView());
  139. pView->SetHisTime( m_tHisDate );
  140. }
  141. void CDlgBmp::OnLastweek()
  142. {
  143. m_tHisDate -= CTimeSpan(7,0,0,0);
  144. UpdateData( false );
  145. OnFreshview();
  146. }
  147. void CDlgBmp::OnLastday()
  148. {
  149. m_tHisDate -= CTimeSpan(1,0,0,0);
  150. UpdateData( false );
  151. OnFreshview();
  152. }
  153. void CDlgBmp::OnNextday()
  154. {
  155. m_tHisDate += CTimeSpan(1,0,0,0);
  156. UpdateData( false );
  157. OnFreshview();
  158. }
  159. void CDlgBmp::OnNextweek()
  160. {
  161. m_tHisDate += CTimeSpan(7,0,0,0);
  162. UpdateData( false );
  163. OnFreshview();
  164. }