Thank you so much for taking the time to send me that sample code. It was very helpful - and showed me what I was doing wrong. I was trying to set and remove the hook every time I opened the popup menu - which meant the messages weren't getting through properly the first time. I hadn't tried setting the hook once only, when the dialog opened - like you had done. Since I made that change it has been working beautifully.
Thanks again, you've made my day!