|
It is helpful to at least understand some basic concepts of multi-threading before you actually attempt it.
1) The vast majority of machines have one CPU. One CPU = one active thread at any given time, period.
2) One CPU = one thread, period. Windows does not run threads concurrently. It switches between threads to give the appearance that tasks are running concurrently.
3) Multi-threading does not speed anything up - it slows it down because of the additional overhead of thread switching.
4) Since multi-threading slows an application down, it is generally useful only in cases where you want to keep an application responsive while running some slow background task. A good example is where you want to print something on a background thread.
5) There are only a few types of applications that really require the use of multiple threads. Almost all of these fall in the realm of "real time applications" or debuggers. For example, an IVR telephone system generally requires multiple threads so that a call that comes in on the 4th channel does not wait on the three channels that are already active to try to answer the call.
As a general rule of thumb, if your application is not a debugger and does not involve supporting special hardware, like a telephone card, multi-threading is probably not a good idea in general unless you really know what you are doing.
6) 10,000 threads? LOL! The concept is absurd!!! If an application creates 10 threads it is cause to question why so many? Try sticking to 5 or less unless some special requirements dictate more.
Robert
|
|
|
|
|
Is there a preferred way to insert items in a tree, non leaf items, that follow a predefined ordering ( not using TVI_SORT ) ?
I have to insert those items on the fly, so that when an item is inserted, they can be inserted between to other existing items.
I have to insert the items "Tomato", "Potato", "Leaks", "Avocado", "Celery" in that order.
If I insert "Leaks", it's a no brainer, but if I insert "Potato" after that, I need to manually check to see if "Tomato" is already inserted to be able to put that item as the hInsertAfter field ( or TVI_FIRST ); and so on and so forth for the other items ...
Luckilly, I have a small set of items to check.
Is there a better way ?
Thanks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
That's exactly how I do it when I'm inserting a new item. However when I'm loading up the whole tree, I can usually sort the strings better myself using for loops and then once I know they are in order, I can add them with TVI_LAST.
|
|
|
|
|
Is it possible to assign the "image value" of a CImage object to a Bitmap object?
I have to use CBitmap class but i have to load a jpg file.
Like this code:
---------------------------------------------
CImage CImg;
CImg.Load("c:\\background.jpg");
CBitmap bitmap;
// bitmap = CImg; !?? How can I do?
-------------------------------------
Thanx
|
|
|
|
|
Perhaps something like this is what your looking for. Just drawing the CImage to a CBitmap.
CImage image;
CBitmap bitmap;
int width = image.GetWidth();
int height = image.GetHeight();
CDC window_dc(m_hWnd);
CDC dc;
dc.CreateCompatibleDC(window_dc);
bitmap.CreateCompatibleBitmap(dc, width, height);
dc.SelectObject(bitmap);
image.Draw(&dc, CRect(0, 0, width, height));
|
|
|
|
|
How to create and read a file where the exe is residing?
How to open a file using ShellExec() from the current directory so that i can avoid problems that may arise when porting to other system as i can't expect the same drive name etc in other systems also;)
|
|
|
|
|
If you want portability, use the STL and don't bother with the Win32 API calls.
// read a file
std::ifstream f("localfile.txt"); // this will get localfile.txt in the current directy
if(f)
{
std::string contents;
std::ostringstream ss;
ss << f.rdbuf();
ss.str().swap(contents);
// file buffer is now in contents
}
f.close();
// write a file
std::ofstream f("localfile.txt");
f << "Bienvenidos a Mexico";
f.close();
|
|
|
|
|
Seenivasan Palaniappan wrote:
...porting to other system...
What other systems?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Does anyone have any experience embedding LISP within their application? Specifically, I am looking for a wrapper class to aid with the integration of the Common LISP engine.
There are a couple commerical LISP derivatives out there that are built on top of COM objects, but I cannot tell if they are ANSI compliant.
Any insight is greately appreciated.
Jim
QTExtender - The OFFICIAL addon for QuoteTracker.
|
|
|
|
|
CString tr=m_edit1.Left (m);
tr.Delete (0,m-1);
ch=tr.GetAt (0);
tr.Format ("%d",ch);
data =(double)ch;
i want to convert this double to ascii and then ascii to string.....
|
|
|
|
|
Are you sure you know what it is that you want? Converting something to/from ASCII is really a misnomer as all characters are from the ASCII set anyhow. Perhaps you wanted something like:
double d = 12.34;
CString str;
str.Format("%f", d); If not, please elaborate on what you are trying to achieve.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
c this is the main code:
i am supposed to decrypt a string :
int NO_BITS;
double c=0,d=1;
char bits[100];
double n=(double)m_n;
double data;//19;
long i,k;
CString str;
int sizeof_d=sizeof(double);
/*FILE *inFP, *outFP;
inFP=fopen(infile,"rb");
if(inFP==NULL)
{
str.Format("\nERROR: Couldn't open input file: %s\nAborting operation",infile);
DumpNotes(str);
return;
}
outFP=fopen(outfile,"wt+");
if(outFP==NULL)
{
str.Format("\nERROR: Couldn't create output file: %s\nAborting operation",outfile);
DumpNotes(str);
fcloseall();
return;
}*/
//change integer 'd' to binary
D_to_B(m_d,32,bits);
GetOnlyProperBits(bits);
k=NO_BITS = strlen(bits)-1;
// while(1)
for(int m=1;m<=m_edit2.GetLength ();m++)
{
//read from ip file into 'data'
/* if(fread(&data,sizeof_d,1,inFP)==0)
break;*/
data=strtod(m_edit2,NULL);
//calculate ((data)^e mod n) .i.e the remainder
c=0;d=1;
for(i=k;i>=0;i--)
{
c=2*c;
d=fmod(d*d,n);
if(bits[NO_BITS-i] == '1')
{
c=c+1;
d=fmod(data*d,n);
}//end of IF
}//end of for loop
//write to op file from 'd'
//unsigned char ch=(unsigned char)d;
unsigned char ch=(unsigned char)d;
fprintf(outFP,"%c",ch);
write(&ch,1,1,outFP); (c all i have to do is i have to change the fprintf and write statements b'coz they r used to decrypt to a file)
}//end of while loop
DumpNotes(CString("\nDecryption over..."));
//fcloseall();
plzzzz help me with this.........
i have got problem with those 2 stmts......
|
|
|
|
|
Hi*!
I have a listview in my application (basically a simple Win32 overlapped window). I am painting some bitmap as the background of the ListView. For that I subclass the ListView and paint the bitmap and the let the ListView paint the Items, I also paint my custom scroll bar also. Now my problem is when i want to scroll the ListView I send the LVM_SCROLL to the ListView and ListView scrolls but somehow i dont get the WM_PAINT message and background doesnt not get erased & looks messy like some items getting painted over some other items (probably it scrolls the WindowDC not generating the WM_PAINT at all), so I have to call invalidate/update ListCtrl after calling scroll, that makes the window look normal again but for a breif moment i see the window not getting painted properly. How can i avoid this situation??? I have tried using SET_REDRAW TRUE/FALSE but that doesnt help either , I still can see theat mess. My application is Win32 based. I am not using MFC. Any comments/suggestions are most welcome & appreciated....
Thanks for your time,
Regards,
Usman.
|
|
|
|
|
|
Thanks for the reply. But since I have to draw the scrollbars myself (i wasnt able to subclass the original scrollbars present in ListView) so i have to handle WM_PAINT for the ListCtrl.
Regards,
Usman.
|
|
|
|
|
Hi,
I'm trying to load a bitmap by following code but it always returns me a NULL handle
LoadBitmap(NULL,"bitmapfile.bmp");
any pointers for how to make the code work?
P.S.
Bitmap is in application folder, also I have tried with complete path.
Ciao
- Nilesh
|
|
|
|
|
LoadBitmap is used for loading resource bitmaps.
Try
http://support.microsoft.com/kb/q158898/
Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
|
|
|
|
|
that works.. thanks a lot
- Nilesh
|
|
|
|
|
Use LoadImage API if you want to load from the disk.
Hope this helps,
Usman.
|
|
|
|
|
I want a small MFC application that picks up paramters from the command line.
There are command line parser examples but all of them assume you already have the command line to parse.
Any suggestions as the VC++ help refers to ocnsole apps.
Thanks.
Elaine
The tigress is here
|
|
|
|
|
m_lpCmdLine member of CWinApp class contains command line string. You may parse this string in InitInstance()
ARSALAN MALIK
|
|
|
|
|
or you could use __argc and __argv (double _ before arg)
|
|
|
|
|
Thanx, I didn't knew that before!!!
ARSALAN MALIK
|
|
|
|
|
|