Re: Getting notification for dynamically added controls
I just did such a dialog a few days ago.
It has a variable number of edit and
slider controls.
I'll just post the complete code, so you
may take a look at it.
HTH
in Ressource.h:
#define IDC_STATIC_PARAMETER 1489
#define IDC_SLIDER_PARAMETER 1490
#define IDC_EDIT_PARAMETER 1491
#define IDC_STATIC_SLIDER_MIN 1792
#define IDC_EDIT_SLIDER_MIN 1793
#define IDC_STATIC_SLIDER_MAX 1794
#define IDC_EDIT_SLIDER_MAX 1795
the dialog template:
IDD_DLG_PARAMETER DIALOG DISCARDABLE 0, 0, 432, 127
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Parameter"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "Parameter 1",IDC_STATIC_PARAMETER,8,7,100,8
EDITTEXT IDC_EDIT_PARAMETER,60,4,100,14,ES_AUTOHSCROLL
CONTROL
"Slider1",IDC_SLIDER_PARAMETER,"msctls_trackbar32",
TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,170,4,195,15
DEFPUSHBUTTON "OK",IDOK,374,4,50,14
PUSHBUTTON "Abort",IDCANCEL,374,23,50,14
CTEXT "Slider Range\nfrom",IDC_STATIC_SLIDER_MIN,
374,52,50,16
EDITTEXT IDC_EDIT_SLIDER_MIN,374,73,50,14,ES_AUTOHSCROLL
CTEXT "to",IDC_STATIC_SLIDER_MAX,374,92,50,8
EDITTEXT IDC_EDIT_SLIDER_MAX,374,105,50,14,ES_AUTOHSCROLL
END
the header file:
////////////////////////////////////////////////////////////////////////////=
/
// DlgParameter.h : Header-Datei
//
////////////////////////////////////////////////////////////////////////////=
/
#if !
defined(AFX_DLGPARAMETER_H__C5C66A53_BC24_4EB3_B91F_20E0BB92E711__INCLUDED_)=
#define
AFX_DLGPARAMETER_H__C5C66A53_BC24_4EB3_B91F_20E0BB92E711__INCLUDED_
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#pragma once
#endif
#include "Matrix.h"
////////////////////////////////////////////////////////////////////////////=
/
// Dialogfeld CDlgParameter
#define ON_EN_CHANGE_RANGE(id, idLast, memberFxn) \
ON_CONTROL_RANGE(EN_CHANGE, id, idLast, memberFxn)
class CDlgParameter : public CDialog
{
// Konstruktion
public:
CDlgParameter(CWnd* pParent = NULL); // Standardkonstruktor
// Dialogfelddaten
//{{AFX_DATA(CDlgParameter)
enum { IDD = IDD_DLG_PARAMETER };
CEdit m_SliderMaxEdit;
CEdit m_SliderMinEdit;
CStatic m_SliderMaxStatic;
CStatic m_SliderMinStatic;
CButton m_ButtonCancel;
CButton m_ButtonOK;
double m_dSliderRangeMin;
double m_dSliderRangeMax;
//}}AFX_DATA
int m_nCount;
CArray<CStatic, CStatic&> m_StaticParameter;
CArray<CSliderCtrl, CSliderCtrl&> m_SliderParameter;
CArray<CEdit, CEdit&> m_EditParameter;
CArray<double, double&> m_dParameter;
void SetSize(int k);
BOOL SetMatrix(const CMatrix& inMatrix);
BOOL GetMatrix(CMatrix& outMatrix);
void SetSliderRangeMinMax();
// =DCberschreibungen
// Vom Klassen-Assistenten generierte virtuelle
Funktions=FCberschreibungen
//{{AFX_VIRTUAL(CDlgParameter)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV-
Unterst=FCtzung
//}}AFX_VIRTUAL
// Implementierung
private:
int m_nScrollPos;
protected:
BOOL UpdateDataPart(int k, BOOL bSaveAndValidate = TRUE);
BOOL UpdateDataPart1(BOOL bSaveAndValidate = TRUE);
BOOL UpdateDataPart2(BOOL bSaveAndValidate = TRUE);
void UpdateEdit(int k);
void UpdateSlider(int k);
// Generierte Nachrichtenzuordnungsfunktionen
//{{AFX_MSG(CDlgParameter)
virtual BOOL OnInitDialog();
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg void OnChangeEditSliderMin();
afx_msg void OnChangeEditSliderMax();
//}}AFX_MSG
afx_msg void OnChangeEditParameter(UINT nID);
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ f=FCgt unmittelbar vor der vorhergehenden Zeile
zus=E4tzliche Deklarationen ein.
#endif //
AFX_DLGPARAMETER_H__C5C66A53_BC24_4EB3_B91F_20E0BB92E711__INCLUDED_
the source file:
////////////////////////////////////////////////////////////////////////////=
/
// DlgParameter.cpp: Implementierungsdatei
//
#include "StdAfx.h"
#include "ZoneCorr.h"
#include "DlgParameter.h"
#include "DdxDdvSupport.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////////=
/
// Dialogfeld CDlgParameter
CDlgParameter::CDlgParameter(CWnd* pParent /*=NULL*/)
: CDialog(CDlgParameter::IDD, pParent)
{
int k;
//{{AFX_DATA_INIT(CDlgParameter)
m_dSliderRangeMin = 0.0;
m_dSliderRangeMax = 0.0;
//}}AFX_DATA_INIT
m_nCount = 1;
m_nScrollPos = 0;
m_StaticParameter.SetSize(m_nCount);
m_SliderParameter.SetSize(m_nCount);
m_EditParameter.SetSize(m_nCount);
m_dParameter.SetSize(m_nCount);
for (k = 0; k < m_nCount; k++)
{
m_dParameter[k] = 0.0;
}
}
void CDlgParameter::DoDataExchange(CDataExchange* pDX)
{
int k;
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgParameter)
DDX_Control(pDX, IDC_EDIT_SLIDER_MAX, m_SliderMaxEdit);
DDX_Control(pDX, IDC_EDIT_SLIDER_MIN, m_SliderMinEdit);
DDX_Control(pDX, IDC_STATIC_SLIDER_MAX, m_SliderMaxStatic);
DDX_Control(pDX, IDC_STATIC_SLIDER_MIN, m_SliderMinStatic);
DDX_Control(pDX, IDCANCEL, m_ButtonCancel);
DDX_Control(pDX, IDOK, m_ButtonOK);
DDX_TextComma(pDX, IDC_EDIT_SLIDER_MIN, m_dSliderRangeMin);
DDX_TextComma(pDX, IDC_EDIT_SLIDER_MAX, m_dSliderRangeMax);
//}}AFX_DATA_MAP
for (k = 0; k < m_nCount; k++)
{
DDX_Control(pDX, IDC_STATIC_PARAMETER+3*k, m_StaticParameter[k]);
DDX_Control(pDX, IDC_SLIDER_PARAMETER+3*k, m_SliderParameter[k]);
DDX_Control(pDX, IDC_EDIT_PARAMETER+3*k, m_EditParameter[k]);
DDX_TextComma2(pDX, IDC_EDIT_PARAMETER+3*k, m_dParameter[k]);
}
}
BEGIN_MESSAGE_MAP(CDlgParameter, CDialog)
//{{AFX_MSG_MAP(CDlgParameter)
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_MOUSEWHEEL()
ON_EN_CHANGE(IDC_EDIT_SLIDER_MIN, OnChangeEditSliderMin)
ON_EN_CHANGE(IDC_EDIT_SLIDER_MAX, OnChangeEditSliderMax)
//}}AFX_MSG_MAP
ON_EN_CHANGE_RANGE(IDC_EDIT_PARAMETER, IDC_EDIT_PARAMETER + 3*50,
OnChangeEditParameter) // 50 is the maximal number of optimization
coefficients
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////=
/
// Behandlungsroutinen f=FCr Nachrichten CDlgParameter
void CDlgParameter::SetSize(int k)
{
if (k > 0)
{
m_nCount = k;
m_StaticParameter.SetSize(m_nCount);
m_SliderParameter.SetSize(m_nCount);
m_EditParameter.SetSize(m_nCount);
m_dParameter.SetSize(m_nCount);
}
}
BOOL CDlgParameter::SetMatrix(const CMatrix& inMatrix)
{
if (inMatrix.IsEmpty())
return FALSE;
int k, size = inMatrix.GetTotalSize();
SetSize(size);
for (k = 0; k < size; k++)
{
m_dParameter[k] = inMatrix[k];
}
SetSliderRangeMinMax();
return TRUE;
}
BOOL CDlgParameter::GetMatrix(CMatrix& outMatrix)
{
int k;
BOOL bModified = FALSE;
if (outMatrix.GetTotalSize() != m_nCount)
{
outMatrix.SetSize(m_nCount);
bModified = TRUE;
}
for (k = 0; k < m_nCount; k++)
{
if (outMatrix[k] != m_dParameter[k])
{
outMatrix[k] = m_dParameter[k];
bModified = TRUE;
}
}
return bModified;
}
void CDlgParameter::SetSliderRangeMinMax()
{
double dMin = HUGE, dMax = -HUGE;
int k;
for (k = 0; k < m_nCount; k++)
{
dMin = min(dMin, m_dParameter[k]);
dMax = max(dMax, m_dParameter[k]);
}
double dValueMin = fabs(dMin);
double dValueMax = fabs(dMax);
double dDiff = dMax-dMin;
double dDiff1 = 1., dDiff2;
if (dDiff > 0.)
{
double dDiffLog = log10(dDiff);
double dDiffLog1 = floor(dDiffLog);
double dDiffLog2 = dDiffLog - dDiffLog1;
dDiff1 = pow(10., dDiffLog1);
dDiff2 = pow(10., dDiffLog2);
if (dDiff2 < 2.)
dDiff1 *= .3;
else if (dDiff2 < 5.)
dDiff1 *= .5;
}
else
{
double dDiffLog = log10(dValueMax);
double dDiffLog1 = floor(dDiffLog);
double dDiffLog2 = dDiffLog - dDiffLog1;
dDiff1 = pow(10., dDiffLog1);
dDiff2 = pow(10., dDiffLog2);
if (dDiff2 < 2.)
dDiff1 *= .3;
else if (dDiff2 < 5.)
dDiff1 *= .5;
}
if (dValueMin > 0.)
{
double dValueMin1, dValueMin2;
dValueMin1 = dDiff1;
dValueMin2 = dValueMin/dDiff1;
if (dMin < 0.)
{
m_dSliderRangeMin = -ceil(dValueMin2-10*eps) * dValueMin1;
}
else if (dMin > 0.)
{
m_dSliderRangeMin = floor(dValueMin2+10*eps) * dValueMin1;
}
}
else
{
m_dSliderRangeMin = 0.;
}
if (dValueMax > 0.)
{
double dValueMax1, dValueMax2;
dValueMax1 = dDiff1;
dValueMax2 = dValueMax/dDiff1;
if (dMax > 0.)
{
m_dSliderRangeMax = ceil(dValueMax2-10*eps) * dValueMax1;
}
else if (dMax < 0.)
{
m_dSliderRangeMax = -floor(dValueMax2+10*eps) * dValueMax1;
}
}
else
{
m_dSliderRangeMax = 0.;
}
}
BOOL CDlgParameter::OnInitDialog()
{
int k, top = INT_MAX, bottom = INT_MIN;
CPoint point(0,0);
CRect rect(0,0,0,0);
HFONT hFont;
CString strTitle, strOld, strNew;
DWORD dwStyle, dwStyleEx;
k = m_nCount;
m_nCount = 1;
BOOL bRet = CDialog::OnInitDialog();
m_nCount = k;
m_ButtonOK.GetWindowRect(&rect);
ScreenToClient(&rect);
point.y = -rect.top;
m_ButtonCancel.GetWindowRect(&rect);
ScreenToClient(&rect);
point.y += rect.top;
for (k = 1; k < m_nCount; k++)
{
dwStyle = m_StaticParameter[k-1].GetStyle();
dwStyleEx = m_StaticParameter[k-1].GetExStyle();
m_StaticParameter[k-1].GetWindowRect(&rect);
ScreenToClient(&rect);
m_StaticParameter[k-1].GetWindowText(strTitle);
strOld.Format(_T("%d"), k);
strNew.Format(_T("%d"), k+1);
strTitle.Replace(strOld, strNew);
m_StaticParameter[k].CreateEx(dwStyleEx, _T("STATIC"), strTitle,
dwStyle, rect, this, IDC_STATIC_PARAMETER+3*k);
rect.OffsetRect(point);
m_StaticParameter[k].SetWindowPos(&m_SliderParameter[k-1],
rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE);
hFont = (HFONT)m_StaticParameter[k-1].SendMessage(WM_GETFONT);
if (hFont)
{
m_StaticParameter[k].SendMessage(WM_SETFONT, (WPARAM)hFont);
}
dwStyle = m_EditParameter[k-1].GetStyle();
dwStyleEx = m_EditParameter[k-1].GetExStyle();
m_EditParameter[k-1].GetWindowRect(&rect);
ScreenToClient(&rect);
m_EditParameter[k].CreateEx(dwStyleEx, _T("EDIT"), NULL, dwStyle,
rect, this, IDC_EDIT_PARAMETER+3*k);
rect.OffsetRect(point);
m_EditParameter[k].SetWindowPos(&m_StaticParameter[k], rect.left,
rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE);
hFont = (HFONT)m_EditParameter[k-1].SendMessage(WM_GETFONT);
if (hFont)
{
m_EditParameter[k].SendMessage(WM_SETFONT, (WPARAM)hFont);
}
dwStyle = m_SliderParameter[k-1].GetStyle();
dwStyleEx = m_SliderParameter[k-1].GetExStyle();
m_SliderParameter[k-1].GetWindowRect(&rect);
ScreenToClient(&rect);
m_SliderParameter[k-1].GetWindowText(strTitle);
strOld.Format(_T("%d"), k);
strNew.Format(_T("%d"), k+1);
strTitle.Replace(strOld, strNew);
m_SliderParameter[k].CreateEx(dwStyleEx, TRACKBAR_CLASS, strTitle,
dwStyle, rect, this, IDC_SLIDER_PARAMETER+3*k);
rect.OffsetRect(point);
m_SliderParameter[k].SetWindowPos(&m_EditParameter[k], rect.left,
rect.top, rect.Width(), rect.Height(), SWP_NOACTIVATE);
hFont = (HFONT)m_SliderParameter[k-1].SendMessage(WM_GETFONT);
if (hFont)
{
m_SliderParameter[k].SendMessage(WM_SETFONT, (WPARAM)hFont);
}
}
for (CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild-
GetNextWindow(GW_HWNDNEXT))
{
pChild->GetWindowRect(&rect);
ScreenToClient(&rect);
top = min(top, rect.top);
bottom = max(bottom, rect.bottom);
}
bottom += 2*top;
GetClientRect(&rect);
if (rect.Height() < bottom-top)
{
k = bottom-top - rect.Height();
GetWindowRect(&rect);
rect.bottom += k;
if (rect.Height() > GetSystemMetrics(SM_CYSCREEN))
{
k = rect.Height() - GetSystemMetrics(SM_CYSCREEN);
rect.bottom = rect.top + GetSystemMetrics(SM_CYSCREEN);
rect.right += GetSystemMetrics(SM_CXVSCROLL);
ModifyStyle(0, WS_VSCROLL, SWP_FRAMECHANGED);
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
si.nMin = 0;
si.nMax = k;
//si.nPage = si.nMax/10;
si.nPage = 1;
si.nPos = 0;
si.nTrackPos = 0;
SetScrollInfo(SB_VERT, &si, TRUE);
}
SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(),
SWP_NOZORDER | SWP_NOACTIVATE);
}
for (k = 0; k < m_nCount; k++)
{
m_SliderParameter[k].SetRange(-400, 400, TRUE);
m_SliderParameter[k].SetPos(0);
UpdateSlider(k);
}
UpdateData(FALSE);
return bRet;
}
void CDlgParameter::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar)
{
if (GetStyle() & WS_VSCROLL)
{
CRect rect;
int nDelta, nLeft, nRight;
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
GetScrollInfo(SB_VERT, &si, SIF_ALL);
int nMaxPos = si.nMax;
switch (nSBCode)
{
case SB_LINEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/m_nCount, nMaxPos-m_nScrollPos);
break;
case SB_LINEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(nMaxPos/m_nCount, m_nScrollPos);
break;
case SB_PAGEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(nMaxPos/10, nMaxPos-m_nScrollPos);
break;
case SB_PAGEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(nMaxPos/10, m_nScrollPos);
break;
case SB_THUMBPOSITION:
nDelta = (int)nPos - m_nScrollPos;
break;
default:
return;
}
SetRedraw(FALSE);
m_nScrollPos += nDelta;
SetScrollPos(SB_VERT, m_nScrollPos, TRUE);
ScrollWindow(0, -nDelta);
m_ButtonOK.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.OffsetRect(CSize(0, nDelta));
m_ButtonOK.MoveWindow(&rect);
m_ButtonCancel.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.OffsetRect(CSize(0, nDelta));
m_ButtonCancel.MoveWindow(&rect);
m_SliderMinStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.OffsetRect(CSize(0, nDelta));
m_SliderMinStatic.MoveWindow(&rect);
m_SliderMaxStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.OffsetRect(CSize(0, nDelta));
m_SliderMaxStatic.MoveWindow(&rect);
m_SliderMinEdit.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.OffsetRect(CSize(0, nDelta));
m_SliderMinEdit.MoveWindow(&rect);
m_SliderMaxEdit.GetWindowRect(&rect);
ScreenToClient(&rect);
rect.OffsetRect(CSize(0, nDelta));
m_SliderMaxEdit.MoveWindow(&rect);
SetRedraw(TRUE);
m_ButtonOK.GetWindowRect(&rect);
ScreenToClient(&rect);
nLeft = rect.right+1;
nRight = rect.left-1;
GetClientRect(&rect);
rect.right = nRight;
RedrawWindow(&rect, NULL, RDW_INVALIDATE | RDW_UPDATENOW |
RDW_ALLCHILDREN | RDW_ERASE);
GetWindowRect(&rect);
ScreenToClient(&rect);
rect.left = nLeft;
RedrawWindow(&rect, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME
| RDW_ERASE);
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CDlgParameter::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar*
pScrollBar)
{
int k;
for (k = 0; k < m_nCount; k++)
{
if (pScrollBar == (CWnd*)&m_SliderParameter[k])
{
switch (nSBCode)
{
case SB_LEFT:
case SB_RIGHT:
case SB_ENDSCROLL:
case SB_LINELEFT:
case SB_LINERIGHT:
case SB_PAGELEFT:
case SB_PAGEDOWN:
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
UpdateEdit(k);
break;
default:
{}
}
}
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
BOOL CDlgParameter::OnMouseWheel(UINT nFlags, short zDelta, CPoint
pt)
{
SendMessage(WM_VSCROLL, MAKEWPARAM(zDelta > 0 ? SB_PAGEUP :
SB_PAGEDOWN, 0), (LPARAM)NULL);
return CDialog::OnMouseWheel(nFlags, zDelta, pt);
}
void CDlgParameter::OnChangeEditParameter(UINT nID)
{
int k = (nID-IDC_EDIT_PARAMETER)/3;
if (UpdateDataPart(k, TRUE))
UpdateSlider(k);
}
void CDlgParameter::OnChangeEditSliderMin()
{
if (UpdateDataPart1(TRUE))
{
int k;
for (k = 0; k < m_nCount; k++)
{
UpdateSlider(k);
}
}
}
void CDlgParameter::OnChangeEditSliderMax()
{
if (UpdateDataPart2(TRUE))
{
int k;
for (k = 0; k < m_nCount; k++)
{
UpdateSlider(k);
}
}
}
BOOL CDlgParameter::UpdateDataPart(int k, BOOL bSaveAndValidate)
{
// this function is adapted from CWnd::UpdateData.
ASSERT(::IsWindow(m_hWnd)); // calling UpdateData before DoModal?
CDataExchange dx(this, bSaveAndValidate);
// prevent control notifications from being dispatched during
UpdateData
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
HWND hWndOldLockout = pThreadState->m_hLockoutNotifyWindow;
ASSERT(hWndOldLockout != m_hWnd); // must not recurse
pThreadState->m_hLockoutNotifyWindow = m_hWnd;
int nStartChar = -1, nEndChar = -1;
BOOL bOK = FALSE; // assume failure
TRY
{
//DoDataExchange(&dx);
CDataExchange* pDX = &dx;
m_EditParameter[k].GetSel(nStartChar, nEndChar);
DDX_TextCommaNMB(pDX, IDC_EDIT_PARAMETER+3*k, m_dParameter[k]);
bOK = TRUE; // it worked
}
CATCH(CUserException, e)
{
// validation failed - user already alerted, fall through
ASSERT(!bOK);
m_EditParameter[k].SetSel(nStartChar, nEndChar);
// Note: DELETE_EXCEPTION_(e) not required
}
AND_CATCH_ALL(e)
{
// validation failed due to OOM or other resource failure
e->ReportError(MB_ICONEXCLAMATION, AFX_IDP_INTERNAL_FAILURE);
ASSERT(!bOK);
DELETE_EXCEPTION(e);
}
END_CATCH_ALL
pThreadState->m_hLockoutNotifyWindow = hWndOldLockout;
return bOK;
}
BOOL CDlgParameter::UpdateDataPart1(BOOL bSaveAndValidate)
{
// this function is adapted from CWnd::UpdateData.
ASSERT(::IsWindow(m_hWnd)); // calling UpdateData before DoModal?
CDataExchange dx(this, bSaveAndValidate);
// prevent control notifications from being dispatched during
UpdateData
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
HWND hWndOldLockout = pThreadState->m_hLockoutNotifyWindow;
ASSERT(hWndOldLockout != m_hWnd); // must not recurse
pThreadState->m_hLockoutNotifyWindow = m_hWnd;
int nStartChar = -1, nEndChar = -1;
BOOL bOK = FALSE; // assume failure
TRY
{
//DoDataExchange(&dx);
CDataExchange* pDX = &dx;
double dSliderRangeMinOld = m_dSliderRangeMin;
m_SliderMinEdit.GetSel(nStartChar, nEndChar);
DDX_TextCommaNMB(pDX, IDC_EDIT_SLIDER_MIN, m_dSliderRangeMin);
bOK = TRUE; // it worked
if (m_dSliderRangeMin > m_dSliderRangeMax)
{
bOK = FALSE;
m_dSliderRangeMin = dSliderRangeMinOld;
}
}
CATCH(CUserException, e)
{
// validation failed - user already alerted, fall through
ASSERT(!bOK);
m_SliderMinEdit.SetSel(nStartChar, nEndChar);
// Note: DELETE_EXCEPTION_(e) not required
}
AND_CATCH_ALL(e)
{
// validation failed due to OOM or other resource failure
e->ReportError(MB_ICONEXCLAMATION, AFX_IDP_INTERNAL_FAILURE);
ASSERT(!bOK);
DELETE_EXCEPTION(e);
}
END_CATCH_ALL
pThreadState->m_hLockoutNotifyWindow = hWndOldLockout;
return bOK;
}
BOOL CDlgParameter::UpdateDataPart2(BOOL bSaveAndValidate)
{
// this function is adapted from CWnd::UpdateData.
ASSERT(::IsWindow(m_hWnd)); // calling UpdateData before DoModal?
CDataExchange dx(this, bSaveAndValidate);
// prevent control notifications from being dispatched during
UpdateData
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
HWND hWndOldLockout = pThreadState->m_hLockoutNotifyWindow;
ASSERT(hWndOldLockout != m_hWnd); // must not recurse
pThreadState->m_hLockoutNotifyWindow = m_hWnd;
int nStartChar = -1, nEndChar = -1;
BOOL bOK = FALSE; // assume failure
TRY
{
//DoDataExchange(&dx);
CDataExchange* pDX = &dx;
double dSliderRangeMaxOld = m_dSliderRangeMax;
m_SliderMaxEdit.GetSel(nStartChar, nEndChar);
DDX_TextCommaNMB(pDX, IDC_EDIT_SLIDER_MAX, m_dSliderRangeMax);
bOK = TRUE; // it worked
if (m_dSliderRangeMax < m_dSliderRangeMin)
{
bOK = FALSE;
m_dSliderRangeMax = dSliderRangeMaxOld;
}
}
CATCH(CUserException, e)
{
// validation failed - user already alerted, fall through
ASSERT(!bOK);
m_SliderMaxEdit.SetSel(nStartChar, nEndChar);
// Note: DELETE_EXCEPTION_(e) not required
}
AND_CATCH_ALL(e)
{
// validation failed due to OOM or other resource failure
e->ReportError(MB_ICONEXCLAMATION, AFX_IDP_INTERNAL_FAILURE);
ASSERT(!bOK);
DELETE_EXCEPTION(e);
}
END_CATCH_ALL
pThreadState->m_hLockoutNotifyWindow = hWndOldLockout;
return bOK;
}
void CDlgParameter::UpdateEdit(int k)
{
int nMinRange = m_SliderParameter[k].GetRangeMin();
int nMaxRange = m_SliderParameter[k].GetRangeMax();
int nPos = m_SliderParameter[k].GetPos();
m_dParameter[k] = (m_dSliderRangeMax-m_dSliderRangeMin)*(nPos-
nMinRange)/(nMaxRange-nMinRange) + m_dSliderRangeMin;
UpdateDataPart(k, FALSE);
}
void CDlgParameter::UpdateSlider(int k)
{
int nMinRange = m_SliderParameter[k].GetRangeMin();
int nMaxRange = m_SliderParameter[k].GetRangeMax();
int nPos;
nPos = (int)round((nMaxRange-nMinRange)*(m_dParameter[k]-
m_dSliderRangeMin)/(m_dSliderRangeMax-m_dSliderRangeMin) + nMinRange);
if (nMinRange <= nPos && nPos <= nMaxRange)
{
m_SliderParameter[k].EnableWindow(TRUE);
m_SliderParameter[k].SetPos(nPos);
}
else
{
m_SliderParameter[k].EnableWindow(FALSE);
if (nPos < nMinRange)
m_SliderParameter[k].SetPos(nMinRange);
else
m_SliderParameter[k].SetPos(nMaxRange);
}
}