Windows Programming-Aircraft War notes (use of Access databases)

Source: Internet
Author: User
Tags set background

2015/07/22///////////////////

by XBW/////////////////////////

Environmental vs2013/////////////////

In order to login the registration of the interface database Tinker Day, you have to write an article vent a bit,

The article published yesterday or there is a little bug, the shortcomings are easy to see, so, today has changed a bit, is a big change oh

int first = 1;while (! Dbset.iseof ())///There is no end to table {Dbset.getfieldvalue (_t ("Name"), Var); Sname = (LPCSTR) var.pbstrval;dbset. GetFieldValue (_t ("PSW"), Var); SPSW = (LPCSTR) var.pbstrval;dbset. GetFieldValue (_t ("score"), Var); Sscore = (LPCSTR) var.pbstrval;if (Sname.compare (m_logname) = = 0 && spsw.compare (m_logpsw) = = 0)//If the password and account are consistent with the database { MessageBox (_t ("Login success!"), _t ("tenderness hint")); Cdialog::onok (); first = 0;break;} Else{dbset.movenext ();}} if (first) {MessageBox (_t ("User or password Error!"), _t ("tenderness hint"));}

This is the modification of the place, the data for a half-day, just know that MFC calls the database there are so many ways, this is suitable for me,

Because my definition is

CDaoDatabase DB; Database

CDaoRecordset Recset (&DB); Record set

Header file #include "afxdao.h"

Alas, not much to say, directly on the complete code, stickers out good distressed, we exchange learning with each other,,,,,

Loading.cpp: Implement file//#include "stdafx.h" #include "PlaneGame.h" #include "loading.h" #include "afxdialogex.h" #include "                                       Afxdao.h "#include" zhuce.h "//Loading dialog implement_dynamic (loading, CDialogEx) CDaoDatabase db;                   Database CDaoRecordset Recset (&AMP;DB); Recordset loading::loading (cwnd* pparent/*=null*/): CDialogEx (Loading::idd, pparent), open (false), Open1 (false), m_ LogName (_t (")), M_LOGPSW (_t (") ") {CString Filepath = _t (" Database.mdb "); CDaoRecordset Dbset (&AMP;DB); CFileFind Ffind; BOOL flag = Ffind.findfile (Filepath); Ffind.close (); if (!flag) {CString sqlcmd = _t ("CREATE TABLE DataTable (Name VARCHAR), PSW varchar (), score varchar (20) );d B. Create (Filepath);d B. Execute (sqlcmd);D bset. Open (Afx_dao_use_default_type, _t ("SELECT * from DataTable", 0));D bset. AddNew ();D bset. SetFieldValue (_t ("Name"), _variant_t (_t ("plucky"));D bset. SetFieldValue (_t ("PSW"), _variant_t (_t ("Mfc_py")));//Set initial user name and password dbset.setfieldvalue (_t ("Score"), _variant_t (_t ("0 "));DbSET. Update ();D bset. Close ();d B. Close ();} This creates the database file and sets the initialization account}loading::~loading () {}void loading::D odataexchange (cdataexchange* pdx) {ddx_text (PDX, IDC _EDIT3, M_logname);DD x_text (PDX, IDC_EDIT4, M_LOGPSW);} Begin_message_map (loading, CDialogEx) on_wm_nchittest () On_wm_ctlcolor () on_bn_clicked (IDCANCEL, &loading::o Nbnclickedcancel) on_bn_clicked (IDOK, &loading::onbnclickedok) on_bn_clicked (IDOK2, &loading::o NBNCLICKEDOK2) on_notify (Nm_click, Idc_syslink1, &loading::onnmclicksyslink1) on_notify (Nm_click, IDC_SYSLINK2,                                       &AMP;LOADING::ONNMCLICKSYSLINK2) End_message_map ()//Loading message handler//mouse drag window to move//cdaodatabase DB;                   Database//cdaorecordset Recset (&AMP;DB); Recordset Lresult Loading::onnchittest (CPoint point) {//TODO: Add the message Handler code here and/or call the default value ScreenToClient (&point); CRect RC; GetClientRect (&AMP;RC), if (RC. PtInRect (point)) {return htcaption;} Else{return cdialogex::onnchittest (point);}} Hbrush Loading::onctlcolor (cdc* PDC, cwnd* pWnd, UINT NCTlcolor) {//hbrush HBR = Cdialogex::onctlcolor (PDC, PWnd, nCtlColor);//cfont Font;//font. CreatePointFont (_t ("Arial"), NULL),//getdlgitem (idc_static)->setfont (&font);//TODO: Change any of the properties of the DC here// In the OnInitDialog () function, add the following://TODO: Add an additional initialization generation if (nCtlColor = = ctlcolor_static) {Pdc->settextcolor (RGB (200, 100, 50)) here;   Pdc->setbkmode (RGB (200, 100, 50)); Set background transparent return Hbrush (Getstockobject (Hollow_brush));} TODO: If the default is not the desired brush, return another brush//return Hbr;return 0;} void Loading::onbnclickedcancel () {//TODO: In this Add control notification handler code open = FALSE; Cdialogex::oncancel ();} void Loading::onbnclickedok () {//TODO: Add control Notification Handler code//cstring Filepath = _t ("Database.mdb");//cdaorecordset Dbset ( &AMP;DB);//cfilefind ffind;//bool flag = ffind.findfile (Filepath);//ffind.close ();/*if (!flag) {CString sqlcmd = _t (" CREATE TABLE DataTable (Name VARCHAR, PSW varchar (), score varchar) ");d B. Create (Filepath);d B. Execute (sqlcmd);D bset. Open (Afx_dao_use_default_type, _t ("SELECT * from DataTable", 0));D bset. AddNew ();D bset. SeTfieldvalue (_t ("Name"), _variant_t (_t ("plucky"));D bset. SetFieldValue (_t ("PSW"), _variant_t (_t ("Mfc_py")));//Set initial user name and password dbset.setfieldvalue (_t ("Score"), _variant_t (_t ("0 "));D bset. Update ();D bset. Close ();d B. Close ();} This creates the database file, and sets the initial account *//*cstring spath; GetModuleFileName (NULL, Spath.getbuffersetlength (MAX_PATH + 1), MAX_PATH); Spath.releasebuffer (); int nPos;nPos = Spath.reversefind (' \ \ '); spath = Spath.left (NPos); CString strfile = spath + _t ("\\Database.mdb");d B.               Open (strfile); Open the Created demo database and demotable table Recset.open (Afx_dao_use_default_type, _t ("select* from DataTable"), NULL); *///updatedata (TRUE);//cstring M_tablefield, m_searchsql;//if (M_sfield.compare ("name") = = 0)//{//m_tablefield. Format ("Name");//}/*updatedata (true); CDaoRecordset Dbset (&AMP;DB); CString Filepath =_t ("Database.mdb"); CString Sname, spsw,sscore;_variant_t varname, varpsw,varscore;db. Open (Filepath);D bset. Open (Afx_dao_use_default_type, _t ("SELECT * from DataTable"), 0); varname = Dbset.getfieldvalue (_t ("NamE ")); VARPSW = Dbset.getfieldvalue (_t (" PSW ")); Varscore = Dbset.getfieldvalue (_t (" score ")); Sname = (LPCSTR) _bstr_t (varname); SPSW = (LPCSTR) _bstr_t (VARPSW); Sscore = (LPCSTR) _bstr_t (varscore);D bset. Close ();d B. Close (); if (Sname.compare (m_logname) ==0&&spsw.compare (M_LOGPSW) = = 0)//If the password and account are consistent with the database {MessageBox (_t ("Log in successfully!") , _t ("tenderness hint")); Cdialog::onok ();} Else{messagebox (_t ("User or password wrong!"), _t ("tenderness hint"); return;} */updatedata (TRUE); COleVariant var;//field type var. ChangeType (VT_BSTR, NULL);//cstring strName, Strage, strfile; CString Sname, SPSW, Sscore; CDaoRecordset Dbset (&AMP;DB); CString Filepath = _t ("Database.mdb");d B. Open (Filepath);D bset. Open (Afx_dao_use_default_type, _t ("SELECT * from DataTable"), 0); int first = 1;while (! Dbset.iseof ())///There is no end to table {Dbset.getfieldvalue (_t ("Name"), Var); Sname = (LPCSTR) var.pbstrval;dbset. GetFieldValue (_t ("PSW"), Var); SPSW = (LPCSTR) var.pbstrval;dbset. GetFieldValue (_t ("score"), Var); Sscore = (LPCSTR) var.pbstrval;if (Sname.compare (m_logname) = = 0 && spsw.compare (m_lOGPSW) = = 0)//If the password and account are consistent with the database {MessageBox (_t ("Login successful!"), _t ("tenderness hint")); Cdialog::onok (); first = 0;break;} Else{dbset.movenext ();}} if (first) {MessageBox (_t ("User or password Error!"), _t ("tenderness hint"));} Db. Close ();D bset. Close ();/*uint nIndex = 0; CString TempStr; COleVariant olevariant;//Delete list control all records Booklist.deleteallitems ();//define Recordset object and open recordset CDaoRecordset record (&AMP;DB); Record.open (dbOpenDynaset, L "select * from book");//move to the first record Record.movefirst (); while (! Record.iseof ()) {//Add record Tempstr.format (L "%d", NIndex + 1) in the list control, This->booklist.insertitem (NIndex, TempStr); for (int i = 1; I <= 3; i++) {Record.getfieldvalue (I, olevariant); This->booklist.setitemtext (NIndex, I, olevariant.bstrval);} Record.getfieldvalue (4, olevariant); Tempstr.format (L "%d", olevariant.uintval); This->booklist.setitemtext (NIndex, 4, TEMPSTR);// Move to the next record Record.movenext (); nindex++;} Close Recordset Record.close (); */}void Loading::onbnclickedok2 () {open1 = false;//TODO: Add control notification handler code here}void loading::o NNMClickSyslink1 (NMHDR *pnmhdr, LRESULT *presult) {//TODO: In this Add control notification handler code Zhuce dlg;//opening = true;if (dlg. DoModal () = = IDOK) {Invalidate ();} *presult = 0;} void Loading::onnmclicksyslink2 (NMHDR *pnmhdr, LRESULT *presult) {//TODO: Add control notification handler code here MessageBox (_t ("Do not have this feature, contact the developer" ), _t ("tenderness hint")); *presult = 0;}



Too many comments in the middle part, because changed and changed, not afraid of hard work, made it really happy,,,,, to you to share;

The registration section has also been amended;;

Go directly to the code;;;;

Zhuce.cpp: Implement file//#include "stdafx.h" #include "PlaneGame.h" #include "zhuce.h" #include "afxdialogex.h" #include " Afxdao.h "//Zhuce dialog box Implement_dynamic (Zhuce, CDialogEx) zhuce::zhuce (cwnd* pparent/*=null*/): CDialogEx (Zhuce::IDD, pparent), M_regname (_t ("")), M_REGPSW (_t (")) {}zhuce::~zhuce () {}void zhuce::D odataexchange (cdataexchange* PDX) { CDialogEx::D odataexchange (PDX);DD x_text (PDX, Idc_edit1, M_regname);DD x_text (PDX, Idc_edit2, M_REGPSW);} Begin_message_map (Zhuce, CDialogEx) on_bn_clicked (Idc_button1, &zhuce::onbnclickedbutton1) ON_BN_CLICKED (IDOK,  &zhuce::onbnclickedok) End_message_map ()//Zhuce Message handler void Zhuce::onbnclickedbutton1 () {//TODO: Add control in this notification handler code UpdateData (TRUE);//Last video has been said, continue to update the data in a timely manner CString Filepath = _t ("Database.mdb");//cstring Sname; CDaoDatabase db;//_variant_t varname; CDaoRecordset Dbset (&db);d B. Open (Filepath);D bset. Open (Afx_dao_use_default_type, _t ("SELECT * from DataTable"), 0),//varname = Dbset.getfieldvalue (_t ("Name"));//sname = (LPCSTR) _bstr_t (varname); (M_regname. IsEmpty () | | M_REGPSW. IsEmpty ()) {MessageBox (_t ("Information cannot be empty!"), _t ("tenderness hint"));} Else{cstring Sname; COleVariant var;//field type var. ChangeType (VT_BSTR, NULL); int first = 1;while (! Dbset.iseof ())///There is no end to table {Dbset.getfieldvalue (_t ("Name"), Var); Sname = (LPCSTR) var.pbstrval;if (Sname.compare (m_regname) = = 0)//If the password and account are consistent with the database {MessageBox (_t ("The user already exists!"), _t ("tenderness hint")) ; Cdialog::onok (); first = 0;//break;} Else{dbset.movenext ();}} if (first) {dbset.movelast ();//dbset.edit ();//Because only one data is allowed in the table, the new data is replaced with the old Data dbset.addnew ();D bset. SetFieldValue (_t ("Name"), _variant_t (m_regname));D bset. SetFieldValue (_t ("PSW"), _variant_t (M_REGPSW));D bset. SetFieldValue (_t ("Score"), _variant_t (_t ("0"));D bset. Update (); MessageBox (_t ("User registration succeeded!"), _t ("tenderness hint"));}} Dbset.close ();d B. Close ();} void Zhuce::onbnclickedok () {//TODO: Add control notification Handler code here Cdialogex::onok ();}


This code let me laugh and cry, out of a bug, in the group to share with others said this if you add the power on the auto-start invincible, in fact, not so scary, just a dead loop, has been shown that the user has existed, to avoid this method is what clear it, is not to repeat the registration, joking, You just have to break that place to uncomment the good, do not mess with Oh, to maintain a good network security oh;;;;;;

Well, I am also a slag, can only organize information, and can not speak very thorough,,,,, to make a login account registration can try this code;; yes.

Exhausted, don't play,,,, next get the MFC socket, fight to put the data on the server, with the client call server registration,,,,

Have a message for me to understand, thank you;;;

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Windows Programming-Aircraft War notes (use of Access databases)

Related Article

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.