Production VC Form Control - Comprehensive Programming - VC

xiaoxiao2021-04-11  552

When we use Visual C to develop a database-based software, we often use a large number of tables, while Visual C does not provide the corresponding table control, so we need our programmers to make itself, this article will introduce a simple form control. process. In fact, a form is constructed from a series of cells in a window, so the most important step of making a form control is the design of the cell. From the simplest angle, it is the easiest to make cell classes by retrofitting editing boxes (Edit Box), so the focus of the sample program is to derive a ccell class from the CEDIT class and do appropriate to this class. modify. When writing this unit, it is necessary to pay attention to the user operating cells, and should appropriately change the appearance of the cell to make the user feel more intuitive. We use AppWizard to create a single document program, named CGRIDDEMO. Use ClassWizard to join two new classes: Base class as CCell classes for CEDIT classes and base classes are CGRIDWnd classes for CWND classes. The main code of these two classes is listed below: // The following is the primary code void ccell :: OnsetFocus () // When the user operates cell, change the design of the cell {setfocus = true; // setfocus Bool type variable CDC * PDC = this-> getWindowdc (); this-> oneRaseBkGnd (PDC); // change cell extraraction} BOOL CCell :: OneRaseBkGnd (CDC * PDC) // Change unit Extract, overreloading onrasebkgn Function {RECT RECT; CPEN PEN;

CBRUSH brush;

Logbrush logbrush; if (setfocus == true) // When the user operates a cell, add a black border for cells.

{Pen.createpen (PS_SOLID, 2, RGB (0, 0, 0)); // Set the line width is two pixels logbrush.lbcolor = RGB (0, 0, 0); logbrush.lbstyle = BS_HOLLOW; brush.createbrushindirectirect (&& logbrush); PDC-> SelectObject (&& pen); PDC-> SelectObject (&& brush); this-> getClientRect (&& Rect); PDC-> Rectangle (&& Rect); // is a cellular black border} Else // When users Operate additional cells, eliminate the black border {Pen.createpen (PS_SOLID, 2, RGB (255, 255, 255)); // Create a white PEN to cover the border logbrush.lbcolor = RGB (0, 0, 0); logbrush.lbstyle = BS_HOLLOW; BRUSH.CREATEBRUSHINDIRECT (&& logbrush); PDC-> SelectObject (&& Pen); PDC-> SelectObject (&& brush); this-> getClientRect (&& Rect);

PDC-> Rectangle (&& Rect);} Return Cedit :: OneRaseBkGnd (PDC);} void ccell :: ONKILLFOCUS () // User focus leaves cell, eliminating black border {setfocus = false; cdc * pdc = this-> getWindowdc (); "} //} // below is the main code of the CGridWnd class CGridWnd :: CGridWnd (CWND * PWND, UINT NROW, UINT NCOL) // CGridWnd class constructor {m_pparentWnd = PWnd; // Father Window handle row = nROW; // row number col = ncol; // column number} BOOL CGRIDWND :: Create () // Reserved CREATE function, build a Grid window with the same size as the parent window {Rect; m_pparentWnd-> GetClientRect; Return CWnd :: Create (NULL, NULL, WS_CHILD | WS_VISIBLE, RECT, M_PPARENTWND, NULL, NULL);} BOOL CGRIDWND :: OneRaseBkGnd (CDC * PDC) // This function is based on the line, column Digital Drawn Grid {for (INT I = 0; I Moveto (0, i * 24); // Grid size is 104 × 24 PDC-> LineTo (COL * 104, I * 24);} for (int J = 0; j Moveto (j * 104, 0); PDC-> LineTo (J * 104, Row * 24);} Return True;} int CGRIDWND :: OnCreate (LPCREATESTRUCT LPCREATESTRUCT) // Put cells into the painted grid {RECT; for (int i = 0; I Create (WS_CHILD | WS_VISIBLE, RECT, THIS, 0 ); // put cells in the mesh} Return 0;} // The following code demonstrates how to use the table window D CGRIDDEMOVIEW :: OnDRAW (CDC * PDC) {CGRIDDEMODOC * PDOC = getDocument (); assert_valid (PDOC) ); If (! Flags) {grid = new cgridwnd (this, 5, 5); // Create a 5-row of 5 columns of table Grid-> Create (); Flags = true;}}

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

New Post(0)