Realization of several common functions in Visual C ++ software development

xiaoxiao2021-03-06  130

Published: 2004-08-07 15:23:48 Popularity: 33 floor main score: 0

[Original] Realization of several common functions in Visual C software development

Introduction to the middle of the Vchelp Forum, often see the largest basic issues mentioned in many software development, and now they are listed, I hope to be useful to you.

The body is in the middle of the software development process, there is a lot of small features, although these things you can do, but if the application will be your program more professional. First, the setup program is automatically run. Many monitoring software requirements software can be able to click the icon launch project after the system is restarted, but can be able to start running directly, the method is to write the registry Software // Microsoft // windows // currentversion //run. The reference program can be seen below: (Find the execution file of the program directory, exist, add a registry operation) HKEY Regkey; cstring spath; getModuleFileName (null, spath.getBuffersetLength; spath.releasebuffer (); spath.releasebuffer Int npos; npos = spath.reverseFind ('//'); spath = spath.left (npos); cstract lpszfile = spath "// ****. EXE"; // Add you to find the execution file name CFileFind fFind; BOOL bSuccess; bSuccess = fFind.FindFile (lpszFile); fFind.Close (); if (bSuccess) {CString fullName; fullName = lpszFile; RegKey = NULL; RegOpenKey (HKEY_LOCAL_MACHINE, "Software // Microsoft // Windows // currentversion //run ", & regkey); RegSetValueex (RegKey," ***** ", 0, reg_sz, (const unsigned char *) fullname, fullname.getLength ()); // Here You need to register in the registry this-> updatedata (false);} else {THEAPP.SETMAINSKIN (); :: afxMessageBox ("Didn't find executive, automatic run failure"); exit (0);}

Second, the procedure for automatically configuring data sources must be used to use the database combined operation, here examples, because Access is most commonly used in small and medium-sized VC system development, if the program is transplanted, if the program is transferred You still need him to configure the data source to the configuration panel, then it is a bit not going. #Include // Configure the data source, the database is in the application directory, such as the database file name ***. MDB, the program can be copied to the program directory below. CString sPath; GetModuleFileName (NULL, sPath.GetBufferSetLength (MAX_PATH 1), MAX_PATH); sPath.ReleaseBuffer (); int nPos; nPos = sPath.ReverseFind ( '//'); sPath = sPath.Left (nPos); CString LPSZFILENAME = SPATH "//***.mdb";// This is modified to your database file name cfilefind ffind; if (! ffind.FindFile (lpszfilename)) {:: AfXMessageBox (" Database "); exit (0);} cstring szdesc; szdesc.format ("dsn = ****; description = ****; description = the database for ***; fil = microsoftAccess; defaultdir =% s; DBQ =% S; "SPATH, LPSZFILENAME); // Here *** can be added to your description // Add data source if (! :: sqlconfigDataSource (null, odbc_add_dsn," Microsoft Access Driver (* .mdb) ", (LPCSTR) Szdesc)) {:: AfxMessageBox ("32-bit ODBC Data Source Configuration Errors!"); exit (0);}

Third, set the display mode: Many programs' ported operating environment is changing. It is possible that your original development environment is 1024x768, but when the display is greater than 17 (the resolution is more than the resolution of your development), the program's display may not look good. DEVMODE lpDevMode; lpDevMode.dmPelsHeight = 768; // Y direction pixel dots lpDevMode.dmPelsWidth = 1024; // X direction pixel dots lpDevMode.dmDisplayFrequency = 85; // the screen refresh rate lpDevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY; ChangeDisplaySettings (& lpdevmode, 0);

Fourth, loading other applications in your program: Your program In addition to calling to each module, you can call not the application in the same development environment, such as Delphi, VB in the VC environment. The implementation program of the development you can use the following method (in the application copy program directory): cstring spath; getModuleFileName (null, spath.getbuffersetlength; spath.releasebuffer (); spath.releasebuffer (); spath.releasebuffer (); spath.releasebuffer (); spath.releaseBuffer (); Int npos; npos = spath.reversefind ('//'); spath = spath.left (npos); cstring lpszfilename = spath "//***.exe";// here to modify it into your call application File name cfilefind ffind; if (! Ffind.findfile (lpszfilename)) {:: afxMessageBox ("No call to the application!"); Return False;} else shellexecute (null, null, _t ("***. EXE "), NULL, SPATH, NULL;

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

New Post(0)