Waiting function

07/01/2012 22:38 Krasti#1
Sup
I wanna know if there is any way make the program wait for a process.
I was about to use while,but it's blocking the execution of the program,so...

There is a button which is waiting the process and then it doing its stuff.
The program is a window application and using dialogs

Code:
case IDC_BUTTON1:        v Process
        while(isRunning("S4Client.exe")==false){}
                 ^The waiting func
07/01/2012 22:49 MrSm!th#2
You cannot wait in that case-block, since you are within the message loop of a window and it wouldn't react anymore, if you did.
You could use a thread or a timer; since it's just that little task, i would tend to use the timer. You create a timer that ticks every 100ms and add a handler for it to your message loop.
07/01/2012 22:50 xNopex#3
I've never tried this before but it should be possible to install a global windows hook which receives a notification when the S4Window has been created:

>> [Only registered and activated users can see links. Click Here To Register...]
>>[Only registered and activated users can see links. Click Here To Register...]

Quote:
You could use a thread or a timer; since it's just that little task, i would tend to use the timer. You create a timer that ticks every 100ms and add a handler for it to your message loop.
Polling is... :(
07/01/2012 22:58 Naworia#4
Use Autoit library so you can it easy.
07/01/2012 23:05 Krasti#5
Quote:
Originally Posted by MrSm!th View Post
You cannot wait in that case-block, since you are within the message loop of a window and it wouldn't react anymore, if you did.
You could use a thread or a timer; since it's just that little task, i would tend to use the timer. You create a timer that ticks every 100ms and add a handler for it to your message loop.
Use timer?SetTimer or?

Quote:
Originally Posted by Naworia View Post
Use Autoit library so you can it easy.
You may use Autoit function in C++ or?
EDIT: Tried but again it's freeze
07/02/2012 01:00 Naworia#6
Use this.
While(true)
{
if(ProcessExists("S4") == true)
{
"successs";
}
}
07/02/2012 01:23 MrSm!th#7
Quote:
Originally Posted by Naworia View Post
Use this.
While(true)
{
if(ProcessExists("S4") == true)
{
"successs";
}
}
You clearly did not understand the problem.
07/02/2012 13:09 .SkyneT.#8
Quote:
Originally Posted by Naworia View Post
Use Autoit library so you can it easy.
Plz not :<


@Topic:
Create a thread: [Only registered and activated users can see links. Click Here To Register...]

And let it check every, for instance 100ms, if the Process is running
with [Only registered and activated users can see links. Click Here To Register...] .
(I know a new thread isnt the best way to do this, but it should work)
07/02/2012 15:21 Krasti#9
Quote:
Originally Posted by .SkyneT. View Post
Plz not :<


@Topic:
Create a thread: [Only registered and activated users can see links. Click Here To Register...]

And let it check every, for instance 100ms, if the Process is running
with [Only registered and activated users can see links. Click Here To Register...] .
(I know a new thread isnt the best way to do this, but it should work)
The thread i should make at begin of program?
Cause the users should choose by checkboxes and then button should wait process etc.
07/02/2012 16:31 .SkyneT.#10
Quote:
Originally Posted by Krasti View Post
The thread i should make at begin of program?
Cause the users should choose by checkboxes and then button should wait process etc.
Code:
If (Checkbox == checked)
{
    CreateThread
}
if (Checkbox != checked)
{
    SuspendThread or TerminateThread
}
The thread runs the loop to check if the Process is running.
07/02/2012 19:51 tnd0#11
The Correct way:

[Only registered and activated users can see links. Click Here To Register...]
to get the Handle of the process, use 'PROCESS_ALL_ACCESS', and inherit the handle (second parameter true).

[Only registered and activated users can see links. Click Here To Register...]
pass the handle and the maximum time you wish to wait.

[Only registered and activated users can see links. Click Here To Register...]
Create an Event after the WaitForSingleObject call to notify your main thread.

Put these three calls in a function and in your main thread you just let yourself be notified via the event you set up (see MSDN).

Finally, call [Only registered and activated users can see links. Click Here To Register...] on that function. Once the target application terminates, your secondary thread will unblock and create an event which notifies your main thread.
07/04/2012 00:36 MrSm!th#12
Quote:
Originally Posted by xNopex View Post
I've never tried this before but it should be possible to install a global windows hook which receives a notification when the S4Window has been created:

>> [Only registered and activated users can see links. Click Here To Register...]
>>[Only registered and activated users can see links. Click Here To Register...]



Polling is... :(
Impossible, S4 is protected by XTrap, a long time before the window is created and i am damn sure, he wants to write a trainer.

Quote:
Originally Posted by tnd0 View Post
The Correct way:
Nope, it's wrong, he wants to wait untill S4 starts and not untill it terminates.
07/04/2012 07:25 Omdi#13
Here how to do that with a thread
Code:
DWORD WINAPI Thread(LPVOID lpParam)
{
UNREFERENCED_PARAMETER(lpParam);

while(isRunning("S4Client.exe")==false)
Sleep(100);

//do ur stuff

return TRUE;
}

case IDC_BUTTON1:        
        CreateThread(NULL, NULL, Thread, NULL, NULL, NULL);
        break;
07/04/2012 16:29 Krasti#14
I put the stuff i wanna do in a function,but the IsDlgButtonChecked isn't work.
I mean after the while,i made it,but it didn't do anything...I hope you get me
07/04/2012 16:31 Omdi#15
Quote:
Originally Posted by Krasti View Post
I put the stuff i wanna do in a function,but the IsDlgButtonChecked isn't work.
I mean after the while,i made it,but it didn't do anything...I hope you get me
Did your programm freez or what ?
It shouldn't freeze if you do ur stuff in a thread.