Create and use Toolbar Statusbar Dialog Bar with AppWizard

xiaoxiao2021-03-06  39

The runtime program interface is shown in the interface. The program has a toolbar for displaying two command buttons, one for demonstrating how the button is inspected, and the other is disabled / allowed according to the status of the first button. (Set check status and allowed status through onupdateCommand) In addition, there is an input box and button on the Dialog Bar. The prohibition / allowance of the two sub-windings is also determined according to the status status on the toolbar, when Press Dialog Bar The text content in the input box will appear when the button is button. The first part of the state bar is used to display various prompts, and the second part is used to display the current time with onupdateCommand. At the same time, in the program, how to set up a command interpretation of the menu item (will display the first part of the status bar) and how to set the toolbar prompt (using a small Tooltip window).

Generating App: Generate an MFC engineering, legend, and set to a single document interface legend, finally select the toolbar, status and rebar support, legend

Modify menu: Use the resource editor to delete an extra menu and add a new pop-up menu and three submenus, the legend, respectively:

Name ID Description Character Checkidm_ChecksetCheck Demo / NSETCHECKSETCHECK DEMO / NSETCHECK DEMODISABLEIDM_DISABEDISABLE DEMO / NDISABLE DEMOSHOWTEXT ON DIALOGBARIDM_SHOW_TXTSHOWTEXT ON DIALOGBAR DEMO / NSHOWTEXT On Dialogbar

The string before / n will be displayed in the status bar as a command, and the portion after the / n will appear as a prompt of the toolbar button with the same ID in the Tooltip window.

Modify Dialog Bar: Add a input box and button to the Dialog Bar, the button has the same ID as IDM_SHOW_TXT with a menu item, which can use the mapping menu message to process the button message (of course, using different ID values ​​can also be used with ON_COMMAND) Map the button message on the Dialog Bar, but ClassWizard does not provide a way to map to the Dialog Bar, which can only be manually adding message mapping code). legend

Modifying toolbar: Add two buttons to the toolbar, IDM_CHECK and IDM_DISABLE and two menu items have the same ID value. legend

Add a message mapping and update command to three menu items using ClassWizard. legend

Modify the mainfrm.h file

// Add a member variable to record the check status of the CHECK button on the toolbar.

protected:

Bool m_fcheck;

/ / Manually add the status strip second part for display time update commands, and update commands for disabling / allowing input boxes

// {{AFX_MSG (CMAINFRAME)

AFX_MSG Int Oncreate (LPCReatestruct LPCreateStruct);

AFX_MSG void oncheck ();

AFX_MSG Void OnUpdateCheck (ccmdui * pcmdui);

AFX_MSG void OnDisable ();

AFX_MSG Void OnupdatedIsable (CCMDUI * PCMDUI);

AFX_MSG VOID OnShowt ();

AFX_MSG void onupdateshowtxt (ccmdui * pcmdui);

//}} AFX_MSG

/ / The above part of the code automatically generated by ClassWizard

AFX_MSG VOID ONUPDATETIME (CCMDUI * PCMDUI); // Display Time

AFX_MSG Void OnUpdateInput (ccmdui * pcmdui); // Disable / Allow input box

Modify the mainfrm.cpp file // Modify the partial ID on the status bar

#define id_time 0x705 // As the second part ID on the status bar

Static uint indeicators [] =

{

ID_separator, // status line indeicator

ID_SEPARATOR, // Set to ID_SEPARATOR, then modify after the status bar is created

}

// Modify message mapping

// {{AFX_MSG_MAP (CMAINFRAME)

ON_WM_CREATE ()

ON_COMMAND (IDM_CHECK, ONCHECK)

ON_UPDATE_COMMAND_UI (IDM_CHECK, ONUPDATECHECK)

ON_COMMAND (IDM_DISABLE, ONDISABLE)

ON_UPDATE_COMMAND_UI (IDM_DISABLE, ONUPDATEDISABLE)

ON_COMMAND (IDM_SHOW_TXT, ONSHOWTXT)

ON_UPDATE_COMMAND_UI (IDM_SHOW_TXT, ONUPDATESHOWTXT)

//}} AFX_MSG_MAP

// The above part is ClassWizard automatically generates code.

ON_UPDATE_COMMAND_UI (ID_TIME, ONUPDATETIME) Display Time

ON_UPDATE_COMMAND_UI (IDC_INPUT_TEST, ONUPDATEINPUT) / / Disable / Allow input box

/ / Modify the oncreate function, reset the status strip second part ID value

INT CMAINFRAME :: OnCreate (lpcreatestruct lpcreatestruct)

{

....

// by Wenyy Modify the second part of the status bar

M_WndStatusBar.SetPaneInfo (1, ID_TIME, SBPS_NORMAL, 60); // set the width

Return 0;

}

/ / Modify the mappled message processing function code

Void CMAINFRAME :: oncheck ()

{

// change and save the status when the check button is pressed

m_fcheck =! m_fcheck;

}

Void CMAINFRAME :: OnUpdatecheck (ccmdui * pcmdui)

{

// check whether the button is set to check the status

PCMDUI-> setCheck; M_FCHECK

}

void cmainframe :: onDisable ()

{

// disable button is pressed

AfxMessageBox ("You Press Disable Test");

}

Void CMAINFRAME :: onupdatedisable (ccmdui * pcmdui)

{

/ / Determine itself / allowed state according to the CHECK status

PCMDUI-> Enable; M_FCHECK

}

Void CMAINFRAME :: OnShowtxt ()

{

// Get the text word in the box on the Dialog Bar and display

CEDIT * PE = (CEDIT *) m_wnddlgbar.getdlgitem (IDC_INPUT_TEST);

CString SZO;

PE-> getWindowText (SZO);

AfxMessageBox (SZO);

}

Void CMAINFRAME :: OnUpdateShowtxt (ccmdui * pcmdui)

{

// Dialog Bar button on the CHECK status determines itself / allowed state

PCMDUI-> Enable; M_FCHECK

}

Void CMAINFRAME :: OnUpdateInput (ccmdui * pcmdui)

{

// Dialog Bar on the input box to determine the prohibition / allowed state according to the Check status

PCMDUI-> Enable; M_FCHECK

}

Void CMAINFRAME :: OnUpdatetime (ccmdui * pcmdui)

{

// Set the second part of the second part on the status bar according to the current time

CTIME TIMECUR = CTime :: getcurrenttime ();

Char Szout [20];

Sprintf (Szout, "% 02D:% 02D:% 02D", timecur.gethour (), timecur.getminute (), timecur.getsecond ());

PCMDUI-> SetText (Szout);

}

Download Demonstration Code 17K

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

New Post(0)