|
I think a bit of lateral thinking and lots of guesswork is needed here. I only noticed that because he mentioned the MessageBox call in two posts. I've no idea what the rest of it is, or is supposed to be, doing.
It's time for a new signature.
|
|
|
|
|
Hi, I have written a function to cause a thread to wait for a given time. But the problem is that If this function is called, I notice from task manager (in Windows) that the CPU Usage shoots up to 100 percent. But if I rather use the Windows function Sleep(), the CPU Usage falls back to around 2%, 3%, and 4%. The following is how I wrote the function, with the header file <time.h> included.
void Wait(clock_t milliseconds)
{
clock_t delay_time = milliseconds + clock();
while (delay_time > clock())
;
return;
}
I don't know why my CPU usage shoots up to 100% when I use this function rather than Windows Sleep() function. I don't want my application to assume the use of Windows. Please help.
|
|
|
|
|
Dan_K wrote: that the CPU Usage shoots up to 100 percent
No wonder: you're using the CPU, aren't you?
That's not the best way to pause an application on a multitasking system.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You should upgrade your hardware. If you buy a dual-core system, it will become twice as efficient: the CPU load will be around 50%. Or go for a quad-core and see it sitting idle with a load of a mere 25%.
If you don't like that idea, you should either use a sleep function or a timer.
FWIW: you could do both to make absolutely sure.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Your CPU usage goes to 100% simply because you are actually doing something: the while loop and the checks are operations done by the CPU, and in your case without interruption, so the CPU is always busy.
|
|
|
|
|
Cedric Moonen wrote: so the CPU is always busy
It's the ancient wise's rule: "keep the CPU busy and the brain sleeping..."
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
All the CPU cycles are going to reaing the clock over and over. If you want to be independant of windows, the function uSleep is Unix the equivelent of Sleep, just add
<br />
#ifndef WIN32<br />
#define Sleep(x) uSleep(x * 1000)<br />
#endif<br />
<br />
To the top of your code
|
|
|
|
|
Dan_K wrote: I don't know why my CPU usage shoots up to 100%
Time to start learning how computers work.
It's time for a new signature.
|
|
|
|
|
I have a strange problem : an .pdf file load in IE is not printed !
I made an MDI project , with CView based on CHtmlView , where I load an .pdf file. The problem is that Print , from File menu not working !!! If I load an any other kind of file ( .html , etc. ), Print function ... Why ? I work in VC6 , and I have Foxit pdf client ...
|
|
|
|
|
Ok , I found the problem , it was my pdf client : Foxit Reader .
|
|
|
|
|
Hi,
I am working in a porting project where i have to convert the thread local variables (declared with __declspec(thread)) to TLS allocations (using TLS APIs).
I am able to do it for variables.
How to do it for function pointers? (thread local function pointers)
for example,
I have a thread local function pointer declared as,
__declspec(thread) BOOL (WINAPI *Test)(Short a, _TCHAR b, BOOL c);
Is it possible to convert this by using TLS APIs?
Is it possible to allocate the memory (4 bytes) for pointer "Test"?
Any help is appreciated.
Thanks.
Selva
|
|
|
|
|
Test is just a variable with type:
BOOL (WINAPI *)(Short, _TCHAR, BOOL );
so all you need to do is cast the result of you TLS allocation to that type. If you use a quick typedef it's pretty trivial:
typedef BOOL (WINAPI *test_function_ptr)( Short, _TCHAR, BOOL );
test_function_ptr Test = (test_function_ptr)malloc( sizeof( test_function_ptr ) );
Replace malloc with what ever TLS function you're using and snip, snip, Bob's your Aunty.
Cheers,
Ash
|
|
|
|
|
Hi Ash,
Thanks. It works.
Selva
|
|
|
|
|
Hi all,
i want to use Codeproject Left Sidebar type sidebar in my SDI type Splitter MFC application.
please tell me how can i use it .
if possible please tell me any other styles and designs of side navigation bar.
thanks in advance.
|
|
|
|
|
You would probably need a Tree View[^] control, or CTreeView[^] class.
It's time for a new signature.
|
|
|
|
|
Can u please show me any example or demo application its really help me.
|
|
|
|
|
You really should learn how to use MSDN/Google/Bing for yourself. Try here[^] for some explanations and samples.
It's time for a new signature.
|
|
|
|
|
how to check the window is opened or not in a win32 application
|
|
|
|
|
FindWindow and FindWindowEx are what you want. You have to know the window class or the title of the window you're digging for but not both.
Cheers,
Ash
|
|
|
|
|
If "opened" stands for "visible" than IsWindowVisible is the API.
If "opened" means "existent" than IsWindow is the API.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
VS2008 puts a manifest file in my exe automatically (the "embedding manifest" build step). But when I start the exe it shows the dialogs in the classic theme. I opened the exe in the resource editor and noticed that the manifest lacked "Common Controls" section. How can I fix that?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
WTF?! Why does the New Project Wizard add the #ifdef _UNICODE...#endif
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
in the code that adds the XP style buttons.
This code was created by the wizard, no changes from me. It basically means "I'll create a manifest for you unless your program is ANSI, in which case f**k you". When I removed the #ifdef everything worked without problems. The only purpose for putting it seems to be to make me waste an hour wondering why I don't have visual styles, and creating 2 projects one with manifest one without, and comparing them with WinMerge, before noticing this little insidious #ifdef. And I'm sure there are people who don't know about the whole manifest thing, they'd be stuck with ugly controls if they make an ANSI project. I've made my project ANSI from the beginning since I had to add a lot of code that won't compile if it's unicode.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
sashoalm wrote: WTF?! Why does the New Project Wizard add the #ifdef _UNICODE...#endif
Because technically... common controls 6 and above does not have full ANSI support. Some window messages will be returning Unicode text buffers if you use common controls 6 in an ANSI build. Depending on your application architecture... you may or may not bump into this limitation.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi Everybody,
How to find a text file is already opened or not?
I have used the following code. but it is not working correctly.
ifstream inFile;
inFile.open("C:\\test.txt");
if (!inFile)
{
AfxMessageBox("file is opened");
}
else
{
AfxMessageBox("file not opened");
}
can anyone help me to how to find a file opened or not?
Thanks....
G.Paulraj
|
|
|
|
|
It all depends on how you opened the file. There's no reason why you can't have two streams based on the same file. e.g. on my system:
int main()
{
std::ifstream str1( "c:\\test.txt" );
std::ifstream str2( "c:\\test.txt" );
int n = 0;
int m = 0;
if( ( str1 >> n ) && ( str2 >> m ) )
{
std::cout << "Woo hoo! Opened both!" << std::endl;
}
}
Always comes up with the "Woo hoo!" message and both n and m are set to the integer that's in the first token of the file.
Unfortunately there's no way of opening a file using the standard library that locks it against further reading so if you're using streams you're not going to be able to tell easily if someone else has got it open.
Cheers,
Ash
|
|
|
|