Click here to Skip to main content
11,492,523 members (59,266 online)
Click here to Skip to main content
Add your own
alternative version

Owner Drawn ListViews In WTL

, 26 Jun 2004 55.7K 3.7K 32
An overview of handling owner drawn listview controls in WTL.
// MainDlg.cpp : implementation of the CMainDlg class

#include "stdafx.h"
#include "resource.h"

#include "aboutdlg.h"
#include "MainDlg.h"

BOOL CMainDlg::PreTranslateMessage(MSG* pMsg)
	return IsDialogMessage(pMsg);

BOOL CMainDlg::OnIdle()
	return FALSE;

LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	// center the dialog on the screen

	// set icons
	HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
		IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
	SetIcon(hIcon, TRUE);
	HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME), 
	SetIcon(hIconSmall, FALSE);

	// register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	m_lvwDemoListViewCtrl.SubclassWindow(GetDlgItem(IDC_LIST1)); // ADDED
	m_lvwDemoListViewCtrl.ForceMeasureItemMessage(); // ADDED

	for(int n = 0; n < 20; n++) // ADDED
		m_lvwDemoListViewCtrl.AddItem(n, 0, 0); // ADDED

	for(n = 0; n < 20; n++) // ADDED
		m_lvwDemoListViewCtrl.AddColumn(_T("col"), n); // ADDED

	return TRUE;

LRESULT CMainDlg::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	CAboutDlg dlg;
	return 0;

LRESULT CMainDlg::OnOK(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	// TODO: Add validation code 
	return 0;

LRESULT CMainDlg::OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	return 0;

void CMainDlg::CloseDialog(int nVal)
	m_lvwDemoListViewCtrl.UnsubclassWindow(); // ADDED


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.


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

Mark Petrik

United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 27 Jun 2004
Article Copyright 2004 by Mark Petrik
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid