How to "a line of code" control all function calls in the main interface

zhaozj2021-02-17  168

How to "a line of code" control all function calls in the main interface

Www.lvyin.net 2002-4-22 Green Network

In most software, there are menu, toolbar, buttons, or tree features. The same feature template, it is possible to call it in the menu, also call it in the toolbar, or call it in other ways, that is, there is a problem with multiple calls.

In a deliberate exploration, I found a very convenient function call method. After using this method, it can be said to be "a line of code" to control all the function calls in the main interface.

However, how to achieve it, please listen to me slowly.

Taking the procedures used when I explore as an example: all functional operations are integrated in the main form, all templates are available in the form of TFrame (ie, the framework), including menu calls, toolbar calls, and tree features Trees.

Implementation:

First, first define several arrays to facilitate construction of the functional tree:

PRIVATE: // user declarations

TTREENODE * m_currentnode; // current node

TTREENODE * MTREE [MAXNODE]; // Node pointer

INT MTREENO [MAXNODE]; // Node ID

INT MTREEPNO [MAXNODE]; // Father Junction ID

Ansistring Mtreename [MAXNODE]; // Name Name

Tframe * childframe [MAXNODE]; // Tframe Submoduption

Second, define a function of constructing a function tree

Public: // user declarations

Void CreateTree ();

Third, the structure of the function tree

Void tfrmmain :: CreateTree ()

{

Mtreename [0] = "Company Basic Information"; MtreePno [0] = MaxNode;

Mtreename [1] = "department setting"; MtreePNO [1] = 0; ChildFrame [1] = new TFRADEPARTMENT (PLFRAME);

Mtreename [2] = "position setting"; MtreePNO [2] = 0; childframe [2] = new TFRAPSITION (PLFrame);

Mtreename [3] = "employee information"; MtreePNO [3] = 0; ChildFrame [3] = New TFRAEMPLOYEE (PLFrame);

Mtreename [4] = "Holiday Settings"; MtreePNO [4] = 0; ChildFrame [4] = New Tfraholiday (PLFrame);

Mtreename [5] = "Code setting"; MtreePNO [5] = 0; ChildFrame [5] = New TfradePloyClass (PLFrame);

Mtreename [6] = "Attendance Management"; MtreePno [6] = MaxNode;

Mtreename [7] = "Data Import"; MtreePNO [7] = 6; ChildFrame [7] = New TfraimportData (PLFrame);

Mtreename [8] = "Sign"; MtreePNO [8] = 6; ChildFrame [8] = New TfrasingCard (PLFrame); Mtreename [9] = "Please manage"; MtreePno [9] = 6; childframe [9] = New Tfraleave (PLFrame);

Mtreename [10] = "Overtime Management"; MtreePno [10] = 6;

Mtreename [11] = "Overtime application"; MtreePNO [11] = 10; ChildFrame [11] = New Tfraovertime (PLFrame);

Mtreename [12] = "Obstel Taking Review"; MtreePNO [12] = 10; ChildFrame [12] = New TfraauditingOvertime (PLFrame);

Mtreename [13] = "Temporary Change"; MtreePNO [13] = 6; ChildFrame [13] = New TFRAMPRELIEF (PLFrame);

Mtreename [14] = "Data Maintenance"; MtreePNO [14] = 6; ChildFrame [14] = New TfraMaintenceDatabase (PLFrame);

Mtreename [15] = "Report"; mtreePno [15] = MaxNode;

Mtreename [16] = "Basic Information Report"; MtreePNO [16] = 15; ChildFrame [16] = New TfrabaseReport (PLFrame);

Mtreename [17] = "Daily Report"; MtreePno [17] = 15; ChildFrame [17] = New TfradayReport (PLFrame);

MTREENAME [18] = "Month Report"; MtreePNO [18] = 15; ChildFrame [18] = New TframonThreport (PLFrame);

Mtreename [19] = "Custom Report"; MtreePNo [19] = 15; ChildFrame [19] = New TFracustomReport (PLFrame);

Mtreename [20] = "Statistical Report"; MtreePNO [20] = 15; ChildFrame [20] = New TFraconeNTreport (PLFrame);

Mtreename [21] = "User Management"; MtreePNo [21] = MaxNode;

Mtreename [22] = "Add User"; MtreePNO [22] = 21; ChildFrame [22] = New TfraadDadmin (PLFrame);

Mtreename [23] = "Modify Password"; MtreePNO [23] = 21; ChildFrame [23] = New TframodifyPassword (PLFrame);

Mtreename [24] = "Modify Permissions"; MtreePNO [24] = 21; ChildFrame [24] = New TFRAMODIFYPOPEDOM (PLFRAME); for (int i = 0; i

{

Mtreeno [i] = i;

Mtree [i] = tvmain-> items-> addchild ((MtreePNO [i] == MAXNODE)? NULL: MTREE [MtreePno [I]], Mtreename [i]);

Mtree [I] -> Data = & MTREENO [I];

IF (Childframe [i]! = null)

{

Childframe [I] -> Visible = false;

Childframe [I] -> Parent = PLFrame;

Childframe [I] -> align = alclient;

}

}

}

Fourth, add the following code in the oncreate method

CreateTree ();

5. Add the following code to the onchange method of the tree control.

Void __fastcall tfrmmain :: TVMainChange (Ttreenode * node)

{

// If it does not replace it, it is not anything.

IF (node ​​== m_currentnode)

Return;

Int flag;

FLAG = * ((int *) Node-> Data);

IF (Flag == 0 | FLAG == 6 || Flag == 15 || Flag == 21 || Flag == 10)

Return;

IF (m_currentframe! = null)

m_currentframe-> visible = false;

m_currentframe = childframe [flag];

m_currentframe-> visible = true;

m_currentnode = node;

}

6. Add a TActionList control in the main form, and create a series of action methods to function name commands, set relevant Caption, Hint, ImageIndex, Shortcut, Tag; the most important thing is the Tag property of each Action method, its value Be sure to be the same as the array subscript with the corresponding function to invoke the tree; double click any action method, and join the code:

TVMain-> SELECTED = MTREE [((TACTION *) Sender) -> tag];

This code is the core of the entire program! That is, this code controls the module call of the entire program.

7. Finally, in the corresponding Action method in the control attribute to call!

转载请注明原文地址:https://www.9cbs.com/read-31458.html

New Post(0)