Monday, April 28, 2014

Creating your own personalised HBCDMenu - Part 1

This article will guide you through the process you can take to program your very own HBCDMenu program. The HBCDMenu is the menu you run from within a Windows environment i.e. to perform diagnostics from within the Windows OS.
We are going to use the AutoIt scripting language, its free, easy and requires no additional runtimes to run the programs.
So first, head over to the AutoIt website and download the AutoIt package as well as the ScITE script editor.
Once we have these installed we can start writing our script.
Note: You will need to have a bit of programming knowledge or at least be willing to learn, otherwise this will be a long and boring article. You can simply skip to the end of the article to download a zip of all the associated files for downloading and modifying.

Create our Script file

To start off we need to create the file we will use to write our script. This is extremely easy, and can be done a couple of ways. Either right click in your desired location and go to New > AutoIt v3 Script.

Or create a .txt file and rename the file extension to .au3 (more advanced users).
After that the file should automatically open in ScITE script editor.

Designing the Main Menu screen

Ok, so first we will design our 'Main Menu' screen. This is the GUI we will be seeing when the script is booted. To make this process a little more streamlined (also for beginners) we can use the Koda (FormDesigner) tool included in the full version of ScITE (we download and installed earlier). Note: if you are using the Lite version of ScITE (installed with the AutoIt library) this will not work.

So, we locate Koda in the Tools menu of ScITE (shown Below).



I'm not going to get into the details of creating a form using Koda. You can go nuts and create it however you would like it to look. For this tutorial, I have simply gone for the classic HBCD menu look (with a couple of small changes).
The main element you will need for this tutorial to work is a Main Menu object with an item named 'Programs' (or whatever you name it.)

Once you have had fun designing your marvelous Main Menu form, select Tools > Generate Form Code... This will give you your forms AutoIt code, so copy it and paste it into your AutoIt script. This is the beginning of our new HBCDMenu.
So once you have finished you will have something like this...
#include <GUIConstantsEx.au3>
#include <GUIMenu.au3>
 
MainMenu()
 
Func MainMenu()
 ;Create and show our main GUI
 Global $Form1
 $Form1 = GUICreate("anarcist's USB Menu", 300, 200, 195, 123)
 ;This is the menu that will hold all of our User-Defined menus
 Global $MenuItem1 = GUICtrlCreateMenu("Programs")
 
 ;Create our About Menu
 $AboutMenu = GUICtrlCreateMenu("About")
 $Blog = GUICtrlCreateMenuItem("anarcist's Blog", $AboutMenu)
 $AboutItem = GUICtrlCreateMenuItem("About", $AboutMenu)
 ;Now create our 'Browse' button
 $Folder = GUICtrlCreateButton("Browse USB...", 80, 65, 140, 50)
 GUISetState(@SW_SHOW)
 
 While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
   Case $GUI_EVENT_CLOSE
    Exit
 
   Case $Folder
    Run("C:\WINDOWS\explorer.exe /n /e, .\Programs")
 
   Case $Blog
    ShellExecute("http://anarcist69.blogspot.com/")
 
   Case $AboutItem ;This come later...
    ;GUISetState(@SW_HIDE)
    ;AboutMenu()
 
  EndSwitch
 WEnd
EndFunc   ;==>MainMenu 
To explain this code a bit better there a a few things to explain:
  1. I have wrapped the menu form in a function name MainMenu(), this allows us to easy hide it and call it again later if we need to. This also means that we don't need to have this as our boot screen (Notice the call to the MainMenu function at the beginning of the script.)
  2. I have renamed a few items (i.e. $AboutMenu and $Blog), this makes them a bit easier to ID later in the script.
  3. There is a 'While' loop at the end of the function, this handles all of our 'Click' events. We will modify this later for our 'Programs' menu once we populate it with our .csv file.
  4. At the very top of our script we have a couple of include files, this contain our functions for creating the GUI and knowing what to do with it. We will be adding more later.
This concludes the first part of the tutorial, stay tuned for part 2 in the next week or so. If you have any questions, ask in the comments, I am always happy to help.