home *** CD-ROM | disk | FTP | other *** search
/ The Mother of All Windows Books / CD-MOM.iso / cd_mom / newsletr / vbz / vbz1-3 / dll_src.exe / MWATCH.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-25  |  5KB  |  174 lines

  1. library MWatch;
  2. {DLL to Support Status bar help in Visual Basic}
  3. {Copyright 1993 Jonathan Zuck & User Friendly, Inc.}
  4.  
  5. {$C Fixed Permanent}
  6. {$R MWATCH}
  7.  
  8. uses WinTypes, WinProcs, VBAPI2;
  9.  
  10. type
  11.     WinInfo = Record
  12.        hWatch:hWnd;
  13.        hTell:hWnd;
  14.     Old:hWnd;
  15.     DefProc:TFarProc;
  16.   end;
  17.  
  18. var
  19.   WinArray: array [1..1024] of WinInfo;
  20.   TWins:Integer;
  21.   SaveExit:Pointer;
  22.   Menu:Integer;
  23.   PopUp:Bool;
  24.  
  25. function Wnd2El (Wnd:HWND):Integer;
  26.     Var
  27.       El:Integer;
  28.     Match:Bool;
  29.     Begin
  30.       El := 0;
  31.     Match := FALSE;
  32.     While (Match = FALSE) do
  33.         Begin
  34.           Inc (El);
  35.         if (WinArray[El].hWatch = Wnd) then Match := TRUE;
  36.       end;
  37.     Wnd2El := El;
  38.   end;
  39.  
  40. procedure RemoveEl (El:Integer);
  41.     Begin
  42.       SetWindowLong (WinArray[El].hWatch, GWL_WNDPROC, LongInt (WinArray[El].DefProc));
  43.        Move (WinArray[El + 1].hWatch, WinArray[El].hWatch,
  44.           SizeOf (WinInfo) * (TWins - El));
  45.     Dec (TWins);
  46.     end;
  47.  
  48.  
  49. function FrameProc (Wnd:HWND; Msg, wParam:WORD; lParam:Longint):longint;export;
  50.     var
  51.       El:Integer;
  52.  
  53.     begin
  54.         El := Wnd2El(Wnd);
  55.     if (Msg = WM_DESTROY) then
  56.         Begin
  57.                FrameProc := CallWindowProc (WinArray[El].DefProc, Wnd, Msg, wParam, lParam);
  58.             RemoveEl (El);
  59.       end
  60.       else
  61.         Case (Msg) of
  62.             WM_SETCURSOR:
  63.           Begin
  64.                      FrameProc := CallWindowProc (WinArray[El].DefProc, Wnd, Msg, wParam, lParam);
  65.                  if WinArray[El].Old <> wParam then
  66.                 Begin
  67.                       SendMessage (WinArray[El].hTell, WM_KEYDOWN, wParam, 0);
  68.                         WinArray[El].Old := wParam;
  69.               end;
  70.           end;
  71.          WM_MENUSELECT:
  72.               Begin
  73.                   WinArray[El].Old := 0;
  74.                    if (Integer (LoWord(lParam)) <> -1)  And
  75.                      Bool(Not Bool((LoWord(lParam) And MF_SYSMENU))) then
  76.                     Begin
  77.                     if Bool (LoWord(lParam) And MF_POPUP)
  78.                         then PopUp := True
  79.                     else
  80.                         PopUp := False;
  81.                         Menu := HiWord(lParam);
  82.                           SendMessage (WinArray[El].hTell, WM_KEYDOWN, -1 * wParam, 0);
  83.                   end;
  84.                          FrameProc := CallWindowProc (WinArray[El].DefProc, Wnd, Msg, wParam, lParam);
  85.               end;
  86.          Else
  87.                      FrameProc := CallWindowProc (WinArray[El].DefProc, Wnd, Msg, wParam, lParam);
  88.         end;
  89.     end;
  90.  
  91. procedure StartMouseWatch (hWatch, hTell:hWnd);export;
  92.   begin
  93.       Inc (TWins);
  94.     WinArray[TWins].hWatch := hWatch;
  95.     WinArray[TWins].hTell := hTell;
  96.     WinArray[TWins].Old := 0;
  97.     WinArray[TWins].DefProc := TFarProc(GetWindowLong (hWatch, GWL_WNDPROC));
  98.     SetWindowLong (hWatch, GWL_WNDPROC, Longint (@FrameProc));
  99.   end;
  100.  
  101. procedure StopMouseWatch (Wnd:hWnd);export;
  102.     Begin
  103.       RemoveEl (Wnd2El (Wnd));
  104.   end;
  105.  
  106. function HWndTag (Wnd:HWND):HLSTR;export;
  107. Var
  108.   StdPropIndex:Integer;
  109.   TempHsz:HSZ;
  110.   CtlTemp:HCTL;
  111.   TempStr:PChar;
  112.  
  113. Begin
  114.   CtlTemp := VBGetHwndControl (Wnd);
  115.   if CtlTemp = nil then CtlTemp := VBGetHwndControl (GetParent (Wnd));
  116.   StdPropIndex := GetStdPropIndex(CtlTemp, IPROP_STD_TAG);
  117.   VBGetControlProperty (CtlTemp, StdPropIndex, @TempHsz);
  118.   TempStr := VBLockHsz (TempHsz);
  119.   HWndTag := VBCreateHlStr (TempStr, lstrlen(TempStr));
  120.   VBUnLockHsz (TempHsz);
  121.   VBDestroyHsz (TempHsz);
  122. end;
  123.  
  124. function HWndCtlName (Wnd:HWND):HLSTR;export;
  125. Var
  126.   Buff: array [0..40] of Byte;
  127.   CtlTemp:HCTL;
  128. Begin
  129.     CtlTemp := VBGetHwndControl (Wnd);
  130.   if CtlTemp = nil then CtlTemp := VBGetHwndControl (GetParent (Wnd));
  131.     VBGetControlName (CtlTemp, @Buff);
  132.     HWndCtlName := VBCreateHlStr (@Buff, lstrlen (@Buff));
  133. end;
  134.  
  135.  
  136. function MenuCaption (MenuID:Integer):HLSTR;export;
  137. Var
  138.     Buff: array [0..40] of Byte;
  139.   i: Integer;
  140. Begin
  141.     if PopUp then
  142.       Begin
  143.         i := 0;
  144.       while GetSubMenu (Menu, i) <> MenuID do Inc (i);
  145.           GetMenuString (Menu, i, @Buff, 40, MF_BYPOSITION);
  146.     end
  147.   else
  148.      GetMenuString (Menu, MenuID, @Buff, 40, MF_BYCOMMAND);
  149.      MenuCaption := VBCreateHlStr (@Buff, lstrlen (@Buff));
  150. end;
  151.  
  152. procedure LibExit; far;
  153.  var
  154.        El:Integer;
  155.  begin
  156.        For El := 1 to TWins do
  157.           SetWindowLong (WinArray[El].hWatch, GWL_WNDPROC, LongInt(WinArray[El].DefProc));
  158.         ExitProc := SaveExit;
  159.     end;
  160.  
  161. Exports
  162.   FrameProc,
  163.   StartMouseWatch resident,
  164.   StopMouseWatch resident,
  165.   HWndTag resident,
  166.   HWndCtlName resident,
  167.   MenuCaption resident;
  168.  
  169. begin
  170.   TWins := 0;
  171.   SaveExit := ExitProc;
  172.   ExitProc := @LibExit;
  173. end.
  174.