Print Page | Close Window

CXTPControlCustom within customize dialog

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=1701
Printed Date: 07 November 2025 at 2:26pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTPControlCustom within customize dialog
Posted By: Green
Subject: CXTPControlCustom within customize dialog
Date Posted: 25 January 2005 at 11:35am

Hi! Is there any way to add CXTPControlCustom into the customize dialog? I try to do this using CommonControls sample but attempt was unsuccessful:

1. I try to add Slider control using toolbar as category:

CXTPCustomizeSheet dlg(pCommandBars);
CXTPCustomizeOptionsPage pageOptions(&dlg);
pPageCommands->AddToolbarCategory(_T("Slider"), IDR_SLIDERBAR);

Result: A dozen of assert occurs within MFC interior when customize dialog is called.

2. I try to add Slider control manually:

    CXTPControls* pOther = pPageCommands->InsertCategory(_T("Slider"));
    CXTPControlCustom* pControlSlider =   CXTPControlCustom::CreateControlCustom(&m_wndSlider);
    pOther->Add(pControlSlider, IDC_SLIDER);

Result: Customize dialog is shown successfully, but:
1) command in the Slider category is shown as some unknown icon
2) it is impossible add this command anywhere except menu
3) Access Violation error occurs, after you finish drag from customize dialog into menu.

With best  regards,
Green




Replies:
Posted By: Green
Date Posted: 26 January 2005 at 1:11am

>> 1) command in the Slider category is shown as some unknown icon
It's not unknown icon, but icon from toolbar sure

The 1-st method became partly successful. I add:

int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
{
    if (lpCreateControl->nID == IDC_SLIDER)
    {  
        if (m_wndSlider.m_hWnd == 0)
        {
             if (!m_wndSlider.Create(TBS_HORZ | WS_CHILD | WS_VISIBLE,
               CRect(0, 0, 200, 16), this, IDC_SLIDER))
             {
                return FALSE;
             }    
        }
        ........
        ........
        ........
    }
}

But it is possible to insert control into menu only. And it can't be removed from menu in the customize mode.
Can anybody help?








Posted By: Oleg
Date Posted: 31 January 2005 at 5:41am

Green, how do you see it?

Imagine you already have  m_wndSlider in toolbar and used drag another from

customize dialog, so it must be second  m_wndSlider with same handle?



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Ark42
Date Posted: 31 January 2005 at 11:58am

Here is a start, which I use, and is fully customizable and more or less seems to work the way it should:

.h file:

////////////////////////////////////////////////////////// ///////////////////
// CXTPSliderCtrl

class CXTPSliderCtrl : public CSliderCtrl
{
    DECLARE_DYNAMIC(CXTPSliderCtrl)
protected:
    afx_msg BOOL OnEraseBkgnd(CDC* pDC) { return FALSE; }
    afx_msg void OnPaint(void);
    DECLARE_MESSAGE_MAP()
};

////////////////////////////////////////////////////////// ///////////////////
// CXTPControlSlider

class CXTPControlSlider : public CXTPControlCustom
{
    DECLARE_XTP_CONTROL(CXTPControlSlider)

public:
    CXTPControlSlider();
    virtual void OnCalcDynamicSize(DWORD dwMode);
    virtual void Copy(CXTPControl* pControl, BOOL bRecursive = FALSE);
    virtual BOOL IsCustomizeDragOverAvail(CXTPCommandBar* pCommandBar, CPoint /*point*/, DROPEFFECT& dropEffect);
    int OnHookMessage(HWND hWnd, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& lResult);
    CXTPSliderCtrl *GetSliderCtrl(void) { return &m_wndSlider; }

protected:
    CWnd m_wndHookParent;
    CXTPSliderCtrl m_wndSlider;
};



.cpp file:

////////////////////////////////////////////////////////// ///////////////////
// CXTPSliderCtrl

IMPLEMENT_DYNAMIC(CXTPSliderCtrl, CSliderCtrl)

BEGIN_MESSAGE_MAP(CXTPSliderCtrl, CSliderCtrl)
    ON_WM_ERASEBKGND()
    ON_WM_PAINT()
END_MESSAGE_MAP()

void CXTPSliderCtrl::OnPaint(void)
{
    PAINTSTRUCT ps;
    CDC *pDC = BeginPaint(&ps);

    CRect rect;
    GetClientRect(&rect);
    CXTMemDC *memDC = new CXTMemDC(pDC, rect);

    DefWindowProc(WM_PAINT, (WPARAM)memDC->m_hDC, 0);

    CXTPPaintManager *pPaintMgr = static_cast<CXTPMDIFrameWnd *>(AfxGetMainWnd())-&g t;GetCommandBars()->GetPaintManager();

    if( GetStyle() & WS_DISABLED ) {
        COLORREF clr = pPaintMgr->GetXtremeColor(XPCOLOR_TOOLBAR_FACE);
        for( int y = rect.top; y < rect.bottom; y++ ) {
            for( int x = rect.left; x < rect.right; x++ ) {
                if( (x & 1) == (y & 1) ) {
                    memDC->SetPixel(x, y, clr);
                }
            }
        }
    }
    memDC->Draw3dRect(&rect, pPaintMgr->GetXtremeColo r(COLOR_BTNSHADOW), pPaintMgr->GetXtremeColor(COLOR_BTNH IGHLIGHT));

    delete memDC;

    EndPaint(&ps);
}

////////////////////////////////////////////////////////// ///////////////////
// CXTPControlSlider

#define SLIDER_WIDTH        400
#define SLIDER_HEIGHT        30
#define SLIDER_HEIGHTROT    34

IMPLEMENT_XTP_CONTROL(CXTPControlSlider, CXTPControlCustom)

CXTPControlSlider::CXTPControlSlider() : CXTPControlCustom()
{
    m_dwFlags = 0; //remove nomovable flag

    m_wndHookParent.Create(_T("STATIC"), "", WS_CHILD, CRect(0, 0, 0, 0), AfxGetMainWnd(), 0);

    m_wndSlider.Create(TBS_HORZ | WS_CHILD, CRect(0, 0, SLIDER_WIDTH, SLIDER_HEIGHT), &m_wndHookParent, 0);
    SetControl(&m_wndSlider);
    XTPHookManager()->SetHook(m_wndHookParent.GetSafeHwnd(), this);
}

void CXTPControlSlider::OnCalcDynamicSize(DWORD dwMode)
{
    if( dwMode & LM_VERTDOCK ) {
        m_wndSlider.SetWindowPos(NULL, 0, 0, SLIDER_HEIGHTROT, SLIDER_WIDTH, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
        m_wndSlider.ModifyStyle(TBS_HORZ, TBS_VERT|TBS_LEFT);
        m_szControl = CSize(SLIDER_HEIGHTROT, SLIDER_WIDTH);
    } else {
        m_wndSlider.SetWindowPos(NULL, 0, 0, SLIDER_WIDTH, SLIDER_HEIGHT, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
        m_wndSlider.ModifyStyle(TBS_VERT|TBS_LEFT, TBS_HORZ);
        m_szControl = CSize(SLIDER_WIDTH, SLIDER_HEIGHT);
    }
}

void CXTPControlSlider::Copy(CXTPControl* pControl, BOOL bRecursive)
{
    ASSERT(DYNAMIC_DOWNCAST(CXTPControlSlider, pControl));

    //avoid CXTPControlCustom copying m_pControlWnd
    CXTPControl::Copy(pControl, bRecursive);
}

BOOL CXTPControlSlider::IsCustomizeDragOverAvail(CXTPCommandBar* pCommandBar, CPoint /*point*/, DROPEFFECT& dropEffect)
{
    return TRUE;
}

int CXTPControlSlider::OnHookMessage(HWND hWnd, UINT nMessage, WPARAM& wParam, LPARAM& lParam, LRESULT& lResult)
{
    switch( nMessage ) {
    case WM_LBUTTONDOWN:
    case WM_LBUTTONUP:
        if( !IsCustomizeMode() ) {
            return FALSE;
        }
    case WM_RBUTTONDOWN:
    case WM_RBUTTONUP: {
        CPoint point(lParam);
        MapWindowPoints(hWnd, m_pParent->GetSafeHwnd(), &point, 1);
        GetParent()->SendMessage(nMessage, wParam, MAKELPARAM(point.x, point.y));
        return TRUE;
        break; }
    case WM_MOUSEMOVE: {
        CPoint point(lParam);
        MapWindowPoints(hWnd, m_pParent->GetSafeHwnd(), &point, 1);
        GetParent()->SendMessage(nMessage, wParam, MAKELPARAM(point.x, point.y));
        return FALSE;
        break; }
    case WM_HSCROLL:
    case WM_VSCROLL: {
        if( (HWND)lParam == m_wndSlider.GetSafeHwnd() ) {
            OnExecute();
            return TRUE;
        }
        break; }
    }
    return FALSE;
}




Posted By: Green
Date Posted: 01 February 2005 at 3:56am

Hello guys! Thank you for response.

To Oleg: You are right example is quite ugly. You can use another instance of control for the customize dialog and result will be the same (It is possible to insert control into menu only. And it can't be removed from menu in the customize mode.) Ark42's sample makes it more clear how to resolve problem.



Posted By: Green
Date Posted: 01 February 2005 at 5:07am

BTW, why does CXTPControlCustom::GetType() return xtpControlButton instead xtpControlCustom? In CommonControls sample add following line:

int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
{
    .........

    CXTPControlCustom* pControlAnimation = CXTPControlCustom::CreateControlCustom(&m_wndAnimCntrl);   
    XTPControlType type = pControlAnimation->GetType();

    .........
}

The result will be xtpControlButton. Is it a bug? (Or I don't understand something )



Posted By: Ark42
Date Posted: 01 February 2005 at 11:53am

Green: please post here to let me know if you improve upon this in any way. I use a lot of slider bars in my toolbars for some reason. It would be good to know if there are any significant bugs with this method of deriving from CXTPControlCustom.



Posted By: Green
Date Posted: 02 February 2005 at 2:42am

Hello Arc42! It was just reserch how it is easy to build-in this library into our product. We decide to purchase library at last. But project will start little bit later. So, if any issues appear I will post them here.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net