Click here to Skip to main content
15,881,898 members
Articles / Desktop Programming / WTL

Create a Convenient Toolbar Assistant Using WTL

Rate me:
Please Sign up or sign in to vote.
4.88/5 (30 votes)
11 Mar 2008GPL33 min read 61K   2.5K   58  
A more easy to generate toolbar images.
// This file was generated by WTL Dialog wizard 
// DlgEffect.cpp : Implementation of CDlgEffect

#include "stdafx.h"
#include "DlgEffect.h"

// CDlgEffect
CDlgEffect::CDlgEffect()
: m_bChkToall(TRUE)
{
}

CDlgEffect::~CDlgEffect()
{

}

int CDlgEffect::ApplyEffect(CImgEffect &imgEffect)
{
	if ((imgEffect.m_EffectType == eNULL) || (imgEffect.m_EffectType == eUnknown) )
		return 0;

	int nCount = m_aSelectedItems.GetSize();
	if ((nCount == 0) || (NULL == g_pdlgMain))
		return -1;

	if (!g_pdlgMain->m_aUndoEffect.Add(imgEffect))
		return -2;

	DoDataExchange(TRUE);

	int nRet = 0;
	CImgListItem *pImgItem;
	if (m_bChkToall)
	{
		for (int i=0; i<nCount; i++)
		{
			pImgItem = &(g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[i]]);
			if (NULL != pImgItem)
			{
				if (pImgItem->AddEffect(imgEffect, m_aSelectedItems[i]))
					nRet += 1;
			}
		}
	}
	else
	{
		int nCurItem = m_wndPath.GetCurSel();
		if (-1 == nCurItem)
			return 0;

		pImgItem = &(g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[nCurItem]]);
		if (NULL != pImgItem)
		{
			if (pImgItem->AddEffect(imgEffect, m_aSelectedItems[nCurItem]))
				nRet += 1;
		}
	}

	ResetUndoRedoButton();

	g_pdlgMain->m_wndListCtrl.Invalidate();

	return nRet;
}

int CDlgEffect::ResetEffect()
{
	if (MessageBox(_T("This operation will remove all effects to the selected items! Are you sure ?"), _T("Confirm"), MB_YESNO | MB_ICONQUESTION) == IDNO)
		return 0;

	CWaitCursor objWait;

	int nCount = m_aSelectedItems.GetSize();
	if ((nCount == 0) || (NULL == g_pdlgMain))
		return -1;

	int nRet = 0;
	for (int i=0; i<nCount; i++)
	{
		if (g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[i]].RemoveEffectAll())
			nRet += 1;
	}

	g_pdlgMain->m_aUndoEffect.RemoveAll();
	g_pdlgMain->m_aRedoEffect.RemoveAll();

	ResetUndoRedoButton();

	g_pdlgMain->m_wndListCtrl.Invalidate();

	return nRet;
}

bool CDlgEffect::IsCanUndo()
{
	return (g_pdlgMain->m_aUndoEffect.GetSize() > 0);
}

bool CDlgEffect::IsCanRedo()
{
	return (g_pdlgMain->m_aRedoEffect.GetSize() > 0);
}

void CDlgEffect::ResetUndoRedoButton()
{
	m_wndBtnRedo.EnableWindow(IsCanRedo());
	m_wndBtnUndo.EnableWindow(IsCanUndo());
}

int CDlgEffect::UndoEffect()
{
	CWaitCursor objWait;

	int nEffectCount = g_pdlgMain->m_aUndoEffect.GetSize();
	if (nEffectCount == 0)
		return 0;

	CImgEffect imgEffect(g_pdlgMain->m_aUndoEffect[nEffectCount - 1]);
	if (!g_pdlgMain->m_aRedoEffect.Add(imgEffect))
		return -1;

	if (!g_pdlgMain->m_aUndoEffect.RemoveAt(nEffectCount - 1))
		return -2;

	if (NULL == g_pdlgMain)
		return -3;

	int nCount = g_pdlgMain->m_wndListCtrl.GetItemCount();
	if (nCount == 0)
		return -4;

	int nRet = 0;
	for (int i=0; i<nCount; i++)
	{
		if (g_pdlgMain->m_wndListCtrl.m_aImg[i].RemoveEffect(imgEffect) > 0)
			nRet += 1;
	}

	ResetUndoRedoButton();

	g_pdlgMain->m_wndListCtrl.Invalidate();

	return nRet;
}

int CDlgEffect::RedoEffect()
{
	CWaitCursor objWait;

	int nCount = m_aSelectedItems.GetSize();
	if ((nCount == 0) || (NULL == g_pdlgMain))
		return -1;

	int nEffectCount = g_pdlgMain->m_aRedoEffect.GetSize();
	if (nEffectCount == 0)
		return 0;

	CImgEffect imgEffect(g_pdlgMain->m_aRedoEffect[nEffectCount - 1]);
	if (!g_pdlgMain->m_aUndoEffect.Add(imgEffect))
		return -1;

	if (!g_pdlgMain->m_aRedoEffect.RemoveAt(nEffectCount - 1))
		return -2;

	if (NULL == g_pdlgMain)
		return -3;

	int nRet = 0;
	for (int i=0; i<nCount; i++)
	{
		if (g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[i]].AddEffect(imgEffect))
			nRet += 1;
	}

	ResetUndoRedoButton();

	g_pdlgMain->m_wndListCtrl.Invalidate();

	return nRet;
}

LRESULT CDlgEffect::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	DoDataExchange(FALSE);

	if ((NULL != g_pdlgMain) && (NULL != g_pdlgMain->m_hIcoUndo))
	{
		m_wndBtnUndo.SetIcon(g_pdlgMain->m_hIcoUndo);
	}

	if ((NULL != g_pdlgMain) && (NULL != g_pdlgMain->m_hIcoRedo))
	{
		m_wndBtnRedo.SetIcon(g_pdlgMain->m_hIcoRedo);
	}

	ResetUndoRedoButton();

	// center the dialog on the screen
	CenterWindow();

	int nCount = m_aSelectedItems.GetSize();
	if ((nCount == 0) || (NULL == g_pdlgMain))
		return -1;

	int nItemCount = g_pdlgMain->m_wndListCtrl.m_aImg.GetSize();
	for (int i=0; i<nCount; i++)
	{
		if ((m_aSelectedItems[i] >= 0) && (m_aSelectedItems[i] < nItemCount))
            m_wndPath.AddString(g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[i]].m_strCmdID);
	}

	m_wndPath.SetCurSel(0);

	CString strTemp = _T("");
	CxImage *pImg = g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[0]].m_pImg;
	if (NULL != pImg)
	{
		if (pImg->IsValid())
		{
			for (int nFrame=0; nFrame<pImg->GetNumFrames(); nFrame++)
			{
				strTemp.Format(_T("Frame %4d"), nFrame);
				m_wndFrame.AddString(strTemp);
			}

			if (0 == nFrame)
			{
				m_wndFrame.SetCurSel(-1);
				m_wndFrame.EnableWindow(FALSE);
			}
			else
			{
				m_wndFrame.SetCurSel(g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[0]].m_CurFrame);
				m_wndFrame.EnableWindow(TRUE);
			}
		}
	}

	return 1;  // Let the system set the focus
}

// Reset
LRESULT CDlgEffect::OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	// EndDialog(wID);
	ResetEffect();

	return 0;
}

LRESULT CDlgEffect::OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	EndDialog(wID);
	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnShiftrgb(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	CPageShiftRGB dlgEffect;
	if (dlgEffect.DoModal() == IDOK)
	{
		CImgEffect imgEffect(eShiftRGB);
		imgEffect.m_Params[0].lVal = dlgEffect.m_R;
		imgEffect.m_Params[1].lVal = dlgEffect.m_G;
		imgEffect.m_Params[2].lVal = dlgEffect.m_B;

		ApplyEffect(imgEffect);

		return 0;
	}

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnColorize(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	CPageColorize dlgEffect;
	if (dlgEffect.DoModal() == IDOK)
	{
		CImgEffect imgEffect(eColorize);
		imgEffect.m_Params[0].bVal = dlgEffect.m_uHue;
		imgEffect.m_Params[1].bVal = dlgEffect.m_uSat;
		imgEffect.m_Params[2].fltVal = dlgEffect.m_fBlend;

		ApplyEffect(imgEffect);

		return 0;
	}

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnNegative(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	CImgEffect imgEffect(eNegative);

	ApplyEffect(imgEffect);

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnLight(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	CPageLight dlgEffect;
	if (dlgEffect.DoModal() == IDOK)
	{
		CImgEffect imgEffect(eLight);
		imgEffect.m_Params[0].lVal = dlgEffect.m_lBrightness;
		imgEffect.m_Params[1].lVal = dlgEffect.m_lContrast;

		ApplyEffect(imgEffect);

		return 0;
	}

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnRotate(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	CPageRotate dlgEffect;
	if (dlgEffect.DoModal() == IDOK)
	{
		CImgEffect imgEffect(eRotate);
		imgEffect.m_Params[0].fltVal = dlgEffect.m_fAngle;

		ApplyEffect(imgEffect);

		return 0;
	}

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnMirrorh(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	CImgEffect imgEffect(eMirror);

	ApplyEffect(imgEffect);

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnGrayscale(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	CImgEffect imgEffect(eGrayScale);

	ApplyEffect(imgEffect);

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnMirrorv(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	CImgEffect imgEffect(eFlip);

	ApplyEffect(imgEffect);

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnUndo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	UndoEffect();

	return 0;
}

LRESULT CDlgEffect::OnBnClickedBtnRedo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// TODO: �ڴ���ӿؼ�֪ͨ����������
	RedoEffect();

	return 0;
}

LRESULT CDlgEffect::OnPathCbnSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	int nCurItem = m_wndPath.GetCurSel();
	if (-1 == nCurItem)
		return 0;

	m_wndFrame.ResetContent();

	CString strTemp = _T("");
	CxImage *pImg = g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[nCurItem]].m_pImg;
	if (NULL != pImg)
	{
		if (pImg->IsValid())
		{
			for (int nFrame=0; nFrame<pImg->GetNumFrames(); nFrame++)
			{
				strTemp.Format(_T("Frame %4d"), nFrame);
				m_wndFrame.AddString(strTemp);
			}

			if (0 == nFrame)
			{
				m_wndFrame.SetCurSel(-1);
				m_wndFrame.EnableWindow(FALSE);
			}
			else
			{
				m_wndFrame.SetCurSel(g_pdlgMain->m_wndListCtrl.m_aImg[m_aSelectedItems[nCurItem]].m_CurFrame);
				m_wndFrame.EnableWindow(TRUE);
			}
		}
	}

	return 0;
}

LRESULT CDlgEffect::OnFrameCbnSelChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	if (!m_wndFrame.IsWindowEnabled())
		return 0;

	int nCurFrame = m_wndFrame.GetCurSel();
	if (-1 == nCurFrame)
		return 0;

	CImgEffect imgEffect(eSwitchFrame);
	imgEffect.m_Params[0].lVal = nCurFrame;

	ApplyEffect(imgEffect);

	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Team Leader GreatStar Software Technology Development CO., Ltd
China China
Upcoming product - Roya LiveWorld
Integrate video, audio and data with powerful collaborative communication technologies.
Hope that we can let people around the world to communicate more convenient!

The wise choice of the 10 reasons
1, single server to support users far more than the general similar products
2, years of accumulation of professional video technology development, so that the effect of more realistic video
3, even if the dial-up Internet access, can also be smooth, clear, quality sound effects
4, adapt to the various complex network environment
5, the powerful, friendly interface, easy to operate
6, better stability and better, higher security
7, Universal Network File Sharing Technology (Global original) can be simple and efficient sharing of arbitrary files
8, close to the ordinary user's design
9, the hardware and software requirements are very low, server can even run in the virtual machine.
10, more personalized service

http://www.soft234.com

Comments and Discussions