Zoltan,
Is the ER where you do this from in the same Form as which OK button you are trying to click?
What, I suspect, is happening is that your call becomes recursive: the ER is still in progress when you clicking the button and your own process is preventing it from functioning by deadlocking it.
What I suggest you do, if that's the case, is to finish your ER with a call to an external program, which would in turn click the OK button - _AFTER_THE_ER_HAD_FINISHED_. This way you may have a chance.
To try this idea, I am attaching a command-line executable, which accepts one parameter - the "lpBhvrCom->hDlg", from what Darren has suggested. It then executes the same "PostMessage" call as his BSFN - only this time, it will be called _outside_ of the ER. Just execute a call an external program call, passing the lpBhvrCom->hDlg, converted to string, as the only parameter. Make sure that you call this command as the last statement in your ER, in order that it finishes _before_ the external program runs. If the external command call is synchronous, you may need to also create a couple of batch files, so that the one you call from ER would spawn the second one with a "start" and terminate, returning control back to the ER:
|
:: First Batch will call the Second Batch in a separate thread:
start BATCH2.CMD %1
:: and then terminate, returning control back to the ER
|
while the second batch should call "sleep" to pause for a second, waiting for the ER to finish and then execute the attached EXE:
|
:: The second batch will pause for a second:
sleep 1000
:: and then call the ClickOK program, passing the parameter along:
ClickOK %1
|
The lpBhvrCom->hDlg parameter should be passed from call to call along this chain.
This may sound a bit convoluted, but so are your requirements ;-)
Hope, this helps.
Regards,
Alexander Pastuhov
http://www.pastuhov.com.au/index.htm