Click here to Skip to main content
15,881,172 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.8K   4.5K   81  
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.
#include "stdafx.h"
#include "../include/filedialog.h"
namespace xm{namespace ui{
UINT_PTR CALLBACK CxmFileDialog::OFNHookProc(HWND hdlg,UINT uiMsg,WPARAM wParam, LPARAM lParam)
{
	if(uiMsg==WM_INITDIALOG){
		/*
		HWND hWnd=GetParent(hdlg);
		HWND hWndParent=GetParent(hWnd);
		RECT rcMain,rc;
		::GetWindowRect(hWndParent,&rcMain);
		::GetWindowRect(hWnd,&rc);
		int x=rcMain.left+(rcMain.right-rcMain.left-(rc.right-rc.left))/2;
		int y=rcMain.top+(rcMain.bottom-rcMain.top-(rc.bottom-rc.top))/2;
		::SetWindowPos(hWnd,0,x,y,0,0,SWP_NOZORDER|SWP_NOSIZE);
		*/
		CWindow wnd=GetParent(hdlg);
		wnd.CenterWindow(wnd.GetParent());
		return TRUE;
	}
	return FALSE;
}

CxmFileDialog::CxmFileDialog(
			BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
			LPCTSTR lpszFilter,
			LPCTSTR lpszTitle,
			HWND hWndParent,
			LPCTSTR lpszDefExt,
			LPCTSTR lpszFileName,
			DWORD dwFlags
		)
{
	memset(&m_ofn, 0, sizeof(m_ofn)); // initialize structure to 0/NULL
	m_szFileName[0] = '\0';
	m_szFileTitle[0] = '\0';
	if(lpszTitle)
	{
		lstrcpy(m_szFileTitle,lpszTitle);
	}
	m_bOpenFileDialog = bOpenFileDialog;

	m_ofn.lStructSize = sizeof(m_ofn);
//	m_ofn.lStructSize = 88;
	
	m_ofn.lpstrTitle		= m_szFileTitle;//_T("ѡ��һ�������ļ�"); // Caption
	m_ofn.hwndOwner         = hWndParent;
	m_ofn.lpstrFile         = m_szFileName;
	m_ofn.nMaxFile          = MAX_PATH;
	m_ofn.lpstrInitialDir	= NULL;//_T("c:\\");
	m_ofn.lpstrFilter		= lpszFilter;
	m_ofn.lpfnHook			= (LPOFNHOOKPROC)OFNHookProc;
	//m_ofn.nFilterIndex      = 2;
	m_ofn.Flags             = dwFlags;//OFN_CREATEPROMPT | OFN_LONGNAMES |OFN_ENABLEHOOK|OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY ;//| OFN_OVERWRITEPROMPT|OFN_ENABLEHOOK|OFN_EXPLORER;//dwFlags;//
}
INT_PTR CxmFileDialog::DoModal(HWND hWndParent)
{
	if(m_ofn.hwndOwner == NULL)		// set only if not specified before
		m_ofn.hwndOwner = hWndParent;
	BOOL bRet;
	if(m_bOpenFileDialog)
		bRet = ::GetOpenFileName(&m_ofn);
	else
		bRet = ::GetSaveFileName(&m_ofn);

	return bRet ? IDOK : IDCANCEL;
}
}}//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