Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedding a button in CListView

Status
Not open for further replies.

daverkennedy

Programmer
Jul 13, 2005
10
US
Hi could anyone help me here?

I have a SDI ListView app that allows the user to add buttons in the listview... the buttons will also overlap a couple of rows.

I use the something like the code below to show the button in a given cell...

Code:
CButton* p_button; 
CRect rcNew;
theCtrl.GetItemRect(StartRow,&rcNew,LVIR_BOUNDS);

pButton->Create(strTitle, BS_FLAT, rcNew, this, m_nIDCount++);
	
pButton->ShowWindow(SW_SHOWNORMAL);

The problem is when the list view is scrolled the button will move up and down depending on the users scroll movements.

I need to lock the button in place so that it maintains the original position... any ideas?

Thanks in advance.
 
Your using the listview as your client rectangle. You should probably use the SDI client area instead. but if you move the listview around, the buttons will not follow, unless you do code to do that as well.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
Thanks for your reply

Well I had worked on it a alot last night and got it working by redrawing the button evertime the view was scrolled or resized.

Basically i created a new class CMyButton derived from CButton, this class stores the row position(s) the button covers, and redraws to these rows on sizing or scrolling. Now I know deep down this is not the most elegant thing to do, but its stopped my temporary hair loss.

I know its to do with the buttons just being drawn over the listview, so it makes sense that when the view is scrolled the button is redrawn in the same place relative to the view.

Im not too sure how to use the SDI client area, im certainly no c++ guru my background is embedded programming (8bit micros in assembler), im living of sites like this and codeproject. SO if you could provide and examples links of using the SDI area instead Id be grateful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top