|
Create a power scheme where USER_POWER_POLICY.VideoTimeoutAc is set to 1 (second). Save the policy by calling WritePwrScheme() . Then call SetActivePwrScheme() to set the current power scheme to the one that you just created. This is just a high-level overview, but hopefully you get the gist enough to fill in the blanks.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Yeah thanks I successfully used your description to send my screen into darkness after one second.
But (there's always one ) theres the problem of waking up again. If I don't move the mouse around continously the screen blankens immediately again (no surprise, timer is still set to 1 second).
So I thought, well, why don't wait the second until standby mode kicks in, and then write the old timer back? I use Sleep() for this, but the problem is, after Sleep() returns, the system thinks that it should awaken itself again and the screen turns on.
So, I need a way to wait this second and write the old scheme back WITHOUT letting the system think it should wakeup.
|
|
|
|
|
You might need to use GetLastInputInfo() to know when the mouse/keyboard was last used.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I'd like to introduce into my app a control like Dundas Chart (it's so pretty..., but so expensive too..., no cracks wanted and no burning either) but I don't want to use Microsoft's Chart Control...
OH !!, I'm a MFC programmer.
Please, if you know about a class like Dundas Chart make me know it...
Thankx !!
|
|
|
|
|
|
If a computer is suspended/hibernating, does that affect then length of time a process will sleep for?
If a process is told to Sleep () for 1 hour and after half an hour the computer is put into hibernate for 2 hours, when it starts back up again and Windows resumes, does the process still have half an hour to Sleep (), or is its Sleep () time up (having effectively slept for 2 1/2 hours already)?
|
|
|
|
|
i don't know for your effective question, but don't use sleep() function for so long waits...
i uses active waits, and so need full CPU time.
TOXCCT >>> GEII power
|
|
|
|
|
Yeah, it's not good - I got a program dropped on my desk and while I'm fixing it by re-writing it, I still have to try and make the old version work
|
|
|
|
|
I am not quite sure if Sleep really waits actively...
See MSDN:
<quote>The Sleep function suspends the execution of the current thread for at least the specified interval.
Jens
|
|
|
|
|
yes, what does it say with that ??! give us the entire paragraph please...
i already read the MSDN ; it is not advised
TOXCCT >>> GEII power
|
|
|
|
|
My comment didn't answer your original question.
I just wanted to state that I don't think that
calling "Sleep" will cause the thread to wait actively.
It would be rather dumb to implement a task scheduler which lets a thread that called Sleep wait actively, wouldn't it?
To clarify:
By "waiting actively" I mean a continous loop until a condition is reached, like this one:
<br />
while ( true )<br />
{<br />
if ( bConditionIsReached )<br />
{<br />
break;<br />
}<br />
}<br />
Jens
|
|
|
|
|
yes, i understood what your previous post said about this, and i know what is an active wait.
just paste here what MSDN say about sleep() (but give the entire text on it).
TOXCCT >>> GEII power
|
|
|
|
|
|
well, you didn't want to copy the text, i give you :
If you have a thread that uses Sleep with infinite delay, the system will deadlock.
How do you understand this ????
TOXCCT >>> GEII power
|
|
|
|
|
Well the context of this sentence deals with messages, and if you read a little bit more it reads
Message broadcasts are sent to all windows in the system. If you have a thread that uses Sleep with infinite delay, the system will deadlock
And this one makes sense. Think about a SendMessage call to all windows with no timeout and one of the threads sleeps endlessly. Then the calling process will also hang.
But I don't see this as an evidence that Sleep waits actively.
Jens
|
|
|
|
|
no messages are advised ! do you read entierely the particle or you only see some word ?!
MSDN says that if you have to create a nex thread, you mustn't use sleep() because of this problem.
TOXCCT >>> GEII power
|
|
|
|
|
The system will only deadlock if a message is sent to a window that is on a thread using "Sleep" in a non-alertable state. If you use "SleepEx", the second parameter allows the thread to wait in an "alertable" state.
A "SendMessage" queues an APC on the window's thread and will be processed if the thread is in an "alertable" state. So, if you use SleepEx() and maintain an alertable thread state you will be able to become signaled.
Sleep() is also a system call. It's not implemented in user-mode, so it doesn't do a while(x < 10). It's not a spinlock either. The thread should be delayed in the scheduler until the sleep has expired.
I'm not sure what the original question was, but it was something about going into a hibernate state. Perhaps this should answer the question (Link Below)
If this is true, I would think that the thread sleep would continue to sleep once the machine resumed, since it technically hasn't slept the full period. The only way it wouldn't is unless the scheduler bases the sleep off of time (Which would have changed) and it processes this information upon restart. Of course, even if it is based off of time, generally the OS is probably notified of a hibernation and it could make special arrangements to honor the full sleep independent of the hibernation, ie, resume after the system restarted.
I can't be sure of that without a test. You could write a thread to sleep and after the sleep write a debug message or something. Perform the test and verify the results. Though, generally speaking, the results could vary by implementation (hardware, OS, etc.) but most likely the implementations should match what you find.
http://www.veritest.com/benchmarks/battmark/bb3power_man/b3sleep.asp
Hibernation
Hibernation is one of several terms describing a state of reduced power consumption that a power-managed computer may support.
According to the conventional definition of hibernation, a notebook copies all memory contents and hardware state information to non-volatile storage (typically the hard disk, which requires no power to retain information), and the notebook is completely powered down.
Leaving hibernation and returning the system to full operation requires booting the computer as usual and then waiting while the system restores the memory contents and hardware state. The process is finished when the computer is at exactly the point it was when the hibernate process started.
Hibernation trades time for power: maintaining the system state requires no power (because the state has been saved to disk), so the computer can remain in hibernation indefinitely. However the user must wait when entering and returning from hibernation—sometimes several minutes or more if the system has a lot of memory.
|
|
|
|
|
BTW, Sleep() calls SleepEx with FALSE.
|
|
|
|
|
Well.. TEST IT !!
You can send a MessageBox after the Sleep() function, so if you start back up again and the message is on your screen it means that it worked.
I think is the best option...
|
|
|
|
|
I'm inclined to agree - just I got an attack of lazyitis and didn't want to hibernate a pc
|
|
|
|
|
I need source code for a program that copies itself into a certain directory with a certain name like "C:\Program Files\something.exe"
-Ryan M.
|
|
|
|
|
I'm not sure if an app that is running can be copied itself or even can be copied by other process...
|
|
|
|
|
It can - like this:
TCHAR szFileName[MAX_PATH];
::GetModuleFileName(szFileName, MAX_PATH];
LPCTSTR pszDest = _T("C:\\Program Files\\SomeApp.exe");
::CopyFile(szModuleFileName, pszDest);
|
|
|
|
|
look for [ShFileOperation] api!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Hi guys,
I've developed in C++ for many years, but more recently have been working in C# and VB.NET.
I am developing my own version of themed controls where the user can govern just about any aspect of control drawing, like shape and colour etc.
I want to extend this control now to Windows Captions (i.e. Form captions). One thing that I have never fully gained is an understanding of what windows messages to trap, whether to let the default processing always take place, and what values to return. Even when I think I am following the MSDN SDK documention on WM_... notifications I still can't seem to get it right.
My problem seems to mainly be in getting setup, i.e. calling GetWindowDC to give me the entire drawing area of the window. Once I have called GetWindowDC I can construct a .NET Graphics object, and later dispose of both after my drawing is complete.
I do this and clear the Graphics object to red, so I should see all the non-client area turn red, which happens when the window is first drawn, but after that, as I start to move the window or size it I dont see the DC get consistently filled with red.
In summary then, if I could get a control of non-client drawing then I would have raised my programming standard significantly.
I would really be immensley greatful if you guys could point me at a definitive guide to subclassing or window's message processing, without recommending 3rd part controls as I am a DIY fanatic! 8-)
Also, if any of you can spare some time now and again, perhaps on MSN messenger to chat about this issue that would just be solid gold.
I await your responses with baited breath!
Thanks all!
Nursey
|
|
|
|