CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2009
    Posts
    23

    Question Code for slider control - how to ...

    Hello everybody,

    attached i send you a simplified code (VISUAL C++ 6.0) about the slider control ..... It shows the problem discussed with you in the previous posts ...

    A snippet follows about the unresolved problem. It refers to a dialg with only one CSlider control.

    The only aim of the slider is to choose values in the a range.


    IMPLEMENTATION

    THE OnHScroll function do some actions, in this example sends the string "0".

    THE OnMouseWheel function sends the strings "1" or "2".


    As you know in this situation the OnMouseWheel never wil be executed !!. It will be executed only and only the
    OnHScroll function.


    How is it possible do indipendent the two functions ?


    In other words, the slider is there only to select values. Every time a value has been selected i must give the possibility to use the scrolling mouse ring to do other operations.

    NOTE: there is a way to disconnect the mouse actions from OnHScroll ... it is to use EnableWindow(FALSE) inside the OnHScroll .... but ths works on for a time.



    THANKS IN ADVANCE FOR YOUR HELP !

    Vincenzo




    Code:
    // SliderControlDlg.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "SliderControl.h"
    #include "SliderControlDlg.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CSliderControlDlg dialog
    
    CSliderControlDlg::CSliderControlDlg(CWnd* pParent /*=NULL*/)
    	: CDialog(CSliderControlDlg::IDD, pParent)
    {
    	//{{AFX_DATA_INIT(CSliderControlDlg)
    		// NOTE: the ClassWizard will add member initialization here
    	//}}AFX_DATA_INIT
    	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }
    
    void CSliderControlDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CSliderControlDlg)
    		// NOTE: the ClassWizard will add DDX and DDV calls here
    	//}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CSliderControlDlg, CDialog)
    	//{{AFX_MSG_MAP(CSliderControlDlg)
    	ON_WM_PAINT()
    	ON_WM_QUERYDRAGICON()
    	ON_WM_HSCROLL()
    	ON_WM_MOUSEWHEEL()
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    
    
    
    
    /////////////////////////////////////////////////////////////////////////////
    // CSliderControlDlg message handlers
    
    BOOL CSliderControlDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// Set the icon for this dialog.  The framework does this automatically
    	//  when the application's main window is not a dialog
    	SetIcon(m_hIcon, TRUE);			// Set big icon
    	SetIcon(m_hIcon, FALSE);		// Set small icon
    	
    	// TODO: Add extra initialization here
    
    
    	
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }
    
    // If you add a minimize button to your dialog, you will need the code below
    //  to draw the icon.  For MFC applications using the document/view model,
    //  this is automatically done for you by the framework.
    
    void CSliderControlDlg::OnPaint() 
    {
    	if (IsIconic())
    	{
    		CPaintDC dc(this); // device context for painting
    
    		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
    
    		// Center icon in client rectangle
    		int cxIcon = GetSystemMetrics(SM_CXICON);
    		int cyIcon = GetSystemMetrics(SM_CYICON);
    		CRect rect;
    		GetClientRect(&rect);
    		int x = (rect.Width() - cxIcon + 1) / 2;
    		int y = (rect.Height() - cyIcon + 1) / 2;
    
    		// Draw the icon
    		dc.DrawIcon(x, y, m_hIcon);
    	}
    	else
    	{
    		CDialog::OnPaint();
    	}
    }
    
    // The system calls this to obtain the cursor to display while the user drags
    //  the minimized window.
    HCURSOR CSliderControlDlg::OnQueryDragIcon()
    {
    	return (HCURSOR) m_hIcon;
    }
    
    
    
    
    
    
    
    
    
    void CSliderControlDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
    {
    	// TODO: Add your message handler code here and/or call default
    	
    
    	MessageBox("0");	
    
    	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
    
    }
    
    
    
    BOOL CSliderControlDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
    {
    	
    	// TODO: Add your message handler code here and/or call default
    
    
    	if(zDelta == -120)		{MessageBox("1");}
    				
    	if(zDelta ==  120)		{MessageBox("2");}
    
    
    	return CDialog::OnMouseWheel(nFlags, zDelta, pt);
    
    }

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Code for slider control - how to ...

    I can appreciate that English is probably not your native language, but it is still very hard to figure out what you are asking. I might suggest you look at the PreTranslateMessage() override of either your CDialog derived class, or your CSliderCtrl derived class. You can override the default message routing in that function.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured