Is there a better way to Shuffle through a listbox then depending on SendMessage? Like getting the Count of items....Getting text.... removing items...
Is there a better way to Shuffle through a listbox then depending on SendMessage? Like getting the Count of items....Getting text.... removing items...
That's simply how you do any of those things with a listbox, you send it Windows messages. You can make your own nice little wrapper function sthat do the above things for you, or use a library that provides such wrapper functions, but there isn't any other way to do those things besides sending Windows messages to the control.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Ok thats kinda what i figured. One problem I'm having shuffling threw my listbox is sometimes it doesnt return a value. Do you think u could take a look?
This functions job is to return a proxy from the active listbox and if the active listbox's coutn is less then the value in my edit box, return all values from the disabled listbox to the active list box and return the next in line proxy.Code:char buf[300]; std::string tmp = ""; memset(buf,0,sizeof(buf)); HWND active = GetDlgItem(ListHwnd,ID_LBACTIVE); HWND disabled = GetDlgItem(ListHwnd, ID_LBDISABLED); GetWindowText(GetDlgItem(SettingHwnd,ID_REACTEDIT),buf,300); while(tmp == "") { if(SendMessage(active,LB_GETCOUNT,0,0) <= atoi(buf)) { memset(buf,0,sizeof(buf)); while(SendMessage(disabled,LB_GETCOUNT,0,0) > 0) { SendMessage(disabled,LB_GETTEXT,0,(LPARAM)buf); SendMessage(active,LB_ADDSTRING,0,(LPARAM)buf); SendMessage(disabled,LB_DELETESTRING,0,0); } ProxyCount = 1; SendMessage(active,LB_GETTEXT,0, (LPARAM)buf); tmp = buf; }else{ int count = SendMessage(active,LB_GETCOUNT,0,0); memset(buf,0,sizeof(buf)); if(ProxyCount == ( count - 1)) { ProxyCount = 0; SendMessage(active,LB_GETTEXT,count - 1,(LPARAM)buf); tmp = buf; }else{ ProxyCount += 1; SendMessage(active,LB_GETTEXT,ProxyCount - 1, (LPARAM)buf); tmp = buf; } } } return tmp;
Edit: I added the while loop to prevent it from returning "" until ii could find the problem
are you using MSVC++?
then, why not trying MFC...?
Yes i am using VC++ and it is a dialog based application. This is the code from my GetNewProxy function
Add some error checking, windows is a fickle beast and likes to throw random errors, just to keep you on your toes...
GetLastError() if a WIN API call fails, vey useful for debugging
For example, if LB_GETCOUNT fails it returns LB_ERR, which is defined as -1 in my SDK. That would have a negative impact on your app....
[atoi() returns zero if it can't process the text, so your loop would be 'if(-1 < 0 )']
LB_GETTEXT returns the number of char copied to the buf. You should check this to make sure you want to add the string, it may still hold the last value.
I also set the edit to ES_NUMBER to restrict user input (but your looks app set).Code://this has multiple points of failure //and no way to know if that fail will cause issues some where else GetWindowText(GetDlgItem(SettingHwnd,ID_REACTEDIT),buf,300); //I suggest something more like int iSuccess=0,iCount=-1; char szBuf[MAX_PATH]={0}; iCount=GetDlgItemInt (SettingHwnd,ID_REACTEDIT,&iSuccess,FALSE); //test for success as zero is a vaild count && the return for a fail if(!iSuccess) {//first thing find out why it failed iSuccess=GetLastError(); //log it failed _snprinf(szBuf,MAX_PATH-1,"Get count in REACT edit failed with error#%d.",iSuccess); //msgbox or file MessageBox(NULL,szBuf,"My App Error",MB_ICONERROR|MB_OK); //handle fail return -1;} //we got a count, but are there any items? if(iCount) {
Last edited by novacain; 01-23-2009 at 09:53 PM.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill