TweetFollow Us on Twitter

Detect Multifinder
Volume Number:6
Issue Number:3
Column Tag:TechNotes

Related Info: OS Utilities

Detecting MultiFinder

By Paul Davis, Dunedin, New Zealand

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

Detecting MultiFinder from THINK Pascal

I am currently engaged in researching Mac language technology for the application of expert systems to the finance industry. I’ve been involved in IBM PC software since 1983, and managed the company which developed and released Pertmaster Advance, a project management package, on that platform. Since buying my first 128k Mac I’ve been interested in the potential of the Mac. With the release of the Mac II, I began working with Mac software full time.

I am convinced that OOP is here to stay, and using THINK Pascal V2.0 to explore it. After a brief exposure to MacApp I started writing a smaller MultiFinder friendly OOP application shell I’m calling MiniMac, working from the Apple demo programs OOPTextEdit and Events, the class structures of Coral LISP, Prograph, and SmallTalk; and any other Mac system class structures I can find.

While doing this, I noticed that it is useful when trying to decide how to deal with DA’s and activate events to be able to tell if MultiFinder is running, and not just if _WaitNextEvent is implemented as Apple DTS seems to think. If MultiFinder is running you can depend on resume, suspend and mouse-moved events. With just Finder running you have to use some other scheme to handle the cursor and detect whether an activate involves scrap conversion.

Noticing that one of the tech notes mentions that mouse-moved events are received as long as the mouse is outside the cursorRgn provided in a WaitNextEvent call, I wrote the following small routine. For my purposes it works beautifully.

By the way, you have to compile it into a standalone application to try it, THINK never passes my applications any app4 events while running under MultiFinder. I’ve tried it and it works great on my system: MacSE with 2.5Mb Ram, Radius 68020,68881 and TPD, System Software 6.0.3.

Explanation of the Code:

Multifinder test: hasWaitNextEvent is a boolean function set by the normal checking of the _WaitNextEvent trap described in Tech Notes and repeated below. If it is not true then MultiFinder couldn’t be running anyway. If WNE is implemented then I create a new region, which according to Inside Mac is set to a (0,0,0,0) rectangle. The mouse couldn’t be in there, so I do WNE’s with that region for kTries times or until I get an App4 (MultiFinder) event. I found that on my system I receive 4 null events before I get an App4 event so kTries of 10 works fine. You may need to experiment for an absolutely safe number of tries.

Shortcomings: You lose the first kTries events when your application is launched. This shouldn’t be critical, as applications generally flush the event queue anyway. Hasn’t been a problem for me anyway. You probably should use this routine before you put up any windows or other screen items so you don’t lose any update or activate events.

{1}

function multiFinderTest: Boolean;
{ a little event loop to test for MF }
{ if MF is running we are sure to get }
{ mouse-moved events with a tiny region }
  const
    kTries = 10;
{ number of events to check for mouse event }
  var
    mouseRgn: RgnHandle;
    count: Integer;
    gotEvent: Boolean;
    theEvent: EventRecord;
  begin
    multiFinderTest := False;
    { assume false }
    if hasWaitNextEvent then
    { otherwise always false }
      begin
        debugBanner(‘has WaitNextEvent’);
        gotEvent := False;
        count := 1;
        mouseRgn := NewRgn;
        { should be empty region (0,0,0,0) }
        while (gotEvent = False) and 
              (count < kTries) do
          begin
            gotEvent := WaitNextEvent(        
           EveryEvent, theEvent, 0, mouseRgn);
            if theEvent.what = app4Evt then
              multiFinderTest := True;
            count := count + 1;
          end;
        DisposeRgn(mouseRgn);
      end;
  end; { multiFinderTest }

Since THINK won’t give you MultiFinder events you have to have a way to check on what is going on from outside the THINK environment. The following routine displays a little box with a message in it without messing up the event queue or MultiFinder levels like an alert did. In the above routine I insert a:

{2}

debugBanner(StringOf(‘MultiFinder found after ‘,count,’ tries.’));

in the innermost if. This routine requires a WIND resource of convenient size and I use a proc of 2 though others would do. You can also use it to check the type of events coming through and debug your detection of mouse moved, resume, suspend and scrap convert events in the main event loop, none of which come through THINK. The {$R+-} is to disable/enable range checking to use the string as an array.

{3}

procedure debugBanner (msg: Str255);
  const
    numTicks = 1 * 60; { seconds * ticks/sec }
    kResWIND128 = 128; { WIND resource }
  var
    discard: LongInt;
    banner: WindowPtr;
    oldPort: GrafPtr;
    lineWidth: Integer;
  begin
    GetPort(oldPort);
    banner := GetNewWindow(kResWIND128, nil, 
                           Pointer(-1));
    if banner <> nil then
      begin
        ShowWindow(banner);
        { make the window visible }
        SetPort(banner);
        PenNormal;
        ClipRect(banner^.portRect);
{$R-}
        lineWidth := TextWidth(QDPtr(@msg[1]), 
                          0, Integer(msg[0]));
{$R+}
        with banner^.portRect do
          MoveTo(((right - left) - lineWidth) 
                div 2, (bottom - top) div 2);
{$R-}
        DrawText(QDPtr(@msg[1]), 0, 
                 Integer(msg[0]));
{$R+}
        Delay(numTicks, discard);
        { wait a while }
        DisposeWindow(banner);
        { get rid of window }
      end;
    SetPort(oldPort);
  end; { debugBanner }

Finally, for those who aren’t sure how to test for WNE, I include the following:

{4}

function hasWaitNextEvent: Boolean;
{ determines if hardware has WNE trap }
  const
    kVersRequested = 2;    { as of 6.0.1 }
    kWaitNextEventTrap = $A860;
    { trap address for WaitNextEvent }

{ system error constants that are missing }
{ from THINK interface }
    envBadVers = -5501;
    envVersTooBig = -5502;

  type
    pInteger = ^Integer;

  var
    result: OSErr;
    theRec: SysEnvRec;
    theRecPtr: ^SysEnvRec;

  function GetTrapType (theTrap: Integer)
                       :TrapType;
    const
      kOSTrapMask = $0F00; 
{ OS traps start with A0, Tool with A8 or AA.}
    begin
      if BAND(theTrap, $0F00) = 0 then
        GetTrapType := OSTrap
      else
        GetTrapType := ToolTrap;
    end; {GetTrapType}

  function TrapExists (theTrap: Integer)
                      : Boolean;
    const
      kUnimplementedTrap = $A89F;
      { unimplemented trap value }
    begin
      TrapExists := GetTrapAddress(kUnimplementedTrap)
         <> NGetTrapAddress(
      theTrap,GetTrapType(theTrap)
      );
    end; {TrapExists}

  begin
    hasWaitNextEvent := False;
    theRecPtr := @theRec;
    result := SysEnvirons(kVersRequested, 
                          theRecPtr^);
    with theRec do
      case result of
        envNotPresent: 
          debugBanner(’64k ROMS’);
        envBadVers: 
          debugBanner(‘negative version number 
                       passed SysEnvirons’);
        envVersTooBig, noErr: 
          begin 
   { good environs call, fill related fields }
            if machineType > envMac then
              hasWaitNextEvent := 
               TrapExists(kWaitNextEventTrap);
          end;
      end; { case }
  end; { hasWaitNextEvent }

The above routines are incorporated in a small application which calls MultiFinderTest and then displays whether finder is running or not:

{5}

program test;
  var
    multiFinderIsRunning: Boolean;

begin
  multiFinderIsRunning := multiFinderTest;
  if multiFinderIsRunning then
    debugBanner(‘multiFinder running’)
  else
    debugBanner(‘multiFinder not running’);

end. { test }

That about sums it up. Let me know if this doesn’t work in any other environments.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »
Play Together teams up with Sanrio to br...
I was quite surprised to learn that the massive social network game Play Together had never collaborated with the globally popular Sanrio IP, it seems like the perfect team. Well, this glaring omission has now been rectified, as that instantly... | Read more »
Dark and Darker Mobile gets a new teaser...
Bluehole Studio and KRAFTON have released a new teaser trailer for their upcoming loot extravaganza Dark and Darker Mobile. Alongside this look into the underside of treasure hunting, we have received a few pieces of information about gameplay... | Read more »

Price Scanner via MacPrices.net

14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more
B&H has 16-inch MacBook Pros on sale for...
Apple 16″ MacBook Pros with M3 Pro and M3 Max CPUs are in stock and on sale today for $200-$300 off MSRP at B&H Photo. Their prices are among the lowest currently available for these models. B... Read more
Updated Mac Desktop Price Trackers
Our Apple award-winning Mac desktop price trackers are the best place to look for the lowest prices and latest sales on all the latest computers. Scan our price trackers for the latest information on... Read more
9th-generation iPads on sale for $80 off MSRP...
Best Buy has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80 off MSRP on their online store for a limited time. Prices start at only $249. Sale prices for online orders only, in-store prices... Read more
15-inch M3 MacBook Airs on sale for $100 off...
Best Buy has Apple 15″ MacBook Airs with M3 CPUs on sale for $100 off MSRP on their online store. Prices valid for online orders only, in-store prices may vary. Order online and choose free shipping... Read more

Jobs Board

Sublease Associate Optometrist- *Apple* Val...
Sublease Associate Optometrist- Apple Valley, CA- Target Optical Date: Mar 22, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92307 **Requisition Read more
Early Preschool Teacher - Glenda Drive/ *Appl...
Early Preschool Teacher - Glenda Drive/ Apple ValleyTeacher Share by Email Share on LinkedIn Share on Twitter Read more
Retail Assistant Manager- *Apple* Blossom Ma...
Retail Assistant Manager- APPLE BLOSSOM MALL Brand: Bath & Body Works Location: Winchester, VA, US Location Type: On-site Job ID: 04225 Job Area: Store: Management Read more
Housekeeper, *Apple* Valley Village - Cassi...
Apple Valley Village Health Care Center, a senior care campus, is hiring a Part-Time Housekeeper to join our team! We will train you for this position! In this role, Read more
Sonographer - *Apple* Hill Imaging Center -...
Sonographer - Apple Hill Imaging Center - Evenings Location: York Hospital, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now See Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.