void CXTPSkinObjectFrame::UpdateFrameRegion(CSize szFrameRegion)
{
    if (m_bInUpdateRegion)
        return;

    m_bInUpdateRegion = TRUE;

    if (m_bRegionChanged && !HasCaption())
    {
        SetWindowRgn(NULL, TRUE);
        m_bRegionChanged = FALSE;
    }
//  DWORD dwStyle = GetStyle();

    if (HasCaption() && (m_szFrameRegion != szFrameRegion))
    {
        if (GetSkinManager()->IsEnabled() && GetSkinManager()->GetApplyOptions() & xtpSkinApplyFrame)
        {
            HRGN hRgn = GetSchema()->CalcFrameRegion(this, szFrameRegion);

            SetWindowRgn(hRgn, TRUE);
            m_bRegionChanged = TRUE;
        }
        else if (m_bRegionChanged)
        {
            SetWindowRgn(NULL, TRUE);
            m_bRegionChanged = FALSE;
        }

        m_szFrameRegion = szFrameRegion;
    }

    m_bInUpdateRegion = FALSE;
}
void CXTPSkinObjectFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
    UINT nCmd = (nID & 0xFFF0);

    if ((nCmd == SC_MAXIMIZE) && m_pManager->HasApplyOptions(xtpSkinApplyMetrics | xtpSkinApplyFrame) &&
            ((GetExStyle() & WS_EX_MDICHILD) == WS_EX_MDICHILD) &&
            ((GetStyle() & WS_MAXIMIZE) == 0))
    {
        CXTPSkinObject::OnSysCommand(nID, lParam);

        RECT rc;
        GetParent()->GetClientRect(&rc);
        int cx = rc.right - rc.left;
        int cy = rc.bottom - rc.top;

        rc.left = -m_rcBorders.left;
        rc.top = -m_rcBorders.top;
        rc.right = cx + m_rcBorders.right;
        rc.bottom = cy + m_rcBorders.bottom;

        MoveWindow(rc.left, rc.top,
                   rc.right - rc.left, rc.bottom - rc.top, TRUE);
        return;
    }

    if (HandleSysCommand(nID, lParam))
        return;

    if ((nCmd == SC_MOVE) && (GetStyle() & WS_MINIMIZE) && (GetSkinManager()->GetApplyOptions() & xtpSkinApplyFrame))
    {
        DoDefWindowProc(WM_NCPAINT, 0, 0);
        RedrawFrame();
    }


    CXTPSkinObject::OnSysCommand(nID, lParam);

    if ((nCmd == SC_MINIMIZE) && (GetSkinManager()->GetApplyOptions() & xtpSkinApplyFrame))
    {
        RedrawFrame();
    }
}
BOOL CXTPSkinObjectFrame::HandleSysCommand(UINT nID, LPARAM lParam)
{
    if ((GetSkinManager()->GetApplyOptions() & xtpSkinApplyMenus) == 0)
        return FALSE;

    UINT nCmd = (nID & 0xFFF0);

    if (nCmd == SC_MOUSEMENU)
    {
        return TRUE;
    }

    if (nCmd == SC_KEYMENU)
    {
        if ((GetStyle() & WS_CHILD )== 0)
            return TRUE;

        HWND hWnd = m_hWnd;

        while (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
        {
            if (GetWindowLong(hWnd, GWL_STYLE) & WS_SYSMENU)
                break;

            hWnd = ::GetParent(hWnd);
        }

        if (::GetMenu(hWnd) || (GetWindowLong(hWnd, GWL_STYLE) & WS_SYSMENU))
        {
            CXTPSkinObjectFrame* pFrame = (CXTPSkinObjectFrame*)GetSkinManager()->Lookup(hWnd);
            if (pFrame)
            {
                pFrame->HandleSysCommand(nID, lParam);
            }
        }

        return TRUE;
    }

    return FALSE;
}
HBRUSH CXTPSkinObjectFrame::GetClientBrush(HDC hDC, HWND hWnd, UINT nCtlColor)
{
	if (m_dwDialogTexture != ETDT_ENABLETAB)
	{
		GrayCtlColor(hDC, hWnd, nCtlColor, GetMetrics()->m_brushDialog, GetColor(COLOR_BTNTEXT));
		return GetMetrics()->m_brushDialog;
	}

	if (GetMetrics()->m_brushTabControl == NULL)
	{
		CWindowDC dcWindow(this);

		CXTPSkinManagerClass* pClass = GetSkinManager()->GetSkinClass(this, _T("TAB"));

		CString strImageFile = pClass->GetThemeString(TABP_BODY, 0, TMT_STOCKIMAGEFILE);
		if (strImageFile.IsEmpty())
		{
			return GetMetrics()->m_brushDialog;
		}

		CXTPSkinImage* pImage = pClass->GetImages()->LoadFile(m_pManager->GetResourceFile(), strImageFile);

		if (!pImage)
		{
			return GetMetrics()->m_brushDialog;
		}

		CRect rc(0, 0, pImage->GetWidth(), pImage->GetHeight());

		CBitmap bmp;
		bmp.CreateCompatibleBitmap(&dcWindow, rc.Width(), rc.Height());

		CXTPCompatibleDC dc(&dcWindow, bmp);

		pImage->DrawImage(&dc, rc, rc, CRect(0, 0, 0, 0), COLORREF_NULL, ST_TRUESIZE, FALSE);

		GetMetrics()->m_brushTabControl = ::CreatePatternBrush(bmp);
	}


	if (hWnd != m_hWnd)
	{
		CXTPWindowRect rcPaint(hWnd);
		CXTPWindowRect rcBrush(m_hWnd);
		::SetBrushOrgEx(hDC, rcBrush.left - rcPaint.left, rcBrush.top - rcPaint.top, NULL);

		::SetBkMode(hDC, TRANSPARENT);
		::SetTextColor(hDC, GetColor(COLOR_BTNTEXT));
	}

	return GetMetrics()->m_brushTabControl;

}
int CXTPSkinObjectTreeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CXTPSkinObjectFrame::OnCreate(lpCreateStruct) == -1)
		return -1;

	if (GetSkinManager()->IsEnabled())
	{
		SendMessage(TVM_SETBKCOLOR, 0, GetColor(COLOR_WINDOW));
		SendMessage(TVM_SETTEXTCOLOR, 0, GetColor(COLOR_WINDOWTEXT));
	}

	return 0;
}
void CXTPSkinObjectFrame::DrawFrame(CDC* pDC)
{
    if (m_bLockFrameDraw)
        return;

    CXTPWindowRect rc(this);
    rc.OffsetRect(-rc.TopLeft());

    GetSchema()->DrawThemeFrame(pDC, this);

    if (m_spi[SB_VERT].fVisible || m_spi[SB_HORZ].fVisible)
    {
        if (m_spi[SB_VERT].fVisible)
        {
            if (!m_pSBTrack || !m_pSBTrack->bTrackThumb)
                SetupScrollInfo(&m_spi[SB_VERT]);

            CXTPBufferDCEx dcMem(*pDC, m_spi[SB_VERT].rc);
            DrawScrollBar(&dcMem, &m_spi[SB_VERT]);
        }

        if (m_spi[SB_HORZ].fVisible)
        {
            if (!m_pSBTrack || !m_pSBTrack->bTrackThumb)
                SetupScrollInfo(&m_spi[SB_HORZ]);

            CXTPBufferDCEx dcMem(*pDC, m_spi[SB_HORZ].rc);
            DrawScrollBar(&dcMem, &m_spi[SB_HORZ]);
        }

        if (m_spi[SB_HORZ].fVisible && m_spi[SB_VERT].fVisible)
        {
            CRect rcSizeGripper(m_spi[SB_HORZ].rc.right, m_spi[SB_VERT].rc.bottom,
                                m_spi[SB_VERT].rc.right, m_spi[SB_HORZ].rc.bottom);

            if (GetExStyle() & WS_EX_LEFTSCROLLBAR)
            {
                rcSizeGripper.left = m_spi[SB_VERT].rc.left;
                rcSizeGripper.right = m_spi[SB_HORZ].rc.left;
            }

            pDC->FillSolidRect(rcSizeGripper, GetSchema()->GetScrollBarSizeBoxColor(this));

            if (IsSizeBox())
            {
                CXTPSkinManagerClass* pClassScrollBar = GetSkinManager()->GetSkinClass(this, _T("SCROLLBAR"));
                pClassScrollBar->DrawThemeBackground(pDC, SBP_SIZEBOX, SZB_RIGHTALIGN, rcSizeGripper);
            }
        }
    }
}
LRESULT CXTPSkinObjectFrame::OnSetText(WPARAM wParam, LPARAM lParam)
{
    if (((GetStyle() & WS_CAPTION) == WS_CAPTION) && (GetSkinManager()->GetApplyOptions() & xtpSkinApplyFrame))
    {
        LRESULT lRet = DefWindowProc(WM_SETTEXT, wParam, lParam);

        RedrawFrame();

        if ((GetExStyle() & WS_EX_MDICHILD) && (GetStyle() & (WS_MAXIMIZE | WS_CHILD)) == (WS_MAXIMIZE | WS_CHILD))
        {
            CWnd* pWnd = GetTopLevelParent();
            pWnd->SendMessage(WM_NCPAINT, 0, 0);
        }

        return lRet;
    }

    return Default();
}
void CXTPSkinObjectFrame::RefreshFrameStyle()
{
    if ((GetSkinManager()->GetApplyOptions() & xtpSkinApplyFrame) == 0)
        return;

    m_bLockFrameDraw++;
    DWORD dwStyle = GetStyle();
    DWORD dwStyleRemove = (WS_DLGFRAME | WS_VSCROLL | WS_HSCROLL);

    if (dwStyle & dwStyleRemove)
    {
        SetWindowLong(m_hWnd, GWL_STYLE, dwStyle & ~dwStyleRemove);

        RECT rc = CXTPWindowRect(this);
        SendMessage(WM_NCCALCSIZE, FALSE, (LPARAM)&rc);

        SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);
    }
    m_bLockFrameDraw--;
}
BOOL CXTPSkinObjectToolBar::IsAlphaImageList(HIMAGELIST himl)
{
	if (!GetSkinManager()->IsComCtlV6())
		return FALSE;

	BOOL bAlpha = FALSE;
	if (m_mapAlphaImageList.Lookup(himl, bAlpha))
		return bAlpha;

	m_mapAlphaImageList[himl] = FALSE;

	IMAGEINFO ii;
	if (!ImageList_GetImageInfo(himl, 0, &ii))
		return FALSE;

	BITMAP bmp;
	GetObject(ii.hbmImage, sizeof(bmp), &bmp);

	if (bmp.bmBitsPixel != 32)
		return FALSE;

	COLORREF clr = ImageList_GetBkColor(himl);

	if (clr != 0xFFFFFFFF)
		return FALSE;

	LPBYTE pBitsI = NULL;
	bAlpha = -1;

	HBITMAP hBitmap = CXTPImageManagerIcon::PreMultiplyAlphaBitmap(ii.hbmImage, &bAlpha, &pBitsI);

	BOOL bResult = (bAlpha == TRUE) && pBitsI;

	if (hBitmap) DeleteObject(hBitmap);

	m_mapAlphaImageList[himl] = bResult;
	return bResult;
}
void CXTPSkinObjectTab::FillTabFace(CDC* pDC, CRect rcItem, int iItem, int iCount, BOOL bSelected)
{
	if (GetStyle() & TCS_BUTTONS)
	{
		CXTPSkinManagerClass* pClassButton = GetSkinManager()->GetSkinClass(this, _T("BUTTON"));
		int nState = bSelected? PBS_PRESSED: PBS_NORMAL;
		pClassButton->DrawThemeBackground(pDC, BP_PUSHBUTTON, nState, rcItem);
		return;
	}

	if (bSelected)
	{
		rcItem.InflateRect(2, 2, 2, 2);
	}

	CXTPSkinManagerClass* pClass = GetSkinClass();

	int nStateId = bSelected ? TIS_SELECTED: m_nHotItem == iItem ? TIS_HOT : TIS_NORMAL;

	pClass->DrawThemeBackground(pDC, iItem == 0 ? TABP_TOPTABITEMLEFTEDGE :
		iItem == iCount - 1 && !bSelected ? TABP_TOPTABITEMRIGHTEDGE : TABP_TOPTABITEM,
		nStateId, &rcItem);
}
void CXTPSkinObjectSpin::OnDraw(CDC* pDC)
{

	CRect rcClient;
	GetClientRect(&rcClient);

	CXTPBufferDC dcMem(*pDC, rcClient);

	DWORD dwStyle = GetStyle();

	int nLower = 0, nUpper = 0;
	SendMessage(UDM_GETRANGE32, (WPARAM) &nLower, (LPARAM) &nUpper);
	BOOL bEnabled = (nUpper != nLower) && IsWindowEnabled();
	HWND hWndBuddy = (HWND)SendMessage(UDM_GETBUDDY);

	if (hWndBuddy && bEnabled && !::IsWindowEnabled(hWndBuddy))
		bEnabled = FALSE;

	dcMem.FillSolidRect(rcClient, GetColor(COLOR_3DFACE));


	CRect rcBtn = rcClient;

	CXTPSkinManagerClass* pClassSpin = GetSkinClass();


	if (hWndBuddy && GetWindowLong(hWndBuddy, GWL_EXSTYLE) & WS_EX_CLIENTEDGE)
	{
		dcMem.FillSolidRect(rcClient, GetColor(COLOR_WINDOW));

		if (dwStyle & UDS_ALIGNRIGHT)
		{
			rcBtn.DeflateRect(0, 1, 1, 1);

			CXTPSkinManagerClass* pClassEdit = GetSkinManager()->GetSkinClass(this, _T("EDIT"));
			COLORREF clrBorderColor = pClassEdit->GetThemeColor(0, 0, TMT_BORDERCOLOR);
			dcMem.Draw3dRect(rcClient, clrBorderColor, clrBorderColor);
			dcMem.FillSolidRect(rcClient.left, rcClient.top + 1, 1, rcClient.Height() - 2, GetColor(COLOR_WINDOW));
		}
		else if (dwStyle & UDS_ALIGNLEFT)
		{
			rcBtn.DeflateRect(1, 1, 0, 1);

			CXTPSkinManagerClass* pClassEdit = GetSkinManager()->GetSkinClass(this, _T("EDIT"));
			COLORREF clrBorderColor = pClassEdit->GetThemeColor(0, 0, TMT_BORDERCOLOR);
			dcMem.Draw3dRect(rcClient, clrBorderColor, clrBorderColor);
			dcMem.FillSolidRect(rcClient.right - 1, rcClient.top + 1, 1, rcClient.Height() - 2, GetColor(COLOR_WINDOW));
		}
	}

	RECT rc = rcBtn;

	if (dwStyle & UDS_HORZ)
	{
		int nState = DNHZS_NORMAL;
		if (!bEnabled)
			nState = DNHZS_DISABLED;
		else if (m_nPressedButton == UD_HITDOWN && m_nHotButton == UD_HITDOWN)
			nState = DNHZS_PRESSED;
		else if ((m_nHotButton == UD_HITDOWN || m_nPressedButton == UD_HITDOWN)  && (m_nPressedButton != UD_HITUP))
			nState = DNHZS_HOT;

		rc.right = (rcBtn.right + rcBtn.left) / 2;
		pClassSpin->DrawThemeBackground(&dcMem, SPNP_DOWNHORZ, nState, &rc);


		nState = UPHZS_NORMAL;
		if (!bEnabled)
			nState = UPHZS_DISABLED;
		else if (m_nPressedButton == UD_HITUP && m_nHotButton == UD_HITUP)
			nState = UPHZS_PRESSED;
		else if ((m_nHotButton == UD_HITUP || m_nPressedButton == UD_HITUP) && (m_nPressedButton != UD_HITDOWN))
			nState = UPHZS_HOT;

		rc.left = rcBtn.right - (rc.right - rc.left); // handles odd-x case, too
		rc.right = rcBtn.right;
		pClassSpin->DrawThemeBackground(&dcMem, SPNP_UPHORZ, nState, &rc);

	}
	else
	{
		int nState = UPS_NORMAL;
		if (!bEnabled)
			nState = UPS_DISABLED;
		else if (m_nPressedButton == UD_HITUP && m_nHotButton == UD_HITUP)
			nState = UPS_PRESSED;
		else if ((m_nHotButton == UD_HITUP || m_nPressedButton == UD_HITUP) && (m_nPressedButton != UD_HITDOWN))
			nState = UPS_HOT;

		rc.bottom = (rcBtn.bottom + rcBtn.top) / 2;

		pClassSpin->DrawThemeBackground(&dcMem, SPNP_UP, nState, &rc);

		nState = DNS_NORMAL;
		if (!bEnabled)
			nState = DNS_DISABLED;
		else if (m_nPressedButton == UD_HITDOWN && m_nHotButton == UD_HITDOWN)
			nState = DNS_PRESSED;
		else if ((m_nHotButton == UD_HITDOWN || m_nPressedButton == UD_HITDOWN)  && (m_nPressedButton != UD_HITUP))
			nState = DNS_HOT;

		rc.top = rcBtn.bottom - (rc.bottom - rc.top); // handles odd-y case, too
		rc.bottom = rcBtn.bottom;
		pClassSpin->DrawThemeBackground(&dcMem, SPNP_DOWN, nState, &rc);
	}
}