How to bring up a single document view from a dialog box

Source: Internet
Author: User

I believe many people have such problems in database programming. How to set a login box and enter the single-document view through the login box. I have seen many books on database programming, all of which are switching between dialogs. Many people are not familiar with adding menus in the dialog box (of course this can be done ). I was wondering why I couldn't bring up a single document in the dialog box, so it would be much easier to add menus. After several explorations, I finally realized how to bring up a single document view from a dialog box.

The following uses a Login Dialog Box as an example to describe how to bring up a single document view from a dialog box.

First, create a dialog box resource, such:

Anyone familiar with MFC programming knows that the initialization program instance is completed by the InitInstance function. Therefore, the code for this dialog box is stored in this function.

The Code is as follows:

BOOL CDlgTestApp: InitInstance ()

{

AfxEnableControlContainer ();

// Standard initialization

// If you are not using these features and wish to reduce the size

// Of your final executable, you should remove from the following

// The specific initialization routines you do not need.

# Ifdef _ AFXDLL

Enable3dControls (); // Call this when using MFC in a shared DLL

# Else

Enable3dControlsStatic (); // Call this when linking to MFC statically

# Endif

// Change the registry key under which our settings are stored.

// Todo: You shocould modify this string to be something appropriate

// Such as the name of your company or organization.

Setregistrykey (_ T ("Local Appwizard-generated Applications "));

Loadstdprofilesettings (); // Load Standard INI File options (including MRU)

// Register the application's document templates. document templates

// Serve as the connection between documents, frame windows and views.

Clogsys testdlg;

If (testdlg. domodal () = idok) // Click OK to initialize the program instance.

{

Csingledoctemplate * pdoctemplate;

Pdoctemplate = new csingledoctemplate (

Idr_mainframe,

Runtime_class (cdlgtestdoc ),

Runtime_class (cmainframe), // main SDI frame window

Runtime_class (cdlgtestview ));

Adddoctemplate (pdoctemplate );

// Parse command line for standard shell commands, DDE, file open

Ccommandlineinfo using info;

Parsecommandline (partition info );

// Dispatch commands specified on the command line

If (! Processshellcommand (cmdinfo ))

Return false;

// The one and only window has been initialized, so show and update it.

M_pmainwnd-> showwindow (sw_show );

M_pmainwnd-> updatewindow ();

Return true;

}

Else // exit directly if you click the cancel button

Return false;

}

Click OK to go to the single document view. After you click OK, you must check the user name and password. Therefore, you must add the corresponding processing code in the onok function of the dialog box.

Void clogsys: onok ()

{

// Todo: add extra validation here

Updatedata (true); // obtain the input data

If (m_struser = "admin" & m_strpwd = "1234 ")

{

Cdialog: onok (); // if the user name and password are correct, close the dialog box.

}

/* If the user name or password is incorrect and the number of logon attempts has not exceeded, a prompt is displayed */

If (m_struser! = "Admin" | m_strpwd! = "1234") & (m_time <3) // if the password and user name are correct

{

Afxmessagebox ("incorrect user name or password ");

M_time ++;

}

/* If the number of logins exceeds the limit, the system prompts and exits */

If (m_time> 2)

{

Afxmessagebox ("the number of Logon errors exceeds 3 ");

Postquitmessage (0 );

}

}

Of course, the function should be expanded in practice. For example, after three failed logins, the computer should be limited to be unable to log on within a certain period of time, and how to verify multiple user names for login.

Source: http://ladymaidu.iteye.com/blog/1263336

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.