📄 shapecutdlg.cpp
字号:
// ShapeCutDLG.cpp : implementation file
//
#include "stdafx.h"
#include "picviewer.h"
#include "ShapeCutDLG.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const int THUMBWIDTH = 30 ;
const int THUMBHEIGHT = 40 ;
const int nGap = 6 ; // the space between thumbnails
/////////////////////////////////////////////////////////////////////////////
// CShapeCutDLG dialog
CShapeCutDLG::CShapeCutDLG()
{
//{{AFX_DATA_INIT(CShapeCutDLG)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CShapeCutDLG::~CShapeCutDLG()
{
}
void CShapeCutDLG::DoDataExchange(CDataExchange* pDX)
{
DDX_Control (pDX, IDC_LIST_THUMBSHAPE, m_ListThumb) ;
CDialogBarEx::DoDataExchange(pDX);
}
void CShapeCutDLG::OnInitDialogBar()
{
FCFileFind filefind ;
int nCount = 0 ;
TCHAR szExeName[MAX_PATH] ;
TCHAR szDriver[MAX_PATH] ;
TCHAR szPath[MAX_PATH] ;
::GetModuleFileName (NULL, szExeName, MAX_PATH) ;
::_splitpath (szExeName, szDriver, szPath, NULL, NULL) ;
::_makepath (szExeName, szDriver, szPath, _T("shapes\\*.*"), NULL);
// search directory "shapes" to get mask file name
if (filefind.FindFile (szExeName))
{
nCount++ ;
m_filename.push_back (CString(filefind.GetFullName ())) ;
while (filefind.FindNext ())
{
nCount++ ;
m_filename.push_back (CString(filefind.GetFullName ())) ;
}
filefind.FindClose () ;
}
else
return ;
// create and set the size of the image list
m_ImageListThumb.Create (THUMBWIDTH, THUMBHEIGHT, ILC_COLOR24, 0, 1) ;
m_ImageListThumb.SetImageCount (nCount) ;
m_ListThumb.SetRedraw (FALSE) ;
m_ListThumb.SetImageList (&m_ImageListThumb, LVSIL_NORMAL) ;
// load mask file and make thumbnails
nCount = 0 ;
vector<CString>::iterator iter ;
for(iter = m_filename.begin() ; iter != m_filename.end() ; iter++, nCount++)
{
// load the bitmap and make thumbnail
FCImage * img = new FCImage () ;
img->Load (*iter) ;
img->Stretch (THUMBWIDTH, THUMBHEIGHT, 0) ;
img->ConvertTo24Bit () ;
// add bitmap to image list
CBitmap * pImage = new CBitmap() ;
pImage->Attach (img->GetHandle ()) ;
m_ImageListThumb.Replace (nCount, pImage, NULL) ;
pImage->Detach () ;
delete pImage ;
delete img ;
// insert mask thumbnail
m_ListThumb.InsertItem(nCount, _T(""), nCount);
// adjust current thumbnail position to desired position
POINT pt ;
m_ListThumb.GetItemPosition (nCount, &pt) ;
pt.x = nGap + nCount * (THUMBWIDTH + nGap) ;
m_ListThumb.SetItemPosition (nCount, pt) ;
}
m_ListThumb.SetRedraw (TRUE) ;
m_ListThumb.SetFocus () ;
m_ListThumb.SetItemState (0, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED) ;
m_ListThumb.InvalidateRect (NULL) ;
}
BEGIN_MESSAGE_MAP(CShapeCutDLG, CDialogBarEx)
//{{AFX_MSG_MAP(CShapeCutDLG)
ON_NOTIFY(NM_CLICK, IDC_LIST_THUMBSHAPE, OnClickListThumbshape)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShapeCutDLG message handlers
void CShapeCutDLG::OnClickListThumbshape(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMITEMACTIVATE pItemAct = (LPNMITEMACTIVATE) pNMHDR ;
if (pItemAct->iItem != -1)
{
FCImage mask ;
mask.Load ((CString)m_filename.at (pItemAct->iItem)) ;
mask.ConvertToGray () ;
RGBQUAD rgb = {255,255,255,0} ;
m_CurrImg.Create (mask.Width(), mask.Height(), 32) ;
m_CurrImg.RegionFill (rgb) ;
m_CurrImg.AppendAlphaChannel (mask) ;
// m_CurrImg.InvertAlphaChannel () ;
}
*pResult = 0 ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -