본문 바로가기

Windows/MFC

CHeaderCtrl Skin image

[code]// HeaderCtrlEx.cpp : implementation file
//

// NOTE : July 28, 2006
// --------------------------------------------------------------------
// * 머랄까.. 흠. -_-; 간당 간당.. 정말 ㅋㅋㅋ 운좋게 찾는 경우도있고..
// 밑거름이 될 진 모르겠지만.. 혼자하니 겁나 어렵3 -_-;

#include "stdafx.h"
#include "SMS_WIZARD.h"
#include "HeaderCtrlEx.h"
#include "memdc.h"                // double buffering
#include "Common.h"


// CHeaderCtrlEx

IMPLEMENT_DYNAMIC(CHeaderCtrlEx, CHeaderCtrl)

CHeaderCtrlEx::CHeaderCtrlEx()
{

}

CHeaderCtrlEx::~CHeaderCtrlEx()
{
}


BEGIN_MESSAGE_MAP(CHeaderCtrlEx, CHeaderCtrl)
    ON_WM_ERASEBKGND()
    ON_WM_PAINT()
    ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CHeaderCtrlEx::OnNMCustomdraw)
    ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()



// CHeaderCtrlEx message handlers



BOOL CHeaderCtrlEx::OnEraseBkgnd(CDC* pDC)
{
    return true;
    //return CHeaderCtrl::OnEraseBkgnd(pDC);
}

void CHeaderCtrlEx::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    
    CRect rect, rectItem, clientRect;
    GetClientRect(&rect);
    GetClientRect(&clientRect);
    CMemDC mDC(&dc, &rect);

    CBitmap bmpLeft;
    CBitmap bmpCenter;
    CBitmap bmpRight;
    
    CDC bitmapDC;
    bitmapDC.CreateCompatibleDC(&dc);

    bmpLeft.LoadBitmap(IDB_LISTBG_LEFT);
    bmpCenter.LoadBitmap(IDB_LISTBG_CENTER);
    bmpRight.LoadBitmap(IDB_LISTBG_RIGHT);
    
    int nItems = GetItemCount();
    int i;
    
    CFont font;
    LOGFONT lf;
    memset(&lf, 0, sizeof(LOGFONT));
    lf.lfHeight = 13;
    wsprintf(lf.lfFaceName, L"Tahoma");
    font.CreateFontIndirect(&lf);
    CFont* def_font = mDC.SelectObject(&font);
    mDC.SetBkMode(TRANSPARENT);

    for (i=0; i<nItems; ++i)
    {
        wchar_t wszBuff[256];
        CBitmap* pOldBitmap = NULL;
        HD_ITEM hdItem;

        hdItem.mask            = HDI_TEXT | HDI_FORMAT | HDI_ORDER;
        hdItem.pszText        = wszBuff;
        hdItem.cchTextMax    = 255;
        GetItem(i, &hdItem);
        GetItemRect(i, &rect);
        
        // 첫 번째 [ 이미지
        if(hdItem.iOrder == 0)
        {
            pOldBitmap = bitmapDC.SelectObject(&bmpLeft);
            mDC.BitBlt(rect.left, rect.top, 8, 19, &bitmapDC, 0, 0, SRCCOPY);
        }
        else if (nItems-1 == i)
        {
            pOldBitmap = bitmapDC.SelectObject(&bmpCenter);
            mDC.BitBlt(rect.left-1,rect.top,1,19,&bitmapDC,0,0,SRCCOPY);
        }
        else
        {
            pOldBitmap = bitmapDC.SelectObject(&bmpLeft);
            mDC.BitBlt(rect.left,rect.top,8,19,&bitmapDC,0,0,SRCCOPY);
        //    pOldBitmap = bitmapDC.SelectObject(&bmpCenter);
        //    mDC.BitBlt(rect.left,rect.top,1,19,&bitmapDC,0,0,SRCCOPY);
        }
        bitmapDC.SelectObject(pOldBitmap);

        // 두번째 = 이미지
        int nWidth = rect.Width();// - 16;
        CBitmap* pOldBitmap2 = bitmapDC.SelectObject(&bmpCenter);
        mDC.StretchBlt(rect.left+8, 0, nWidth, 19, &bitmapDC, 0,0, 1, 19, SRCCOPY);
        bitmapDC.SelectObject(pOldBitmap2);

        // 세번째 ] 이미지
        CBitmap* pOldBitmap3 = bitmapDC.SelectObject(&bmpRight);
        mDC.BitBlt((rect.right-8), 0, 8, 19, &bitmapDC,0,0,SRCCOPY);
        bitmapDC.SelectObject(pOldBitmap3);

        // 글내 텍스트
        DRAWITEMSTRUCT    DrawItemStruct;
        GetItemRect(i, &rectItem);
        UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_TOP |DT_CENTER | DT_END_ELLIPSIS ;        
        rectItem.DeflateRect(2,2,2,2);
        mDC.DrawText(wszBuff, &rectItem, uFormat);        
    }
    mDC.SelectObject(def_font);
    font.DeleteObject();
}
[/code]

'Windows > MFC' 카테고리의 다른 글

Current icon image types (Icon type 종류별 선택)  (0) 2013.10.02
CComboBox Ownerdraw combobox(skin)  (0) 2013.10.02
CListCtrl Changing color of gridlines in a listctrl  (0) 2013.10.02
CustomDraw ListView  (0) 2013.10.02
NM_CUSTOMDRAW (LISTCTRL)  (0) 2013.10.02