Creating simple menu in Pascal

  • Follow


Hi,

This is for my son Ding Wen learning GS programming. He is now quite
good in event driven programming and wanted to learn desktop
programming. I think it is probably too hard for him to learn so I
think maybe the simplest way to solve his curiosity is not to teach
him all those window, etc, but to create a simple menu bar with some
simple menus, and when click, do a simple functions like Quit, Clear
Screen that does not involved any windows.

What's the simplest way to create menu bar and menus in Pascal? Is
pointer or handles involved in these (I try to avoid these if
possible).

Thanks!
0
Reply limtc 6/1/2008 4:00:07 AM

Just a note: I am now reading up Toolbox References... but I have
never done a desktop program for Apple IIGS before. It looks pretty
complicated to me. So if someone think we can make this looks simple
to a young programmer, appreciate the feedback.
0
Reply limtc 6/1/2008 4:08:08 AM


A kind gentleman sent me this piece of codes, which I still think
looks a little complicated (especially when pointer is involved, many
tools are loaded, and grafport is set - But can these be avoided if
all we want is the menubar/menu and nothing else?).

program Quit;
uses Common, QuickDrawII, EventMgr, WindowMgr, ControlMgr, DeskMgr,
DialogMgr, MenuMgr;
const
   return        = 13;                  {return key code}
   File_Quit     = 256;                 {Menu ID #s}
type
   long = record                        {for splitting 4 bytes to 2
bytes}
      case boolean of
         true : (long: longint);
         false: (lsw,msw: integer);
      end;

var
   done: boolean;                       {tells if the program should
stop}
   myEvent: eventRecord;                {last event returned in event
loop}
   menuNum,menuItemNum: integer;        {menu number & menu item
number}
   where: integer;                      {where the mouse event
occurred}
   wPtr: grafPortPtr;                   {window where event occurred}
   procedure InitMenus;
   { Initialize the menu bar.                                   }
   var
      height: integer;                  {height of the largest menu}
      menuHand: menuHandle;             {for 'handling' windows}
      s: textPtr;                       {for building menus}
   begin {InitMenus}
   new(s);                              {create the file menu}
   s^ := concat('>> File \N1',chr(return));
   s^ := concat(s^,'--Quit\N256',chr(return));
   s^ := concat(s^,'.',chr(return));
   menuHand := NewMenu(s);
   InsertMenu(menuHand,0);
   height := FixMenuBar;                {draw the completed menu bar}
   DrawMenuBar;
   end; {InitMenus}
   procedure HandleMenu;
   { Handle a menu selection.                                   }
   begin {HandleMenu}
   case menuItemNum of                  {go handle the menu}
      file_Quit:   done := true;
      otherwise:   ;
      end; {case}
   HiliteMenu(false, menuNum);          {unhighlight the menu}
   end; {HandleMenu}
begin {Quit}
StartDesk(640);
InitMenus;                              {set up the menu bar}
InitCursor;                             {show the cursor}
done := false;                          {main event loop}
repeat
   if GetNextEvent(everyEvent, myEvent) then
      if myEvent.eventWhat = mouseDownEvt then begin
         with myEvent.eventWhere do
            where := FindWindow(wPtr, h, v);
         if where = wInMenuBar then begin
            MenuSelect(myEvent, nil);
            menuNum := long(myEvent.taskData).msw;
            menuItemNum := long(myEvent.taskData).lsw;
            if menuItemNum <> 0 then
               HandleMenu;
            end; {if}
         end; {if}
until done;
EndDesk;
end.
0
Reply limtc 6/1/2008 4:20:58 AM

What would be interesting for you is find and buy the Programmer's
introduction to the Apple IIgs by Apple (ISBN 0-201-17745-5)

Another interesting book is Toolbox programming in Pascal:
http://store.syndicomm.com/index.php?main_page=product_info&cPath=4&products_id=196

Regards,

antoine
0
Reply Toinet 6/1/2008 10:14:58 AM

I think they are a little too complex... I am trying to see whether it
is possible to simplify it to such a way that we can at least do a
menu bar without the complexity. Well you know, I am trying to teach
an 8 years old.

On 6=D4=C21=C8=D5, =CF=C2=CE=E76=CA=B114=B7=D6, Toinet <antoine.vig...@lapos=
te.net> wrote:
> What would be interesting for you is find and buy the Programmer's
> introduction to the Apple IIgs by Apple (ISBN 0-201-17745-5)
>
> Another interesting book is Toolbox programming in Pascal:http://store.syn=
dicomm.com/index.php?main_page=3Dproduct_info&cPath=3D4&p...
>
> Regards,
>
> antoine

0
Reply limtc 6/6/2008 4:10:33 PM

4 Replies
782 Views

(page loaded in 0.115 seconds)

Similiar Articles:













7/21/2012 7:46:01 PM


Reply: