Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interupt Action?

Status
Not open for further replies.

Watts

Programmer
Jan 18, 2001
80
US
I have an application that is sending/receiving data over a Windows socket. I want to know how to interupt this process when the user clicks the Cancel button on my Dialog.

Is there something like a Windows ProcessMessages function?
 
just call return inside WinMain or main function. I don't unedrstand, what does it have common with sockets. John Fill
1c.bmp


ivfmd@mail.md
 
This is what is happening:

I connect to a remote device and begin sending data in a while loop. I want the user to be able to interrupt this while loop by clicking a Cancel button in the Dialog box. Currently the while loop continues until it finishes and all of the Dialog functions are disabled (not handled) until the loop finishes. I don't want to return from the function unless the button is actually clicked.
 
In this case, the cancel clicking of the user should send some specific data. By parsing this data, your program should decide, is it data for closing or for workning forward. John Fill
1c.bmp


ivfmd@mail.md
 
The Cancel button is on the Client side of the communication.

The client clicks Connect and starts sending data, then say he wants to click Cancel to interrupt the process. Currently the client application is busy sending data. There is no user on the other side of the connection.
 
I think there should a separate thread what reads, does the user want to cancel or not. In the client side also should be a separate thread what send the user's wishes, to cancel or not to cancel. By the way, DCOM has every you want. There you don't need to invent some new, just implement existent interfaces. John Fill
1c.bmp


ivfmd@mail.md
 
I think there are many solutions for your problem:

1. As JohnFill says you make a separate thread for the window in witch you have the cCancel Button, and on cancel event you can do this:
* make a SetEvent call to announce tha main thread that cancel was pressed.
* in the Send loop of the main program (of your socket class), you should verify the state of this event. if it is Signaled you should call Abort or cancel in other way the sending of the data (I suppose you make it through packets).

Hope of being of some help, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...

 
Just to let you know the function is called PeekMessage, which stops and looks at the current queue of Windows messages and processes any that it finds. I put this inside my loop so it is constantly looking for the Cancel button to be pressed while it communicates with the remote device.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top