VS 2005 (C++), MFC, dialog based app, ASCII
Czesc. Dodałem do dialogu 2 kontrolki (edit control oraz slider control) przyporządkowałem im zmienne tak jak w kodzie. Komentarzami w stylu //******* zaznaczyłem kod, który wprowadziłem ręcznie. Ten przykład ma za zadanie spowodować wysłanie wartości położenia slider'a do pola edit control, przy każdym przesunięciu suwaka.
Robiąc to w VC++6 działa, lecz w VS2005 projekt kompiluje się jedynie nie ma reakcji ze strony funkcji OnHScroll() (wg mnie).
Czy ktoś mógłby mi pomóc? Może nastąpiły jakieś zmiany v.6 - v.2005, przez które to wszystko.
Oto kod:
// ExoSliderDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ExoSlider.h"
#include "ExoSliderDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CExoSliderDlg dialog
CExoSliderDlg::CExoSliderDlg(CWnd* pParent /*=NULL*/)
: CDialog(CExoSliderDlg::IDD, pParent)
, m_SliderValue(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CExoSliderDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SLIDER, m_Slider);
DDX_Text(pDX, IDC_SLIDER_VALUE, m_SliderValue);
}
BEGIN_MESSAGE_MAP(CExoSliderDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CExoSliderDlg message handlers
BOOL CExoSliderDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
//**************************************************************** TUTAJ WPROWADZILEM KOD
m_Slider.SetRangeMin(1, false);
m_Slider.SetRangeMax(100, false);
m_SliderValue = "1";
UpdateData(FALSE);
//*********************************************************************** DOTAD
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CExoSliderDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CExoSliderDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
//******************************************************************************* NAPISALEM TA FUNKCJE
void CExoSliderDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
if(nSBCode == SB_THUMBPOSITION) {
m_SliderValue.Format("%ld", nPos);
UpdateData(false);
}
else {
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
a to plik .h:
// ExoSliderDlg.h : header file
//
#pragma once
#include "afxcmn.h"
// CExoSliderDlg dialog
class CExoSliderDlg : public CDialog
{
// Construction
public:
CExoSliderDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
enum { IDD = IDD_EXOSLIDER_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
//***************************************************************** DODALEM TA LINIJKE
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
DECLARE_MESSAGE_MAP()
public:
CSliderCtrl m_Slider;
public:
CString m_SliderValue;
};
w razie co zródła , tzn caly projekt jest tutaj. http://www.box.net/shared/eihgb1f15k