Method with VC5 Development Monitoring Interface Nanjing Normal University Physics (黄 黄 顾 顾 芬) VC5 development tool provides ready-made window, control and toolbar making means, greatly simplifies the development process of the interface, and makes the development interface has Configuring software style, easy to use, flexible, easy to learn. This article describes how to implement three independent separation windows: monitor window, control window, and animation window, and transmit data sharing on how to implement control functions and different windows in Figure 1. And introduce a method of implementing no flashing animation. (图)) As shown in Figure 1, separation of the workbench into three windows, the animation window is used to simulate the inlet, water, and the toner of the temperature rise, where the screen corresponds to the data collected by the system. The control window is used to implement the preset temperature value, adjust the water level, control heating, and pause. The monitor window is used to track the temperature value of the sample in real time, make a temperature-time curve. First, create a separation window To implement multi-window display, you must use the CSPLitterWnd class to divide the window into three sub-windows, then connect each function class with the window. When creating an application, select Single Document Interface in the first step, and select the Chinese Biling Library, press Advanced in step 4, select the Use Split Window option. Set the application name name animation. At present, we only have a view class CANIMATIONVIEW, which will correspond to the animation window, and we also generate a monitor window (corresponding CSHOWVIEW class) and control window (corresponding to CControlView classes). The context menu is pushed in the Resource View and selects INSERT. Select Properties to IDD_FormView, create a monitor dialog IDD_SHOWVIEW, and control dialog IDD_CONTROLVIEW, and click the mouse button to select the Chinese Biling Library in the Properties selection. Then edit IDD_CONTROLVIEW: Use the control generator provided by the VC5 to generate the text editing domain named IDC_SetTemperature and generate caption to "Set the initial value". Use the Button generator, generate control IDC_waterin, IDC_Confirm, and Caption are "in water" and "confirmation", respectively. Use ClassWizard to create a new class based on the CFormView class, which is CSHOWVIEW and CCONTROLVIEW classes, respectively, and connect them with the two dialogs you have just created.
In the CMAINFRAME class, the overcreateclient () function creates three static separation windows, first declare the required variables in MainFrame.h: protected: csplitterwnd m_wndsplitter2; transfer to the mainframe.cpp program, including the header file "ShowView. h ", find the function oncreateclient (), add the following code, generate two windows, three views: bool cmainframe :: oncreateclient (lpcreateStruct / * lpcs * /, ccreatecontext * pContext) {// Split into two windows Two columns of IF (! M_Wndsplitter.createStatic (THILED TO CREATESTATISPLITTER / N); RETURN FALSE;} / / Plus the animation window, put it on the left IF (! M_wndsplitter .Createview (0, 0, PCONTEXT-> M_PNEWVIEWCLASS, CSIZE (425, 50), PContext) {trace0 ("Failed to Create First Pane / N"); Return False;} // Retire the second window for two if (m_wndSplitter2.CreateStatic (& m_wndSplitter, // original m_wndSplitter is the parent pointer, m_wndSplitter2 child pointer is 2,1, // window is divided into two lines, one WS_CHILD |! WS_VISIBLE | WS_BORDER, m_wndSplitter.IdFromRowCol (0,1 ))) {Trace0 ("failed to create nested splitter / n"); Return False;} // Add two views, and adjust the view size if (! M_wndsplitter2.createview (0, 0, runtime_class (csh Owview), CSIZE (0,175), PCONTEXT) {trace0 ("failed to create second pane / n"); return false;} if (! m_wndsplitter2.createview (1, 0, runtime_class (ccontrolview), CSIZE (0, 0 ), PCONTEXT) {traet0 ("failed to create third pane / n"); returnial;} Return true;} Remove in animation.cpp, modify the initInstance () function, will m_pmainWnd-> showwindow (sw_show ), Change to m_pmainwnd-> showWindow (sw_showmaximized); to this, we can generate the interface framework of Figure 1.
Second, the animation of the animation display window is implemented by calling a picture, so first load the desired picture into the resource bitmap, and edits their ID number according to the order, then in the timer, every time Call a movie function at a certain amount of time. In the first step, a timer is used to add a message handler to the CanimationView with ClassWizard: the oncreate () function corresponds to the message WM_CREATE, and the onTimer () function corresponds to the message WM_TIMER. Edit function oncreate (), generate a clock every 0.1 second. INT canimationView :: OnCreate (lpcreatestruct lpcreatestruct) {if (cview :: oncreate (lpcreateStruct) = = -1) Return -1; setTimer (2,100, null); // Generate a clock RETURN 0 for every 0.1 second;} in function Ontimer (), call the animation service function serviceDanimation (), which makes no flash animation according to the system, and can select the screen according to different functions. Void canimationView :: ONTIMER (Uint Nidevent) {CClientDC ClientDC (THIS); ServiceDaniMation (& ClientDC); // Call the animation service function CView :: ONTIMER (); serviceDaniMation () is used to check the system's clock and can calculate The last animation event starts to calculate the time passed, then this function checks the delay time of this frame animation, and decides whether to reach another update time, if the time is updated, then the m_ncurrentframe variable increases, this When the water feed flag is successful, DrawWaterinaniMation () will start a new frame of animation screen. If other reasons have, the delay that reaches the serviceDanimation () function is also calculated.
First in CanimationView, define variables: public: dWord mlasteventserviced; bool m_bpause, m_bdone; // Pause, MA_NFRAME; // Current animation frame number, total animation frame number constructor, Add: canimationView: : CAnimationView () {mLastEventServiced = 0; m_bPause = FALSE; m_bDone = FALSE; m_nCurrentFrame = 0; m_nFrame = 100; // picture frames to edit 100} ServicedAnimation () function: void CAnimationView :: ServicedAnimation (CDC * pDC) {DWORD Elapsed = 0L; DWORD FirstSample = :: GetTickCount (); DWORD WorkValue = mLastEventServiced; CAnimationDoc * pDoc = (CAnimationDoc *) GetDocument (); ASSERT (pDoc-> IsKindOf (TUNTIME_CLASS (CAnimationDoc))); if ( m_bpause || m_bdone) Return; // If the animation is paused or end, return while (firstsample! = WorkValue) {WorkValue ; ELAPSED ;} // If the ELAPSED reaches its threshold point, and satisfies or exceeds the latency of this frame The next code // information block can be entered so that the movie sequence will move to the next frame: if (ELAPSED> = 1L) // Sets the delay value of each frame to 1 {m_ncurrentframe ; if (m_ncurrentframe> = m_nframe) {m_ncurrentframe = 0; // At the beginning, the frame should be placed in zero if (! pDoc-> m_bWaterInFlagDoc) {m_nCurrentFrame = m_nFrame-1; m_bDone = TRUE;} if (pDoc-> m_bWaterInFlagDoc && m_bDone!) {DrawAnimationWaterIn (pDC); m_bWaterInFlagDoc = FALSE; mLastEventServicced = :: GetTickCount (); // put The current clock records}}}} DrawanimationWaterin () is a function that displays a picture of the different inlet water level. To display a moving chart as a static array.
Static int bitmapswaterin [] = {IDB_WATERIN1, IDB_WATERIN2 ...... IDB_WATERIN100}; CAnimationView using ClassWizard declared variables: protected: CBitmap bmpWI [100]; CDC dcMemWI [100]; BITMAP bmWI; Add to the constructor's CAnimationView The following statement: for (int i = 0; i <100; i ) {bmpwi [i] .loadbitmap (bitmapswaterin [i]); bmpwi [i] .getObject (sizeof (bitmap), & bmwi [i]);} editing DrawanimationWaterin () function, in this function, the BMPWI [100], DCMemWi [100] should be partial variables so that when the same amplitude is reused, the memory can be refreshed in time, and the conflict can not cause conflicts. void CAnimationView: DrawAnimationWaterIn (CDC * pDC) {CBITMAP bmpWI [100]; CDC dcMemWI [100]; CRect rect; GetClientRect (rect); // selection rectangle window dcMemWI [m_nCurrentFrame] .CreateCompatibleDC (pDC) currently used by the user; / / prepared in the image memory bmpWI [m_nCurrentFrame] .LoadBitmap (bitmapsWaterIn [m_nCurrentFrame]); // // load of a bitmap resource lpszResourcceName identified, and connect it to the object CBitmap CBitmap * pOldBitmapIn = dcMemWI [m_nCurrentFrame] .SelectObject (& bmpwi [m_ncurrentframe]); // Select the GDI object to the device description table PDC-> Bitblt ((reccct.right-bmwi [m_ncurrentframe] .bmwidth) / 2, (Rect.Bottom-BMWI [m_ncurrentframe] .bmHEight ) / 2, windows @ bitmap in the middle bmWI [m_nCurrentFrame] .bmWidth, bmWI [m_nCurrentFrame] .bmHeight, & dcMemWI [m_nCurrentFrame], 0,0, SRCCOPY); // display a bitmap dcMemWI [m_nCurrentFrame] .SelectObject ( PoldbitMapin;
Control Type Control member ID IDC_SETTEMPERATURE int m_nSetTemperature preset temperature value increases in CControlView message handler: Object Object ID message function keys water IDC_WATERIN OnWaterIn () BN_CLICKED confirm key IDC_CONFIRM OnComfirm () BN_CLICKED below to input preset temperature value and water The response is an example to tell how to implement control functions. When the preset temperature setting is preset in the control window (CControlView class), press the confirmation key to respond to the message onconfirm (), and draw a preset temperature in the state monitoring of the state in the monitor window (CSHOWVIEW class). Press the water button in the control window (CControlView class), which is generated in the animation view (canimationView class). At this point, the control view should be transmitted to the monitoring view, but the data sharing cannot be directly implemented between them. The CDocument class and its derived class in the MFC class library are used to manage job data, which can read and store data to be observed and processed by the view, and can have multiple views at the same time. So, here, use cdocument's derived class CANIMATIONDOC as an intermediary of data transmission, to implement data transfer between different windows. The data transfer diagram of the preset temperature (variable name m_nsetTemperature) is shown in Figure 2.
2 are omitted in FIG. m_nSetTemperature m_nSetTemperatureDoc CAnimationDoc, a common variable is provided: public: int m_nSetTemperatureDoc; // used to pass the Document m_nSetTemperature derived class variable BOOL m_bSetTemperatureFlagDoc; // set temperature success flag BOOL m_bWaterInFlagDoc; // Flag constructed CAnimationDoc of water function initializes variables: CAnimationDoc :: CAnimationDoc () {m_nSetTemperatureDoc = 0; m_bSetTemperatureFlagDoc = FALSE; m_bWaterInFlagDoc = FALSE;} edit CControlView of OnConfirm () function: void CControlView :: OnConfirm () {CAnimationDoc * pDoc = (CAnimationDoc *) GetDocument (); ASSERT (pDoc-> IsKindOf (RUNTIME_CLASS (CAnimationDoc))); // // CDocument find the current class UpdateData (); // update the view data pDoc-> m_nSetTemperatureDoc = m_nSetTemperature; pDoc-> m_bSetTemperatureFlagDoc = TRUE; / /} success flag preset temperature of editing CControlView OnWaterIn () function: void CControlView :: OnWater () {CAnimationDoc * pDoc = (CAnimationDoc *) GetDocument (); ASSERT (pDoc-> IsKindOf (RUNTIME_CLASS (CAnimationDoc))); pDoc -> m_bwaterinflagdoc = true; // Water Responsive Success} Finally, in the beginning of ControlView.cpp, "AnimationDoc.h" is included. Then transfer to CShowView, in order to achieve the purpose of real-time monitoring, the reception of the data should be done in the timer, so that there is a new data entry can be constantly detected. After the temperature setting flag is detected, draw a horizontal line.