Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

handling slider control messages

Posted on 2005-04-06
19
Medium Priority
?
3,199 Views
Last Modified: 2013-11-20
Hi,

I am having an MFC - SDI application. I added a slider control to the main window (not in a dialog). Actually I wanted to add it to a toolbar.

I did add it to a toolbar, but when I add it to a toolbar I cannot receive WM_HSCROLL events when the slider is moved.

The nature of problem is as below.

I created a slider like this in the main window (child of CFrameWnd)

m_transpSlider = new CSliderCtrl();
m_transpSlider->Create(TBS_HORZ, CRect(310, 2, 410, 22), this, 1); // I am making main window as the parent of slider                  
                                                                                                    // control
m_transpSlider->ShowWindow(SW_SHOW);
m_transpSlider->SetRange(0, 255, true);
m_transpSlider->SetPos(255);
m_transpSlider->EnableWindow(false); // I want it to be disabled first

In the same way I created a toolbar like this,
                                            _______________-> main window (CFrameWnd) is parent
                                           |
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
            | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
            !m_wndToolBar.LoadToolBar(IDR_MAINTOOLBAR))
      {
            TRACE0("Failed to create toolbar\n");
            return -1;      // fail to create
      }

In this class's implementation's message map I have ON_WM_HSCROLL() message map which calls OnHScroll() function.

Everything is fine till here.

But if I change the slider control creation code to make the above toolbar as its parent, like this,

m_transpSlider = new CSliderCtrl();
m_transpSlider->Create(TBS_HORZ, CRect(310, 2, 410, 22), (CWnd *)&m_wndToolBar, 1);

I am not receiving the WM_HSCROLL events and the function OnHScroll() is not being called.

I am getting the slider control in the toolbar but when I move the slider I am not getting any events.

How to handle this issue.

thanks.

0
Comment
Question by:ramavorray
  • 11
  • 8
19 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 13718403
Because the Frame is not the slider's parent, the WM_HSCROLL message has to be treated in the toolbar class (as now it receives the mesasges)
0
 

Author Comment

by:ramavorray
ID: 13718445
yes, but how to resolve it.

shall I have to declare a class that is derived from CToolBar and call CreateX from its contructor and shall I have create the slider control in that class and write a message map for WM_HSCROLL in that class
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13718498
You do not need to declare a class derived from CToolBar if you don't want. You can simply subclass the control using SubclassWindow. See MSDN on CWnd::SubclassWindow. Make sure to unsubclass it on destroying.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ramavorray
ID: 13718550
that looks good, but sorry that I did not understand it completely. MSDN pages are confusing to me.

Can you explain it a bit with respect to the above code, so that I can get a clear idea about it.

thanks.
0
 

Author Comment

by:ramavorray
ID: 13718771
This is totally cofusing. I did not get any idea of why this SubclassWindow() is for.  I rea the MSDN pages and some other pages on web. But did not get any idea of what this is for.

what I did not understand is, how will the CFrameWnd class gets messages if we declare slider control as a child of CToolBar and where to use this subclasswindow() thing in order to handle this issue.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13718785
I'm trying to experience this myslef but I have a problem: I cannot seem to make the slider appear when settign the toolbar as parent...
So I cannot test the SubclassWindow thingy yet
0
 

Author Comment

by:ramavorray
ID: 13718819
oh, But I can see it in the toolbar if I make it a child of CToolBar

m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);      
DockControlBar(&m_wndToolBar);

I have these two lines of code to create the tool bar in addition to what I gave above, in case this might help you in trying out
0
 

Author Comment

by:ramavorray
ID: 13718881
this might help you,

the tool bar should have enough length to accomodate slider control.

so, what I made it I just added some buttons to the toolbar that does nothing and they are overwritten by the Slider when it is displayed. funny way, in QT it is a lot easier.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13718922
I make it appear :)
But you have to forget what I've said about the subclasswindow. It does not work in this case.
Try making a class for the toolbar.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13718944
Or you can write a WindowProc for the toolbar where you handle only the WM_HSCROLL message and then change the wndproc of the toolbar with SetWindowLong.
0
 

Author Comment

by:ramavorray
ID: 13718947
I tried making a separate class, but then I did not get the toolbar displayed.

Just a line instead of toolbar is being displayed, no idea why.

I made a class (derived from CToolBar) and I called CreateEx like above from that class, but I could not display it.
0
 

Author Comment

by:ramavorray
ID: 13725886
Hi nonubik,

I succedded in making a separate class for the toolbar and attaching a slider control to it and displayed it. I can receive slider controls WM_HSCROLL notifcations in that class itself and I am able to handle it.

Now another issue has come up. when I select the slider control, it is being selected (a dotted line box around control is displayed) and when I click on left or right arrow keys on keyboard the slider control's thumb is changing position but then it doesnt generate WM_HSCROLL message,

I found out that, slider control when operated with keyboard gives messages like TB_LINEDOWN, TB_LINEUP

How to handle these. I used ON_COMMAND(TB_LINEDOWN, memberfxn) with no arguments to member fxn but it did not work

after that I tried using ON_NOTIFY(TB_LINEDOWN, 1, memberfxn)

with arguments NMHDR *, LRESULT * to the memberfxn, even this did not work.

application works well in both cases but those handler fucntions are not being called.

0
 
LVL 16

Accepted Solution

by:
nonubik earned 333 total points
ID: 13727092
>when I click on left or right arrow keys on keyboard the slider control's thumb is changing position but then it doesnt generate WM_HSCROLL message,
This sounds strange, you should still receive the WM_HSCROLL. TB_LINEDOW / UP are just the values of the nSBCode.
0
 

Author Comment

by:ramavorray
ID: 13727310
oh yes, I was debugging by placing breakpoint with in a condition in the OnHScroll() function which is not reachable by debugger. It was my fault.

Another thing please, when I select the slider control, it is being activated and is displaying a dotted rectangle around it,
after that how to deactivate it. Not disabling it, but just remove it from focus of keyboard. How to just remove the focus of keyboard from the slider control.
0
 

Author Comment

by:ramavorray
ID: 13728026
after the slider control is being selected only that slider is receiving the keyboard focus. The CFrameWnd class or CWnd class are not receving the KeyDown or KeyUp events.

Only the slider control is receving the WM_HSCROLL event with TB_LINEUP or TB_LINEDOWN messages. no other key event handlers are receving messages from keyboard after the slider control has been selected and only it is receiving those events.

I did not find any function in CToolBar class that helps in killing the focus from keyboard when not required
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13733599
Can use SetFocus()
0
 

Author Comment

by:ramavorray
ID: 13734573
yes, thank you very much.

Now everything is working well, as I expected

when the slider control is selected it gets the focus and when user clicks mouse in other windows (like oepngl CWnd class) I am calling SetFocus() from with in that class and then that window is receiving keyboard focus.

I just called SetFocus() in OnMouseLButtonDown() of CWnd and it worked well

thanks
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13751666
Glad to have the problem sorted out
0
 

Author Comment

by:ramavorray
ID: 13751677
cheers
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question