I am making mapinfo addon and I am having problem with close action of buttonpads. How to add close action to dialog and buttonpad so that we can execute certain action on close of buttonpad or dialog?
A dialog and a buttonpad are two quite different things in the MapBasic language.
You would always know when a dialog has been closed. That's when the code after the Dialog statement is executed. So for a dialog you could do you "house cleaning" after the Dialog statement.
You could also add handlers to your OKButton and your CancelButton. These handlers would be called when the user "activates" these buttons and so you would also know that the user either okay'ed or cancel'ed the dialog. However these handlers will not be called if the user dismisses the dialog thru the cross in the upper right corner or thru the Esc key.
A buttonpad is a bit different. The user can't really close this "window" - he can only hide it. So when the user clicks the small cross on the buttonpad, the buttonpad still exists - it's just hidden. If you rightclick any of the other buttonpads, you can see a list of buttonpads, and yours would also be there.
You could add a specific Close button to the buttonpad, either as the first or the last button on the buttonpad. Then you could make this button call your "CloseButtonPad" handler and so you would know when the user wants the buttonpad closed.