Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
pascal bosquet
|
Nov 28, 2004 - 3:05 AM
|
hello,
thanks for your previous reply, now i got another tiny troubles, my CExtscrollbars doesn’t appears in my CExtScrollWnd. I set the virtual space using the method .OnSwSetScrollRange(SB_VERT ,0,mybitmap_width,true) then .OnSwRecalcLayout(true); but nothing show up. But if i do OnSwHasScrollBar(SB_HORZ) that return me true. kinda weird What’s the proper way to force the display of cextscrollbars within a cextscrollwnd ?
here s a extract of my code:
BOOL CBankPanel::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { BOOL ret;
if(!CWnd::Create( lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext)) { ASSERT(FALSE); return FALSE; }
// create the bars if(!m_HBar.Create(SBS_HORZ | SBS_TOPALIGN | WS_CHILD, CRect(5, 5, 100, 30), this,10000)) { ASSERT(FALSE); return FALSE; } m_HBar.m_bReflectParentSizing=true;
if(!m_VBar.Create(SBS_VERT | SBS_LEFTALIGN | WS_CHILD, CRect(5, 5, 100, 30), this,10001)) { ASSERT(FALSE); return FALSE; } m_VBar.m_bReflectParentSizing=true;
return TRUE; }
CBankPanel::~CBankPanel() { }
void CBankPanel::OnSwPaint(CDC & dc) { }
CScrollBar* CBankPanel::GetScrollBarCtrl(int nBar) const { if(nBar==SB_HORZ) return (CScrollBar*) ( (m_HBar.GetSafeHwnd() != NULL) ? (&m_HBar) : NULL ); else return (CScrollBar*) ( (m_VBar.GetSafeHwnd() != NULL) ? (&m_VBar) : NULL ); }
bool CBankPanel::OnSwDoScroll(UINT nScrollCode,UINT nPos,bool bDoScroll) {
return true; }
|
|
Technical Support
|
Nov 29, 2004 - 2:21 AM
|
We decided to help you code your image viewer based on the CExtScrollWnd class. We called it CChildView and you may use it (instead of the child view) in your MDI/SDI application that is not based on the document/view architecture. To assign a bitmap to the image viewer window, the CChildView::LoadBitmap or CChildView::SetBitmap method can be used. Here is the contents of the header file:
#if (!defined __CHILD_VIEW_H)
#define __CHILD_VIEW_H
#if _MSC_VER > 1000
#pragma once
#endif
class CChildView : public CExtScrollWnd
{
public:
CChildView();
public:
bool Create(
CWnd * pWndParent,
UINT nDlgCtrlID = AFX_IDW_PANE_FIRST,
DWORD dwWndStyle =
WS_CHILD
|WS_VISIBLE
|WS_CLIPSIBLINGS
|WS_CLIPCHILDREN,
CRect rc = CRect(0,0,0,0)
);
static LPCTSTR RegisterChildViewWndClass();
void SetBitmap(
HBITMAP hBitmap
);
bool LoadBitmap(
UINT nResourceID
);
protected:
CBitmap m_bmp;
CSize m_sizeHelperBmp;
CExtScrollBar
m_wndScrollBarH,
m_wndScrollBarV;
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CChildView)
public:
virtual CScrollBar * GetScrollBarCtrl(int nBar) const;
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
public:
virtual ~CChildView();
virtual CSize OnSwGetTotalSize() const;
virtual CSize OnSwGetPageSize(
int nDirection
) const;
virtual CSize OnSwGetLineSize(
int nDirection
) const;
virtual void OnSwPaint(
CDC & dc
);
// Generated message map functions
protected:
//{{AFX_MSG(CChildView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
#endif (!defined __CHILD_VIEW_H)
Here is its source file:
#include "stdafx.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CChildView::CChildView()
: m_sizeHelperBmp( 0, 0 )
{
}
CChildView::~CChildView()
{
SetBitmap( NULL );
}
BEGIN_MESSAGE_MAP( CChildView, CExtScrollWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
bool CChildView::Create(
CWnd * pWndParent,
UINT nDlgCtrlID, // = AFX_IDW_PANE_FIRST
DWORD dwWndStyle, // =
// WS_CHILD
// |WS_VISIBLE
// |WS_CLIPSIBLINGS
// |WS_CLIPCHILDREN
CRect rc // = CRect(0,0,0,0)
)
{
if( ! CWnd::Create(
RegisterChildViewWndClass(),
_T(""),
dwWndStyle,
rc,
pWndParent,
nDlgCtrlID
)
)
{
ASSERT( FALSE );
return false;
}
return true;
}
LPCTSTR CChildView::RegisterChildViewWndClass()
{
return
::AfxRegisterWndClass(
CS_DBLCLKS
|CS_HREDRAW
|CS_VREDRAW,
::LoadCursor(
NULL,
IDC_ARROW
)
);
}
void CChildView::SetBitmap(
HBITMAP hBitmap
)
{
if( ((HBITMAP)m_bmp.GetSafeHandle())
== hBitmap )
return;
if( m_bmp.GetSafeHandle() != NULL )
m_bmp.DeleteObject();
m_sizeHelperBmp.cx
= m_sizeHelperBmp.cy
= 0;
if( hBitmap != NULL )
{
m_bmp.Attach( hBitmap );
BITMAP bmpInfo = { 0 };
m_bmp.GetBitmap( &bmpInfo );
m_sizeHelperBmp.cx =
bmpInfo.bmWidth;
m_sizeHelperBmp.cy =
bmpInfo.bmHeight;
} // if( hBitmap != NULL )
OnSwUpdateScrollBars();
OnSwDoRedraw();
}
bool CChildView::LoadBitmap(
UINT nResourceID
)
{
CBitmap bmp;
if( ! bmp.LoadBitmap( nResourceID ) )
return false;
SetBitmap( (HBITMAP)bmp.Detach() );
return true;
}
CSize CChildView::OnSwGetTotalSize() const
{
CSize sizeTotal( m_sizeHelperBmp );
if( sizeTotal.cx == 0 )
sizeTotal.cx = 1;
if( sizeTotal.cy == 0 )
sizeTotal.cy = 1;
return sizeTotal;
}
CSize CChildView::OnSwGetPageSize(
int nDirection
) const
{
ASSERT_VALID( this );
nDirection;
CRect rcClient = OnSwGetClientRect();
CSize sizePage = rcClient.Size();
CSize sizeTotal = m_sizeHelperBmp;
if( sizePage.cx > sizeTotal.cx )
sizePage.cx = 0;
if( sizePage.cy > sizeTotal.cy )
sizePage.cy = 0;
return sizePage;
}
CSize CChildView::OnSwGetLineSize(
int nDirection
) const
{
ASSERT_VALID( this );
nDirection;
return CSize( 1, 1 );
}
void CChildView::OnSwPaint( CDC & dc )
{
ASSERT_VALID( this );
ASSERT( dc.GetSafeHdc() != NULL );
CRect rcClipBox;
dc.GetClipBox( &rcClipBox );
COLORREF clrBk =
g_PaintManager->GetColor(
CExtPaintManager::CLR_3DFACE_OUT
);
dc.FillSolidRect(
&rcClipBox,
clrBk
);
if( m_bmp.GetSafeHandle() != NULL )
{
ASSERT(
m_sizeHelperBmp.cx > 0
&& m_sizeHelperBmp.cy > 0
);
CDC dcSrc;
if( dcSrc.CreateCompatibleDC(&dc) )
{
CBitmap * pOldSrc =
dcSrc.SelectObject(&m_bmp);
dc.BitBlt(
0,
0,
m_sizeHelperBmp.cx,
m_sizeHelperBmp.cy,
&dcSrc,
0,
0,
SRCCOPY
);
dcSrc.SelectObject(&pOldSrc);
} // if( dcSrc.CreateCompatibleDC(&dc) )
} // if( m_bmp.GetSafeHandle() != NULL )
CScrollBar * pScrollBarH =
GetScrollBarCtrl( SB_HORZ );
CScrollBar * pScrollBarV =
GetScrollBarCtrl( SB_VERT );
if( pScrollBarH != NULL
&& pScrollBarV != NULL
&& (pScrollBarH->GetStyle()&WS_VISIBLE) != 0
&& (pScrollBarV->GetStyle()&WS_VISIBLE) != 0
)
{
CPoint ptVpRestore = dc.SetViewportOrg( 0, 0 );
CRect rcSbH, rcSbV;
pScrollBarH->GetWindowRect( &rcSbH );
pScrollBarV->GetWindowRect( &rcSbV );
CRect rcSbBoth(
rcSbV.left,
rcSbH.top,
rcSbV.right,
rcSbH.bottom
);
ScreenToClient( &rcSbBoth );
dc.FillSolidRect(
&rcSbBoth,
clrBk
);
dc.SetViewportOrg( ptVpRestore );
}
}
int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if( CExtScrollWnd::OnCreate(lpCreateStruct) == -1 )
return -1;
if( ! m_wndScrollBarV.Create(
WS_CHILD
|WS_VISIBLE
|SBS_VERT
|SBS_RIGHTALIGN,
CRect(0,0,0,0),
this,
1
)
)
{
ASSERT( FALSE );
return -1;
}
if( ! m_wndScrollBarH.Create(
WS_CHILD
|WS_VISIBLE
|SBS_HORZ
|SBS_BOTTOMALIGN,
CRect(0,0,0,0),
this,
2
)
)
{
ASSERT( FALSE );
return -1;
}
m_wndScrollBarH.SyncReservedSpace(
&m_wndScrollBarV
);
m_wndScrollBarV.SyncReservedSpace(
&m_wndScrollBarH
);
return 0;
}
CScrollBar * CChildView::GetScrollBarCtrl(int nBar) const
{
ASSERT_VALID( this );
if( m_hWnd == NULL || (! ::IsWindow(m_hWnd) ) )
return NULL;
ASSERT( nBar == SB_HORZ || nBar == SB_VERT );
if( nBar == SB_HORZ )
{
if( m_wndScrollBarH.GetSafeHwnd() != NULL )
return
( const_cast
< CExtScrollBar * >
( &m_wndScrollBarH ) );
} // if( nBar == SB_HORZ )
else
{
if( m_wndScrollBarV.GetSafeHwnd() != NULL )
return
( const_cast
< CExtScrollBar * >
( &m_wndScrollBarV )
);
} // else from if( nBar == SB_HORZ )
return NULL;
}
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if( ! CExtScrollWnd::PreCreateWindow(cs) )
{
ASSERT( FALSE );
return FALSE;
}
cs.lpszClass = RegisterChildViewWndClass();
return TRUE;
}
Here is how the OnCreate() method of the main frame window may look like ( CMainFrame::m_wndView is a window of the CChildView class:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if( CFrameWnd::OnCreate(lpCreateStruct) == -1 )
return -1;
SetIcon(
(HICON)::LoadImage(
::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON,
16,
16,
0
),
FALSE
);
SetIcon(
(HICON)::LoadImage(
::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON,
32,
32,
0
),
TRUE
);
if( ! m_wndView.Create( this ) )
{
ASSERT( FALSE );
return -1;
}
VERIFY(
m_wndView.LoadBitmap(
IDB_BITMAP_TEST
)
);
return 0;
}
Please note that the CChildView code above uses CExtScrollBar -based scroll bar controls. But you may safely comment the lines that create the CChildView::m_wndScrollBarH and CChildView::m_wndScrollBarV windows in the CExtScrollWnd::OnCreate method so that you can see how the CChildView class works with built-in scroll bar areas in the non-client area of the window. But, of course, you can use ordinary scroll bar controls instead of built-in scroll bar-like areas if you don’t need to inject some additional controls next to the scroll bar window as it is done in, for example, MS Word.
|
|