remarknibor wrote:
> I'm using Visual C++ 2005 in Windows, and I'm writing a console 
> application to run from the command prompt.
> I was just wondering if it was possible to have my program open up 
> Notepad at a certain point so that users could write an essay in it, 
> and then have my program save the file to a specified location after a 
> certain amount of time has passed and close Notepad again. Basically, 
> I'd like to use Notepad for the essay writing capabilities rather than 
> the command prompt, but would like complete control over when it 
> opens/closes and where it saves the current writing to.
> If this is possible, could you explain how it can be done? (It doesn't 
> have to be Notepad, rather it could be any basic text editor.
> So far, all I've found is that I can open Notepad up from my code  
> using:
> system("notepad.exe");
> 
> Thanks in advance.

What you want to do is non-ANSI Standard (but so is anything else 
involving timed user input).  You are going to have to deviate from 
Standard C++ and delve into the Windows API to do what you want.  Search 
MSDN Library for the following APIs:

CreateProcess()
WaitForSingleObject()
GetForegroundWindow()
GetWindowThreadProcessId()
keybd_event()

You'll use them in that specific order.  I recommend sending Ctrl+S (or 
Alt+F and then S) and then Alt+F4 (or Alt+F and then X) to force the 
app. to exit.  You should start Notepad with a file to load (create an 
empty file).  WaitForSingleObject() will keep the CPU at 0% while 
waiting for the time to run out OR the person exits Notepad (whichever 
comes first).

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to