Search code examples
wixwindows-installercustom-action

Is it possible to paste into an masked edit control in a windows installer?


Starting off with what I need the end result to be: Customer is able to paste a product key, of the correct format, off of the clipboard into an input box during the install.

Where I am at the minute: We use WiX to create our MSI. We currently use a masked edit control which works fine. The product key verification is already done using a custom action when pressing the 'next' button. The product key verification should remain the same, only the input method is the issue.

I've spent the last day researching the possible ways of achieving this and have a few ideas, although i'm not sure if any of them will work. I've already ruled out trying to trigger a custom action on paste because I know MSI has no way of capturing that event.

So, my thoughts are a 'paste from clipboard' button. This would trigger a custom action which would capture the clipboard item, decide whether or not it looks like a product key (that would be the easy part) and then somehow paste that into edit control. Note how I say edit control, I'm not sure it would be at all possible with a masked edit control and i'm not certain it'd even work with a standard edit control. I already have a custom action which manages to check whether the licence text has been viewed, and this is achieved by finding the window and the 'richedit' class window where the licence resides and retrieving the scroll position. I had thought that this method may allow me to set the edit control to my clipboard key, again though, I'm not certain this would work.

I have already read about the possibility of writing my own UI controller. I know this is a big task but nothing is ruled out at this stage, I just have no idea where to start.

My final idea, although I have no thoughts on how it could be implemented, would be by changing my masked edit control to a standard edit control, which would obviously allow the full product key to be pasted, although without using a custom action to verify it is in the correct format i'll still be no further forward. But this would then require for some sort of automatic adding of dashes if the customer was to type the product key in manually.

Could anyone can shed any light on the feasibility of any of my ideas and how to implement them or any other ways of meeting my goal?


Solution

  • I have managed to do this using the 'paste from clipboard' option I originally thought of. I added a button to my form, which calls a custom action which queries the clipboard and, if successful, sets two properties in the installer. One containing the formatted product key, and one a basic property to tell whether or not the clipboard operation has been successful or not. The masked edit control is linked to the product key property, and by refreshing the control,

    <Publish Event="Reset" Value="0" Order="3">ClipboardSuccess = 1</Publish>
    

    the product key is populated in the masked edit control.