Original address: http://www.yesky.com/20030211/1651565_2.shtml Problem 1: How to implement the CD-ROM playback of the specified drive letter
The key is here:
Void ctrl_cdrom_door (LPCTSTR Drivename, // The name of the drive is like f:, etc.. Bool Fopen file: // When pop-up, use false {tchar devstr [128], ctrlstr [128]; WSPrintf (DevStr, _t) ("Open% S Type Cdaudio Alias Mycd Wait"); WSPrintf (CtrlStr, _T ("SET mycd door% s wait"), fopen? _t ("open"): _ t ("closed)); mcISendstring (devstr, null, 0, null); mcIndstring (Ctrlstr, NULL, 0, NULL); McISendString (_T ("Close Mycd Wait"), NULL, 0, NULL);} File: // Test example code .void CMainFrame :: OnTestOpen () {// TODO: Add your command handler code here ctrl_cdrom_door ( "F:", true);} void CMainFrame :: OnTestClose () {// TODO: Add your command handler code here ctrl_cdrom_door ( "F ", false);
Question 2: How to achieve the interability of a smore? The key is here:
// j2f.cpp: Simplified (GB) ==> Traditional process // reverse conversion is similar .// Note Direct from Simplified -> BIG5 can not do one or one. Do you have a lot? The appearance, //, this needs to be turned into a traditional. Re-turned into big5.// I feel that this method should be consistent with the interaction with the interaction provided by Winnt or Office. #Include "stdafx.h" # Include
#include
#include
#include
#include
Using namespace std;
void j2f (const string & s) {int n = s.length (); int r = LCMapString (MAKELCID (MAKELANGID (LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_PRC), LCMAP_TRADITIONAL_CHINESE, s.c_str (), s.length (), NULL, 0); if (! R) cout << "Error:" <
<
Char * ft = new char [r 1];
R = lcmapstring
Makelcid (Makelangid (Lang_CHINESE, SUBLANG_CHINESE_SIMPLIFIED), SORT_CHINESE_PRC,
Lcmap_traditional_chinese,
s.c_str (), s.length (), ft, r 1); // This API is simplified simplified translucent, the following will print more
IF (r) {
FT [r] = 0;
Cout <
<
Wchar_t * pws = new wchar_t [r 1];
INT r1 = MultibyToWideChar (936, 0, FT, R, PWS, R 1);
BOOL F = FALSE;
R1 = Widechartomultibyte (950, 0, PWS, R1, FT, R 1, "?", & f); // code page switching 掂 GB-> BIG5FT [R1] = 0;
Cout <
<< "(";
For (int i = 0; i
Cout << ";
Printf ("0x% 02x", (Byte) ft [i]);
}
COUT << ")" << "
DELETE [] PWS;
}
delete [] ft;
}
// From the standard input Simplified States -> BIG5 Traditional Standard Output, enter two empty lines to exit int Main (int Argc, char * argv []) {for (;;) {char line [1024]; cin.getLine LINE, SIZEOF (LINE)); String S (Line); if (! cin || s.LENGTH () == 0) Break; J2F (s);} _ getCH (); return 0;}
Question 3: How to get a view pointer in multi-thread? Key Here: There are two ways to achieve your requirements: 1) The first method: If the multi-thread is not appearing in app.cpp, then add extern cyourapp theApp in multi-threaded .CPP;
// get document template: POSITION curTemplatePos = theApp.GetFirstDocTemplatePosition (); CDocTemplate * m_doc = theApp.GetNextDocTemplate (curTemplatePos); file: // get the document: curTemplatePos = m_doc-> GetFirstDocPosition (); CYourDoc * m_pdoc = (CA8Doc *) m_doc-> GetNextDoc (curTemplatePos); file: // get a view: curTemplatePos = m_pdoc-> GetFirstViewPosition (); CYourView * m_pview = (CYourView *) m_pdoc-> GetNextView (curTemplatePos); file: // call the view function: m_pview- > PUT ();
2) Second method:
// Get the form pointer: cmainframe * pframe = (cMAINFRAME *) AFXGetApp () -> m_pmainwnd; file: // Get a view with the form: cyorView * m_pview = (cyourView *) Pframe-> getActiveView (); File: // Call the view function: m_pview-> Put ();
Question 4: How do I make the program do not create a new document when starting?
The key is here: Join before the ProcessShellcommand function in the program's initInstance:
CMDINFO.M_NSHELLCOMMAND = ccommandlineinfo :: Filenothing
Problem 5: How do I get all the views in the MDI program? The key is here: Must use the functions not recorded in some documents:
CDocument :: GetFirstViewPosition (); // DOCCORE.CPPCDocument :: GetNextView (); // DOCCORE.CPPCMultiDocTemplate :: GetFirstDocPosition (); // DOCMULTI.CPPCMultiDocTemplate :: GetNextDoc (); // DOCMULTI.CPP
At the same time, you also need to deal with CWINAPP members M_TemplateList. Problem 6: How do I get all the tables in a database? The key is here:
HRESULT hr = S_OK; _ConnectionPtr pConnection = NULL; _CatalogPtr pCatalog = NULL; _bstr_t strCnn ( "Provider = sqloledb; Data Source = MyServer;" "Initial Catalog = pubs; User Id = sa; Password =;"); try {file: // Define a command object for a stored procedure pConnection.CreateInstance (__ uuidof (Connection));. hr = pCatalog.CreateInstance (__ uuidof (Catalog)); hr = pConnection-> Open (strCnn, "", "", adConnectUnspecified) PCATALOG-> PTACTIVECONNECTION (_VARIANT_T *) PCONNECTION)); long ntbcount = pcatalog-> TABLES-> count; // This is the number of tables you want PConnection-> close (); pConnection = null;} Catch (_COM_ERROR & E) {....}