Click here to Skip to main content
14,174,039 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
I have a c++ MFC MDI based project using visual studio 2013 community. Mainframe class is derived as class CMainFrame : public CMDIFrameWndEx

In mainframe class in pre-create, the scroll bar is set as below.
cs.style |= WS_VSCROLL | WS_HSCROLL;
An OnVScroll call back function has been added to receive a call back whenever the main frame scroll bar is moved. ON_WM_VSCROLL() has been added to the message map in the mainframe. We find that OnVScroll never gets called. How do we enable callbacks on OnVScroll whenever the user moves the scrollbar. Any help will be very appreciated. Thanks & Regards, Rakesh

What I have tried:

I don't know what to do. I wanted to to call SetScrollSizes any where in the mainframe class.
Posted
Updated 25-Apr-18 10:26am
v2
Comments
Richard MacCutchan 25-Apr-18 13:19pm
   
Have you called SetScrollSizes, and does a scroll bar appear on your window?
Member 11380615 25-Apr-18 22:02pm
   
Thanks Richard, Yes a scroll bar appears on the main frame window. Whenever the number of child windows and their end to end extent go beyond the MDI client area and vertical and horizontal scroll bar automatically appears.
I was not able to call SetScrollSizes since the function is not available in the main frame class.
Richard MacCutchan 26-Apr-18 2:52am
   
That is because the scroll bars are associated with the View windows, not the MainFrame. You need to set the scroll sizes for each individual view.
Member 11380615 26-Apr-18 9:53am
   
Each individual view the scroll sizes have been set.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

That is because CFrameWnd based classes route those message to the active view and CMDIFrameWnd traps the WS_VSCROLL and WS_HSCROLL and styles:
The CFrameWnd class provides management of the active view. The following messages are routed through the active view:
  • All command messages (the active view gets first access to them).
  • WM_HSCROLL and WM_VSCROLL messages from sibling scroll bars (see below).
  • WM_ACTIVATE (and WM_MDIACTIVATE for MDI) get turned into calls to the virtual function CView::OnActivateView.

...
On a side note, there are two CWnd derived classes where the scroll bar styles specified at create time are trapped and not passed to Windows.
...
For CMDIFrameWnd the scroll bar styles you pass in to Create or LoadFrame are used to create the MDICLIENT.

So you can't use scrollbars with CFrameWnd based classes. It would be only possible by implementing your own (CWnd based) classes that must provide all the necessary MDI functionality. Due to the relationship between the MFC document and view classes you might have to create a complete new document and view implementation.

Note also that frame windows are for hosting and organising the views and usually do not require scrollbars.
   
Comments
Member 11380615 25-Apr-18 22:10pm
   
Thanks Jochen. I do find that the MDI frame window automatically creates a vertical and horizontal scroll bar when the child windows go beyond the extent of the mdi client area. The MDI frame window scroll bar works fine when it is there. Scrolling works fine.
My objectve is to trap the scrolling event when ever the user tries to scroll. Would it be possible to trap the MDI frame window scrolling in the active view class using WM_HSCROLL, WM_VSCROLL. If so how would we differentiate between the scrolling of the view window and the MDI main frame window.
Jochen Arndt 26-Apr-18 2:51am
   
I don't know. Just try it.

See the MS documentation for WM_[H|V]SCROLL:
lParam
If the message is sent by a scroll bar control, this parameter is the handle to the scroll bar control. If the message is sent by a standard scroll bar, this parameter is NULL.

You would have to create at least one set of scroll bars as control to know from which the message has been send (I actually don't know if CScrollView uses a standard bar or a control). Then you can differentiate in the view and might send a user defined message to the view or provide a function in your main frame class.
Member 11380615 26-Apr-18 9:53am
   
I tried adding the OnVScroll to the ScrollView class. SetScrollSizes were also called in the view class. There was only one scroll bar and that was in the main frame window. Despite me being able to scroll up and down through the mdi client area the call back function OnVScroll never got called.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190524.3 | Last Updated 25 Apr 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100