I've done this exact thing just in different parts. First got the topmost window under the mouse (in my asm kill program which i believe is on this forum if it isn't just msg me and I'll re-post it) using the api
WindowFromPoint this doesn't have to be under the mouse, just i used the moue to get the point.
After that it's just a matter of sending the right message to that window most programs react to WM_LBUTTONDOWN, WM_LBUTTONUP. WM_LBUTTONDBLCLK, BN_CLICKED, BN_DBLCLK, or BN_DOUBLECLICKED. depending on how the program is handling it i'd send WM_LBUTTONDOWN then BN_CLICKED then WM_LBUTTONUP. if you need to have your mouse in a certan position then you can use
SetCursorPos, note i've read just having the cursor over a point when the message is sent will fake tell the program the message was sent from the cursor's position, however i have been too lazy to confirm this.
I've also read you can use the
SendImput function for this however I have not used this method. But it looks like it's a lower level approach, with a few restrictions.