MFC CScrollbar Question.  
Author Message
Vasic





PostPosted: Visual C++ Language, MFC CScrollbar Question. Top

I'm having some issues with a scrollbar. I can get it displayed and everything, but I can't get any messages. Below is the code. Any ideas

// BrowseMissionDlg.cpp : implementation file

//

#include "stdafx.h"

#include "MDAE.h"

#include ".\browsemissiondlg.h"

// CBrowseMissionDlg dialog

IMPLEMENT_DYNAMIC(CBrowseMissionDlg, CDialog)

CBrowseMissionDlg::CBrowseMissionDlg(CWnd* pParent /*=NULL*/)

: CDialog(CBrowseMissionDlg::IDD, pParent)

, m_nMaxWindowLines(0)

, m_Exit(FALSE)

, m_Viewable(FALSE)

, m_WindowBuffer(m_DeviceInterface)

, m_CurrentRecordOffset(0)

{

}

CBrowseMissionDlg::~CBrowseMissionDlg()

{

}

void CBrowseMissionDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

DDX_Control(pDX, IDC_MISSION_DISPLAY, m_BrowseWindow);

}

BEGIN_MESSAGE_MAP(CBrowseMissionDlg, CDialog)

ON_WM_TIMER()

ON_WM_VSCROLL()

END_MESSAGE_MAP()

// CBrowseMissionDlg message handlers

BOOL CBrowseMissionDlg::PreTranslateMessage(MSG* pMsg)

{

if(pMsg->message == WM_KEYDOWN)

{

if(((int) pMsg->wParam) == VK_UP)

{

DisplayPreviousRecord();

}

if(((int) pMsg->wParam) == VK_DOWN)

{

DisplayNextRecord();

}

if(((int) pMsg->wParam) == VK_PRIOR)

{

PageUp();

}

if(((int) pMsg->wParam) == VK_NEXT)

{

PageDown();

}

}

return CDialog::PreTranslateMessage(pMsg);

}

BOOL CBrowseMissionDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// Figure out the height of a line.

CDC * pDC;

pDC = m_BrowseWindow.GetDC();

TEXTMETRIC Metrics;

pDC->GetTextMetrics(&Metrics);

int LineHeight = Metrics.tmExternalLeading + Metrics.tmHeight;

// Figure out how many lines can be put into the window.

CRect WindowRect;

m_BrowseWindow.GetRect(&WindowRect);

int WindowHeight = WindowRect.BottomRight().y - WindowRect.TopLeft().y;

m_nMaxWindowLines = WindowHeight/LineHeight;

m_WindowBuffer.StartBufferFiller();

int SizeDataUsed = m_DeviceInterface.GetSizeUsedData();

SCROLLINFO ScrollInfo;

m_BrowseWindow.GetScrollInfo(SB_VERT, &ScrollInfo);

ScrollInfo.fMask = SIF_DISABLENOSCROLL | SIF_POS | SIF_RANGE;

ScrollInfo.nMax = m_DeviceInterface.GetSizeUsedData();

ScrollInfo.nMin = 0;

m_BrowseWindow.SetScrollInfo(SB_VERT, &ScrollInfo);

//m_TimerID = SetTimer(1, 500, NULL);

return TRUE; // return TRUE unless you set the focus to a control

// EXCEPTION: OCX Property Pages should return FALSE

}

// Display's the next record in the display window.

void CBrowseMissionDlg::DisplayNextRecord(void)

{

CString WindowText;

m_WindowBuffer.MoveWindowBy(1);

m_CurrentRecordOffset = m_WindowBuffer.GetCurrentWindow(WindowText);

if(m_CurrentRecordOffset != -1)

{

AddMessageToWindow(WindowText);

}

}

// Display's the previous record in the display window.

void CBrowseMissionDlg::DisplayPreviousRecord(void)

{

CString WindowText;

m_WindowBuffer.MoveWindowBy(-1);

m_CurrentRecordOffset = m_WindowBuffer.GetCurrentWindow(WindowText);

if(m_CurrentRecordOffset != -1)

{

AddMessageToWindow(WindowText);

}

}

// Displays the next page of data.

void CBrowseMissionDlg::PageUp(void)

{

CString WindowText;

m_WindowBuffer.MoveWindowBy(-m_nMaxWindowLines);

m_CurrentRecordOffset = m_WindowBuffer.GetCurrentWindow(WindowText);

if(m_CurrentRecordOffset != -1)

{

AddMessageToWindow(WindowText);

}

}

// Displays the next page of data.

void CBrowseMissionDlg::PageDown(void)

{

CString WindowText;

m_WindowBuffer.MoveWindowBy(m_nMaxWindowLines);

m_CurrentRecordOffset = m_WindowBuffer.GetCurrentWindow(WindowText);

if(m_CurrentRecordOffset != -1)

{

AddMessageToWindow(WindowText);

}

}

// Gets the next block of data and puts it in m_NextBlock array.

void CBrowseMissionDlg::GetNextBlock(void)

{

}

// Gets the next block of data and puts it in m_PreviousBlock.

void CBrowseMissionDlg::GetPreviousBlock(void)

{

/*

if(m_PreviousBlock.GetCount() == 0)

{

return;

}*/

}

void CBrowseMissionDlg::OnCancel()

{

KillTimer(m_TimerID);

CDialog::OnCancel();

}

void CBrowseMissionDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)

{

switch(nSBCode)

{

case SB_LINEDOWN:

{

TRACE("LINE DOWN\n");

break;

}

case SB_LINEUP:

TRACE("LINE UP\n");

break;

case SB_PAGEUP:

TRACE("PAGE UP\n");

break;

case SB_PAGEDOWN:

TRACE("PAGE DOWN\n");

break;

default:

TRACE("Got a wierd code\n");

break;

}

CDialog::OnVScroll(nSBCode, nPos, pScrollBar);

}



Visual C++13  
 
 
Vasic





PostPosted: Visual C++ Language, MFC CScrollbar Question. Top

I think I figured it out. I'm basically trying to override the scroll bar functionality of the RichEdit scroll bar, which isn't going to work since I'm not going to get any event messages from a CRichEdit pertaining to the scrollbar. I'm going to have to create my own window and use GDI to draw my text and manipulate the scroll bar provided to me by the CWnd. If anyone disagree's with my thoughts please let me know. THANKS!!
 
 
Martin Richter





PostPosted: Visual C++ Language, MFC CScrollbar Question. Top

Your scrollbars are inside m_BrowseWindow, so they are sending their WM_VSCROLL/WM_HSCROLL messages to this window. The Dialog would receive the scrollmessages for the scrollbars inside the dialog window only.