How to use CEdit Control variable updated from a tab to the dialog box ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: How to use CEdit Control variable updated from a tab to the dialog box ?

  1. #1
    Join Date
    Jun 2014
    Posts
    6

    How to use CEdit Control variable updated from a tab to the dialog box ?

    Hello everyone,

    I have one Tab called Tab4 and one main dialog box called CGrabDlg. The values of my variables are not updated when I change them. Does someone have an idea ?

    Here my constructor of my Tab :

    Code:
    CTab4::CTab4(CWnd* pParent /*=NULL*/)
    	: CDialogEx(CTab4::IDD, pParent )
    	, iFilter1(_T("F1_350"))
    	, iFilter2(_T("F2_400"))
    	, iFilter3(_T("F3_450"))
    	, iFilter4(_T("F4_500"))
    	, iFilter5(_T("F5_550"))
    	, iFilter6(_T("F6_600"))
    	, iFilter7(_T("F7_650"))
    	, iFilter8(_T("F8_700"))
    	, iFilter9(_T("F9_750"))
    	, iFilter10(_T("F10_800"))
    
    	, iExTimeF1(1000)
    	, iExTimeF2(5000)
    	, iExTimeF3(10000)
    	, iExTimeF4(15000)
    	, iExTimeF5(20000)
    	, iExTimeF6(25000)
    	, iExTimeF7(30000)
    	, iExTimeF8(30000)
    	, iExTimeF9(30000)
    	, iExTimeF10(30000)
    
    	, iGainF1(300)
    	, iGainF2(350)
    	, iGainF3(400)
    	, iGainF4(450)
    	, iGainF5(500)
    	, iGainF6(550)
    	, iGainF7(600)
    	, iGainF8(650)
    	, iGainF9(700)
    	, iGainF10(800)
    	, iDirectoryPath(_T("C://Filter Wheel/DIR1"))
    	, iPrefix(_T("Images"))
    	, iFileType(_T("BMP"))
    {
    	
    }
    My function to get the variable to the main dialog box :

    Code:
    int* CTab4::ModeCustom(int k)
    {
    	int* GainExTimeF = new int[2];
    
    	GainF[1] = iGainF1;
    	GainF[2] = iGainF2;
    	GainF[3] = iGainF3;
    	GainF[4] = iGainF4;
    	GainF[5] = iGainF5;
    	GainF[6] = iGainF6;
    	GainF[7] = iGainF7;
    	GainF[8] = iGainF8;
    	GainF[9] = iGainF9;
    	GainF[10] = iGainF10;
    
    	ExTimeF[1] = iExTimeF1;
    	ExTimeF[2] = iExTimeF2;
    	ExTimeF[3] = iExTimeF3;
    	ExTimeF[4] = iExTimeF4;
    	ExTimeF[5] = iExTimeF5;
    	ExTimeF[6] = iExTimeF6;
    	ExTimeF[7] = iExTimeF7;
    	ExTimeF[8] = iExTimeF8;
    	ExTimeF[9] = iExTimeF9;
    	ExTimeF[10] = iExTimeF10;
    
    	GainExTimeF[1] = GainF[k];
    	GainExTimeF[2] = ExTimeF[k];
    
    	return GainExTimeF;
    }
    Here my call in the main dialog box :

    Code:
    void CGrabDlg::OnBnClickedButtonStartAutomode()
    {
    	MyCom.Initialization();
    
    	CString* cConsole = new CString[2];
    	DWORD D;
    	INT64* pGainExTime = new INT64[6];
    	int* GainExTimeF = new int[2];
    
    
    	for (int k = 1; k < 11; k++)
    	{
    		UpdateData(true);
    		// Custom Gain and Exposure Time from Tab4 (settings)
    		GainExTimeF = SettingsTab.ModeCustom(k);
    
    		// Set Gain and Exposure Time
    		pGainExTime = Call.ExposureTime(GainExTimeF[1], GainExTimeF[2]);
    
    		// Grab an image 
    		cConsole = Call.MultiSpectral(k);
    	}
    	
    }
    Actually it is working but the only values I can get are the ones initialized.

    Screen : http://hpics.li/c1a190e

    Thanks

    Mikael

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    I'm not really sure what your question is, but arrays are 0 based. If you have an array of length 2, valid index values are 0 and 1.

  3. #3
    Join Date
    Jun 2014
    Posts
    6

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    Well I know that I should use index 0 but it is working like this.

    Ok so let me clarify my problem. I have 20 variables, 10 for the "Gain" and 10 for the "Exposure Time" from CEdit Controls in my Tab. Now I wanna use those variables with a function in my main Dialog Box. It is working but when I change the variables in the CEdit Controls, the variables are not updated in my function. So the function is working only with the values I initialized in the constructor of my Tab.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    Quote Originally Posted by Mendeln View Post
    Well I know that I should use index 0 but it is working like this.
    If it appears to be working with those indexes, it's sheer dumb luck. That code is incorrect and will cause you problems.

    As to your question, you'd need to call UpdateData (which takes a BOOL, not a bool) from CTab4, not CGrabDlg. I don't see why you need to call it every time through the loop either.
    Last edited by GCDEF; June 24th, 2014 at 01:30 PM.

  5. #5
    Join Date
    Jun 2014
    Posts
    6

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    I tried and nothing has changed.

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    Quote Originally Posted by Mendeln View Post
    I tried and nothing has changed.
    Post your current code, but please change those indexes. That behavior is undefined, and that's really the first thing you need to fix.

  7. #7
    Join Date
    Jun 2014
    Posts
    6

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    Here my code :

    Tab4.h

    Code:
    #include "Stream.h"
    #include "Serie.h"
    #pragma once
    
    
    // CTab4 dialog
    
    class CTab4 : public CDialogEx
    {
    	DECLARE_DYNAMIC(CTab4)
    
    public:
    	CTab4(CWnd* pParent = NULL);   // standard constructor
    	virtual ~CTab4();
    
    // Dialog Data
    	enum { IDD = IDD_TAB4 };
    
    protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    
    	DECLARE_MESSAGE_MAP()
    public:
    	BOOL CTab4::OnInitDialog();
    	CTab4* SettingsTab;
    
    	CString iFilter1;
    	CString iFilter2;
    	CString iFilter3;
    	CString iFilter4;
    	CString iFilter5;
    	CString iFilter6;
    	CString iFilter7;
    	CString iFilter8;
    	CString iFilter9;
    	CString iFilter10;
    
    	long iExTimeF1;
    	long iExTimeF2;
    	long iExTimeF3;
    	long iExTimeF4;
    	long iExTimeF5;
    	long iExTimeF6;
    	long iExTimeF7;
    	long iExTimeF8;
    	long iExTimeF9;
    	long iExTimeF10;
    
    	int iGainF1;
    	int iGainF2;
    	int iGainF3;
    	int iGainF4;
    	int iGainF5;
    	int iGainF6;
    	int iGainF7;
    	int iGainF8;
    	int iGainF9;
    	int iGainF10;
    
    	Stream Call;
    	CSerie MyCom;
    	CString iDirectoryPath;
    	CString iPrefix;
    	CString iFileType;
    	CComboBox jFileType;
    
    	afx_msg void OnBnClickedButtonset();
    	void CTab4::FormatComboBox();
    	int* CTab4::ModeCustom(int k);
    	int* GainF = new int[11];
    	int* ExTimeF = new int[11];
    };
    Tab4.cpp

    Code:
    #include "stdafx.h"
    #include "Grab.h"
    #include "Tab4.h"
    #include "afxdialogex.h"
    #include "Stream.h"
    #include "Serie.h"
    
    
    // CTab4 dialog
    
    IMPLEMENT_DYNAMIC(CTab4, CDialogEx)
    
    CTab4::CTab4(CWnd* pParent /*=NULL*/)
    	: CDialogEx(CTab4::IDD, pParent )
    	, iFilter1(_T("F1_350"))
    	, iFilter2(_T("F2_400"))
    	, iFilter3(_T("F3_450"))
    	, iFilter4(_T("F4_500"))
    	, iFilter5(_T("F5_550"))
    	, iFilter6(_T("F6_600"))
    	, iFilter7(_T("F7_650"))
    	, iFilter8(_T("F8_700"))
    	, iFilter9(_T("F9_750"))
    	, iFilter10(_T("F10_800"))
    
    	, iExTimeF1(1000)
    	, iExTimeF2(5000)
    	, iExTimeF3(10000)
    	, iExTimeF4(15000)
    	, iExTimeF5(20000)
    	, iExTimeF6(25000)
    	, iExTimeF7(30000)
    	, iExTimeF8(30000)
    	, iExTimeF9(30000)
    	, iExTimeF10(30000)
    
    	, iGainF1(300)
    	, iGainF2(350)
    	, iGainF3(400)
    	, iGainF4(450)
    	, iGainF5(500)
    	, iGainF6(550)
    	, iGainF7(600)
    	, iGainF8(650)
    	, iGainF9(700)
    	, iGainF10(800)
    	, iDirectoryPath(_T("C://Filter Wheel/DIR1"))
    	, iPrefix(_T("Images"))
    	, iFileType(_T("BMP"))
    {
    	
    }
    
    CTab4::~CTab4()
    {
    
    }
    
    void CTab4::DoDataExchange(CDataExchange* pDX)
    {
    	CDialogEx::DoDataExchange(pDX);
    	DDX_Text(pDX, IDC_EDITFILTER1, iFilter1);
    	DDX_Text(pDX, IDC_EDITFILTER2, iFilter2);
    	DDX_Text(pDX, IDC_EDITFILTER3, iFilter3);
    	DDX_Text(pDX, IDC_EDITFILTER4, iFilter4);
    	DDX_Text(pDX, IDC_EDITFILTER5, iFilter5);
    	DDX_Text(pDX, IDC_EDITFILTER6, iFilter6);
    	DDX_Text(pDX, IDC_EDITFILTER7, iFilter7);
    	DDX_Text(pDX, IDC_EDITFILTER8, iFilter8);
    	DDX_Text(pDX, IDC_EDITFILTER9, iFilter9);
    	DDX_Text(pDX, IDC_EDITFILTER10, iFilter10);
    
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F1, iExTimeF1);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F2, iExTimeF2);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F3, iExTimeF3);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F4, iExTimeF4);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F5, iExTimeF5);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F6, iExTimeF6);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F7, iExTimeF7);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F_8, iExTimeF8);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F9, iExTimeF9);
    	DDX_Text(pDX, IDC_EDIT_EXTIME_F10, iExTimeF10);
    
    	DDX_Text(pDX, IDC_EDIT_GAIN_F1, iGainF1);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F2, iGainF2);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F3, iGainF3);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F4, iGainF4);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F5, iGainF5);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F6, iGainF6);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F7, iGainF7);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F8, iGainF8);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F9, iGainF9);
    	DDX_Text(pDX, IDC_EDIT_GAIN_F10, iGainF10);
    
    	DDX_Text(pDX, IDC_MFC_DIRECTORY_BROWSE, iDirectoryPath);
    	DDX_Text(pDX, IDC_EDITPREFIX, iPrefix);
    	DDX_CBString(pDX, IDC_COMBO_FILETYPE, iFileType);
    	DDX_Control(pDX, IDC_COMBO_FILETYPE, jFileType);
    }
    
    
    BEGIN_MESSAGE_MAP(CTab4, CDialogEx)
    	ON_BN_CLICKED(IDC_BUTTONSET, &CTab4::OnBnClickedButtonset)
    END_MESSAGE_MAP()
    
    BOOL CTab4::OnInitDialog()
    {
    	CDialogEx::OnInitDialog();
    	COLORREF color;
    	color = RGB(220, 220, 220);
    	CDialogEx::SetBackgroundColor(color, 1);
    	FormatComboBox();
    
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }
    
    // CTab4 message handlers
    
    
    
    void CTab4::OnBnClickedButtonset()
    {
    	UpdateData(TRUE);
    	UpdateData(FALSE);
    }
    
    void CTab4::FormatComboBox()
    {
    	CString str;
    	int nIndex;
    	str.Format(L"PNG");
    	nIndex = jFileType.AddString(str);
    
    	str.Format(L"JPG");
    	nIndex = jFileType.AddString(str);
    
    	str.Format(L"TIFF");
    	nIndex = jFileType.AddString(str);
    
    }
    
    int* CTab4::ModeCustom(int k)
    {
    	int* GainExTimeF = new int[2];
    
    	GainF[1] = iGainF1;
    	GainF[2] = iGainF2;
    	GainF[3] = iGainF3;
    	GainF[4] = iGainF4;
    	GainF[5] = iGainF5;
    	GainF[6] = iGainF6;
    	GainF[7] = iGainF7;
    	GainF[8] = iGainF8;
    	GainF[9] = iGainF9;
    	GainF[10] = iGainF10;
    
    	ExTimeF[1] = iExTimeF1;
    	ExTimeF[2] = iExTimeF2;
    	ExTimeF[3] = iExTimeF3;
    	ExTimeF[4] = iExTimeF4;
    	ExTimeF[5] = iExTimeF5;
    	ExTimeF[6] = iExTimeF6;
    	ExTimeF[7] = iExTimeF7;
    	ExTimeF[8] = iExTimeF8;
    	ExTimeF[9] = iExTimeF9;
    	ExTimeF[10] = iExTimeF10;
    
    	GainExTimeF[0] = GainF[k];
    	GainExTimeF[1] = ExTimeF[k];
    
    	return GainExTimeF;
    }
    GrabDlg.h

    Code:
    public:
    	Stream Call;
    	CSerie MyCom;
    	CGrabDlg* Dialog;
    	CTab4 SettingsTab;
    
    GrabDlg.cpp
    Code:
    void CGrabDlg::OnBnClickedButtonStartAutomode()
    {
    	MyCom.Initialization();
    
    	CString* cConsole = new CString[2];
    	DWORD D;
    	INT64* pGainExTime = new INT64[6];
    	int* GainExTimeF = new int[2];
    
    
    	for (int k = 1; k < 3; k++)
    	{
    		UpdateData(true);
    		// Custom Gain and Exposure Time from Tab4 (settings)
    		GainExTimeF = SettingsTab.ModeCustom(k);
    
    		// Set Gain and Exposure Time
    		pGainExTime = Call.ExposureTime(GainExTimeF[0], GainExTimeF[1]);
    		iGain = GainExTimeF[0];
    		iExTime = GainExTimeF[1];
    		UpdateData(false);
    
    		// Grab an image 
    		cConsole = Call.MultiSpectral(k);
    	}
    	
    }
    I can't show more cause my code is too big.

    Thank you for your help. Please look at the screenshot in my first post you will maybe get a better idea.

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    I don't see you calling UpdateData in CTab4. And again, the arguments to UpdateData are TRUE and FALSE, not true and false, and again, I'm not sure why you're calling it in the loop.

  9. #9
    Join Date
    Jun 2014
    Posts
    6

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    When I call UpdateData(TRUE) in the function int* CTab4::ModeCustom(int k) I have a fatal error while I call it with my main dialog box.

    There is also a button where I have UpdateData(TRUE) but it's not working.

    And I tried to do it in the loop because I am desperate.

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    Your use of subscripts is still troubling me. If GainF and ExTimeF are defined with a size of 10, I would expect ModeCustom to crash.

    Just putting UpdateData(TRUE) at the start of that function shouldn't cause a crash. Time to use the debugger.

  11. #11
    Join Date
    Jun 2014
    Posts
    6

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    The problem is clearly not arrays, even if I tried your solution.

    I don't know why UpdateData(TRUE) makes my program crash while using it in my function. I don't know either how to use debugger to find this bug.

    But as I told you I am using a button where UpdateData(TRUE) is there.

  12. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    Quote Originally Posted by Mendeln View Post
    The problem is clearly not arrays, even if I tried your solution.

    I don't know why UpdateData(TRUE) makes my program crash while using it in my function. I don't know either how to use debugger to find this bug.

    But as I told you I am using a button where UpdateData(TRUE) is there.
    Stepping over array boundaries is a big problem that will make a program do all kinds of weird things. I can't stress enough how important it is that you realize that that is a problem that needs to be fixed. There's really no point in even looking at anything else until you do. If you're still getting a crash, use your debugger to find out why.

    There's stuff in your code that doesn't make sense to me. What's the point in this for example?
    UpdateData(TRUE);
    UpdateData(FALSE);

    You need to slow down and fix one thing at a time rather than just throwing stuff at the problem in the hope you get lucky. Fix the arrays, then use the debugger.
    Last edited by GCDEF; June 24th, 2014 at 02:42 PM.

  13. #13
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,848

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    If GainF and ExTimeF are defined with a size of 10, I would expect ModeCusto
    They are defined as size 11.

    I don't know why UpdateData(TRUE) makes my program crash while using it in my function. I don't know either how to use debugger to find this bug.
    You single step through the code in the debugger looking at the contents of the variables until one doesn't contain the value expected or the program crashes. You then know which line caused the problem. You can set break points so that the program stops when it comes to a set breakpoint and then single step from there and you can either step into a function or treat the function call as just one statement.

    For info about using the debugger see http://msdn.microsoft.com/en-us/library/k0k771bt.aspx
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  14. #14
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    Quote Originally Posted by 2kaud View Post
    They are defined as size 11.
    Don't know how I missed that. I looked for it several times.

  15. #15
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,606

    Re: How to use CEdit Control variable updated from a tab to the dialog box ?

    Quote Originally Posted by Mendeln View Post
    The problem is clearly not arrays, even if I tried your solution.
    But your recent code does NOT show that you "tried" GCDEF's solution!

    Quote Originally Posted by Mendeln View Post
    I don't know why UpdateData(TRUE) makes my program crash while using it in my function. I don't know either how to use debugger to find this bug.
    http://msdn.microsoft.com/en-us/libr...__Just_My_Code
    Victor Nijegorodov

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center