|
DeleteString() and InsertString()
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
|
Strings are numbered from zero to count_of_strings minus one, so to replace a string at a certain index, first delete the existing string, then insert the replacement
int SwapString(CListBox &Box, int Index, LPCTSTR NewString)
{
ASSERT (Index < Box.GetCount());
Box.DeleteString(Index);
return Box.InsertString(Index, NewString);
} If you insert the replacement string first, you then have to increase the index value before you delete the old string or else you will just end up deleting the string you just inserted.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
be careful that your listbox is not set to "auto sort";
also, when deleting/inserting an item, the indexes will shift.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
According to MSDN[^]
[quote]
An application sends an LB_INSERTSTRING message to insert a string into a list box. Unlike the LB_ADDSTRING message, the LB_INSERTSTRING message does not cause a list with the LBS_SORT style to be sorted.
[/quote]
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
|
Crap... I tried everything, nothing worked... How do I do that "auto sort" thing? Here's my code:
void CMazzeeMapGrouperDlg::OnBnClickedMoveUp()<br />
{<br />
int initialCurSel = this->maps.GetCurSel();<br />
if (this->maps.GetCurSel() > 0)<br />
{<br />
mapGroup.MoveDown(maps.GetCurSel());<br />
<br />
CString str;<br />
this->maps.GetText(this->maps.GetCurSel() - 1, str);<br />
<br />
this->maps.DeleteString(this->maps.GetCurSel() - 1);<br />
this->maps.InsertString(this->maps.GetCurSel() - 1, str);<br />
<br />
this->maps.SetCurSel(initialCurSel + 1);<br />
}<br />
}<br />
<br />
void CMazzeeMapGrouperDlg::OnBnClickedMoveDown()<br />
{<br />
int initialCurSel = this->maps.GetCurSel();<br />
if (this->maps.GetCurSel() < this->maps.GetCount() - 1)<br />
{<br />
mapGroup.MoveDown(maps.GetCurSel());<br />
<br />
CString str;<br />
this->maps.GetText(this->maps.GetCurSel(), str);<br />
<br />
this->maps.DeleteString(this->maps.GetCurSel());<br />
this->maps.InsertString(this->maps.GetCurSel(), str);<br />
<br />
this->maps.SetCurSel(initialCurSel + 1);<br />
}<br />
}
Am I doing something wrong? Thanks!
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
By "auto sort" I think he may have meant "alpha sort". If you are using a ComboBox, there is a checkbox on the Styles tab called 'Sort'. If you check this, the ComboBox will automatically AlphaSort the contents ( unchecked it Index Sorts)
|
|
|
|
|
|
Sorry for the delay, I have been on vacation over Xmas.
Yes the ListBox works the same. in the Resource editor, right click the ListBox and under the Styles tab you will see the Sort checkbox. Check for Alpha , uncheck for index. The problem with sort is it cannot be toggled. It can only be assigned when the object is created. There are several excellent tutorials in the CodeProject that demonstrate the properties of ListBoxes etc.
Happy New Year.
cgb
|
|
|
|
|
|
I'm making a simple VC6 MFC dialog application that, when you push a button, pops up a small dialog that has a progress control and an action button. When you press the button, it performs a lengthy iterative task and reports its progress via the progress control; the action button changes from "Go" to "Stop", such that a second press will cancel the lengthy task. If the task completes, it simply dismisses the dialog; if the user cancels the task, the button returns to "Go" and the dialog stays.
Not being a guru in multithreaded applications, I used my old standby peek-and-pump message dispatcher in the loop to handle the Cancel activity. I also tried for the first time to use a worker thread to perform the same task. They both worked, but the threaded version took almost 3 times as long to complete.
To distill the problem, I wrote another pair of applications that just write 1,000,000 numbers sequentially to a text file (print the for-loop iterator). I get the same result. The peek-and-pump version takes 5.2 seconds, while the thread version takes 12.5 seconds. Granted this isn't a big difference, but the original application updates a very large database and runs on the order of 2 minutes vs. 5½ minutes. Is this difference in performance to be expected?
Thanks,
[gb]
--
I've killed again, haven't I?
|
|
|
|
|
My guess is you're seeing the overhead of context switching between threads. Keep track of the time since the last progress update and only report the progress every X milliseconds. 250ms is a good starting point, but you can increase that time if you don't mind fewer updates to your progress UI.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
"Just because the box has 2 gigabytes of memory doesn't mean you get to use it all!"
-- Rico Mariani, CLR perf guy
|
|
|
|
|
Having not written (or really considered) explicitly multithreaded applications in nearly 7 years, I had forgotten about those two words: "context switch".
Lowering the frequency of the progress update is a generally good idea, which I will implement shortly. Unfortunately, even removing the progress update completely, I'm still experiencing about a 2:1 slowdown.
I suspect this threaded program will run better--at least closer to the peek-and-pump program--when I get to my HT-enabled computer, as DavidCrow's observation would imply.
Thanks a lot!
[gb]
--
I've killed again, haven't I?
|
|
|
|
|
Office Lineman wrote: They both worked, but the threaded version took almost 3 times as long to complete.
Multi-threaded applications on a uni-processor machine generally run slower.
"Take only what you need and leave the land as you found it." - Native American Proverb
|
|
|
|
|
Wow.
I forgot I had an old dual 500-MHz machine here. I changed the progress update frequency on both applications, then took this test to it. I had to bump the test up to 100,000,000 iterations to tell the difference!
The peek-and-pump program took 47.6 seconds, and the threaded program took 46.8.
You guys are awesome. I officially unfurl my brow at the worker thread.
Thanks,
[gb]
--
I've killed again, haven't I?
-- modified at 15:29 Wednesday 21st December, 2005
|
|
|
|
|
how can i resize the window (frame and client area) of my app, when i create it, when load a document and when i create a new document
thanks!
|
|
|
|
|
Use MoveWindow or SetWindowPos in the appropriate message handlers (I suppose you have MFC, so this must be in OnCreate , OnOpen and so on. I am not so familiar with SDI/MDI)
~RaGE();
|
|
|
|
|
hey guys,
just wondering if any of you guys happen to visit the C# forum any, as I posted a question there hoping someone could help, but it seems that no one in the C# world can, or i'm just asking for the wrong info...
either way just wondering if someone could go check it out and see if they know anything...
here's the link:
http://codeproject.com/script/comments/forums.asp?forumid=1649&fr=76&select=1312256#xx1312256xx[^]
I'm basicly trying to find a way to access info on my hardware that i know exist, have found it using other software tools, and would like to reproduce with my own code. I understand that I may run into a problem trying to access this info through managed code, so if any of you know which "yellow brick road" to follow and are willing to help me out I would appreciate it TREMENDOUSLY!!!
Thanks in advance
Merry Christmas,
Happy Hanukkah!
-
string Beautiful;
Beautiful = "ignorant";
label1.Text = "The world is full of " + Beautiful +" people.";
Why is common sense such an un-common comodity?
|
|
|
|
|
HI,
i have a problem with this function...
void show(){
int hour,minu,sec;
char time1;
hLUIseDLL = LoadLibrary("LUIse.dll");
if (hLUIseDLL != NULL)
{
LUI_OpenDevice = (T_LUI_OpenDevice)GetProcAddress(hLUIseDLL, "LUI_OpenDevice");
LUI_CloseDevice = (T_LUI_CloseDevice)GetProcAddress(hLUIseDLL, "LUI_CloseDevice");
LUI_DispOnOff = (T_LUI_DispOnOff)GetProcAddress(hLUIseDLL, "LUI_DispOnOff");
LUI_CCFL = (T_LUI_CCFL)GetProcAddress(hLUIseDLL, "LUI_CCFL");
LUI_GetContrast = (T_LUI_GetContrast)GetProcAddress(hLUIseDLL, "LUI_GetContrast");
LUI_SetContrast = (T_LUI_SetContrast)GetProcAddress(hLUIseDLL, "LUI_SetContrast");
LUI_OutPort = (T_LUI_OutPort)GetProcAddress(hLUIseDLL, "LUI_OutPort");
LUI_InPort = (T_LUI_InPort)GetProcAddress(hLUIseDLL, "LUI_InPort");
LUI_LCDmode = (T_LUI_LCDmode)GetProcAddress(hLUIseDLL, "LUI_LCDmode");
LUI_Bitmap = (T_LUI_Bitmap)GetProcAddress(hLUIseDLL, "LUI_Bitmap");
LUI_Text = (T_LUI_Text)GetProcAddress(hLUIseDLL, "LUI_Text");
LUI_BMPfile = (T_LUI_BMPfile)GetProcAddress(hLUIseDLL, "LUI_BMPfile");
LUI_SetPixel = (T_LUI_SetPixel)GetProcAddress(hLUIseDLL, "LUI_SetPixel");
LUI_GetSerial = (T_LUI_GetSerial)GetProcAddress(hLUIseDLL, "LUI_GetSerial");
GetDllVersion = (T_GetDllVersion)GetProcAddress(hLUIseDLL, "GetDllVersion");
LUI_ScreenRefreshControl = (T_LUI_ScreenRefreshControl)GetProcAddress(hLUIseDLL, "LUI_ScreenRefreshControl");
LUI_TouchScreen = (T_LUI_TouchScreen)GetProcAddress(hLUIseDLL, "LUI_TouchScreen");
}else MessageBox(0,"DLL Error","Error", MB_OK);
LUI_OpenDevice(0)
LUI_TouchScreen(0,mouse);
do{
if(mouse[1]<300){
CTime t=CTime::GetCurrentTime();
sprintf(&time1,"%d:%d:%d",t.GetDay(),t.GetMinute(),t.GetSecond());
parser.data=&time1;
parser.draw();
LUI_TouchScreen(0,mouse);
Sleep(200);
}while(mouse[1]<=300);
LUI_CloseDevice(0);
Sleep(200);
FreeLibrary(hLUIseDLL);
}
the debugger says that the stack around the time1 is corrupted(runtime errot #2), but...what to do?
when i set the configurationmode to "release", it runs, but time1 isn't the value.
please help me...
thanks
-- modified at 8:29 Wednesday 21st December, 2005
|
|
|
|
|
try the following declaration: char time1[64];
and replace &time1 by just time1.
you are writing too many chars in your time1 in the sprintf.
|
|
|
|
|
|
sorry toxxcct, your solution worked(thx), but i'm a beginner in visual c++ (i programmed borland before) and i hate this type conversion.
|
|
|
|
|
iiscodered wrote: i hate this type conversion.
if you don't like it, you won't like programming C++ sir !!!
[edit]
i don't know who is that anonymous who voted me 1 for this answer, but here is the point. In C++, we have to manage ourselves the memory allocation/dealocation on the heap, so, when one tells that he doesn't like this way of programming, it makes me laugh because it's a bigger part of the C++ usage...
now if that poor guy cannot show off himself, shame on him.
[/edit]
TOXCCT >>> GEII power [toxcct][VisualCalc 2.20][VisualCalc 3.0]
-- modified at 3:36 Thursday 22nd December, 2005
|
|
|
|
|
Hello,
I need to determine the pixel color of a certain area of the screen including the cursor icon.
The GetPixel function receives the pixel color _under_ then cursor
Any ideas?
Thank you in advance,
Mat.
-- modified at 7:32 Wednesday 21st December, 2005
|
|
|
|
|