VC6.0 implements reverse operation and prevents interface flashing

xiaoxiao2021-03-06  81

In system programming, using VC is a good development tool, and for a mature system, almost all need to have a rollback and redo function (ie, document operation reverse) to prevent user malfunctions or inappropriate operations. Improve systemic friendliness and operability. This problem is mentioned in many VC technical articles, but there is always an interface flashing or incompletely reversible. This paper proposes a method of programming system programming that can be fully reversible and preventing flash screens. First, the basic principle should return to the document to return to the function, to do two work, on the one hand, to retain the deleted document (during the operation, the deleted document data must be kept), on the other hand, the system must be able Record the full process of document operation and parameters for each operation process. In order to retain historical operation, all data is very composed of memory space, which is why only the system can only perform a limited period of retraction. The method proposed herein establishes a storage mechanism: built a temporary file storage data analog stack, and performs the relevant operation data into the stack when performing an operation. Retreat once to bring the relevant data to the stack, and re-recover the original data according to the relevant data. It is the benefit of re-entered a stack when it is rolled back and reforms. The stack data emissions are shown in the figure: // Undo, REDO Data Emission Data Data Discharge (M_undodatalist)

/// / ==== // | ### |} // | ### |} ----- >> REDO data // | ### |} / / | ### |} // | /// |} // | /// |} --- >> UNDO data (UNDO data pop-up Then convert to REDO data) // | /// |} // | /// |} // ===== // Undo Table

Second, the engine build a document in the process of document returning and retreating a document reverse stack engine. The main code is: 1. Establish a temporary file. (M_Temppath can form a path according to some rule)

IF (m_file.open ((lpctstr) m_temppath, cfile :: modecreate | cfile :: modeReadwrite | cfile :: ShareExClusive)) {m_file.seektobe (); m_undocount = 0; file: // Currently redox number m_redocount = 0; file: // The currently rollover step} 2. Save the fallback data module.

/ / Save an UNDO data block (provided by the user) int CredoundoEngine :: PushData (LPVOID PDATA, // is provided by the user's memory block, which contains the user-defined data to be saved. // (Note: If the function is successful This memory block will be released by this function, so the memory block must be assigned by :: globalalloc () function) DWORD size, // pdata points to memory block size DWORD param1, // User provides the memory The instruction parameters of the block are defined by the user definition DWORD param2, // user provides the description parameters of the memory block, and the meaning is defined by the user, if it is successful, the function will return to the pressing UNDO block in the stack. The index value. If this return value is not required, NULL can be used as a parameter) {// Remove REDO data if (m_redocount "{while (m_redocount--) delete (lpiseeundoInfo) m_undodatAlist.removetail (); m_redocount = 0;} // Fill in UNDO data index information (LPISeeundoInfo Structure) LPISEUNDOINFO-> m_index = m_undocount; // Index lpiseeundoInfo-> m_userdata1 = param1; // User-defined identification data 1LPiseEundoInfo-> m_userdata2 = param2; // user defined identification data 2lpISeeUndoInfo-> m_DataSize = size; // user data block size Undo lpISeeUndoInfo-> m_FilePosition = _get_current_overwrite_pos (); // add new data to Undo Undo stack tail m_UndoDataList.AddTail ((void *) lpISeeUndoInfo ); // write user's UNDO data into temporary file m_file.seek (lpiseeundoinfo-> m_fileposition, cfile :: begin); m_file.write ((const void *) pdata, size); and make UNDO block plus 1M_undocount ; / / The data block passed by the user is useless, deleted! :: GlobalFree (PDATA); RETURN 1;} 3. Popping the redo data module.

// Pop up a Redo Data Block INT CIUNDOENGINE :: Redodata (LPVOID * PPDATA, / /) Pointer // (Note: This memory block is converted by the caller) Release, use :: GlobalFree () function) DWORD * psize, // PPData memory size (in Byte), if this data can be used as a parameter DWORD * PPARAM1, // Return to the User's additional information on the REDO block If this data can be used as a parameter dword * pParam2, // returns to the additional information of the REDO block, if this data can be used as a parameter INT * PINDEX // returns the index of the REDO block, if not required this data can be used as a parameter NULL) {if (m_RedoCount) return 0;! // address to lock the pop-up index Redo information blocks POSITION pos = m_UndoDataList.FindIndex (m_UndoCount); ASSERT (pos); LPISEEUNDOINFO lpISeeUndoInfo = (LPISEEUNDOINFO) m_UndoDataList .Getat (POS); Assert (lpiseeundoinfo); assert (lpiseeundoinfo-> m_index == m_undocount); if (! (* Ppdata)) return -1; // read UNDO data in the temporary file (also Redo data) m_file.seek ((long) lpiseeundoinfo-> m_fileposition, cfile :: begin); m_file.read (* ppdata, lpiseeundoinfo-> m_datasize); m_undocount ; // can use UNDO data block plus 1m_redocount--; / / Redo data block minus the number of available 1if (pSize) * pSize = lpISeeUndoInfo-> m_DataSize; if (pParam1) * pParam1 = lpISeeUndoInfo-> m_UserData1; if (pParam2) * pParam2 = lpISeeUndoInfo-> m_UserData2; if (pIndex) * pIndex = M_R Edocount; // Note: The index here is the index of REDO, not the UNDO RETURN 1;} Reverse the operation engine by this document, you can get the data of the currently changed document, and update the view according to the changed data, not Refresh the view without changing the data. To prevent flicker generation. Third, the simple development example will undergo the backweight function (document reverseization) added in our development of clothing CAD. 1. Define a rolling type

#define reundo_mov 0x0001 File: // Clothes Slings Move backweigh #define reundo_sel 0x0002 file: // Clothes selection back to retreat ........ 2. Save actions before and after the data (movie moving Back to retreat as an example)

// ---------- Apply for memory -------------------- // int nbyte = 4 * sizeof (dword); HGLobal HMEM = GlobalAlloc (GMEM_FIXED, NBYTE); LPVOID PDATA = (LPVOID) Globalock (hmem); file: // ----- Save the position before and after movie moving ------ // with mobile front and rear clothes Some coordinate points represent Memcpy (DWORD *) PDATA, & M_OLDPOINT, 2 * SIZEOF (DWORD)); Memcpy ((DWORD *) PDATA 2, & Point, 2 * SizeOf (DWORD)); File: // - ------- Data Stack ---------------------------------------- / / m_preundoEngine-> Pushdata (PDATA, // Clothes M_PreundoEngine Document Reverse Engine Object Pointer NBYTE, / / ​​Save Data Coated bytes ReunDo_Mov, // Roll Type NULL, NULL); 3. When the retracted operation event trigger when the pop-up .// backoff value int nByte = m_pReUndoEngine-> GetPopDataSize (); HGLOBAL hMem = GlobalAlloc (GMEM_FIXED, nByte); // allocate memory LPVOID pData = (LPVOID) GlobalLock (hMem); DWORD undo_type; DWORD index; m_pReUndoEngine -> Popdata (& PDATA, NULL, & undo_type, & index); Switch (undo_type) {// Rolling Type Case Reundo_sel: Selundo (PDATA, INDEX, & DC); Break; Case Reun_mov: Movundo (PDATA); Break; ......... ...} void cmarkview :: Movundo (LPVOID PDATA) Function {CPOINT PT1, PT2; Memcpy (& PT1, (DWORD *) PDATA, 8); Memcpy (& PT2, (DWORD *) PDATA 2, 8); ....... You can find a displacement by PT1 and PT2, thereby restoring the position of the colorant.} 4. When the event is triggered

// pop fallback value int nByte = m_pReUndoEngine-> GetRedoDataSize (); HGLOBAL hMem = GlobalAlloc (GMEM_FIXED, nByte); // allocate memory LPVOID pData = (LPVOID) GlobalLock (hMem); DWORD undo_type; DWORD index; m_pReUndoEngine-> RedoData (& pData, NULL, & undo_type, & index); switch (undo_type) {// the type of fallback case REUNDO_SEL: SelRedo (pData, index, & dc, nByte); break; case REUNDO_MOV: MovRedo (pData); break; ......... ...} The function MOVREDO (PDATA) is similar to Movundo (PDATA). It can be seen from 3, 4. In the process of retreating and re-processing, only the process of saving and removing operational objects has changed, making the programmer It is easy to achieve high efficiency refresh and sufficient storage space. Summary in system programming, the retraction of documents is almost essential, this article puts forward a kind of idea, that is, various operations of the document, and put The data value of the object changed under each operation is stored in the temporary file (stack), and the amount of change is easy to restore the operation according to the amount of change in the return and heavy done, avoiding some systems (saving all document data) occupied. A large amount of memory space can only be reversened by limited documents, and all refreshed and flashing, destroying the interface of the interface.

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

New Post(0)