Implement custom listbox control with VC

xiaoxiao2021-03-06  41

In the afternoon, I developed an application on the ARM development board in the afternoon, I need to zoom in to the project on the ListBox control, I first use VC to simulate, but unfortunately, the Listbox does not support Owner Draw on EVC. But fortunately, finally do something on the VC, the process records below: 1. Add a listbox control to the dialog box, change its property to "fixed" (see MSDN). 2. Create a few functions that break the CLISTBOX CCUSTOMLISTBOX, override. 3, add the following code in the PresubClassWindow function: CRect Rect; getClientRect (Rect); this-> setItemHeight (-1, rect.Height () / 4); // Set the ListBox subject height to Listbox height 1/44, if the listbox control does not make any modifications after selecting the "Fixed" property, the sub-item added by the addString and other functions will not be automatically displayed by the system because the user selects the self-painted attribute. This property is completed by the DrawItem and MesureItem functions in CCUSTOMListBox. DrawItem is used to draw subprojects, and MesureItem is used to modify some of the properties of the project (generally no change). Add the following code in DrawItem: ColorRef ClritemText;

Switch (lpdis-> itemaction) // lpdis is a LPMEASUREITEMSTRUCT (Record Control Information) {CASE ODA_SELECT: CASE ODA_DRAWENTIRE: / / IS THE ITEM SELECTED? IF (LPDIS-> ItemState & ODS_SELECTED) // User Select Time Tag Select Project { clrItemText = GetSysColor (COLOR_HIGHLIGHTTEXT); // Clear the rectangle FillRect (lpDIS-> hDC, & lpDIS-> rcItem, (HBRUSH) (COLOR_ACTIVECAPTION 1));} else {clrItemText = GetSysColor (COLOR_WINDOWTEXT); // Clear the rectangle FillRect (Lpdis-> hdc, & lpdis-> rcitem, (hbrush) (color_window 1));}}

CDC DC; Dc.attach (LPDIS-> HDC); CRECT Rectfull = LPDIS-> RCITEFT RECT = RectFull; Rect.Lect = Rect.width (); CRECT RECT2 = RectFull; Rect2.right = Rect.Lect - 1 UINT NINDEX = LPDIS-> ITEMID; if (Nindex! = (UINT) -1) {

Logfont LF;

Dc.getCurrentFont () -> getLogfont (& lf); // get the current device up and down the font

CFONT FONT, * POLDFONT;

Lf.lfcharset = 134;

Lf.lfheight = 25;

Lf.lfwidth = 0;

STRCPY (LF.LFFACENAME, "Lishu");

Font.createFontIndirect (& lf); // Indirect setting font

PoldFont = dc.selectObject (& font); // Reselect the device up and down the font

CString SSS; this-> GetText (NINDEX, SSS);

Dc.setBkmode (Transparent); DC.Drawtext (SSS, CRECT (Rect2.LEFT 3, Rect2.top 3, Rect2.right-3, Rect2.bottom 3), DT_LEFT | DT_SINGLINE); DC.DETACH ( ); After completing the above steps, you can see the changed listbox, additional buttons, etc. Other control steps and ideas are small.

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

New Post(0)