Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

WTL Helper

, 27 Aug 2007
Add-in for Microsoft VC++.NET 2003 that helps to insert message handlers for WTL.
wtlhelper.zip
wtlhelper_exe.zip
wtlhelper_src.zip
source
AddIn.def
Dialog
vssver.scc
Options
res
a1.ico
AddIn.rgs
addin8.rgs
closefld.ico
Clsdfold.ico
DDX.bmp
dialog.bmp
functoolbar.bmp
icons.bmp
message.ico
msg.bmp
mysmall4.bmp
openfld.ico
Openfold.ico
option.bmp
vartoolbar.bmp
vssver.scc
wizard.bmp
Wizard.ico
WtlHelper.dll.manifest
resources
Setup.nsi
WtlHelperRes
res
DDX.bmp
dialog.bmp
msg.bmp
option.bmp
reflect.bmp
wizard.bmp
WtlHelperRes.aps
WtlHelperRes8.vcproj.MINSK.solozhentsev.user
// This file was generated by WTL Dialog wizard 
// ReflectionDlg.cpp : Implementation of CReflectionDlg

#include "stdafx.h"
#include "ReflectionDlg.h"

CAtlArray<CString> CReflectionDlg::m_sReflectMessages;

// CReflectionDlg
CReflectionDlg::CReflectionDlg() : m_dwFlags(RD_MESSAGE)
{
}

CReflectionDlg::~CReflectionDlg()
{
}

void CReflectionDlg::GetDataFromControls()
{
	CComboBox CodeCombo = GetDlgItem(IDC_COMBO_CODE);
	CComboBox IdCombo = GetDlgItem(IDC_COMBO_ID);
	CComboBox RangeCombo = GetDlgItem(IDC_COMBO_RANGE);
	CComboBox WindowCombo = GetDlgItem(IDC_COMBO_WINDOW);
	CButton CodeCheckbox = GetDlgItem(IDC_CHECK_CODE);
	CButton IdCheckbox = GetDlgItem(IDC_CHECK_ID);
	CButton RangeCheckbox = GetDlgItem(IDC_CHECK_RANGE);
	CButton WindowCheckbox = GetDlgItem(IDC_CHECK_WINDOW);

	m_dwFlags = 0;
	if (CodeCheckbox.GetCheck() == BST_CHECKED)
	{
		CodeCombo.GetWindowText(m_Code);
		if (!m_Code.IsEmpty())
			m_dwFlags |= RD_CODE;
	}
	if (IdCheckbox.GetCheck() == BST_CHECKED)
	{
		IdCombo.GetWindowText(m_ID);
		if (!m_ID.IsEmpty())
		{
			m_dwFlags |= RD_ID;
		}
	}
	if (RangeCheckbox.GetCheck() == BST_CHECKED)
	{
		RangeCombo.GetWindowText(m_Range);
		if (!m_Range.IsEmpty())
		{
			m_dwFlags |= RD_RANGE;
		}
	}
	if (WindowCheckbox.GetCheck() == BST_CHECKED)
	{
		WindowCombo.GetWindowText(m_Wnd);
		if (!m_Wnd.IsEmpty())
		{
			m_dwFlags |= RD_WND;
		}
	}
}

LRESULT CReflectionDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CenterWindow();
	CComboBox ReflectCombo = GetDlgItem(IDC_COMBO_REFLECTTYPE);
	ReflectCombo.AddString(_T("All"));
	for (size_t i = 0; i < m_sReflectMessages.GetCount(); ++i)
	{
		ReflectCombo.AddString(m_sReflectMessages[i]);
	}

	if (m_dwFlags & RD_MESSAGE)
	{
		ReflectCombo.SetCurSel(0);
	}else if (m_dwFlags & RD_COMMAND)
	{
		ReflectCombo.SetCurSel(1);
	}else if (m_dwFlags & RD_NOTIFY)
	{
		ReflectCombo.SetCurSel(2);
	}
	
	OnReflectTypeCbnSelchange(CBN_SELCHANGE, IDC_COMBO_REFLECTTYPE, NULL, bHandled);
	if (!m_ID.IsEmpty())
	{
		CComboBox IdCombo = GetDlgItem(IDC_COMBO_ID);
		CButton IdCheckBox = GetDlgItem(IDC_CHECK_ID);
		IdCheckBox.SetCheck(BST_CHECKED);
		OnIdBnClick(BN_CLICKED, IDC_CHECK_ID, NULL, bHandled);
		int Pos = IdCombo.FindString(-1, m_ID);
		if (Pos != CB_ERR)
		{
			IdCombo.SetCurSel(Pos);
		}
		ReflectCombo.EnableWindow(FALSE);
	}
	return 1;  // Let the system set the focus
}

LRESULT CReflectionDlg::OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	GetDataFromControls();
	CComboBox ReflectCombo = GetDlgItem(IDC_COMBO_REFLECTTYPE);
	int CurSel = ReflectCombo.GetCurSel();
	CString Message;
	ReflectCombo.GetLBText(CurSel, Message);
	
	if (Message == _T("WM_COMMAND"))
	{
		m_dwFlags |= RD_COMMAND;
	} else if (Message == _T("WM_NOTIFY"))
	{
		m_dwFlags |= RD_NOTIFY;
	} else if (Message == _T("All"))
	{
		if (!m_dwFlags)
		{
			CString str;
			str.LoadString(IDS_SIMPLE_REFLECT);
			MessageBox(str);
			return 0;
		}
		m_dwFlags |= RD_MESSAGE;
	} else
	{
		m_dwFlags |= RD_MESSAGE;
	}
	m_Message = Message;

	EndDialog(wID);
	return 0;
}

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

LRESULT CReflectionDlg::OnReflectTypeCbnSelchange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CComboBox ReflectCombo = GetDlgItem(IDC_COMBO_REFLECTTYPE);
	int CurSel = ReflectCombo.GetCurSel();
	CString Message;
	ReflectCombo.GetLBText(CurSel, Message);
	if (Message != _T("WM_COMMAND") &&
		Message != _T("WM_NOTIFY"))
	{
		// select all messages
		// not available notification code and range fields
		GetDlgItem(IDC_COMBO_CODE).EnableWindow(FALSE);
		GetDlgItem(IDC_CHECK_CODE).EnableWindow(FALSE);
		GetDlgItem(IDC_COMBO_CODE).SendMessage(CB_RESETCONTENT);

		CComboBox IdCombo = GetDlgItem(IDC_COMBO_ID);
		CComboBox RangeCombo = GetDlgItem(IDC_COMBO_RANGE);

		RangeCombo.EnableWindow(FALSE);
		GetDlgItem(IDC_CHECK_RANGE).EnableWindow(FALSE);

		GetDlgItem(IDC_CHECK_WINDOW).EnableWindow();
		OnWindowBnCkicked(BN_CLICKED, IDC_CHECK_WINDOW, NULL, bHandled);

		IdCombo.EnableWindow();
		OnIdBnClick(BN_CLICKED, IDC_CHECK_ID, NULL, bHandled);
		IdCombo.ResetContent();
		RangeCombo.ResetContent();
		for (size_t i = 0; i < m_CommandIds.GetCount(); ++i)
		{
			IdCombo.AddString(m_CommandIds[i]);
			RangeCombo.AddString(m_CommandIds[i]);
		}
		for (size_t i = 0; i < m_NotifyIds.GetCount(); ++i)
		{
			IdCombo.AddString(m_NotifyIds[i]);
			RangeCombo.AddString(m_NotifyIds[i]);
		}
	}
	else
	{
		// select command or notify messages
		// not available windows filtering
		GetDlgItem(IDC_CHECK_CODE).EnableWindow();
		OnCodeBnClicked(BN_CLICKED, IDC_CHECK_CODE, NULL, bHandled);
		if (Message == _T("WM_NOTIFY"))
		{
			CComboBox CodeCombo = GetDlgItem(IDC_COMBO_CODE);
			for (size_t i = 0; i < m_NotifyCodes.GetCount(); ++i)
			{
				CodeCombo.AddString(m_NotifyCodes[i]);
			}
			CComboBox IdCombo = GetDlgItem(IDC_COMBO_ID);
			CComboBox RangeCombo = GetDlgItem(IDC_COMBO_RANGE);
			IdCombo.ResetContent();
			RangeCombo.ResetContent();
			for (size_t i = 0; i < m_NotifyIds.GetCount(); ++i)
			{
				IdCombo.AddString(m_NotifyIds[i]);
				RangeCombo.AddString(m_NotifyIds[i]);
			}
		}
		if (Message == _T("WM_COMMAND"))
		{
			CComboBox CodeCombo = GetDlgItem(IDC_COMBO_CODE);
			for (size_t i = 0; i < m_CommandCodes.GetCount(); ++i)
			{
				CodeCombo.AddString(m_CommandCodes[i]);
			}
			CComboBox IdCombo = GetDlgItem(IDC_COMBO_ID);
			CComboBox RangeCombo = GetDlgItem(IDC_COMBO_RANGE);
			IdCombo.ResetContent();
			RangeCombo.ResetContent();
			for (size_t i = 0; i < m_CommandIds.GetCount(); ++i)
			{
				IdCombo.AddString(m_CommandIds[i]);
				RangeCombo.AddString(m_CommandIds[i]);
			}
		}

		GetDlgItem(IDC_CHECK_RANGE).EnableWindow();
		OnRangeBnClick(BN_CLICKED, IDC_CHECK_RANGE, NULL, bHandled);

		GetDlgItem(IDC_COMBO_WINDOW).EnableWindow(FALSE);
		GetDlgItem(IDC_CHECK_WINDOW).EnableWindow(FALSE);

		GetDlgItem(IDC_CHECK_ID).EnableWindow();
		OnIdBnClick(BN_CLICKED, IDC_CHECK_ID, NULL, bHandled);
	}
	
	return 0;
}

LRESULT CReflectionDlg::OnCodeBnClicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CButton CheckBox = GetDlgItem(wID);
	if (CheckBox.GetCheck() == BST_CHECKED)
	{
		GetDlgItem(IDC_COMBO_CODE).EnableWindow();
	}
	else
	{
		GetDlgItem(IDC_COMBO_CODE).SetWindowText(NULL);
		GetDlgItem(IDC_COMBO_CODE).EnableWindow(FALSE);
	}
	return 0;
}

LRESULT CReflectionDlg::OnIdBnClick(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CButton CheckBox = GetDlgItem(wID);
	if (CheckBox.GetCheck() == BST_CHECKED)
	{
		GetDlgItem(IDC_COMBO_ID).EnableWindow();
		CString Message;
		GetDlgItem(IDC_COMBO_REFLECTTYPE).GetWindowText(Message);
		if (Message == _T("WM_COMMAND") ||
			Message == _T("WM_NOTIFY"))
		{
			GetDlgItem(IDC_CHECK_RANGE).EnableWindow();
		}
		CButton WndCheckBox = GetDlgItem(IDC_CHECK_WINDOW);
		WndCheckBox.SetCheck(BST_UNCHECKED);
		OnWindowBnCkicked(BN_CLICKED, IDC_CHECK_WINDOW, NULL, bHandled);

		WndCheckBox.EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_COMBO_ID).SetWindowText(NULL);
		GetDlgItem(IDC_COMBO_ID).EnableWindow(FALSE);

		CButton RangeCheckBox = GetDlgItem(IDC_CHECK_RANGE);
		RangeCheckBox.SetCheck(BST_UNCHECKED);
		RangeCheckBox.EnableWindow(FALSE);
		OnRangeBnClick(BN_CLICKED, IDC_CHECK_RANGE, NULL, bHandled);

		CString Message;
		GetDlgItem(IDC_COMBO_REFLECTTYPE).GetWindowText(Message);
		if (Message != _T("WM_COMMAND") &&
			Message != _T("WM_NOTIFY"))
		{
			GetDlgItem(IDC_CHECK_WINDOW).EnableWindow();
		}
	}
	return 0;
}

LRESULT CReflectionDlg::OnRangeBnClick(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CButton CheckBox = GetDlgItem(wID);
	if (CheckBox.GetCheck() == BST_CHECKED)
	{
		GetDlgItem(IDC_COMBO_RANGE).EnableWindow();
	}
	else
	{
		GetDlgItem(IDC_COMBO_RANGE).SetWindowText(NULL);
		GetDlgItem(IDC_COMBO_RANGE).EnableWindow(FALSE);
	}
	return 0;
}

LRESULT CReflectionDlg::OnWindowBnCkicked(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CButton CheckBox = GetDlgItem(wID);
	if (CheckBox.GetCheck() == BST_CHECKED)
	{
		GetDlgItem(IDC_COMBO_WINDOW).EnableWindow();

		CButton IdCheckBox = GetDlgItem(IDC_CHECK_ID);
		IdCheckBox.SetCheck(BST_UNCHECKED);
		OnIdBnClick(BN_CLICKED, IDC_CHECK_ID, NULL, bHandled);

		IdCheckBox.EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_COMBO_WINDOW).SetWindowText(NULL);
		GetDlgItem(IDC_COMBO_WINDOW).EnableWindow(FALSE);

		CString Message;
		GetDlgItem(IDC_COMBO_REFLECTTYPE).GetWindowText(Message);
		if (Message != _T("WM_COMMAND") &&
			Message != _T("WM_NOTIFY"))
		{
			GetDlgItem(IDC_CHECK_ID).EnableWindow();
		}
	}
	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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Sergey Solozhentsev
Web Developer
Belarus Belarus
I am a software developer for 3 years.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 27 Aug 2007
Article Copyright 2004 by Sergey Solozhentsev
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid