|
-
Oct 30th, 2004, 08:27 PM
#1
Thread Starter
PowerPoster
Listbox.Clear .Add Methods
Much like in VB, I figured I would need to create some fancy listbox functions for C++.
Here is one I cannot seem to get to work properly.
PHP Code:
//------------------
//Add an item to the list
//------------------
void ListBox::AddItem(char* Item)
{
//add string
SendMessage(m_hwnd, LB_ADDSTRING, 0, (LPARAM)Item);
SendMessage(m_hwnd, LB_SETITEMDATA, m_IndexCount, (LPARAM)m_IndexCount);
m_IndexCount++;
}
//------------------
//Clear the entire list
//------------------
void ListBox::Clear()
{
LRESULT lRet;
for (int Index = 0; Index < m_IndexCount+1; Index++)
{
lRet = SendMessage(m_hwnd, LB_DELETESTRING, Index,0);
}
m_IndexCount = 0;
}
So I add a bunch of strings using the Add function, then I try and clear it all.
Well now and then it clears all but one, sometimes all but two depending on how many I add. If it clears all but 1 or 2, or more..then I can just keep pressing it and it gets rid of everything one at a time.
What is going on????
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Oct 30th, 2004, 08:37 PM
#2
Lively Member
Instead of sending an LB_DELETESTRING message for each item, just send an LB_RESETCONTENT message.
Rate my posts for a chance to win cash and prizes 
-
Oct 31st, 2004, 12:54 AM
#3
Thread Starter
PowerPoster
You know, I scoured the list of messages, styles, notifications on MSDN for something like that and I just didn't see it.
Thank you, it all works fine now.
RemoveItem, AddItem, Clear...all work
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Oct 31st, 2004, 01:43 AM
#4
Thread Starter
PowerPoster
Index is always 0...it never incrememnts, shouldnt it?
MSDN says that particular SendMessage returns the index of the added string.
PHP Code:
//------------------
//Add an item to the list
//------------------
void ListBox::AddItem(char* Item)
{
int Index=0;
//add string
Index = SendMessage(m_hwnd, LB_ADDSTRING, 0, (LPARAM)Item);
SendMessage(m_hwnd, LB_SETITEMDATA, Index, (LPARAM)Item);
}
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
-
Nov 2nd, 2004, 11:33 AM
#5
Frenzied Member
Why are you adding an item to the list and then setting the text of the item again? The string would be there after LB_ADDSTRING.
Are you subclassing? That may be why it returns 0.
-
Nov 2nd, 2004, 06:15 PM
#6
Thread Starter
PowerPoster
Yes I am subclassing, and it was the reason, fixed that part.
Now wuts wrong the above, I do see setting the string twice...thats just how I saw some code do it so each item had a proper index.
I guess though I don't really need any item data I found ways around all of that already.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|