Click here to Skip to main content
15,885,278 members
Articles / Desktop Programming / WTL

A fast and lightweight cell control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (31 votes)
11 Mar 2008CPOL1 min read 90.9K   4.5K   81  
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.
#pragma once
#include "ResourcelessDlg.h"
namespace xm{namespace ui{
	class CInputDialog : public CResourcelessDlg<CInputDialog>
	{
		typedef CResourcelessDlg<CInputDialog> baseWnd;
		enum{_XM_IDC_EDITINPUT=101,_XM_IDC_STATIC1,_XM_IDC_STATIC2};
	public:
		CInputDialog(LPCTSTR lpszInitText=NULL)
			:m_sInputText(lpszInitText)
		{
		}
		BEGIN_MSG_MAP(CInputDialog)
			MESSAGE_HANDLER(WM_INITDIALOG,OnInitDialog)
			COMMAND_HANDLER(IDOK,BN_CLICKED,OnCloseButton)
			COMMAND_HANDLER(IDCANCEL,BN_CLICKED,OnCloseButton)
		END_MSG_MAP()

		// Dialog function
		void CreateDlg()
		{
			// Start generated dialog
			CreateDlgTemplate(_T("Input"), DS_SETFONT|DS_MODALFRAME|WS_POPUP|WS_CAPTION|WS_SYSMENU, 0, 0, 0, 186, 83, 9, _T("����"), _T(""), _T(""));
			AddStatic(_T("STATIC1"), 0, 0, 24, 3, 153, 11, _XM_IDC_STATIC1);
			AddStatic(_T("STATIC2"), 0, 0, 7, 25, 54, 8, _XM_IDC_STATIC2);
			AddEditBox(_T(""), ES_AUTOHSCROLL | WS_BORDER, 0, 7, 36, 172, 13, _XM_IDC_EDITINPUT);
			AddButton(_T("OK"), BS_NOTIFY|BS_DEFPUSHBUTTON, 0, 68, 57, 52, 14, IDOK);
			AddButton(_T("Cancel"), BS_NOTIFY, 0, 127, 57, 52, 14, IDCANCEL);
			// End generated dialog
		}
		LRESULT  OnInitDialog(UINT,WPARAM, LPARAM,BOOL&)
		{
			SetWindowText(m_sCaption);
			//btnok_=GetDlgItem(IDOK); btncancel_=GetDlgItem(IDCANCEL);
			CStatic st1=GetDlgItem(_XM_IDC_STATIC1);
			st1.SetWindowText(m_sText1);
			CStatic st2=GetDlgItem(_XM_IDC_STATIC2);
			st2.SetWindowText(m_sText2);
			m_pEdit=GetDlgItem(_XM_IDC_EDITINPUT);
			if(m_sInputText.GetLength()){
				m_pEdit.SetWindowText(m_sInputText);
				m_pEdit.SetSel(0,-1);
			}
			::SetFocus(GetDlgItem(_XM_IDC_EDITINPUT));
			GotoDlgCtrl(GetDlgItem(_XM_IDC_EDITINPUT));
			CenterWindow();
			return 1;
		}
		
		LRESULT	OnCloseButton(UINT, int nID, HWND hWndCtrl, BOOL& bHandled)
		{
			if(IDOK==nID)
			{
				TCHAR text[500];
				m_pEdit.GetWindowText(text,500);
				m_sInputText=text;
				if(m_sInputText.IsEmpty())
				{
					::MessageBox(m_hWnd,"Can not input an empty string!","error",MB_OK|MB_ICONERROR);
					return 1;
				}
			}
			EndDialog(nID);
			return 1;
		}
		int DoModal(HWND hParent, LPCTSTR Caption, LPCTSTR Text1, LPCTSTR Text2)
		{
			m_sCaption=Caption;
			m_sText1=Text1;
			m_sText2=Text2;
			return baseWnd::DoModal(hParent);
		}

		CString GetInputText()
		{
			return m_sInputText;
		}
		
	protected:
		CString m_sCaption,m_sText1,m_sText2,m_sInputText;
		CEdit m_pEdit;
	};
}}//namespace xm::ui

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 Code Project Open License (CPOL)


Written By
Web Developer
China China
My name is Yanxueming,i live in Chengdu China.Graduated from UESTC in 1999.

Comments and Discussions