Search code examples
c++visual-studiovisual-studio-2013project-template

How to disable the control in Custom Wizard (Custom Project Template) for Visual Studio (Visual C++)?


I want to disable by default some of the controls in the Project Wizard created with Custom Wizard in Visual Studio 2013 (Visual C++).

The code:

<input class="CheckBox" type="checkbox" id="BOX1" title="Box 1">

creates a checkbox.

So I've tried both:

<input class="CheckBox" type="checkbox" id="BOX1" title="Box 1" disabled>

and:

<input class="CheckBox" type="checkbox" id="BOX1" 
    title="Box 1" disabled="disabled">

But none of them worked (checkbox is still enabled).

I was even trying including JS:

alert('JS works'); //alert occured (indeed, JS works in general)
document.getElementById("BOX1").disabled = true; //did not work

So, how to disable that control?

For the example, here the "Use HTML dialog" is disabled, and I want to get the same effect on my control (the screenshot is from MFC wizard, but it doesn't matter):

enter image description here


Solution

  • I'm basing my answer on an older version of Visual Studio (2010) which probably has a different Wizard system, but at least it's an answer...

    Looking at the MFC AppWizard, the method for creating the (by-default disabled) checkbox is to have a basic checkbox with a name (in this case HTML_DIALOG). The wizard HTML has an onload method that calls some JScript to initialise the page with your required default settings:

    function InitDocument(document) {
      ...
      HTML_DIALOG.disabled = true;
      HTML_DIALOG_LABEL.disabled = true;
      ...
    }
    

    The Visual Studio app wizards are generally located under you base VS install directory, in (for example) VC\VCWizards. The MFC AppWizard I referenced above is even deeper, under (for my install and locale) AppWiz\MFC\Application\html\1033. The exact path may vary depending on version and language.

    For your example, you could go the following route, if that's the only item you want to default-disable:

    <body ... onload="BOX1.disable=true;">
    

    Otherwise call an onload method:

    <body ... onload="initialise(document);">
       ...
    </body>
    <script language="JSCRIPT">
      function initialise(document) {
        BOX1.disabled = true;
        BOX1_label.disabled = true;
      }
    </script>
    

    As I say, that's based on VS2010, and also completely untested, but from that I get the impression that your HTML tags themselves shouldn't contain defaults, they are set after the HTML has loaded. This approach actually gives you more scope to "tweak" the defaults based on parameters. I guess.