图像处理

1.状态栏简单操作:

static UINT indicators[] =
{
ID_SEPARATOR,           // status line indicator
ID_INDICATOR_TIME,
};

void CMainFrame::OnTimer(UINT nIDEvent) 
{
CString str;
CTime time=CTime::GetCurrentTime();
str=time.Format("  %H:%M:%S");
    m_wndStatusBar.SetPaneText(1,str,TRUE);
CFrameWnd::OnTimer(nIDEvent);
}

2.视图结构中处理:

class CMyView : public CView{

public:
CString RetDir(CString str);
BOOL ShowBitmap(CString str);
virtual ~CMyView();

CString TransPath(CString str);
CString path;
CFileFind filefind;
CString strarray[20];
int index;
int max_index;

//。。。。。。。。。。。。。。。。。。。。。

};

void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);


ShowBitmap(path);


}

/
// CMyView printing


BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}

void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}


void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}

/
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}

CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG


/
// CMyView message handlers

int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;


   CString strpath = RetDir(path);
CString strfind,str;
index=0;
max_index=0;
BOOL bWorking=filefind.FindFile(strpath,0);
while(bWorking&&index<20)
{ bWorking=filefind.FindNextFile();
strfind=filefind.GetFilePath();
str=CMyView::TransPath(strfind); 
strarray[index]=str;
index++;
}
max_index=index-1;
index=0;
    
// SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,NULL ,0);
return 0;
}

void CMyView::OnExit() 
{
PostQuitMessage(0); 

}

void CMyView::OnNext() 
{
if(index<max_index)
{
index++;
}  
else index=0;
path=strarray[index];
Invalidate();

}

void CMyView::OnOpen() 
{
CString lpszFilter="位图文件 (*.bmp)|*.bmp|所有文件 (*.*)|*.*||";
CFileDialog file(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT ,lpszFilter,NULL);
int ret = file.DoModal();
if(IDOK ==ret)
{
CString str=file.GetPathName();
path=CMyView::TransPath(str); 
        CString strpath = RetDir(path);
CString strfind;
index=0;
max_index=0;
BOOL bWorking=filefind.FindFile(strpath,0);
while(bWorking&&index<20)
{ bWorking=filefind.FindNextFile();
strfind=filefind.GetFilePath();
str=CMyView::TransPath(strfind); 
strarray[index]=str;
index++;
}
max_index=index-1;
index=0;
Invalidate();
}
}


void CMyView::OnPre() 
{
if(index>0)
{
index--;

else index=max_index;
path=strarray[index];
Invalidate();
}


CString CMyView::TransPath(CString str)
{
int len=str.GetLength();
int i=len-1;
for(i=len-1;i>=0;i--)
{
if('\\'==str.GetAt(i))
{
str.Insert(i,'\\');
}      
}
return str;
}

BOOL CMyView::ShowBitmap(CString str)
{
   CBitmap *bitmap;
BITMAP  pBmpInfo;


HBITMAP bmp =(HBITMAP)::LoadImage(AfxGetInstanceHandle(),str,IMAGE_BITMAP,0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);

if(bmp==NULL)
{
MessageBox("LoadImage Error !");
return FALSE;
}

bitmap=CBitmap::FromHandle(bmp);
bitmap->GetBitmap(&pBmpInfo);
CDC mem;
CDC *pDC=GetDC();
if(!mem.CreateCompatibleDC(pDC))
{
MessageBox("CreateCompatibleDC Error !");
return FALSE;
}

if(! mem.SelectObject(bitmap))
{
MessageBox("SelectObject Error !");
return FALSE;
}
CRect rect;
GetClientRect(&rect);
// int err = pDC->BitBlt(0,0,pBmpInfo.bmWidth,pBmpInfo.bmHeight,&mem,0,0,SRCCOPY);
// int err = pDC->StretchBlt(0,0,pBmpInfo.bmWidth,pBmpInfo.bmHeight,&mem,0,0,rect.Width(),rect.Height(),SRCCOPY); 
        int err = pDC->StretchBlt(0,0,pBmpInfo.bmWidth,pBmpInfo.bmHeight,&mem,0,0,pBmpInfo.bmWidth,pBmpInfo.bmHeight,SRCCOPY); 
if(err==0)
{
MessageBox("BitBlt Error !");
return FALSE;
}
pDC->DeleteDC();
mem.DeleteDC();
                return TRUE;
}

CString CMyView::RetDir(CString str)
{
int index = str.ReverseFind('\\');
CString cs;
cs=str.Left(index+1);
cs+="*.bmp";
return cs;
}

void CMyView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
if('a'==nChar||'A'==nChar)
{
  CMyView::OnPre();
}

if('d'==nChar||'D'==nChar)
{
  CMyView::OnNext();
}
CView::OnChar(nChar, nRepCnt, nFlags);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值