|
The main thread starts the other threads with afxBeginThread, they go and do their work, and then when they're done, the last thing they all do before killing themselves is fill a global array with their results. but while they are working, the main thread doesn't seem to be doing anything. I don't understand why it works ok when I run it through development environment, but not otherwise.
|
|
|
|
|
DaveHuber wrote:
...but while they are working, the main thread doesn't seem to be doing anything.
What should the main thread be doing?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
the main thread should be updating the window. It is basically just printing in a field on the window whenever a thread starts or stops. I use SetWindowText to put my message in the right place, and then UpdateWindow to update the window. Until all the threads are done, the main thread is sitting in a loop: print the message if there is one ready to be printed, Update the window, and sleep for a little while. That is all the main thread is doing while the other threads are doing their work.
|
|
|
|
|
DaveHuber wrote:
Until all the threads are done, the main thread is sitting in a loop: print the message if there is one ready to be printed, Update the window, and sleep for a little while.
Ouch! This is not the way for a well-behaved multithreaded application to be. Anytime you have to use Sleep() to get the threads to work together, rest assured that there is a definite design problem. The secondary threads should post a message back to the main thread when they have something to report (e.g., started, processing, stopped). Have you read these two articles:
User Interface Threads
Worker Threads
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-- modifed at 11:22 Thursday 25th August, 2005
|
|
|
|
|
no, I'm not using sleep to get them to work together, they would work fine without it. I am using it for other reasons, albeit probably bad ones... I am printing one more '.' on a line every half second until the main thread sees that the other threads have all terminated. It is cheesey progress indicator. I didn't know how to make it wait for 500ms other than putting it to sleep for that long.
|
|
|
|
|
Use a timer instead. At the appropriate spot, call SetTimer(500) . In the timer-handling function, if any of the secondary threads are still active (the secondary threads will have indicated to the primary thread that they have finished), output the dot. Does that make sense?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-- modifed at 11:28 Thursday 25th August, 2005
|
|
|
|
|
yes it makes sense. I will never attempt to use Sleep() as a timer again.
I am going to try that now.
Thanks.
|
|
|
|
|
I know this is a really broad question, but...
How would I go about programmatically determining whether a given network connection is wireless or not?
For that matter, what is the "tried and true" method for enumerating network connections? Google searches yield different methods, all with varying degrees of reliability...
One big stumbling block is that if the OS is Win32, my code's gotta be able to get that data reliably. That is, anything from the original Win95 to Win2K3. Although to be frank I'm not terribly concerned about determining whether a connection is wireless or not on a 95 box (are there even adapters that ship with 95 drivers?)
|
|
|
|
|
Daniel Desormeaux wrote:
How would I go about programmatically determining whether a given network connection is wireless or not?
Good question, especially since the wire, or lack thereof, is part of the Physical layer of the OSI.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Windows can determine it. I'm assuming there's gotta be something that can be queried to get to the same information.
|
|
|
|
|
I'm not in disagreement, but I do not know what it would be. If you find out, it would make for a good CP article.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
I have an issue where I have a function that takes an HDC and draws to it. Instead of just displaying the data in a window, I want to write it to a bitmap file. I don't want to show the window at all, so I'm hoping that I can do this with a hidden window some how. I've tried calling GetCurrentBitmap() on the CDC object and that did not give me a valid bitmap. I also tried the following:
hDC = GetDC(hDCWnd);
hBmp = CreateCompatibleBitmap(hDC, 500, 500);
SelectObject(hDC, hBmp);
MyFuncToDraw(hDC);
CBitmap* bitmap = CBitmap::FromHandle(hBmp);
but that only gave me a blank bitmap. Does anyone have any idea how I can get a valid CBitmap so I can save it to a file? Is this even possible??
-- Rocky Dean Pulley
-- DreamSys Software
-- http://www.dreamsyssoft.com
|
|
|
|
|
You need to create a memory dc
hDC = GetDC(hDCWnd);
// create the memory dc
HDC hdcMem = ::CreateCompatibleDC(hDC);
hBmp = ::CreateCompatibleBitmap(hDC, 500, 500);
// select the bitmap into the memory device context instead
HBITMAP hbmpOld = (HBITMAP)::SelectObject(hdcMem, hBmp);
// pass the memory dc handle instead
MyFuncToDraw(hdcMem);
CBitmap* bitmap = CBitmap::FromHandle(hBmp);
... after done
::SelectObject(hdcMem, hbmpOld);
::DeleteDC(hdcMem);
|
|
|
|
|
Ok, here's what I'm trying, it's just giving me a blank (black) 500x500 bitmap:
CDC memDC;
memDC.CreateCompatibleDC(GetDC());
CBitmap *bmp = new CBitmap();
bmp->CreateCompatibleBitmap(&memDC, 500, 500);
CBitmap *old = memDC.SelectObject(bmp);
CRect rc(0, 0, 500, 500);
memDC.FillRect(rc, new CBrush(RGB(0, 255, 255)));
memDC.TextOut(50, 50, "BLAH");
//This stuff writes the bitmap and I know that it works.
HANDLE hDib = DDBToDIB(*bmp, BI_RGB, NULL);
WriteDIB("c:\\test\\testbmp.bmp", hDib);
memDC.SelectObject(old);
I have also tried to put the "memDC.SelectObject(old);" line before the bitmap writes and it gives the same problem. I know that the bitmap writing code works, I've used it before on CBitmaps just fine, so I'm sure that the problem exists in this drawing code somewhere. This code is being run from a CDialog, so that's where the GetDC() comes from.
-- Rocky Dean Pulley
-- DreamSys Software
-- http://www.dreamsyssoft.com
|
|
|
|
|
|
How can i change the circle to a diamond in radio button?
I use MFC.
When I chose the owner draw style and painted the radio button to diamond style one, I don't get the button be checked in the normal default way!
What can I do?
|
|
|
|
|
Besides BS_OWNERDRAW , what other style(s) does the button have?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hi all,
HFONT CreateFont(
int nHeight, // height of font
int nWidth, // average character width
int nEscapement, // angle of escapement
int nOrientation, // base-line orientation angle
int fnWeight, // font weight
DWORD fdwItalic, // italic attribute option
.. .
..
)
I have an option in UI for the user to select Font Size 8 to 72 as in winword. I would like to know how to give this value to create font's height and width parameter.
Ex: suppose user selects a font size of 12, what is the corresponding nHeight and nWidth value..Is there any conversion required ??
Can somebody throw more light on this..
Thanks,
Shiva P
|
|
|
|
|
Set height as follows...
nHeight = -MulDiv(PointSize,
GetDeviceCaps(hDC, LOGPIXELSY), 72);
nWidth = 0;
- NS -
|
|
|
|
|
we r working on file transferring in vc++(without using MFC).when we send small size of file(approx 250- 350 kb).there is no problen in sending.but when we send large file through our program there is some problem to geting in server side.means that there is some additonal bytes added by server program and some time it will hang.
if we debug this program there is no problem it sends successfully big file too.
here another problem that is
we are reading /writing a structure using fread/fwrite. it convert it into binary file. so when we reading the file fread function doesnot read specified bytes or sometimes unable to read.
we have more problem to read / write Structure using fread/fwrite is there any alternate of these fun in c/C++.
plz send us solution or suggession soon.
|
|
|
|
|
Hello.
It's a possibility that your problem depends on that you are using text mode in your fopen()-calls.
Make sure you use fopen("anyFile", "rb"); and fopen("anyfile2", "wb");
The 'b' is the key here. (The default mode usually is text mode, which seens unusable in your application).
Regards
kakan
|
|
|
|
|
manishgandhi wrote:
when we send large file through our program there is some problem to geting in server side.means that there is some additonal bytes added by server program and some time it will hang.
if we debug this program there is no problem it sends successfully big file too.
How are you sending file from client to server? i.e. in Small packet or whole file at a time!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
I need information on ADPCM sound format. Microsoft seems not to love it any more.
I need:
- file header format
- code samples
- links to documentation
We are trying to use it in a project written in C++ (mixed-mode, both managed and unmanaged code
Any ideas?
harrykouk
|
|
|
|
|
http://www.wotsit.org/ has specs on RIFF, which is related to ADPCM. Would that help?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|