123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- // DlgBmp.cpp : implementation file
- //
- #include "stdafx.h"
- #include "IDE.h"
- #include "DlgBmp.h"
- #include "mainfrm.h"
- #include "IDEView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CString g_strViewName;
- extern CString g_strStartPic;
- /////////////////////////////////////////////////////////////////////////////
- // CDlgBmp dialog
- CDlgBmp::CDlgBmp(CWnd* pParent /*=NULL*/)
- : CDlgBase(CDlgBmp::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDlgBmp)
- // m_tHisDate = 0;
- //}}AFX_DATA_INIT
- }
- CDlgBmp::~CDlgBmp()
- {
- }
- void CDlgBmp::DoDataExchange(CDataExchange* pDX)
- {
- CDlgBase::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgBmp)
- DDX_DateTimeCtrl(pDX, IDC_HISDATE, m_tHisDate);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgBmp, CDlgBase)
- //{{AFX_MSG_MAP(CDlgBmp)
- ON_BN_CLICKED(ID_HISEVENT, OnHisevent)
- ON_BN_CLICKED(ID_MAINPAGE, OnMainpage)
- ON_NOTIFY(DTN_DATETIMECHANGE, IDC_HISDATE, OnDatetimechangeHisdate)
- ON_BN_CLICKED(ID_FRESHVIEW, OnFreshview)
- ON_BN_CLICKED(IDC_LASTWEEK, OnLastweek)
- ON_BN_CLICKED(IDC_LASTDAY, OnLastday)
- ON_BN_CLICKED(IDC_NEXTDAY, OnNextday)
- ON_BN_CLICKED(IDC_NEXTWEEK, OnNextweek)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgBmp message handlers
- BOOL CDlgBmp::OnInitDialog()
- {
- CDlgBase::OnInitDialog();
-
- // TODO: Add extra initialization here
- CClientDC dc(this);
- SetupRegion(&dc,m_bmp,RGB(255,255,255));
- VERIFY(m_button[0].AutoLoad(IDC_LASTWEEK,this));
- VERIFY(m_button[1].AutoLoad(IDC_LASTDAY,this));
- VERIFY(m_button[2].AutoLoad(IDC_NEXTWEEK,this));
- VERIFY(m_button[3].AutoLoad(IDC_NEXTDAY,this));
- VERIFY(m_button[4].AutoLoad(ID_HISEVENT,this));
- VERIFY(m_button[5].AutoLoad(ID_MAINPAGE,this));
- VERIFY(m_button[6].AutoLoad(IDOK,this));
- VERIFY(m_button[7].AutoLoad(ID_FRESHVIEW,this));
- m_tHisDate = CTime::GetCurrentTime();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CDlgBmp::SetupRegion(CDC *pDC, CBitmap &cBitmap, COLORREF TransColor)
- {
- CDC memDC;
- //创建与传入DC兼容的临时DC
- memDC.CreateCompatibleDC(pDC);
-
- CBitmap *pOldMemBmp=NULL;
- //将位图选入临时DC
- pOldMemBmp=memDC.SelectObject(&cBitmap);
-
- CRgn wndRgn;
- //创建总的窗体区域,初始region为0
- wndRgn.CreateRectRgn(0,0,0,0);
-
-
- BITMAP bit;
- cBitmap.GetBitmap (&bit);//取得位图参数,这里要用到位图的长和宽
-
- int y;
- for(y=0;y<=bit.bmHeight ;y++)
- {
- CRgn rgnTemp; //保存临时region
-
- int iX = 0;
- do
- {
- //跳过透明色找到下一个非透明色的点.
- while (iX <= bit.bmWidth && memDC.GetPixel(iX, y) == TransColor)
- iX++;
-
- //记住这个起始点
- int iLeftX = iX;
-
- //寻找下个透明色的点
- while (iX <= bit.bmWidth && memDC.GetPixel(iX, y) != TransColor)
- ++iX;
-
- //创建一个包含起点与重点间高为1像素的临时“region”
- rgnTemp.CreateRectRgn(iLeftX, y, iX, y+1);
-
- //合并到主"region".
- wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_OR);
-
- //删除临时"region",否则下次创建时和出错
- rgnTemp.DeleteObject();
- }while(iX <bit.bmWidth );
- iX = 0;
- }
-
- if(pOldMemBmp)
- memDC.SelectObject(pOldMemBmp);
-
- CWnd * pWnd = pDC->GetWindow();
- pWnd->SetWindowRgn(wndRgn,TRUE);
- pWnd->SetForegroundWindow();
-
- ReleaseDC( &memDC );
- DeleteObject( wndRgn );
- }
- void CDlgBmp::OnHisevent()
- {
- int screenx=GetSystemMetrics(SM_CXSCREEN);
- int screeny=GetSystemMetrics(SM_CYSCREEN);
- }
- void CDlgBmp::OnMainpage()
- {
- UpdateData(true);
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- //CIDEView* pView = (CIDEView*)(pFrame->GetActiveView());
- //g_strViewName = _PICTUREDIR;
- g_strViewName = g_strStartPath + "\\" + g_strStartPic + ".view";
- pFrame->AddIDEView(g_strStartPic, g_strViewName);
- }
- void CDlgBmp::OnDatetimechangeHisdate(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // 取视图;
- UpdateData(true);
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- CIDEView* pView = (CIDEView*)(pFrame->GetActiveView());
- pView->SetHisTime( m_tHisDate );
- *pResult = 0;
- }
- void CDlgBmp::OnFreshview()
- {
- UpdateData(true);
- CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
- CIDEView* pView = (CIDEView*)(pFrame->GetActiveView());
- pView->SetHisTime( m_tHisDate );
- }
- void CDlgBmp::OnLastweek()
- {
- m_tHisDate -= CTimeSpan(7,0,0,0);
- UpdateData( false );
- OnFreshview();
- }
- void CDlgBmp::OnLastday()
- {
- m_tHisDate -= CTimeSpan(1,0,0,0);
- UpdateData( false );
- OnFreshview();
- }
- void CDlgBmp::OnNextday()
- {
- m_tHisDate += CTimeSpan(1,0,0,0);
- UpdateData( false );
- OnFreshview();
- }
- void CDlgBmp::OnNextweek()
- {
- m_tHisDate += CTimeSpan(7,0,0,0);
- UpdateData( false );
- OnFreshview();
- }
|