⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 browse.cpp

📁 图像处理软件,功能比较基础
💻 CPP
字号:
// Browse.cpp : implementation file
//

#include "stdafx.h"
#include "linjunjuan.h"
#include "Browse.h"
#include <direct.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBrowse dialog







CBrowse::CBrowse(CWnd* pParent /*=NULL*/)
	:CBitmapDialog(CBrowse::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBrowse)
	m_strPath = _T("");
	//}}AFX_DATA_INIT
	one=TRUE;
//	nowpage=0;
}


void CBrowse::DoDataExchange(CDataExchange* pDX)
{
	CBitmapDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBrowse)
	DDX_Text(pDX, IDC_PATHNAME, m_strPath);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBrowse, CBitmapDialog)
	//{{AFX_MSG_MAP(CBrowse)
	ON_WM_PAINT()
	ON_NOTIFY(TVN_SELCHANGED, IDC_TREE2, OnSelchangedTree1)
	ON_BN_CLICKED(MY_BTN3, OnButtonUp)
	ON_BN_CLICKED(MY_BTN4, OnButtonDown)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_DRAWPIC,OnDrawPic)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBrowse message handlers

void CBrowse::OnPaint() 
{	
	CPaintDC dc(this); // device context for painting	
	
}	


WNDPROC OldWndProc;
int g_num;
HWND g_hwnd[12];
BOOL g_flag[12];
BOOL flag=FALSE;
CSortStringArray strFileArray;
int nowpage=0;
int pagenum;
Picture pic;
HDIB *hdib=NULL;
RECT *rectdib=NULL,*rectdest=NULL;
int whichwindow;
int oldwhichwindow=0;
HBRUSH redbrush;

static int oldsize=0;
void Caculate(int row,int col,int &pre_row,int &pre_col)
{
	float rate;
	int Dest_length=100;
	if(row>col)
	{
		pre_row=Dest_length;
		rate=row/(float)Dest_length;
		pre_col=(int)(col/rate);
	}
	else
	{
		pre_col=Dest_length;
		rate=col/(float)Dest_length;
		pre_row=(int)(row/rate);
	}
}


LRESULT CALLBACK hwndWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	HWND hw;
	hw=hwnd;
	int i=0;
	PAINTSTRUCT ps;
	int temp,whichpic;
	RECT rect;
	BOOL flag=FALSE;
	int count=0;
	
	//============
	if(nowpage<pagenum||(nowpage==pagenum&&(g_num%12==0)))
	{
		for (i=0;i<12;i++)
		{
			if(hwnd==g_hwnd[i])
			{
				whichpic=nowpage*12+i;
				switch(message)
				{				
				case WM_PAINT:			
					hdc=BeginPaint(hwnd,&ps);								
					if(g_flag[i]==TRUE)
					{
						SelectObject(hdc,redbrush);
					}
					else 
					{
						SelectObject(hdc,GetStockObject(GRAY_BRUSH));
					}
					GetClientRect(hwnd,&rect);
					::Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
					PaintDIB(hdc,&rectdest[whichpic],hdib[whichpic],&rectdib[whichpic],NULL);	
					::EndPaint(hwnd,&ps);					
					return 0;
				case WM_NCHITTEST:
					whichwindow=i;	
				default:
					return CallWindowProc(OldWndProc,hwnd,message,wParam,lParam);
				}
			}
		}
	}
	else
	{
		temp=g_num%12;
		if(temp!=0)
		{
			for (i=0;i<temp;i++)
			{
				
				if(hwnd==g_hwnd[i])
				{
					whichpic=nowpage*12+i;
					switch(message)
					{		
					case WM_PAINT:			
						hdc=BeginPaint(hwnd,&ps);						
						if(g_flag[i]==TRUE)
						{
							SelectObject(hdc,redbrush);
						}
						else 
						{
							SelectObject(hdc,GetStockObject(GRAY_BRUSH));
						}
						GetClientRect(hwnd,&rect);
						::Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
						PaintDIB(hdc,&rectdest[whichpic],hdib[whichpic],&rectdib[whichpic],NULL);	
						::EndPaint(hwnd,&ps);
						return 0;
					case WM_NCHITTEST:
						whichwindow=i;	
					default:
						return CallWindowProc(OldWndProc,hwnd,message,wParam,lParam);
					}
				}
			}
		}
		else
		{
			for (i=0;i<12;i++)
			{
				if(hwnd==g_hwnd[i])
				{
					whichpic=nowpage*12+i;
					switch(message)
					{		
					case WM_PAINT:			
						hdc=BeginPaint(hwnd,&ps);
						if(g_flag[i]==TRUE)
						{
							SelectObject(hdc,redbrush);
						}
						else 
						{
							SelectObject(hdc,GetStockObject(GRAY_BRUSH));
						}
						GetClientRect(hwnd,&rect);
						::Rectangle(hdc,rect.left,rect.top,rect.right,rect.bottom);
						PaintDIB(hdc,&rectdest[whichpic],hdib[whichpic],&rectdib[whichpic],NULL);	
						::EndPaint(hwnd,&ps);						
						return 0;
					case WM_NCHITTEST:
						whichwindow=i;	
					default:
						return CallWindowProc(OldWndProc,hwnd,message,wParam,lParam);
					}
				}
			}
		}
	}
	return CallWindowProc(OldWndProc,hwnd,message,wParam,lParam);
}


BOOL CBrowse::OnInitDialog() 
{
//	CDialog::OnInitDialog();
	//设置背景
	CBitmapDialog::OnInitDialog();
	SetBitmap(IDB_BM_SKIN1, CBitmapDialog::BITMAP_TILE);
	TCHAR  szWorkDir[MAX_PATH];	
	if ( !m_TreeCtrl.m_hWnd )
	{
		if ( m_TreeCtrl.SubclassDlgItem( IDC_TREE2, this ) )
		{			
			m_TreeCtrl.DisplayTree( NULL /*Display all*/, FALSE /* TRUE = Display Files*/ );
			
			_getcwd( szWorkDir, 256 );
			// set the Path to the current Work-Directory
			m_TreeCtrl.SetSelPath( szWorkDir );
		}
	}
//==========================画按钮=================
	HRGN rgnR = CreateRectRgn(0, 0, 150, 50);
	HRGN rgnE = CreateEllipticRgn(0, 0, 150,50 );
	OffsetRgn(rgnR, 63, 0);
	CombineRgn(rgnE, rgnE, rgnR, RGN_DIFF);
	m_Btn3.Create("上一页", WS_CHILD | WS_VISIBLE|WS_DISABLED, CPoint(630, 500), rgnE, this, MY_BTN3, 2, GetSysColor(COLOR_BTNFACE), RGB(156,175,194), RGB(237,175,71), GetSysColor(COLOR_BTNFACE)); 
	rgnR = CreateRectRgn(0, 0, 150, 50);
	rgnE = CreateEllipticRgn(0, 0, 150, 50);
	OffsetRgn(rgnR, -63, 0);
	CombineRgn(rgnE, rgnE, rgnR, RGN_DIFF);
	OffsetRgn(rgnE, -64, 0);
	m_Btn4.Create("下一页", WS_CHILD | WS_VISIBLE|WS_DISABLED, CPoint(630 + 64, 500), rgnE, this, MY_BTN4, 2, GetSysColor(COLOR_BTNFACE), RGB(156, 175, 194), RGB(237, 175, 71), GetSysColor(COLOR_BTNFACE)); 
	DeleteObject(rgnE);
	DeleteObject(rgnR);	
	//==================================================================
	g_pWnd=GetDlgItem(IDC_PICTURE_ALL);	
	HWND hDlgwnd=g_pWnd->GetSafeHwnd();	
	HINSTANCE hIns=AfxGetInstanceHandle();
	for (int i=0;i<12;i++)
	{
		g_hwnd[i]=CreateWindow(TEXT("static"),NULL,WS_CHILD|WS_DLGFRAME,0,0,110,110,
			hDlgwnd,(HMENU) i,hIns,NULL);		
		OldWndProc=(WNDPROC)SetWindowLong(g_hwnd[i],GWL_WNDPROC,(LONG)hwndWndProc);
	}
	redbrush=CreateSolidBrush(RGB(255,0,0));
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}



void CBrowse::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	m_strPath = m_TreeCtrl.GetFullPath( pNMTreeView->itemNew.hItem );
	UpdateData(FALSE);	

	//========================================
	CFileFind find;
	CString   strPathFiles = m_strPath;
	BOOL      bFind;	
	CString filename;
	strFileArray.RemoveAll();
	nowpage=0;
	
	if ( strPathFiles.Right(1) != "\\" )
		strPathFiles += "\\";
	strPathFiles += "*.*";

	bFind = find.FindFile( strPathFiles );

	while ( bFind )
	{
		bFind = find.FindNextFile();		
		if ( !find.IsDirectory())
		{
			filename=find.GetFilePath();
			if (filename.Find(".bmp")!=-1||filename.Find(".pic")!=-1)
			strFileArray.Add( find.GetFilePath() );
		}

	}
	strFileArray.Sort();
	int num=strFileArray.GetSize();
	

	if(num!=0)
	{
		g_num=num;
		SendMessage(WM_DRAWPIC,NULL,NULL);
	}
	*pResult = 0;
	
}






LRESULT CBrowse::OnDrawPic(WPARAM wParam,LPARAM lParam)
{	
	pagenum=(int)(strFileArray.GetSize()/12.0)-1;
	if (strFileArray.GetSize()%12!=0)
		pagenum++;
	//=============================
	
	if (rectdib!=NULL)
	{
		delete [] rectdib;
		rectdib=NULL;
	}
	if(rectdest!=NULL)
	{
		delete []rectdest;
		rectdest=NULL;
	}	
	for (int j=0;j<oldsize;j++)
	{
		if(hdib[j]!=NULL)
		{
			GlobalFree((HGLOBAL)hdib[j]);
			hdib[j]=NULL;
		}
	}
	if (hdib!=NULL)
	{
		delete [] hdib;
		hdib=NULL;
	}


	int out_row,out_col;
//	pic= new Picture [strFileArray.GetSize()];
	hdib= new HDIB [strFileArray.GetSize()];
	for(j=0;j<strFileArray.GetSize();j++)
		hdib[j]=NULL;
	rectdib= new RECT [strFileArray.GetSize()];
	rectdest= new RECT [strFileArray.GetSize()];
	
	for (int i=0;i<strFileArray.GetSize();i++)
	{
		pic.p=InputImageWithName(strFileArray.GetAt(i),pic.row,pic.col);
		if (pic.p==NULL)
		{
			strFileArray.RemoveAt(i);
			continue;
		}
		hdib[i]=ChangeToHDIB(pic);
		if (hdib[i]==NULL)
		{
			strFileArray.RemoveAt(i);
			continue;
		}
		rectdib[i].left=rectdib[i].top=0;
		rectdib[i].right=pic.col;
		rectdib[i].bottom=pic.row;
		Caculate(pic.row,pic.col,out_row,out_col);
		if(pic.row<pic.col)
		{
			rectdest[i].left=5;
			rectdest[i].top=5+(50-out_row/2);
			rectdest[i].right=out_col;
			rectdest[i].bottom=out_row+(50-out_row/2);			
		}
		else
		{
			rectdest[i].left=5+(50-out_col/2);
			rectdest[i].top=5;
			rectdest[i].right=out_col+(50-out_col/2);
			rectdest[i].bottom=out_row;
		}
		dspace_2d(pic.p,pic.row,pic.col);
	}
	oldsize=strFileArray.GetSize();
	flag=FALSE;

	//=================================================
	Show_Nowpage_Pic();	
	RECT rect={237,22,766,480};
	InvalidateRect(&rect,TRUE);
	return 0;
}
void CBrowse::Show_Nowpage_Pic()
{
	
	int xnum,ynum,page_total_num;
	page_total_num=strFileArray.GetSize()%12;
//	if (flag==TRUE)
	{
		for (int k=0;k<12;k++)	
		{
			SetWindowLong(g_hwnd[k],GWL_STYLE,WS_CHILD|WS_DLGFRAME);
			::UpdateWindow(g_hwnd[k]);
		}
	}
	for(int i=0;i<12;i++)
		g_flag[i]=FALSE;
	if(nowpage>0&&nowpage<pagenum)
	{
		m_Btn3.EnableWindow(TRUE);
		m_Btn4.EnableWindow(TRUE);
	}
	if (nowpage==0)
	{
		m_Btn3.EnableWindow(FALSE);
		m_Btn4.EnableWindow(TRUE);
	}

	if (nowpage==pagenum&&(g_num%12!=0))
	{
		if(pagenum==0)
		{
			m_Btn3.EnableWindow(FALSE);		
		}
		else
			m_Btn3.EnableWindow(TRUE);
		m_Btn4.EnableWindow(FALSE);		
		xnum=(int)(page_total_num/4.0);
		ynum=strFileArray.GetSize()%4;
		for (int i=0;i<xnum;i++)	
		{
			for (int j=0;j<4;j++)
			{
				::MoveWindow(g_hwnd[j+4*i],20+(20+110)*j,20+(150*i),110,110,TRUE);
				SetWindowLong(g_hwnd[j+4*i],GWL_STYLE,WS_CHILD|WS_DLGFRAME|WS_VISIBLE);				
				::UpdateWindow(g_hwnd[j+4*i]);				
			}
		}
		for (int j=0;j<ynum;j++)
		{
			::MoveWindow(g_hwnd[j+4*xnum],20+(20+110)*j,20+(150*xnum),110,110,TRUE);
			SetWindowLong(g_hwnd[j+4*xnum],GWL_STYLE,WS_CHILD|WS_DLGFRAME|WS_VISIBLE);
			::UpdateWindow(g_hwnd[j+4*xnum]);		
		}
	}
	else 
	{
		if(pagenum==0)
		{
			m_Btn3.EnableWindow(FALSE);
			m_Btn4.EnableWindow(FALSE);
		}

		for (int i=0;i<3;i++)	
		{
			for (int j=0;j<4;j++)
			{
				::MoveWindow(g_hwnd[j+4*i],20+(20+110)*j,20+(150*i),110,110,TRUE);
				SetWindowLong(g_hwnd[j+4*i],GWL_STYLE,WS_CHILD|WS_DLGFRAME|WS_VISIBLE);
				::UpdateWindow(g_hwnd[j+4*i]);
			}
		}
	}
	flag=TRUE;
}
void CBrowse::OnButtonUp() 
{
	if (nowpage>0)
	{
		for(int i=0;i<12;i++)
		g_flag[i]=FALSE;
		nowpage--;		
		Show_Nowpage_Pic();		
		Invalidate(FALSE);		
	}
}

void CBrowse::OnButtonDown() 
{	
	RECT rect={237,22,766,480};
	if (nowpage<pagenum)
	{
		for(int i=0;i<12;i++)
		g_flag[i]=FALSE;
		nowpage++;			
		Show_Nowpage_Pic();
		InvalidateRect(&rect,TRUE);					
	}
}

void CBrowse::OnLButtonDown(UINT nFlags, CPoint point) 
{
	RECT rect={0,0,110,110};
	for(int i=0;i<12;i++)
		g_flag[i]=FALSE;
	g_flag[whichwindow]=TRUE;
	::InvalidateRect(g_hwnd[oldwhichwindow],&rect,FALSE);
	::InvalidateRect(g_hwnd[whichwindow],&rect,FALSE);	
	oldwhichwindow=whichwindow;
	CBitmapDialog::OnLButtonDown(nFlags, point);
}

void CBrowse::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	AfxGetApp()->OpenDocumentFile((LPCTSTR)strFileArray.GetAt(whichwindow+nowpage*12));
	CBitmapDialog::OnLButtonDblClk(nFlags, point);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -