1. How do I get an instance handle of the application? The instance handle of the application is saved in CWINAPPIM_HINSTANCE, which can call the AFXGetInstancdHandle to get the handle .example: handle hinstance = afxgetInstanceHandle (); 2. How to get the application main window of the application main window? The pointer of the window is saved in CwinThread :: m_pmainwnd, call the AFXGetMainWnd implementation. AFXGETMAINWND () -> ShowWindow (sw_showmaxmize); // Maximize the program .3. How to get an icon for other programs in the program? Two methods: (1) SDK function SHGETFILEINFO or use Extractic to get the icon resource to get the icon resource Handle, (2 SDK functions, SHGETFILEINFO, more information about files, such as size icons, properties, types, etc.example (1): display NotePad icon in the upper left corner of the program window .void Csampleview: OnDraw (CDC * PDC) {if (: shGetfileinfo) _T ("c: //pwin95/notepad.exe"), 0, & stfileinfo, sizeof (stfileinfo), shgfi_icon) {PDC -> Drawicon (10, 10, stfileinfo.hicon);}}}}} The same feature, Use Extracticon Functionvoid Csampleview :: OnDraw (CDC * PDC) {HiCon Hicon = :: Extracticon (AFXGetInstanceHandle (), _ T ("Notepad.exe"), 0); IF (Hicon && Hicon! = (Hicon) -1 PDC-> Drawicon (10, 10, HICON);} Description: Get NotePad.exe's path Formant to get the getWindowsDirectory function, if it is a brush to call Win95, you should use the way to access the registry to get its path, you want It is a more important program, considering it to comprehensively .4. How to program end applications? How do I program to control Windows reboot? This is a simple and programmed problems. The first question, send the window WM_CLOSE message, call CWnd :: OnClose member function. Allows whether the user prompts if the modified data is saved .Example: AFXGETMAINDOW () -> SendMessage (WM_CLOSE); you can also create a custom function Terminate Windowvoid Terminate Window (LPCSTR PCAPTION) {CWND * PWND = CWND :: FindWindow (NULL, PCAPTION); if (PWND) PWND -> Sendm Essage (WM_Close);} Description: The FindWindow function is not advocated because it cannot process the title bar automatically change, such as we want to detect NOTEPAD is not running, do not know the title bar of NOTEPAD in advance, then FindWindow does not work, you can Implemented by enumerating a WINDOWS task list. There is a more detailed introduction in the Mechanical Press, "Windows 95API Developer Guide", and no longer say more. The second question, the USE EXITWINDOWSEX FUNCTION function control system is rebooted, or restarting Windows. There is no longer mentioned in front of it. 5. How to add other applications? I remember that this seems to be a high appearance frequency. Three SDK functions WINEXEC, Shellexecute, and createProcess can be used.
Winexec is the easiest, two parameters, the previous specified path, the latter specified display method. The latter parameter is worth mentioning, such as the mud with sw_showmaxmize how to add a program without maximizing the button, huh, NETERM, CALC, etc. There will be no normal form, but it has been added to the task list. SHELLEXECUTE is flexible than WinExex, you can specify a work directory, the following EXAMPLE is open directly C: /TEMP/1.txt, without adding an application associated with TXT files, many installations will open a window after completion, to display Readme or FAQ, even if you do it. SHELLEXECUTE (NULL, NULL, _T ("1.txt"), NULL, _T ("C: // Temp"), sw_showmaxmized); CreateProcess is the most complicated, a total of ten Parameters, but most of them can be replaced with null, which can specify the security attributes of the process, inherit information, priority, and more. Take a very simple EXAMPLE: StartupInfo Stinfo; // Start the window information processInfo procinfo; // The process of the process CreateProcess (NULL, _T ("NOTEPAD.EXE"), NULL, NULL.FALSE, NORMAL_PRIORITY_CLAS, NULL, NULL, & Stinfo, & Procinfo; 6. Determines the path to the application, some people have asked This problem. IUSE getModuleFileName gains the path to the application and then removes the executable file name. Example: TCHAR exeFullPath [MAX_PATH]; // MAX_PATH defined it in the API, as if 128GetModuleFileName (NULL, exeFullPath, MAX_PATH) 7 to obtain a variety of directory information in the Windows directory: Use "GetWindowsDirectory" system directory under Windows: Use. "GetSystemDirectory" Temp Directory: Use "getTemppath" Current Directory: Use "getcurrentdirectory" Please note the first parameter of the first two functions as a directory variable name; the latter is a buffer; the next two opposite. 8. How to customize the message Some people have asked, in fact, it is not difficult. (1) Manually defined the message, can you write #define WM_MY_MESSAGE (WM_USER 100), the MS recommended at least WM_USER 100; (2) Write a message processing function, use WPARAM, LPARAM Return LRESULT.LRESULT CMAINFRAME :: ONMYMESSAGE (WPARAM WPARAM, LPARAM LPARAM) {// Add Your Processing Function} (3) Declaration at the AFX_MSG of the class, that is, the "Macro Mapping" 9. How to change the window icon? Send a WM_SECTION message to the window.
Example: Hicon Hicon = AFXGetApp () -> Loadicon; ASSERT (HICON); AFXGETMAINWND () -> SendMessage (WM_SECTION, TRUE, (LPARAM) Hicon; 10. How to change the default style of the window? Replay CWnd :: PreCreateWindow CREATESTRUCT structure and modify and specify the styles other creating .Example: Delete "Max" Button and Set Original window's Position and SizeBOOL CMainFrame :: PreCreateWindow (CREATESTRUCT & cs) {cs.style & = ~ WS_MAXINIZEMOX; cs.x = cs.y = 0; cs.cx = getSystemMetrics (SM_CXSCREEN / 2); cs.cy = getSystemMetrics (SM_CYSCREEN / 2); Return CmdiframeWnd :: PrecreateWindow (CS);} 11. How to place the window? Easy, Call Function CWnd :: Center WindowsExample (1): Center Window (); // Relative to it's parent // Relative to ScreenExample (2): Center Window (CWnd :: GetDesktopWindow ()); // Relative to Application's MainWindowAfxGetMainWnd () - > Center window (); 12. How to make the window and MDI window to maximize and minimize? First, the window. M_nCmdShow set value in function InitStance .m_nCmdShow = SW_SHOWMAXMIZED; // maximize m_nCmdShow = SW_SHOWMINMIZED; // minimize m_nCmdShow = SW_SHOWNORMAL; // MDI windows normal way: If you are creating a new application can be used MFC AppWizard The Advanced button and the detection maximizes or minimizes the MDI sub-window style group; also overloads the MDI Window's PrecreateWindow function, sets WS_MAXMIZE or WS_MINMIZE; if you derive from cmdichildwnd, call the CWnd :: Show Window in the OnInitialUpdate function to specify MDI CHILD WINDOW style. 13. How to keep the program so small? That is very interesting: When the recovery program is large, Windows will send a WM_Query-Open message, set the member function with ClassWizard ONQUERYOPEN (), Add Following Code: Bool CMAINFRAME :: ONQUERYOPEN () {return false;} 14. How to limit the size of the window?
Windows sends a WM_GETMAXMINICINFO message to track, in response to it, write code in ONGETMAXMINFO: 15. How to make the window not visible? Very simple, use SW_HIDE hidden window, you can combine FindWindow, ShowWindow control .16. How to make the window in the forehead? Bringwindowtotop (Handle); setWindowPos function, the top style of the specified window, using the WS_EX_TOPMOST extension window style example: void ToggleTopMost (CWnd * pWnd) {ASSERT_VALID (pWnd); pWnd -> SetWindowPos (pWnd-> GetStyle () & WS_EX_TOPMOST) & wndNoTopMOST: & wndTopMost, 0,0,0,0, SSP_NOSIZE | WSP_NOMOVE?};} 1 display. And hidden title bar
Method 1: Using API implementation
// Hide Titlebarlong LStyle = :: getWindowlong (this-> m_hwnd, gwl_style); :: setWindowlong (this-> m_hwnd, gwl_style, lstyle & ~ ws_caption); :: setwindowpos (this-> m_hwnd, null, 0, 0, 0, 0, SWP_NOSize | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
// display TitleBar :: SetWindowLong (this-> m_hWnd, GWL_STYLE, lStyle | WS_CAPTION); :: SetWindowPos (this-> m_hWnd, NULL, 0, 0, 0, 0, ?? SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED Method 2: Use the CWND member function modifyStyle implement // Hide TitlebarmodifyStyle (WS_CAPTION, 0, SWP_FRAMECHANGED); // Display TitlebarmodifyStyle (0, WS_CAPTION, SWP_FRAMECHANGED);
2. How to use SendMessage () to send a message to clear its content? HWND HEDITWND = getdlgitem (idc_edit1) -> getsafehwnd (); :: SendMessage (HeditWnd, WM_SETTEXT, (WPARAM) 0, (LPARAM) "")
3. The file property window pop SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof (SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = "properties"; ShExecInfo.lpFile = "c: / "; // can also be file shexecinfo.lpparameters =" "; shexecinfo.lpdirectory = null; shexecinfo.ns = sw_show; shexecinfo.hinstapp = null; shellexecuteex (& shexecInfo);" SHELLEXECUTEEX ";
4. Delete all files in a directory
Bool DeletedIRectory (LPCTSTR DIRNAME) {cfileFind Tempfind; // Declare a cfilefind class variable to search for Char TempFileFind [200]; // Used to define Sprintf (TempFileFind, "% S //*.*", DIRNAME ); // matching format address *. *, All files Bool isfile = (bool) tempfind.FindFile (TempFileFind); // finds the first file while (isfinded) {isfinded = (bool) TempFind. FindNextFile (); // Removable Search Other Files IF (! Tempfind.isdots ()) // If not "." Directory {Char FoundFileName [200]; strcpy (FoundFileName (). GetBuffer (200)) , If (TempFind.Indirectory ()) // If it is a directory, recursively call {// deletedirectory char Tempdir [200]; Sprintf (Tempdir, "% S / / /% S", DIRNAME, FOUNDFILENAME); DELETEDIRECTory (Tempdir );} Else {// If it is a file, CHAR TEMPFILENAME [200]; Sprintf (TempFileName, "% S / /% S", DIRNAME, FOUNDFILENAME); deletefile (TempFileName);}}} tempfind.close ); if (! RemoveDirectory) // Delete the directory {AFXMessageBox ("Delete Directory Failed!", MB_OK); Return False;} Return true;} 5.LIB and DLL file Differences and contact
.dll is the file that is only connected when you run it, so it is a relatively small executable file format, and there are other file formats such as .ocx, all .dll files are executable. .
.lib is a file that is connected when your program is compiled, so you must inform the compiler to connect the lib file there. In general, the LIB file is also referred to as a static connection library than the dynamic connection file. When you compile the code into files in these formats, they can't be changed later. If you want to use a lib file, you must: 1 Contains a corresponding header file to inform the compiler lib file 2 Settings 2 Setting lib files Allow compilers to find compiled binary code
If you want to isolate a DLL file from your code instead of a static connection library, you still need a lib file. This lib file will be connected to the program to tell the operating system When you run, what DLL file you want to use, in general, the name of the corresponding DLL file in the lib file and a sequence table indicating the DLL output function entry. If you don't want to use a lib file or there is no lib file, you can use Win32 API functions to LoadLibrary, getProcAddress. In fact, we can open the lib file in a binary form in Visual C IDE, most of the case of see the C function of the ASCII code or some of the overloaded functions.
Generally, our most important trouble about the lib file is the unresolved symble such an error. This is the LIB file connection error or does not include .c, .cpp file to the project, the key is if the C language is written in C engineering LIB files must be included: extern "c" {#include "myHeader.h"} This is because the C language written LIB file does not have the name destruction of C , the C function cannot be overloaded, so the connector will Error. 1winexec, two parameters, the previous specified path, the latter specified display method. The latter parameter is worth mentioning, such as the mud with sw_showmaxmized way to add a program without maximizing the button, huh, NETERM, CALC, etc. There will be no normal form, but it has been added to the task list. 2Shellexecute is flexible than WinExex, you can specify a work directory, the following EXAMPLE is open directly C: /TEMP/1.txt without adding an application associated with TXT files, and many installer will open a window after completion, to display Readme or FAQ, I'm doing this. SHELLEXECUTE (NULL, NULL, _T ("1.txt"), NULL, _T ("C: // Temp"), sw_showmaxmized); 3CREATEPROCESS is the most complicated, a total of ten Parameters, but most of them can be replaced with null, which can specify the security attributes of the process, inherit information, priority, and more. Take a very simple EXAMPLE: StartupInfo Stinfo; // Start the window information processInfo procinfo; // Process information CreateProcess (NULL, _T ("NOTEPAD.EXE"), NULL, NULL.FALSE, NORMAL_PRIORITY_CLAS, NULL, NULL, & Stinfo, & Procinfo;
The shellexecute function is used in the startup program. The following detailed explains its related parameters! The shellexecute function opens or prints a specified file. Files can be an executable or a document. Hinstance shellexecute (hwnd hwnd, // main window handle LPCTSTSTSTSTSTSTSTSTSTSTSTSTSTSTR LPFILE, / / string pointer, specify file name or directory name LPCTSTR LPPARETERS, / / string pointer, specified Parameters LPCTSTR LPDIRECTORY, / / string pointer to the executable, specify the default directory int nshowcmd // file display mode); the parameter hwnd specifies a main form. LPOPERATION A non-empty string pointer, specifying an operation mode. The following operations can be used to open the files specified by the LPFile using the "Open" function, which can be an executable file or a document file or a directory to open. "Print" This function prints the file specified by lpfile. The file should be a document file. If it is an executable file, running this file is as specified in the "OPNE" mode of operation. The "Explore" function opens browsing the directory window specified by lpfile. If the parameter is NULL, it is equivalent to using the "Open" mode of operation. LPFILE A non-empty string specifies files to open or printed, or to open a directory name to open. This function can open an executable or a document file or print a file. LPParameters If lpfile specifies an executable file, LPParameters is a pointer to non-empty strings that represent parameters to pass to this application. If lpfile specifies a document file, it should be empty. LPDIRECTORY Non-empty string Specifies the default directory nshowcmd If the LPFile specifies an executable, nshowcmd specifies how the application is running. It can be the following value: Value SW_HIDE hides the form, activates another window. SW_MAXIMIZE Zoom SW_MINIMIZE minimized display SW_RESTORE normal status display SW_SHOW activated and displays its current position SW_SHOWMAXIMIZED size display SW_SHOWDEFAULT to create a thread pass into the activation parameters and maximize display SW_SHOWMINIMIZED activated but displayed in a manner to minimize SW_SHOWMINNOACTIVE minimize display The original focus form is constant Active. SW_SHOWNA displays SW_SHOACTIVATE SW_SHOWNORMAL in its current state. If lpfile specifies a document file, nshowcmd should be 0.
Return Value If successful, return the current run application handle or DDE server handle If the return value is less than 32, the meaning of the following means. Value Meaning 0 operating system memory or resources is not enough ERROR_FILE_NOT_FOUND file not found ERROR_PATH_NOT_FOUND specify the wrong path ERROR_BAD_FORMAT not legitimate applications SE_ERR_ACCESSDENIED operating system denied access to the name associated with this file SE_ERR_ASSOCINCOMPLETE file is incomplete or illegal SE_ERR_DDEBUSY not complete the DDE transaction because being Handling other DDE transactions SE_ERR_DDEFAIL DDE transaction failed SE_ERR_DDETIMEOUT Please show the timeout SE_ERR_DLNOTFOUND Did not find the specified dynamic link library SE_ERR_FNF specified that the file is not found. SE_ERR_NOAASSOC does not have an application associated with the current file type SE_ERR_OOM memory without finding a se_err_share shared error Remarks The file specified by the parameter lpfile can be a document file or an executable file. If it is a document file, you can open or print the file, specified by the LPOPERATION parameter. If it is an executable file, you can only open, even if lpopert is specified as "Print". You can use shellexecute to open or expenented a shell folder. To open a shell, Use Either of the following calls: You can use this function to open or browse one Folder: Shellexecute (Handle, Null, Path_to_Folder, Null, Null, SW_SHOWNORMAL); or Shellexecute (Handle, "Open", Path_to_Folder, NULL, NULL, SW_SHOWNORMAL);
Browse folders: Shellexecute (Handle, "Explore", Path_to_Folder, Null, Null, SW_SHOWNORMAL); If lpoperty is null, the function opens this file if "open" or "expens", the function opens a window.
HTMLHELP (NULL, (LPCSTR) strhelp, hh_display_topic, 0); ---------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- ------------------------------------ Vchelp Jiangchuan big brother's experience: 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);} II, There are many procedures for automatic configuration of data sources to use the database combined with the database, which is the most commonly used in small and medium-sized VC system development. If the transplant of the program, if you are a very primary user, you It is also necessary to configure the data source to the configuration panel, then it is a bit not going. #Include
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 Error!"); exit (0);} Three, setting display mode: Many programs of programs are 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); 4, loading other applications in your program: Your program In addition to calling to each module, you can call an application in the same development environment, such as The VC environment is called Delphi, VB development executable, you can use the following method (in the application copy program directory of the call): cstring spath; getModuleFileName (null, spath.getBuffersetLength (Max_Path 1), max_path) Spath.releaseBuffer (); int npos; npos = spath.reversefind ('//'); spath = spath.left (npos); cstract lpszfilename = spath "//***.exe";// here to modify File name cfilefind ffind; if (! Ffind.FindFile ("no found call) {:: afxMessageBox (" No found in the call! "); Return false;} else shellexecute (null, null, _t) ("***. EXE"), NULL, SPATH, NULL); Five, ending processes: End of other program processes in your program, the method adopted is to list, then use the search method: #include "Tlhelp32.h" DWORD processid [50]; cstring kkk [50]; handle snapshot = CreateToolh elp32Snapshot (TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 * info = new PROCESSENTRY32; PROCESSENTRY32 ProcessInfo; // declaration process information variables ProcessInfo.dwSize = sizeof (ProcessInfo); // // set the size of the return system ProcessInfo the first process information BOOL Status = process32first (Snapshot, & processinfo); int m_nprocess = 0; while (status) {CSTRING S, STR1, STR2; S.Format ("% D", ProcessInfo.cntthreads; str1.format ("% s", ProcessInfo .szexefile; str1 = processinfo.szeefile; kkk [m_nprocess] = processinfo.szexefile;
ProcessID [m_nProcess] = ProcessInfo.th32ProcessID; if (str1 == "*** exe.") // *** exe is the name that you want to end the process {HANDLE ProcessHandle;. ProcessHandle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, ProcessID [m_nprocess]); TERMINATEPROCESS (ProcessHandle, 0);} status = process32next (snapshot, & processinfo); m_nprocess ;} problem 1. How is an EDIT support for an input. General Edit control supports a lot of format input, if you want to support data If you enter the input, you can modify the Edit control properties, select the number attribute, but this is not supported. The input is not supported. The solution is not supported. The solution is to derive a class CEDIT, then map messages en_change Because if your control uses this derived class, you will trigger this event when you make your Edit control, you don't have to trigger your EN_CHANGE event for your control. Then judge the newly entered character, if This character meets the digital rules or. Number rules, then calculates already appeared. Number of numbers, allow input operations when complying with this condition, otherwise deleting the just entered characters, performing the operation of the editing box string. Must involve Question, 1: How to determine a string is a number or other type. 2: How to find a number of symbols in a string. 3: How to set the position of the EDIT cursor. 1 Solution to the method can utilize the following method Solved. Cstring straTemp = sztemp.spanincluding ("0123456789"); if (! Strtemp.isempty ()) // This string is a digital ELSE // Non number 2 problem I use the method of recurring method, first look for the first appearance Symbolic position, then use string segmentation technology to take the Right section to loop call call, the relevant code can be seen below: int CNUME Ditctrl :: getStringnum (CString Szval) // Get the middle of the string. Number of numbers {INT nnum = 0; while (1) {int ncount = szVal.find ('.'); if (ncount == - 1) Break; szval = szVal.right (szval.getlength () - ncount-1); nnum ;} return nnum;
} 3 The problem can be implemented using the method of obtaining the EDIT control handle to send an EM_setsel message. So the basic code can be implemented: void cnumeditctrl :: onchange () {// Todo: if this is a richedit control, the control will not //////////////////////////> send this notification unless you override the CEdit :: OnInitDialog () // function and call CRichEditCtrl () SetEventMask () // with the ENM_CHANGE flag ORed into the mask CString m_estr, szTemp;.. GetWindowText (m_estr); int nLen = m_estr .Getlength (); if (! M_estr.isempty ()) {sztemp = m_estr.right (1); BOOL BNUM = true; cstring straTemp = sztemp.spanincluding ("0123456789"); if (! Strtemp.isempty ()) BNUM = true; ELSE BNUM = false; npoint = getStringnum (m_estr); if (Strcmp, ") == 0 || BNUM) {if (Npoint> 1) {npoint--; :: afxMessageBox (" The number of occurrences exceeds twice! "); M_estr = m_estr.Left (m_estr.getlength () - 1); setWindowText (m_estr); Nlen -; SendMessage (EM_SETSEL, NLEN, NLEN); return;}} else {:: afxMessageBox ("Input Format Error"); m_estr = m_estr.Left (m_estr.getLength () - 1); setWindowText (m_estr); Nlen -; SendMessage (EM_SETSEL, NLEN, NLEN); RETURN;}} // Todo: add your control notification handler code he} Question II. How to use the Picture control to display the edit control content Picture control cannot be setwindowText operation, so you can't use it directly The control cannot display the character. But if you derive a CSTATIC, then process the WM_PAINT message to perform the redrawing operation of the control. The code is actually simple. The following method can refer to. Void cshowstrpicWnd :: onpaint () {CPAINTDC DC THIS); // D m_brush.deleteObject ();
M_brush.createsolidbrush (RGB (255, 128, 64)); CDC * PDC = getDC (); PDC-> setBkmode (Opaque); PDC-> SetBkcolor (RGB (255, 128, 64)); PDC-> SelectObject (& M_Brush); CRECT Rc; getClientRect (& rc); ScreenToClient (& RC); PDC-> Rectangle (0, 0, rc.width (), rc.Height ()); PDC-> SetTextColor (RGB (255, 0)); PDC -> TextOut (2, 2, strText.getBuffer (strtext.getLength ())))); // do not call cstatic :: onpaint () for Painting Messages} then triggers the control en_change message, so you can pass the information to the PIC. , Then call the InvalIDateRect interface redrawing work. Some common methods in Vc (20)
// First, open the CD-ROM
McIndstring ("Set Cdaudio Door Open Wait", NULL, 0, NULL;
// Second, turn off CD_ROM
McIndstring ("Set Cdaudio Door Closed Wait", NULL, 0, NULL;
// Third, turn off the computer
OSVERSIONINFO OsVersionInfo; // data structure contains the operating system version information OsVersionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); GetVersionEx (& OsVersionInfo); // Get OS version information if (OsVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {// Windows98, calls the ExitWindowsEx () Function restarts the computer DWORD DWRESERVED; EXITWINDOWSEX (EWX_REBOOT, DWRESERVED); / / You can change the first parameter, implement some processing programs before using the user, // shut down, turn off the power, etc. //
// 4, restart the computer
TypeDef Int (Callback * Shutdowndl) (INT); // Displays the pointer hinstance hinst = loading dialog function ("shell32.dll"); // Load shell32.dllshdowndlg shutdowndialog; // Point to the shell32.dll library display The pointer IF (hinst! = Null) {// get the address of the function and calls ShutDowndialog = (Shutdowndialog) (* shutdowndialog) (* shutdowndialog) (* shutdowndialog) (* shutdowndialog) (* shutdowndialog) (* shutdowndialog) (* shutdowndialog) (0);}
// 5, enumerate all fonts
LOGFONT lf; lf.lfCharSet = DEFAULT_CHARSET; // Initialize the LOGFONT structurestrcpy (lf.lfFaceName, ""); CClientDC dc (this); // Enumerate the font families :: EnumFontFamiliesEx ((HDC) dc, & lf, (FONTENUMPROC) EnumFontFamProc, (lPARAM) this, 0); // enumeration function int CALLBACK EnumFontFamProc (LPENUMLOGFONT lpelf, LPNEWTEXTMETRIC lpntm, DWORD nFontType, long lparam) {// Create a pointer to the dialog window CDay7Dlg * pWnd = (CDay7Dlg *) lparam ; // add the font name to the list box pwnd -> m_ctlfontlist.addstring (lppelf-> Elffont.lffacename); // Return 1 to Continue Font Enumeration Return 1;} // where m_ctlfontlist is a list control variable
// Sixth, only one program instance is run once, if it has been run, exit
IF (FindWindow (NULL, "Program Title")) EXIT (0);
// Seven, get the current mouse location
Cpoint Pt; getCursorpos (& PT); // Get position
// 8, context menu event trigger event: OnContextMenu event
// Nine, display and hide the program menu
CWND * PWND = AFXGETMAINWND (); if (b_m) // Hide menu {PWND-> setMenu (null); PWND-> DrawMenubar (); b_m = false;} else {cmenu menu; menu.loadmenu (idR_mainframe); display Menu can also change the menu item PWND-> SetMenu (& menu); PWND-> DrawMenuBar (); b_m = true; menu.detach ();}
// 10, get the icon for executable
Hicon Hicon = :: Extracticon (AfxGetInstanceHandle (), _ T ("NOTEPAD.EXE"), 0); if (Hicon && Hicon! = (HICON) -1) {PDC-> Drawicon (10, 10, Hicon);} DESTROYICON (hic);
// Eleven, window automatic lean program demonstration
BOOL AdjustPos (CRect * lpRect) {// automatically aside int iSX = GetSystemMetrics (SM_CXFULLSCREEN); int iSY = GetSystemMetrics (SM_CYFULLSCREEN); RECT rWorkArea; BOOL bResult = SystemParametersInfo (SPI_GETWORKAREA, sizeof (RECT), & rWorkAre a, 0); CRect Rcwa; if (! BRESULT) {// If the call is unsuccessful, use GetSystemMetrics to get the screen area RCWA = CRECT (0, ISX, ISY);} el = lpRect-> left; int = = LPRECT-> TOP; IF (ix
// Twelve, add a menu item to the system menu to add a menu item to the system menu to add three steps: // First, use the Resource Symbols dialog (Select Resource Symbols in the View menu ... can be displayed //// This dialog is defined in the menu item ID, which should be greater than 0x0f and less than 0xF000; // Secondly, call the CWnd :: GetSystemMenu to get the pointer to the system menu and call CWnd :: Appendmenu to add the menu // item to the menu. The following example is added to the system menu two new int CMainFrame :: OnCreate (LPCREATESTRUCT lpCreateStruct) {// ... // Make sure system menu item is in the right range ASSERT (IDM_MYSYSITEM <0xF000);. // Get pointer to system menu . CMenu * pSysMenu = GetSystemMenu (FALSE); ASSERT_VALID (pSysMenu);. // Add a separator and our menu item to system menu CString StrMenuItem (_T ( "New menu item")); pSysMenu-> AppendMenu (MF_SEPARATOR); pSysMenu -> appendmenu (mf_string, idm_mysysIstem, strmenuite); // ...}
// 13, run other procedures
// 1, run email or URL
Char szmailaddress [80]; STRCPY (Szmailaddress, "Mailto: Netvc@21cn.com"); Shellexecute (Null, "Open", Szmailaddress, Null, NULL, SW_SHOWNORMAL);
// 2, run the executable Winexec ("notepad.exe", sw_show); // run the bill
// 14, dynamic increase or delete menu
// 1, add menu // Add cmenu * mainmenu; mainmenu = AFXGETMAINWND () -> getMenu (); // Get the main menu (MainMenu-> GetSubMenu (0)) -> appendmenu (mf_separator); // Add Division. (mainmenu-> getSubmenu (0)) -> appendmenu (mf_string, id_app_about, _t ("always on & top")); // Add new menu item DrawMenuBar (); // Heavy painting menu // 2, delete menu / / Delete CMenu * MainMenu; mainmenu = AFXGETMAINWND () -> getMenu (); // Get the main menu
CString str; for (INT i = (MainMenu-> GetSubMenu (0)) -> getMenuItemCount () - 1; i> = 0; I -) // Number of items to get menu. {(MAINMENU-> GetSubMenu (0)) -> getMenustring (i, str, mf_byposition); // copy the label of the specified menu item to the specified buffer. Explanation of MF_BYPosition. IF (str == "always on & top") // If we have just increased menu items, then delete. {(MAINMENU-> GetSubMenu (0)) -> deleteMenu (i, mf_byposition); Break;}} // fifteenth, changing the application icon static changes:
/ / Modify the icon resource IDR_MAINFRAME. It has two icons, one is 16 * 16, the other is 32 * 32, pay attention to modify together.
// Dynamic changes: Send WM_SETICON messages to the main window. The code is as follows: hicon hicon = AFXGetApp () -> loading (idi_icon); Assert (HICON); AFXGETMAINWND () -> SendMesetage (WM_SETICON, TRUE, (LPARAM) Hicon;
//6, another way to change the window title
// Use statement cwnd * m_pcWnd = AFXGETMAINWND (), then call the setWindowText () function in the following form: setWindowText (* m_pcwnd, (lpctstr) m_windowtext); // m_windowText can be a CString class variable.
// sevente, copying image data on the clipboard to copy image data below the code data to any application, // can be placed in a function of CVIEW derived class.
Cmetafiledc * m_pmetadc = new cmetafiled (); m_pmetadc-> createenhacesd (getdc (), null, null, "whatver"); // Draw meta file // do what Ever You Want to do: Bitmaps, Lines, Text ... // close meta file dc and prepare for clipboard; HENHMETAFILE hMF = m_pMetaDC-> CloseEnhanced (); // copy to clipboardOpenClipboard (); EmptyClipboard (); :: SetClipboardData (CF_ENHMETAFILE, hMF); CloseClipboard ();
// deletemetafile (HMF); delete m_pmetad;
// Eighteen, the transfer of text data on the clipboard puts the text onto the splicing board:
CString source; // put your text in sourceif (OpenClipboard ()) {HGLOBAL clipbuffer; char * buffer; EmptyClipboard (); clipbuffer = GlobalAlloc (GMEM_DDESHARE, source.GetLength () 1); buffer = (char *) GlobalLock ( Clipbuffer; STRCPY (Buffer, LPCSTR (Source)); GlobalUnlock (Clipbuff (CF_Text, Clipbuffer; CloseClipboard ();} // Get text from the splic panel:
Char * buffer; if (OpenClipboard ()) {buffer = (char *) getclipboardData (cf_text); // do sometying with buffer here // before it goes out of scope} closeclipboard ();
// 19, capture the screen image to the cutting version
void CShowBmpInDlgDlg :: OnCutScreen () {ShowWindow (SW_HIDE); RECT r_bmp = {0,0, :: GetSystemMetrics (SM_CXSCREEN), :: GetSystemMetrics (SM_CYSCREEN)}; HBITMAP hBitmap; hBitmap = CopyScreenToBitmap (& r_bmp); // hWnd is window handles if (OpenClipboard ()) {EmptyClipboard (); SetClipboardData (CF_BITMAP, hBitmap); CloseClipboard ();} ShowWindow (SW_SHOW);} HBITMAP CShowBmpInDlgDlg :: CopyScreenToBitmap (LPRECT lpRect) {// lpRect representative of the selected region { HDC HSCRDC, HMEMDC; / / Screen and Memory Device Description Table HBitmap Hbitmap, Holdbitmap; // Bit 图 INT NX, NY, NX2, NY2; // Selection Area Coordinate INT NWIDTH, NHEIGHT; // Bitmap Width and Height INT XSCRN, YSCRN; // Screen resolution // Make sure the selected area is not empty rectangular IF (ISRECTEMPTY (LPRECT)) Return Null; / / Creating a device description table hscrdc = createdc ("Display", NULL, NULL, NULL); / / Creating a compatible memory device description table for the screen device description table HMEMDC = CR EateCompatiPLEDC (HSCRDC); // Get selected area coordinate nx = lprect-> left; Nx2 = lpRect-> Right; NY2 = LPRECT-> Right; NY2 = LPRECT-> BOTTOM; // Get screen resolution xscrn = getDevicecaps HSCRDC, Horzres); YSCRN = getDeviceCaps (HSCRDC, Vertres); // Make sure the selected area is visible if (NX <0) nx = 0; if (NY <0) NY = 0; if (nx2> xscrn) NX2 = xscrn; if (NY2> YSCRN) NY2 = YSCRN; NWIDTH = NX2 - NX; NHEIGHT = NY2 - NY; // Create a bitmap Hbitmap (HSCRDC, NWIDTH, NHEIGHT), which is compatible with the screen device descriptor table.
// Put the new bitmap to the memory device descriptor table holdbitmap = (hbitmap) SelectObject (HMEMDC, HBitmap); / / copy the screen device description table to the memory device description table Bitblt (hmemdc, 0, 0, nwidth, NHEight , HSCRDC, NX, NY, SRCCOPY; // Get the handle of the screen bitmap HBitmap = (HbitMap) SelectObject (HbitMDC, Holdbitmap); / / Clear DELETEDC (HSCRDC); deletedc (hmemdc); // Return bitmail Return Return HbitMap;}} // twenty, how to display bitmap scales in the Static control
// Display bitmap void cshowbmpindlgdlg :: showbmpinstaic () {cbitmap hbmpinstaic () {cbitmap hbmpinstaic () {cbitmap hbmpinstaic () {cbitmap hbitmap; // Point PSTATIC * Pstain; pstaic = (cstatic *) getdlgitem (IDC_IMAGE); // Load Resource mm.bmp is my file name, with your replacement hbitmap = (hbitmap) :: loadImage (:: afxgetinstanceHandle (), "mm.bmp", image_bitmap, 0, 0, lr_loadfromfile | lr_createdibsection; hbmp.attach (hbitmap); // get the picture format BITMAP bm; hbmp.GetBitmap (& bm); CDC dcMem; dcMem.CreateCompatibleDC (GetDC ()); CBitmap * poldBitmap = (CBitmap *) dcMem.SelectObject (hbmp); CRect lRect; pStaic -> getClientRect (& LRECT); // Display bitmap pstaic-> getdc () -> stretchblt (limited.wid, limited.top, limited.width (), LRECT.HEIGHT (), & DCMEM, 0, 0, BM. BMWIDTH, BM.BMHEIGHT, SRCCOPY); DCMem.selectObject (& Poldbitmap);} ******************************************* *********************************************************** ********** 1. Get and modify the control text, get the coordinate of the left upper corner of the dialog, use the Messagebox to adjust an INT variable. CString Strtext; Char Buffer [512]; getDlgitemtext (IDC_STATIC, STRTEXT); // get strText = "hoho"; if (Time> = 5) setdlgitemtext (IDC_STATIC, STRTEXT); // Modify
Rect Rect; getWindowRect; sprintf (buffer, "% d", rest.left); :: MessageBox (null, buffer, "text", mb_ok); ccomboBox * pcombox = (ccombox *) getdlgitem (IDC_COMBO); CString strText = _t (""); pcomboBox-> getWindowText (strText); AFXMessageBox (strText); if you want to calculate a piece of code to perform, is there a way to do it? DWORD DWTIME1 = GetTickCount (); // Your code ... dword dwtime2 = gettickcount (); usedtime = dwtime2-dwtime1; // millisecond ********* DEX ***** *************** 1.uneXpected endwile while ==> Page12. Generate 0 - 1 uniform distribution random number ==> Page23.Link2001 error: unresolved External Symbol "Symbol ==> Page34.MFC Application ==> Page85. Get system time in the program ==> Page17btw: Page (n) Continuous Press N-1 Space (change page symbol) to arrive / * **************************** ** RANK: ★★★★★★ ☆☆☆ ** ****** ********************************* / Q: UNEXPECTED End Of File While Looking for Precompiled Header Directive prompts this error, how would this? A : 1. In all .c .cpp files, start with #include "stdafx.h" in all.c .cpp files 2. Also in VC IDE Project-> Setting-> C / C -> Category-> Precompiled Headers for pre-translated settings / ****************************** ** RANK: ★★★★★★ ☆ ☆ ☆ ** **** *************************************************************************** A: The following is a routine : EXample / * rand.c: this program seeds the random-number generator * with th e Time, THEN DISPLAYS 10 Random Integers. * / # include
/ * Display 10 NumBers. * / For (i = 0; i <10; i ) Printf ("% 6F / N", (float) rand () / rand_max);} / ********* ******************** ** RANK: ★★★★★★★★ ☆ *************** **************** / Q: Unresolved External Symbol "Symbol" (Uncertain external "symbol) prompts this error, what is this? A: Someone in front Qink2001 error, a common solution: Learn to VC will often encounter a link error LNK2001, this error is very annoying, because the most preferred error for the programmer is not too compiled, and generally talk When the error is wrong, it has passed. There are very many reasons for generating connection errors, especially the LNK2001 error, often make people unknown. If you don't learn and understand VC , if you want to correct the connection error, LNK2001 is very difficult. Beglologists are studying VC During the process, the error message encountered by the LNK2001 is mainly: unresolved external symbol "Symbol" (Uncertain external "symbol"). If the connection program does not find the referenced function, the variable is found in all libraries and destination files Or label, this error message will be generated. In general, there are two reasons for incorrect: First, the variables are not existed, the spell is not correct or the use of errors; secondly, different versions of the connection library. It is possible to generate a LNK2001 error: 1. Due to the LNK2001 caused by the encoded error. 1. Unpredictable program code or module definition (.def) file can cause the LNK2001. For example, if a variable is declared in the C source file " VAR1 ", but attempts to access the variable in the variable" var1 "in another file, this error will occur. 2. If the inline function used is defined within the .cpp file, not the definition within the header file will result in LNK2001 Error. 3. When the function is called, if the type of parameter type used with the function declaration does not match the function declaration, LNK2001 will be generated. 4. Try to cause the LNK2001. 5 when the virtual function is called from the constructor or description function of the base class. 5. Pay attention to the utility of functions and variables, only global variables, functions are public. Static functions and static variables have the same use Range limit. When trying to access any static variables not declared within the file from the file, it will cause compilation errors or LNK2001. Variables (local variables) declared within functions can only be used within the range of this function. The global constant of C has only static connection performance. This is different from C, and the LNK2001 error will also be generated if the global variable is used in multiple files of C . One solution is to add the initialization code of the constant in the header file, and contain the header file in the .cpp file; another method is used to assign the variable to the constant. Two. The LNK2001 1 caused by the settings of compilation and links. If the / nod (/ nodefaultlib) option is used, the runtime and MFC library required by the program are written to the target file module when the compiler is connected, unless these libraries are not included in the file. Will be linked into the project file. In this case, the use / NOD will result in an error LNK2001.
2. If there is no program entry for WwinMainCrtStartup, "UnreSolved External ON _WINMAIN @ 16" will be obtained when using Unicode and MFC, and will get the LNK2001 error message. 3. When compiling using the / md option, since all the runners are retained within the dynamic link library, "FUNC" is referenced in the source file, the reference to "__Imp__func" in the target file. If you try to use a static library libc.lib or libcmt.lib, LNK2001 will occur on __Imp__func; if you do not compile / MD option, LNK2001 will occur when using the MSVCXX.LIB connection. 4. When compiling using the / ml option, if the LNK2001 occurs on _ERRNO with the libcmt.lib link. 5. When compiling the debug version of the application, the LNK2001 will be generated if the release model is used, and also, the same problem is also generated when using the debug version of the formation library to connect the release application. 6. Mixing use of different versions of libraries and compilers can also generate problems because the new version of the library may contain symbols and descriptions of the previous version. 7. Use the inline and non-inline compilation options in different modules to cause the LNK2001. If the function inline (/ OB1 or / OB2) is turned on when the C library is created, but the function inline (no inline keyword) is turned off in the corresponding header file described, and the error message will be obtained. To avoid the occurrence of this problem, the inline keyword flag should be used in the corresponding header file. 8. Incorrect / subsystem or / entry settings can also cause the LNK2001. In fact, there are many reasons for the production of LNK2001, and the above reasons are only part of it. These for beginners are enough to understand a while. However, the purpose of analyzing the cause is to avoid errors. Although the LNK2001 error is more difficult, as long as the above problem is noted, can it be avoided and solved? / ************************************ ** ** rank: ★★★★★★★★ ☆ **************************************** / MFC application Using the pointer in the program (reproduced - Source Vccode Dragon Tang Forum) 1) Get a DOC pointer in ViewDidoc * pdoc = getDocument (); one can have a document.
2) obtaining MainFrame pointer CWinApp the m_pMainWnd variable is MainFrame pointer may be in the App: CMainFrame * pMain = (CMainFrame *) AfxGetMainWnd (); 3) obtained MainFrame pointer CMainFrame * pMain = (CMaimFrame *) AfxGetApp in View ( ) -> m_pmainwnd; 4) Get View (established) pointer cmainframe * pmain = (cmaimframe *) AFXGetApp () -> m_pmainwnd; cyouview * pView = (cyouview *) PMain-> getActiveView (); 5) Get the current document pointer CDocument * pCurrentDoc = (CFrameWnd *) m_pMainWnd-> GetActiveDocument (); 6) obtained with the toolbar status bar pointer CStatusBar * pStatusBar = (CStatusBar *) AfxGetMainWnd () -> GetDescendantWindow (AFX_IDW_STATUS_BAR); CToolBar * pToolBar = (CtoolBar *) AFXGETMAINWND () -> getDescendantWindow (AFX_IDW_TOOLBAR); 7) If you join the toolbar and status bar variable (CMAINFRAME *) getParent () -> m_WndToolBar; (cmainframe *) getParent () -> m_wndstatusbar; 8) Mainframe gets menu pointer cmenu * pMenu = m_pmainwnd-> getMenu (); 9) gets the application class MFC global function AFXGetApp () in any class. 10) From the document class, I get the pointer of the view class. I learned from http://download.cqcnc.com/soft/program/Article/vc/vc405.html, from the document to get the view class pointer to control the same document Multiple views of multiple views, my experience, especially text, CEDITVIEW, when generating multiple view classes, this feature is very needed. CDocument class provides two functions for the positioning of the view class: GetFirstViewPosition () and GetNextView () virtual POSITION GetFirstViewPosition () const; virtual CView * GetNextView (POSITION & rPosition) const; Note: GetNextView () parentheses are parameters Reference mode, therefore the execution rate may change. GetFirstViewPosition () is used to return the first view location (the returned non-view class pointer, but a position value), getNextView () has two functions: Returns the next view class pointer and change with reference calls. The value of the incoming Position type parameter.
Obviously, in the Test program, there is only one view class, so you only need to call the two functions to get the CTestView pointer as follows (you need to define a Position structure variable to assist the operation): CTestView * PtestView; position pos = getFirstViewPositionPosition (); PTestView = getNextView (POS); you can go to the CTestView class pointer PTestView. After the completion of the sentence, the variable POS = NULL, because there is no next view class, nature does not have the next view class Position. But These statements are too simple, do not have too strong versatility and security features; when you want to return a pointer to a specified class in multiple views, we need to traverse all view classes until Find the specified class. When it is determined if a class pointer points to an instance of a class, you can use the iskindof () member function to check, such as: pView-> iskindof (runtime_class (ctestView)); you can check if the PVIEW refers to whether it is a CTestView class. With the above foundation, we can already get any type of pointer from the document class. For convenience, we use a member function of a document class, which has a parameter that means which type of pointer to get. To achieve the following:! CView * CTestDoc :: GetView (CRuntimeClass * pClass) {CView * pView; POSITION pos = GetFirstViewPosition (); while (! Pos = NULL) {pView = GetNextView (pos); if (pView-> IsKindOf (pClass )));} If (! PView-> iskindof (pclass)) {AFXMessageBox ("Connt Locate the view./r/n"); return null;} return pView;} A member function of two view classes Iskindof () is judged because there are three possibilities of exiting the While loop: 1.pos is null, that is, there is no next view class for operation; 2.PVIEW has met the requirements. 1 and 2 are satisfied. This is because the function of getNextView () is to change the current view pointer to the location of a view, and then return the current view pointer, so POS is the top of the PVIEW's top view class, which is all possible to be both pOS == null is PVIEW. . When the desired view is that the last view is the last view class. Therefore, two judgments are required. Use this function to follow the following format (to get the CTestView pointer as an example): ctestView * PTestView = (ctestView *) GetView (runtime_class (ctestView)); runtime_class is a macro, you can simply understand its role: Transform the name of the class For CruntimeClass as a pointer. As for the mandatory type conversion is also for security features, since the pointer type between the same base class is compatible with each other. This mandatory type conversion may not be necessary, but can avoid some cumbersome possible. 3. Number of pointers 1 and 2 from one view class, it is easy to obtain a method of obtaining a pointer between the view classes: It is to transfer the document class with a document class. Use 2 method to obtain another view class with the view positioning function of the document class.
Similarly, it can be implemented as a function: (Supplementation to get the pointer to other view classes from CTestaview) CView * ctestaview :: getView (cruntimeclass * pclass) {ctestdoc * pdoc = (ctestdoc *) getDocument (); cView * pVIEW; Position POS = PDOC-> getFirstViewPosition (); while (pOS! = Null) {pView = pdoc-> getNextView (POS); if (! PView-> iskindof (pclass)) Break;} if (! PView-> iskindof) PCLASS)) {AFXMessageBox ("Connt Locate the View."); Return Null;} Return PView;} This function is more than the first sentence than the GetView (), one is the first sentence to obtain a document pointer, and the other is Add a document class pointer to GetFirstViewPosition () and getNextView () to indicate that they are document class members. With this function; when you want to get the CTestbView pointer from CTestaview, you just need to follow: ctestbview * ptestbview = (ctestView *) GetView (runtime_class (ctestbview)); 11) You can also add multiple document templates for single documentation, However, the general development uses the MDI mode to develop multi-document templates, which is very close to the acquisition method of the above view. Here is a slight explanation. If it is unclear, please refer to MSDN (11, 12, 13, 14) Source: http://sanjianxia.myrice.com/vc/vc45.htm You can use cwinapp :: getFirstDoCTemplatePost to get the location of the first document template for the application; use this value to call the cwinapp :: getnextDocTemplate function, get the first A CDOCTemplate object pointer .Position getFirstDOCTemplate () const; cdoctemplate * getnextdDoCtemplate (position & pos) const; second function Returns a document template that is identified by POS. Position is an MFC definition for iteration or object pointer retrieval. Through these two functions, the application can traverse the entire document template list. If the retrieved document template is the last one in the template list, the POS parameter is set to null.12) A document template can have multiple documents, each Document templates have retained and maintained a list of pointers for all correspondence documents. Get the location of the first document in the document collection related to the document template with the cdoctemplate :: getFirstDocposition function, and use the POSITION value as the parameters of CDOCTemplate :: getNextDoc to repeat the list of documents related to the template.