I want to shutdown the PC when I click on a button. How do I do this?
Call the ExitWindowsEx API function with the EWX_SHUTDOWN flag.
You can find a sample here: How to Shut Down the System
You can also use a System() call.
Related
I'm writing a VisualC++ program which have code invoke ffmpeg.exe to convert video file.
I wonder is it possible to pause/resume ffmpeg converting thread from C++ code?
LR.
All you need to do is suspend and resume the ffmpeg child process itself.
The main problem is: there is no SuspendProcess API function. And there is no documented or safe way of doing this.
The only simple way of doing this is via SuspendThread/ResumeThread.
See this article on codeproject about how to do it.
There are no ways to controls the conversion using ffmpeg.
However, if you switch you mencoder, you will be able to do it.
This is an equivalent for Unix based command:
mike#krusty:~$ pidof ffmpeg
22730
mike#krusty:~$ sudo kill -STOP 22730
[sudo] password for mike:
mike#krusty:~$ sudo kill -CONT 22730
No. This is a command-line tool, and once it is started, you cannot pause it.
Microsoft API ::SuspendThread function
I want to launch an application using win32 ...
Please let me know your ideas to achieve this
In (approximately) ascending order of control and complexity: WinExec, ShellExecute, ShellExecuteEx, CreateProcess.
Your best option is ShellExecute (It can launch any filetype and will handle elevation) If you need more control of the new process, use CreateProcess
You need to call CreateProcess.
I'm fairly new to Windows programming. I'm doing a simple launcher app for WinCE using VC++ (not MFC). So far I've created the basic interface and buttons and stuff. I just wanted to know the best way to launch an external application when the user clicks the button (on BN_CLICKED).
I found some methods such as ShellExecute, CreateProcess and others. But I couldn't get it to work (yet?). Any suitable reference or simple example on this?
The question don't matter that it happens inside the event of a button click, but...
ShellExecute is a good way to start programs (and the default program for any other type of files) in Windows, but use CreateProcess if you need a return code, or if you need the ability to wait for the program to finish.
Nevermind. I found a working example on MSDN - a comment by a user.
For anyone interested, you can go to this CreateProcess() article and scroll down to a comment entitled "Working code for creating two processes "p1.exe" and "p2.exe" using CreateProcess() Method"
Thanks!
In a windows project I am working on, I intend to have a menu selection that copletely restarts the app. Is there a Windows or C++ function that does this?
There isn't a built-in for this, but a well-designed application can simply stop everything that's going on and then loop back to the start. If you want a true 'fresh start', you will have to spawn a new process (possibly as the last thing you do before the old one shuts down.)
No, you must do it yourself.
For instance, you can run external process which will wait until you exit your application, and then run it again.
Actually you might want to take a look at the Restart Manager API that came in with Windows Vista. As ever you can p-invoke this to your hearts content and theirs explicit support coming for it in Visual C++ 2010.
Already needed to do this. The easiest way without any further reading would be to write a simple .bat-file (either by hand or dynamically by your application) starting your program and then calling that bat-file from your application.
The bat-file may even contain a line to remove itself after having started your app...
You want to call CreateProcess and then close your current instance of the application gracefully with ExitProcess(), or if you link to the C runtime, just return from main().
But first you should ask yourself why you need to recreate the process in the first place.
ExitWindowsEx is what you want. You can also run the shutdown.exe utility built into windows.
shutdown -t0 -r (restart the system after 0 seconds)
Is there any Win32 API to put the machine into hibernate or suspend mode?
I read MSDN and found that WM_POWERBROADCAST message gets broadcasted when power-management events occur. I thought of simulating the same with PostMessage(WM_POWERBROADCAST). Is this the correct way of doing or any Win32 API exists to achieve this?
Check out
SetSuspendState.
Note that you need SE_SHUTDOWN_NAME privilege, as mentioned on the referenced msdn page.
As posted by Ben Schwehn, SetSuspendState is the way to go. On win95, you should call SetSystemPowerState. You can also call IsPwrSuspendAllowed and IsPwrHibernateAllowed or GetPwrCapabilities to tell if the machine supports suspend/hibernate.
In a Windows Form application, use the SetSUspendState (http://msdn.microsoft.com/fr-fr/library/system.windows.forms.application.setsuspendstate.aspx) method. The first parameter allows you to chose between SUspend and Hibernate.
For a non-Windows forms app, call the Win32 API directly : the SetSuspendState function is in the powrprof.dll file.