Advanced Application About List Control - Entrance

zhaozj2021-02-16  56

Search in the forum, you will find a lot of questions: How do I edit List Control's entry? How to edit List Control ..., etc.; List control can be used to do a database table, very useful.

However, the list of List Control can only edit the first column, and the rest of the dead Microsoft is not done for VC. It is afraid that VB can not sell. So C programmer has to DIY. The main thinking is to create a control in List Control, Dynamically move the control to the corresponding position. These methods have been discussed earlier, which is also based on the above ideas, but focusing on the convenience of expandability and use.

List control This is mainly overloading the ONLBUTTONDOWN method, calculating the entry in the point. The important function is SubiteMhittest and getSubItemRect, see the relevant instructions on the MSDN. After the user point, it is necessary to display the control: if it is selected Other, you have to verify that the previous changes are successful. If you are not successful, you will return to the original place. Successfully applied and modified and moved to a new location. Code:

Static const uint idchaild = 3000;

Void Cvalidatelist :: ONLBUTTONDOWN (UINT NFLAGS, CPOINT)

{

Clistctrl :: ONLBUTTONDOWN (NFLAGS, POINT);

Lvhittestinfo Hi;

Hi.pt = Point;

IF (SubiteMhittest (& Hi)! = -1) // There is no point in some items

{IF (m_col == - 1 || // - 1 has not been selected

True == (m_col m_validate) -> Validate (m_row))

{

M_row = hi.iitem, m_col = hi.isubitem; // m_row, m_col

/ / The staff tracks the selected row

}

((M_Col M_Validate)) -> Move (_getRect (), M_ROW);

}

}

WinBlast * CVALIDATELIST :: SETVALIDATE (WinBlast * in) // Set verification

// Control group, IN corresponding to the first column, IN 1 second column ...

{

WINBLAST * RET = m_validate;

m_validate = in;

INT counts = getHeaderCtrl () -> GetItemcount () ;;

RECT;

MEMSET (& Rect, 0, SizeOf (Rect);

For (int i = 0; i

(in i) -> Create (this, Rect, IDChaild i, i);

m_col = -1; // is not selected

Return Ret;

}

Rect CVALIDATELIST :: _ getRect () // Internal use, get the corresponding display location

{

CRECT RET;

GetSubitemRect (m_row, m_col, lvir_bounds, reing);

Return Ret;

}

Void CVALIDATELIST :: NOSELECT () // Set the status

{

m_col = -1; // is not selected

}

I saw WinBlast * Ret = M_Validate .WinBlast is the control used to modify and verify data to see it's implementation:

Class WinBlast

{

INT m_col; // Track columns, why do you want this? Because you can make a control pair

/ / Different columns with different verification strategies

CWND * m_win; // Your control window

Clistctrl * m_parent; // Get text with it

PUBLIC:

WINBLAST () {m_win = null;

~ WinBlast () {m_win-> destroyWindow (); delete m_win;}

Virtual Bool Create (CWND * PParentWnd, Const Rect & Re, UINT NID,

INT COL)

{

M_COL = col; m_parent = (clistctrl *) PParentWnd;

m_win = new CEDIT;

Return (CEDIT *) M_WIN) ->

Create (ES_NOHIDESEL, RECT, PPARENTWND, NID);

}

Void Move (const rect & rece, int in) // The most important function but front

// The two movements are already asked, settext is the virtual, you are doing you like

{

M_WIN-> showwindow; SW_SHOW

M_WIN-> MoveWindow (& Rect);

Settext (row);

}

Virtual Bool Validate (int ROW) // Verify, virtual function. Here you will return TRUE

{

m_win-> showwindow (sw_hide);

Cstring set;

m_win-> getWindowText (SET);

m_parent-> setItemtext (row, m_col, set);

Return True;

}

Virtual Void SetText (int Row)

{

m_win-> setWindowText (m_parent-> getItemtext (row, m_col));

((CEDIT *) M_WIN) -> setsel (0, -1);

}

}

The actual use is usually this:

WinBlast * P = New WinBlast [SizeOf (COL) / Sizeof (col [0])]; // COL is

// Column name character array, sizeof (color) / sizeof (col [0]) calculates the number of columns

m_test.setValidate (P); // m_test is CVALIDATELIST class

You can inherit WINBLAST, overload CREATE to create a drop-down box, join your favorite verification method.

Pay attention to my design vulnerability: CVALIDATELIST should receive WinBlast **, not WinBlast * ----- Don't understand this vulnerability is not tight: But I have to remember that if you don't correct, your WinBlast subsequent class cannot add data members.

The first time I published an article, and I would like to criticize it. Please tell me for the full source code.

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

New Post(0)