

            ========== MAKING A MENU FOR OUR WIN95 PROGRAM ==========

                                        by Dolphinz
                                        dolphinz@lettera.net

Wellcome to my third tutorial under Windows 95 in assembler,
and now I will teach you how you can make menus for your own
Win 32 Bits programs.

What's a .RC and .DEF file?
Well, a Resource file (.RC) can be produces by text programs,
(I use Notepad) or by a special program to generate resource
scripts.

The resource file describes the apperarance of the program in
the screen, such as dialog boxes, menus...

The definition file defines de program name, segments used,
memory requeriments of the program, and also the exported
functions of the program. All functions in your program
that will be called by another program must be declared as
exported.
Let's see our .RC file:
------------------------------------
#include "windows.h"

#define IDM_OPEN      100
#define IDM_EXIT      110

GenericMenu MENU PRELOAD MOVEABLE DISCARDABLE
  {
    POPUP    "File"
    {
      MENUITEM "Open"        , IDM_OPEN
      MENUITEM SEPARATOR
      MENUITEM "Exit"        , IDM_EXIT
    }
  }
------------------------------------

When we select a menu-item, it generated a WM_COMMAND message,
which is a 32 Bit value, and has other parameters,
for example is a 32 Bit application:

      - message         (32-bit number)
      - wParam          (      "      )
      - lParam          (      "      )

* The format of MENUITEM is:

        MENUITEM "Text", id (,options)

* And the format of POPUP is:

        POPUP   "Text" (,options)
          {
            (Menu list)
          }

We could add options to our menu, for example:

        GRAYED: The menu-item is desactivated, and doesn't generate
        WM_COMMAND message.

        INACTIVE: The menu-item is desactivated, and doesn't generate
        WM_COMMAND message.

        CHECKED: There's a mark on the left of the text.

Try to change the .RC file, and change this code:

        MENUITEM "Open"         , IDM_OPEN, GRAYED


And here is the .DEF file:
------------------------------------
NAME         MENU
DESCRIPTION 'Dolphinz Tutorial 3'
CODE         PRELOAD MOVEABLE DISCARDABLE
DATA         PRELOAD MOVEABLE MULTIPLE
EXETYPE      WINDOWS
HEAPSIZE     8192
STACKSIZE    8192
EXPORTS      WndProc
------------------------------------

WndProc() is the callback function. This is where Windows
sends messages to be processed. An application can have
multiple callback functions for each window, dialog box...
Now let me explain  the specifications for the data segment:

PRELOAD means that it loads when the program is first loaded.
MOVEABLE means that can be moved by Windows.
MULTIPLE means that every instance will have a own copy
of the data segment.


Here is the MAKE file:
------------------------------------
c:\tasm\bin\brc32 -r menu.rc
c:\tasm\bin\tasm32 /mx /m3 /z /q menu
c:\tasm\bin\tlink32 -x /Tpe /aa /c menu,menu,, import32.lib,menu.def,menu.res
------------------------------------

I have implemented the MAKE file in a .BAT file,
so I hope you can understand it easy.
The make file determines the compile and link steps.
The first step is to compile MENU.RC to make MENU.RES,
the second step is to compile MENU.ASM to build MENU.OBJ,
and the last step show how TLINK32 incorporate MENU.RES
into MENU.EXE, and IMPORT32.LIB provides the connection
to the Windows 32 bits functions, also TLINK32 refers
to the .DEF file.


What messages are sent to my program by Windows?
WM_CREATE is a message sent by Windows when our window
is created, in response to CreateWindow().
We'll not make anything with this message in our simple
program.

WM_PAINT is sent when anything has happened to the window,
which means that client area must be redrawn.
In all applications we need a little code in response to
WM_PAINT message. Even if you don't do anything you'll need
to put BeginPaint() and EndPaint().

WM_COMMAND is a message sent by Windows when a menu-item
is selected, with the identifier of the menu-item in wParam,
and 0 in the low-half of lParam.

WM_DESTROY is a message sent when our program is finished.
In responde to this message we should make a call to ExitProcess().


There are another type of Windows messages?
Also, your application can receive another Windows messages
such as:

WM_LBUTTONDOWN is a message sent to our program when left
button of the mouse is pressed.

WM_RBUTTONDOWN is other message sent when the right button
of the mouse is pressed.

WM_SIZE is a message sent when the client area has changed
and our window need to be resized.

WM_CHAR is a message sent when the user has pressed
a keyboard key.

And these are only some messages sent by Windows,
there are a few more.

Well, I have commented a little my code, so I hope
you can understand it, and learn a little more about
Windows 95 programming under assembly languaje.

If you would like to contact with me you can reach me
at:

dolphinz@lettera.net
