Click here to Skip to main content
15,891,473 members
Articles / Desktop Programming / MFC

Plug-In framework using DLLs

Rate me:
Please Sign up or sign in to vote.
4.84/5 (39 votes)
25 Jun 200211 min read 311K   8.7K   226  
Explains how to develop applications that support plug-ins
// ListCtrlEx.cpp : implementation file
//

#include "stdafx.h"
#include "PlugSDI.h"
#include "ListCtrlEx.h"

// CListCtrlEx
IMPLEMENT_DYNAMIC(CListCtrlEx, CListCtrl)
CListCtrlEx::CListCtrlEx()
{
}

CListCtrlEx::~CListCtrlEx()
{
}

BEGIN_MESSAGE_MAP(CListCtrlEx, CListCtrl)
	ON_WM_PAINT()
	ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
END_MESSAGE_MAP()

// CListCtrlEx message handlers
void CListCtrlEx::OnPaint()
{
	// TODO: Add your message handler code here
	// Do not call CListCtrl::OnPaint() for painting messages

	Default();

	if (GetItemCount() <= 0)
    {
        COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);
        COLORREF clrTextBk = ::GetSysColor(COLOR_WINDOW);

        CDC* pDC = GetDC();
        // Save dc state
        int nSavedDC = pDC->SaveDC();

        CRect rc;
//        GetWindowRect(&rc);
  //      ScreenToClient(&rc);
		GetClientRect(&rc);

        CHeaderCtrl* pHC;
        pHC = GetHeaderCtrl();
        if (pHC != NULL)
        {
            CRect rcH;
            pHC->GetItemRect(0, &rcH);
            rc.top += rcH.bottom;
        }
        rc.top += 10;

        CString strText((LPCSTR)"No Plug-Ins (*.PLX) found"); // The message you want!

        pDC->SetTextColor(clrText);
        pDC->SetBkColor(clrTextBk);
		CBrush cbrTextbk(clrTextBk);
        pDC->FillRect(rc, &cbrTextbk);
        pDC->SelectStockObject(ANSI_VAR_FONT);
        pDC->DrawText(strText, -1, rc, 
                      DT_CENTER | DT_WORDBREAK | DT_NOPREFIX | DT_NOCLIP);

        // Restore dc
        pDC->RestoreDC(nSavedDC);
        ReleaseDC(pDC);
    }
}

void CListCtrlEx::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
//	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: Add your control notification handler code here

	LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR;

    switch(lplvcd->nmcd.dwDrawStage)
	{
		// Request prepaint notifications for each item.
		case CDDS_PREPAINT:
			*pResult = CDRF_NOTIFYITEMDRAW;
			break;

		// Requested notification
		case CDDS_ITEMPREPAINT:
			if(lplvcd->nmcd.dwItemSpec % 2)
			{
				// Black
				lplvcd->clrText = RGB(0, 0, 0);
				// Yellow
				lplvcd->clrTextBk = RGB(125, 255, 125);
			}
			*pResult = CDRF_DODEFAULT;
			break;
	}
}

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


Written By
Web Developer
India India
Living in New Delhi (India). Did my Engg (Comp. Science) in 2000, and since then working on and off with VC++. It's my passion, and would really love to learn it to the very detail. Presently working as a software engg in a Telecom based firm. I've got around 3yrs experience in NMS (network management systems). Well thats all about me for now. Feel free to contact me...

Comments and Discussions