Home > Software engineering >  VS2008 MFC frame, the Tab controls how to implement the son of variables and functions with each oth
VS2008 MFC frame, the Tab controls how to implement the son of variables and functions with each oth

Time:09-22

Now there is a main dialog box, CMyTab, m_tab,
Have two child dialogs CTabPage1 and CTabPage2,
The two sub box have student id, name, gender three edit box,

Application opens, the default display box 1, and display the student id, name, the default value of gender,

Now want to define three global variable student id, name, gender,

Problem a:
How the three global variables in OnInitDialog initialization?

Problem two:
How to make these three variables box 1, and the box 2 shows?

Question 3:
How to implement the three changes in a child frame 1, when switching to sub box 2, sub box 2 load automatically update the three variables?
2 when a change in a box, box 1 also automatic update,

PS: I am a VC did not start the boy, your bosses can speak detailed point?
Such as which files to add variables, where
In which document to add statements, where

Online to find a lot of information, complete can't find the sort of small white level tutorial,
As the first step to do, the second do the tutorial I like very much, but to this question seems can't find ah,

Speak now to find those who are very general, small white said don't understand what meaning,

Just as that kind of direct use what function, how do I use this function?
I directly with tip error,

Certainly because of use position is wrong, error variable is not defined,
Small white said appear this kind of don't know how to do,
What is in the position to do what?

CodePudding user response:

No one here?

CodePudding user response:

"Now want to define three global variable student id, name, gender,"
Put CMyTab class, m_tab, son, frame 1 and the child should taking m_tab initialization time defined in the variable (GetParent ())

CodePudding user response:

Cstrings str1;
CMyTab: : CMyTab ()
{
M_bHeadStyle=FALSE;
Str1="StrInMyTab";
}
//
CMyTab * pTab=(CMyTab *) GetParent ();
Cstrings STR=pTab - & gt; Str1;
M_Dlg1Edit1. SetWindowText (STR);//"Big Char");

CodePudding user response:

To search the observer pattern
This is typical of the observer pattern usage scenarios,

CodePudding user response:

1. In the main dialog box, two since the dialog box to define three num, name, sex, variable respectively in three dialog OnInitDialog initialized, initialization values are from the inside to read ini configuration file, such as:
 
Int num=GetPrivateProfileInt (" XXX, "" numINI", 1, ". \ \ X.i ni ");
Int name=GetPrivateProfileInt (" XXX, "" nameINI", 1, ". \ \ X.i ni ");
Int sex=GetPrivateProfileInt (" XXX, "" sexINI", 1, ". \ \ X.i ni ");

2. Refer to 1, three after the dialog box to obtain the corresponding value is displayed in the corresponding control in
3. Set a save button in a child frame 1, after modify the value, click the save button, the save button in the corresponding function to rewrite ini configuration file:
 
Cstrings temp.
Temp. The Format (" % s ", num);
WritePrivateProfileString (" XXX, "" numINI", temp, ". \ \ X.i ni ");
Temp. The Format (" % s ", name);
WritePrivateProfileString (" XXX, "" nameINI", temp, ". \ \ X.i ni ");
Temp. The Format (" % s ", sex);
WritePrivateProfileString (" XXX, "" sexINI", temp, ". \ \ X.i ni ");

As for the switch, according to OnInitDialog achieved in 1

CodePudding user response:

Upstairs can point in more detail?
1: which is called the main dialog?
2: which called from the dialog?
3: where there are three OnInitDialog, only a dialog. CPP OnInitDialog,
Please tell me the detail steps, please?
The first step to open the file? .cpp or. H?
The second step is to find which functions or which position, add what code?
The third step 4 to do

CodePudding user response:

The 2nd 3 floor greatly, can speak a bit in detail, card don't understand ah,

What is "in" put CMyTab class, m_tab,?

There are 3 floor of cstrings str1; In the function outside? The global variable?
//
CMyTab * pTab=(CMyTab *) GetParent ();
Cstrings STR=pTab - & gt; Str1;
M_Dlg1Edit1. SetWindowText (STR);//"Big Char");
These you also write outside the function? Which function of content?

Can you hold a moment,
1: which file to open the first, and find which position, add the code?
2: switch to which files, then find where, what code to add?

CodePudding user response:

You are not a main dialog box, CMyTab class, any m_tab,
Put the public variable m_tab,
Cstrings str1;//CMyTab. Public variable h
CMyTab: : CMyTab ()
{
Str1="StrInMyTab";//public variable initialization
}


Two child dialogs CTabPage1 and CTabPage2,
Initialize the
CMyTab * pTab=(CMyTab *) GetParent ();
Cstrings STR=pTab - & gt; Str1;
M_Dlg1Edit1. SetWindowText (STR);//"Big Char");

CodePudding user response:

refer to 7th floor qq_42354588 response:
upstairs can point in more detail?
1: which is called the main dialog?
2: which called from the dialog?
3: where there are three OnInitDialog, only a dialog. CPP OnInitDialog,
Please tell me the detail steps, please?
The first step to open the file? .cpp or. H?
The second step is to find which functions or which position, add what code?
The third step 4 to do

You have two child dialogs, isn't it? That there should be two corresponding dialog functions, two corresponding dialog functions respectively inside there are two OnInitDialog (), if not, manually add, add methods baidu has a tutorial, this is the most basic, then I don't know what you're framework (the body of the two child dialogs) do you want to show the three value, want you inside the framework class CMAINFRAME CMAINFRAME: CMAINFRAME to and OnInitDialog () function is the same operation, don't need not tube, specific code I've been to the above, then you just need to num of each dialog box, name, sex value on the display to the edit control, as the name and sex variable type should I give the wrong above, should use cstrings, because it is a string

CodePudding user response:

In two child dialog box to add a "save" button, double click on the save button to automatically generate a function, copy the following code in the function body:
Note: IDC_EDIT1 names to the corresponding
[code]=c
Char \ [220]={0};
GetPrivateProfileString (" XXX ", "numINI", NULL, temp, 220, ". \ \ X.i ni ");
SetDlgItemText (IDC_EDIT1, temp);
GetPrivateProfileString (" XXX ", "nameINI", NULL, temp, 220, ". \ \ X.i ni ");
SetDlgItemText (IDC_EDIT2, temp);
GetPrivateProfileString (" XXX ", "sexINI", NULL, temp, 220, ". \ \ X.i ni ");
SetDlgItemText (IDC_EDIT3, temp);
[code]

CodePudding user response:

The 11 floor:
According to what you say, I compile also passed,
But a save button, all the data in the EDIT box to empty,
The other where the ini file? Can not find,
I put the ". \ \ X.i ni "into the path of the Desktop C: \ Users \ username \ Desktop \ also can not find the ini file,

Your method is like this:
Event, by pressing the button to write the data of the edit box to the ini file, and then other sub box has read the ini data?

If so, then how to implement the child when the TAB label switching box reading this ini data?
My understanding is that the data is read only happened in OnInitDialog, executed only once,

CodePudding user response:

The 9 floor:
I according to your method,
1: in the main box MyTabDlg. H's public added cstrings str1;
2: in the main box MyTabDlg. CPP added in OnInitDialog str1="StrInMyTab";
3: in a child frame TabPage1. CPP and TabPage2 CPP added in OnInitDialog function, and inside wrote
CMyTab * pTab=(CMyTab *) GetParent ();
Cstrings STR=pTab - & gt; Str1;
M_Dlg1Edit1. SetWindowText (STR);//"Big Char");

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related