RE: Re: Scrolling, Sizing, and Exit Codes...
Nenad Stefanovic <
nenads@...>
2000-10-12 07:58:44 GMT
Hi Scott,
This is a pretty tough problem, because scroll classes were not designed for
this. I came up with a way to do it, by using another window between the
frame and the view window. That window contains the view window, which is
itself a dialog form, and does the scrolling.
If you create an app with the WTL App Wizard, using dialog based form as a
view window, you can add these classes for the view and the scroll window
(view class stays the same, but there is CScrollView as a parent):
class CTestView : public CDialogImpl<CTestView>
{
public:
enum { IDD = IDD_TEST_FORM };
BOOL PreTranslateMessage(MSG* pMsg)
{
return IsDialogMessage(pMsg);
}
BEGIN_MSG_MAP(CTestView)
// your dialog message handlers here
END_MSG_MAP()
};
class CScrollView : public CScrollWindowImpl<CScrollView>
{
public:
DECLARE_WND_CLASS_EX(NULL, 0, COLOR_3DFACE);
CTestView m_view;
BOOL PreTranslateMessage(MSG* pMsg)
{
return m_view.PreTranslateMessage(pMsg);
}
void DoPaint(CDCHandle /*dc*/)
{
}
BEGIN_MSG_MAP(CTestView)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
CHAIN_MSG_MAP(CScrollWindowImpl<CScrollView>)
END_MSG_MAP()
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
CScrollWindowImpl<CScrollView>::OnSize(uMsg, wParam, lParam,
bHandled);
POINT pt = { 0, 0 };
GetScrollOffset(pt);
m_view.SetWindowPos(NULL, -pt.x, -pt.y, 0, 0, SWP_NOZORDER |
SWP_NOSIZE | SWP_NOACTIVATE);
bHandled = FALSE;
return 1;
}
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
CScrollWindowImpl<CScrollView>::OnCreate(uMsg, wParam,
lParam, bHandled);
m_view.Create(m_hWnd);
RECT rcView;
m_view.GetWindowRect(&rcView);
SetScrollSize(rcView.right - rcView.left, rcView.bottom -
rcView.top);
return 1;
}
};
The only other change would be that in CMainFrame we now have CSrollView as
a data member, and we create that window instead of CTestView one.
Additional things, besides scrolling, that CScrollView does are: setting
scroll size based on the size of the form, and positioning the form, which
is a child window, if it goes outside of the CScrollView window.
I hope this is helpful.
Thanks,
Nenad
-----Original Message-----
From: Scott Leonard [mailto:sbl@...]
Sent: Friday, October 06, 2000 8:39 AM
To: wtl@...
Subject: [wtl] Re: Scrolling, Sizing, and Exit Codes...
OK, OK, I guess using one's brain to solve problems is a good thing...
Regarding childframe scrolling the view, I added CHAIN_MSG_MAP
(CScrollImpl<CDlgChildFrame>); that seems to be the right starting
place. I'm still not sure about which class members to call, but
calling SetScrollSize(600,320) (that's the size of my dialog; still
trying to get that autosize-on-create to work) in OnCreate does
something. OK, now I've got scrollbars, and they even sorta work. I
have to override DoPaint; not sure what to do in here... If I scroll
the window, the newly displayed region doesn't get drawn properly
(probably 'cause I'm not doing it in DoPaint). If I then size the
window at all, it snaps the view back to the top left corner, leaving
the scrollbars positioned as they were.
Also, showing and hiding the scrollbars doesn't seem too
straighforward, either. I created a little function to show and hide
the scroll bars as follows:
void BarVisible(){
RECT rcClient;
BOOL bVisible;
GetClientRect(&rcClient);
bVisible = (rcClient.right < 600)?TRUE:FALSE;
ShowScrollBar(SB_HORZ,bVisible);
bVisible = (rcClient.bottom < 320)?TRUE:FALSE;
ShowScrollBar(SB_VERT,bVisible);
}
The trouble is where to call it from. OnSizing doesn't get the last
message as you release the frame border, so if you shrink the frame
and release, then single click the frame, it will show the bars. I
don't get OnLButtonxxx notifications, so I can't do it after the
button is released on the border.
Thanks again from a rambling guy who shouldn't code in the wee hours,
sbl
To unsubscribe from this group, send an email to:
wtl-unsubscribe@...