The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Problem linking controls on tabbed dialog

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
peter.cook Posted - 03/02/2005 : 07:33:48 AM
Origin Version (Select Help-->About Origin): 7.5SR5
Operating System: Win2000

Hi,

Can anyone please help me try to refer to (eg) a checkbox on a tabbed dialog when I click the ok button on the main dialog? The example tabs provided doesn't show this. The message I typically get refers to an unattached wrapper class. The code below is where I'm at. Essentially when I click OK (main dialog) I want to read all control values (from tab sheets) and then save as LT values. Thanks.

 /*------------------------------------------------------------------------------*
* File Name: *
* Creation: *
* Purpose: OriginC Source C file *
* Copyright (c) ABCD Corp. 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 *
* All Rights Reserved *
* *
* Modification Log: *
*------------------------------------------------------------------------------*/

#include <Origin.h>
#include <Dialog.h>
#include "AZDRRes.h"

class DATAANDFITTING : public PropertyPage
{
public:
// Constructor for DATAANDFITTING page
DATAANDFITTING(int nID) : PropertyPage(nID) {}

// Event handlers for DATAANDFITTING page
EVENTS_BEGIN
PAGE_ON_INIT(OnInitPage)
PAGE_ON_ACTIVE(OnActivatePage)
ON_BN_CLICKED( IDC_VARYCURVETOP, OnClickVaryCurveTop )
ON_BN_CLICKED( IDC_VARYSLOPE, OnClickVarySlope )
EVENTS_END

BOOL OnInitPage()
{
// Get all Check Box controls
m_btnVarySlope = GetItem( IDC_VARYSLOPE );
m_btnVaryCurveTop = GetItem( IDC_VARYCURVETOP );
m_btnVaryCurveBottom = GetItem( IDC_VARYCURVEBOTTOM );

m_btnVarySlope.Check=1;
m_btnVaryCurveTop.Check=1;
m_btnVaryCurveBottom.Check=1;

int pete = m_btnVaryCurveBottom.Check;
out_int("value =",pete);

return TRUE;
}

BOOL OnActivatePage()
{
return TRUE;
}

BOOL OnClickVaryCurveTop ( Control ctrl )
{
out_str("Vary Curve Top");
return TRUE;
}

BOOL OnClickVarySlope ( Control ctrl )
{
out_str("Vary Slope Factor");
return TRUE;
}

private:
Button m_btnVarySlope;
Button m_btnVaryCurveTop;
Button m_btnVaryCurveBottom;
};

class RESULTSANDDISPLAY : public PropertyPage
{
public:
// Constructor for RESULTSANDDISPLAY page
RESULTSANDDISPLAY(int nID) : PropertyPage(nID) {}

// Event handlers for RESULTSANDDISPLAY page
EVENTS_BEGIN
PAGE_ON_INIT(OnInitPage)
PAGE_ON_ACTIVE(OnActivatePage)
EVENTS_END

BOOL OnInitPage()
{
return TRUE;
}

BOOL OnActivatePage()
{
return TRUE;
}
};

class ADDITIONALSETTINGS : public PropertyPage
{
public:
// Constructor for ADDITIONALSETTINGS page
ADDITIONALSETTINGS(int nID) : PropertyPage(nID) {}

// Event handlers for ADDITIONALSETTINGS page
EVENTS_BEGIN
PAGE_ON_INIT(OnInitPage)
PAGE_ON_ACTIVE(OnActivatePage)
EVENTS_END

BOOL OnInitPage()
{
return TRUE;
}

BOOL OnActivatePage()
{
return TRUE;
}
};



class AZDRDIALOGPlaceHolder : public PropertySheet
{
public:
AZDRDIALOGPlaceHolder()
{
m_DATAANDFITTING.SetID(IDD_FIRSTTAB);
AddPage(m_DATAANDFITTING);
m_RESULTSANDDISPLAY.SetID(IDD_SECONDTAB);
AddPage(m_RESULTSANDDISPLAY);
m_ADDITIONALSETTINGS.SetID(IDD_THIRDTAB);
AddPage(m_ADDITIONALSETTINGS);
}

void InitMaps()
{
m_DATAANDFITTING.InitMsgMap();
m_RESULTSANDDISPLAY.InitMsgMap();
m_ADDITIONALSETTINGS.InitMsgMap();
}

DATAANDFITTING m_DATAANDFITTING;
RESULTSANDDISPLAY m_RESULTSANDDISPLAY;
ADDITIONALSETTINGS m_ADDITIONALSETTINGS;
};


class AZDRDIALOG : public Dialog
{
public:
AZDRDIALOG() : Dialog(IDD_AZDR, "AZDR")
{
}

int DoModal(HWND hParent = NULL)
{
InitMsgMap();// will be called from internal later
int nRet = Dialog::DoModal(hParent);
return nRet;
}

protected:
///----------------- Message Map ----------------
EVENTS_BEGIN
PAGE_ON_INIT(OnInitDialog)
PAGE_ON_OK(OnClickOk)
EVENTS_END
///----------------------------------------------

BOOL OnInitDialog()
{
m_PlaceHolder.Create(IDC_TAB_PLACEHOLDER, *this);
m_PlaceHolder.InitMaps();

return TRUE;
}

BOOL OnClickOk()
{
out_str("Click OK");
// Save Settings
// Read Settings to LabTalks
int jr = m_btnVarySlope.Check;
out_int("value = ",jr);
//LT_set_var("VaryCurveBottom",m_btnVaryCurveBottom.Check);
return TRUE;
}

AZDRDIALOGPlaceHolder m_PlaceHolder;

};


Cheers,

Pete

7   L A T E S T    R E P L I E S    (Newest First)
peter.cook Posted - 03/09/2005 : 08:04:26 AM
Hi,

Thanks for the example. After a couple of days effort I managed to use this to get my Dialog to do the business. The code looks really complicated (I don't understand it all - no surprise there) and I have wondered if the effort was worthwhile but now it's done easier for the next time. I'd like to suggest some further changes to the tab example and if possible could I send my (longer) example to you to check..it works but I'm not sure how much of the code is required.

Cheers,

Pete

Gary Lane Posted - 03/03/2005 : 4:20:05 PM
Hi Peter,

Eric updated the code for the Dialog Builder Tabs sample which
I posted below. You should be able to just replace all code in
the supplied sample cpp file with the code below. I hope this
helps.

Gary
OriginLab



/*------------------------------------------------------------------------------*
* File Name: Tabs.cpp *
* Creation: GJL 11/11/03 *
* Purpose: OriginC Source CPP file containing sample code for the Tabs Dialog *
* Builder example. *
* Copyright (c) OriginLab Corp. 2003, 2004, 2005, 2006, 2007 *
* *
* Modification Log: *
* EJP 2005-03-03 ADD_DATA_TREE *
*------------------------------------------------------------------------------*/

#include <Origin.h>
#include <Dialog.h>
#include "TabsRes.h"

class TabSheet;

// Base Tab class
class Tab : public PropertyPage
{
public:

// Constructor for base Tab class
Tab(int nID) : PropertyPage(nID) {}

// Event handler when Tab becomes active (inherited by all Tab derived classes)
BOOL OnActiveTab()
{
int iTabNum = GetID() - IDD_FIRSTTAB + 1;
printf("Tab%d Active\n", iTabNum);
return TRUE;
}

/// EJP 2005-03-03 ADD_DATA_TREE
BOOL InitTab(int nID, TabSheet *pSheet)
{
SetID(nID);
m_pSheet = pSheet;
return TRUE;
}

TabSheet *m_pSheet;
/// end ADD_DATA_TREE
};

// Derived Tab class for Tab1
class Tab1 : public Tab
{
public:

// Constructor for Tab1 class
Tab1(int nID) : Tab(nID) { }

// InitMsgMap function setting up event handler map for Tab1
EVENTS_BEGIN
PAGE_ON_INIT(OnInitTab)
PAGE_ON_ACTIVE(OnActiveTab)
ON_BN_CLICKED(IDC_BUTTON1, OnClickToggleButton)
EVENTS_END

// Event handlers for Tab1
BOOL OnInitTab()
{
out_str("Tab1 Init");
m_btnCheckBox = GetItem(IDC_CHECK1);
m_btnCheckBox.Check = 1;

/// EJP 2005-03-03 ADD_DATA_TREE
UpdateData(FALSE); // FALSE = data to dialog
/// end ADD_DATA_TREE

return TRUE;
}

BOOL OnClickToggleButton(Control ctrl)
{
out_str("Click Toggle Button");
m_btnCheckBox.Check = mod(m_btnCheckBox.Check + 1, 2);
return TRUE;
}

/// EJP 2005-03-03 ADD_DATA_TREE
BOOL UpdateData(BOOL bDialogToData=TRUE)
{
if( bDialogToData )
{
if( m_btnCheckBox )
m_pSheet->m_tnData.Tab1.CheckBox.nVal = m_btnCheckBox.Check;
}
else // data to dialog
{
int n;

if( m_btnCheckBox )
{
if( m_pSheet->m_tnData.Tab1.CheckBox )
n = m_pSheet->m_tnData.Tab1.CheckBox.nVal;
else
n = 0; // lets have our internal default be off
m_btnCheckBox.Check = n;
}
}
return TRUE;
}
/// end ADD_DATA_TREE

// Data member controls on Tab1
Button m_btnCheckBox;
};

// Derived Tab class for Tab2
class Tab2 : public Tab
{
public:

// Constructor for Tab2 class
Tab2(int nID) : Tab(nID) {}

// InitMsgMap function setting up event handler map for Tab2
EVENTS_BEGIN
PAGE_ON_INIT(OnInitTab)
PAGE_ON_ACTIVE(OnActiveTab)
ON_BN_CLICKED(IDC_BUTTON2, OnClickUpperCaseButton)
EVENTS_END

// Event handlers for Tab2
BOOL OnInitTab()
{
out_str("Tab2 Init");
m_ebxText = GetItem(IDC_EDIT1);

/// EJP 2005-03-03 ADD_DATA_TREE
UpdateData(FALSE); // FALSE = data to dialog
/// end ADD_DATA_TREE

return TRUE;
}

BOOL OnClickUpperCaseButton(Control ctrl)
{
out_str("Click Upper Case Button");
m_ebxText.Text.MakeUpper();
return TRUE;
}

/// EJP 2005-03-03 ADD_DATA_TREE
BOOL UpdateData(BOOL bDialogToData=TRUE)
{
if( bDialogToData )
{
if( m_ebxText )
m_pSheet->m_tnData.Tab2.EditBox.strVal = m_ebxText.Text;
}
else // data to dialog
{
string str;

if( m_ebxText )
{
if( m_pSheet->m_tnData.Tab2.EditBox )
str = m_pSheet->m_tnData.Tab2.EditBox.strVal;
m_ebxText.Text = str;
}
}
return TRUE;
}
/// end ADD_DATA_TREE

// Data member controls on Tab2
Edit m_ebxText;
};

// Derived Tab class for Tab3
class Tab3 : public Tab
{
public:

// Constructor for Tab3 class
Tab3(int nID) : Tab(nID) { }

// InitMsgMap function setting up event handler map for Tab3
EVENTS_BEGIN
PAGE_ON_INIT(OnInitTab)
PAGE_ON_ACTIVE(OnActiveTab)
ON_BN_CLICKED(IDC_BUTTON3, OnClickOutputButton)
EVENTS_END

// Event handlers for Tab3
BOOL OnInitTab()
{
out_str("Tab3 Init");
m_cmbxStooges = GetItem(IDC_COMBO1);
m_cmbxStooges.SetCurSel(0);

/// EJP 2005-03-03 ADD_DATA_TREE
UpdateData(FALSE); // FALSE = data to dialog
/// end ADD_DATA_TREE

return TRUE;
}

BOOL OnClickOutputButton(Control ctrl)
{
out_str("Click Output Button");
string str;
m_cmbxStooges.GetLBText(m_cmbxStooges.GetCurSel() ,str);
str.Format("You selected %s.",str);
str.Write(WRITE_MESSAGE_BOX);
return TRUE;
}

/// EJP 2005-03-03 ADD_DATA_TREE
BOOL UpdateData(BOOL bDialogToData=TRUE)
{
if( bDialogToData )
{
if( m_cmbxStooges )
m_pSheet->m_tnData.Tab3.ComboBoxSel.nVal = m_cmbxStooges.GetCurSel();
}
else // data to dialog
{
int n;

if( m_cmbxStooges )
{
if( m_pSheet->m_tnData.Tab3.ComboBoxSel )
n = m_pSheet->m_tnData.Tab3.ComboBoxSel.nVal;
m_cmbxStooges.SetCurSel(n);
}
}
return TRUE;
}
/// end ADD_DATA_TREE

// Data member controls on Tab3
ComboBox m_cmbxStooges;
};


// Tab place holder class
class TabSheet : public PropertySheet
{
public:

// Constructor for PropertySheet class
TabSheet()
{
/// EJP 2005-03-03 ADD_DATA_TREE
///m_Tab1.SetID(IDD_FIRSTTAB);
///m_Tab2.SetID(IDD_SECONDTAB);
///m_Tab3.SetID(IDD_THIRDTAB);
m_Tab1.InitTab(IDD_FIRSTTAB, this);
m_Tab2.InitTab(IDD_SECONDTAB, this);
m_Tab3.InitTab(IDD_THIRDTAB, this);
/// end ADD_DATA_TREE

AddPage(m_Tab1);
AddPage(m_Tab2);
AddPage(m_Tab3);
}

// Initialize message maps for each Tab
void InitMaps()
{
m_Tab1.InitMsgMap();
m_Tab2.InitMsgMap();
m_Tab3.InitMsgMap();
}

/// EJP 2005-03-03 ADD_DATA_TREE
BOOL UpdateData()
{
m_Tab1.UpdateData();
m_Tab2.UpdateData();
m_Tab3.UpdateData();
return TRUE;
}

// The data used to init and get the settings from each tab
// will be kept in a tree node.
TreeNode m_tnData;
/// end ADD_DATA_TREE

// Data members of PropertySheet are Tab objects
Tab1 m_Tab1;
Tab2 m_Tab2;
Tab3 m_Tab3;
};



// Main dialog class
class TabbedDialog : public Dialog
{
public:

// Constructor for main Dialog
TabbedDialog(int ID) : Dialog(ID, "Tabs.DLL")
{
SetResizingStyle(RESIZE_DEPENDENCY_DOMINANT_DIALOG);
}

// Function to launch main Dialog
int TabsDoModal(HWND hWnd)
{
InitMsgMap();
return DoModal(hWnd, DLG_MODAL_WITH_KEY);
}

// InitMsgMap function setting up event handlers for main Dialog
EVENTS_BEGIN
PAGE_ON_INIT(Init)
PAGE_ON_OK(OnClickOk)
PAGE_ON_CANCEL(OnClickCancel)
EVENTS_END

// Event handlers for main Dialog
BOOL Init()
{
out_str("Tabbed Dialog Init");
m_Sheet.Create(IDC_TAB_PLACEHOLDER, *this);
m_Sheet.InitMaps();
return TRUE;
}

BOOL OnClickOk()
{
out_str("Click OK Button");
m_Sheet.UpdateData();
return TRUE;
}

BOOL OnClickCancel()
{
out_str("Click Cancel Button");
return TRUE;
}

/// EJP 2005-03-03 ADD_DATA_TREE
BOOL SetData(TreeNode &tnData)
{
m_Sheet.m_tnData = tnData;
return TRUE;
}
/// end ADD_DATA_TREE

// Data member of main Dialog is PropertySheet (place holder)
TabSheet m_Sheet;
};

// Function to launch main Tabs dialog
void Tabs()
{
/// EJP 2005-03-03 ADD_DATA_TREE
Tree trData;
TreeNode tnTab;

tnTab = trData.AddNode("Tab1");
tnTab.AddNumericNode(0, "CheckBox");

tnTab = trData.AddNode("Tab2");
tnTab.AddTextNode("Enter Text to Upper Case", "EditBox");

tnTab = trData.AddNode("Tab3");
tnTab.AddNumericNode(0, "ComboBoxSel");

// Show tree contents before dialog
out_tree(trData);
/// end ADD_DATA_TREE

TabbedDialog tdlg(IDD_TABS);
tdlg.SetData(trData);
tdlg.TabsDoModal(GetWindow());

/// EJP 2005-03-03 ADD_DATA_TREE
// Show tree contents after dialog
out_tree(trData);
/// end ADD_DATA_TREE
}


Edited by - Gary Lane on 03/03/2005 4:23:28 PM
cpyang Posted - 03/03/2005 : 2:50:32 PM
Hi Peter,

we use a tree to store the dialog settings so each tab will get the tree values in OnActivatePage and to update the tree in OnKillActiviePage, so each page class will have code like


EVENTS_BEGIN
PAGE_ON_INIT(OnInitPage)
PAGE_ON_ACTIVE(OnActivatePage)
PAGE_ON_KILLACTIVE(OnKillActiviePage)
EVENTS_END

BOOL OnInitPage()
{
return TRUE;
}

BOOL OnActivatePage()
{
return TRUE;
}
BOOL OnKillActiviePage()
{
return TRUE;
}



We certainly should provide an exmaple, and Eric Parent is working on that.

As for tooltip, there is SetToolTip, so something like


BOOL OnInitDialog()
{
m_sldrVolumeSlider = GetItem( IDC_SETVOL_VOLUME_SLIDER );

m_sldrVolumeSlider.RangeMin = 0;
m_sldrVolumeSlider.RangeMax = 11;
m_sldrVolumeSlider.SetTicFreq(1);
m_sldrVolumeSlider.SetToolTip("some tooltip text");

return TRUE;
}





CP


peter.cook Posted - 03/03/2005 : 09:07:21 AM
Hi Gary,

Thanks for repsonse. If not already undertaken, could you please include tool tips as per other forum request?

Cheers,

pete

Gary Lane Posted - 03/03/2005 : 08:58:20 AM
Hi Pete,

CP has asked us to work with Eric to make an example showing how to do what you want. We will post it here and add it it to documentation when completed.

Gary
OriginLab

peter.cook Posted - 03/03/2005 : 06:48:41 AM
Hi Eric,

Thanks for reply.

1 & 2 solve it!

I understand your comments so what is the best way to do this - is it related to my previous question (I'd appreciate some help here) as in http://www.originlab.com/forum/topic.asp?TOPIC_ID=3764?

Cheers,

Pete

eparent Posted - 03/02/2005 : 2:32:06 PM
Hello Pete,

There are a couple changes you will need to make to your code.

1. In class DATAANDFITTING make the m_btnVarySlope public by moving it above the 'private:' statement. If you want to access all controls then simply remove the 'private:' statement.

2. In AZDRDIALOG's OnClickOk() do the following to get the check box and it's value.

Button btnVarSlope = m_PlaceHolder.m_DATAANDFITTING.m_btnVarySlope;
int jr = btnVarSlope.Check;

I should let you know that this is not a good way to code a dialog. The problem is if you never activate a tab then the controls on that tab are not initialized. So if you try to access controls on a tab that was not activated then you will still get the "unattached wrapper class" error. It is best to init your controls from some data source and then update the data source from the controls. After the dialog closes you simply access the data source.



The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000