• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Finally, you can manage your Google Docs, uploads, and email attachments (plus Dropbox and Slack files) in one convenient place. Claim a free account, and in less than 2 minutes, Dokkio (from the makers of PBworks) can automatically organize your content for you.


Working with the GUI

Page history last edited by Darien Sokolov 4 years ago Saved with comment

It’s been stated elsewhere that GUI for HoMM2 is not the best and that most of the GUI has been reverse engineered; however, sometimes you will need to work with parts of the original GUI. GUI Helper Functions, found in msg.cpp, have been created to aid in the modification and use of the original GUI, as well as to help with understanding the original code and how it works. Additionally, there are several constants that are used throughout the code for the original GUI, the definitions for which can be found in gui.h and msg.h.

A basic example of the HoMM2 GUI in action:

And an excerpt of the code that goes with the example:

This is an example of the HoMM2 GUI; specifically, the Spell Scroll Edit Screen. The GUI Helper Functions, which start with “GUI”, are responsible for creating what you see in the first image. The first two, GUISetText(), write “Spell Scroll” and “Attach Spell” to the screen, while GUIDroplistAdd() creates a droplist element for each spell.

Here is an excerpt of the GUI Helper Function definitions found in msg.h:

When working with the original GUI code, you may notice that the BroadcastMessage(tag_message) method was used to execute various GUI commands. The tag_message type is a structured data type that contains fields whose values determine the behavior of the BroadcastMessage(tag_message) function when it is called. The GUI Helper Functions utilize defined constants for these field values and make calls to the original BroadcastMessage(tag_message) method, but they are formatted such that the name of each GUI Helper Function directly correlates with the GUI command executed. The GUI Helper Functions take care of all the assignments to the fields of the tag_message structure behind the scenes and they call BroadcastMessage(tag_message) for you, making code for the GUI easier to look at and understand.

When working with the original GUI code, you should reformat any constants or BroadcastMessage(tag_message) calls with the GUI Field ID constants found in gui.h and msg.h and the GUI Helper Functions found in msg.cpp. For example:

If you see this:

  evt.eventCode = 512;
  evt.xCoordOrKeycode = 3;

you would check msg.h/gui.h and find the defined constants for the values, changing it to this:

  evt.eventCode = INPUT_GUI_MESSAGE_CODE;
  evt.xCoordOrKeycode = GUI_MESSAGE_SET_TEXT;

Also, if you had this:

  evt.eventCode = INPUT_GUI_MESSAGE_CODE;
  evt.xCoordOrKeycode = GUI_MESSAGE_SET_TEXT;
  evt.payload = &gText;
  evt.yCoordOrFieldID = 101;
  strcpy((char *)&gText, "Spell Scroll");

you would change it to this:

  GUISetText(gpCellEditDialog, 101, "Spell Scroll");

because the definition of GUISetText(…) is:

and the definition of GUIBroadcastMessage(…) is:

It may also be worth noting that on rare occasions, you may need to create a new GUI Helper Function if one does not exist for a particular command.


Comments (0)

You don't have permission to comment on this page.