TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Johan Siegers
from: Peter Fitzsimmons
date: 1995-05-10 00:17:14
subject: Hooks 2/3

[init.asm -- masm 5 -----------------------------------------------------]

     .386

 _TEXT segment dword public use32 'CODE'
     assume  cs:_TEXT

 extrn DllInit:PROC

 Init proc near
     jmp DllInit
 Init endp

 _TEXT ends

 end Init

[ghook.c ----------------------------------------------------------------]

 #define INCL_WIN
 #define INCL_DOS
 #include 

 static HAB ghab = 0;
 static int ghm = 0;


 BOOL EXPENTRY InputHook(HAB hab, PQMSG pQmsg, USHORT fs)
 {

     if(pQmsg->msg == WM_USER + 0x848){ // this user message should really
                                        // be an atom!
         HWND hwndSysMenu;
         MENUITEM mi;
         HWND hwnd = pQmsg->hwnd;

         hwndSysMenu = WinWindowFromID(hwnd, FID_SYSMENU);
         if(!hwndSysMenu)
             return 0;
         mi.iPosition   = MIT_END;
         mi.afStyle     = MIS_TEXT | MIS_SYSCOMMAND;
         mi.afAttribute = 0;
         mi.id          = SC_CLOSE;
         mi.hwndSubMenu = 0;
         mi.hItem       = 0;

         WinSendMsg(hwndSysMenu, MM_INSERTITEM, (MPARAM)&mi, "Close");

         WinSendMsg(hwnd, WM_UPDATEFRAME, (MPARAM)FCF_SYSMENU, NULL);
         DosBeep(2000, 50);  // this let's us know it is working -- remove.
         return TRUE;        /* do not pass to next hook proc */
     }
     return 0;
 }

 VOID EXPENTRY SendMsgHook(HAB hab, PSMHSTRUCT psmh, BOOL fInterTask)
 {
     PCREATESTRUCT pCrs;
     PFRAMECDATA   fcd;

     if(psmh->msg != WM_CREATE)
         return;     // not creating a window

     pCrs =  (PCREATESTRUCT)psmh->mp2;
     if(pCrs->pszClass != WC_FRAME)
         return;     // not a frame.

     fcd = (PFRAMECDATA)psmh->mp1;
     if(!fcd || !(fcd->flCreateFlags & FCF_TITLEBAR))
         return;     // no title bar

     if(!(fcd->flCreateFlags & FCF_SYSMENU))
         return;     // no sys menu

     // Post a message so that it is received (above in the input hook)
     // after the whole frame has been created.
     WinPostMsg(psmh->hwnd, WM_USER + 0x848, 0, 0);
 }

 void APIENTRY CleanUp(void)
 {
     WinReleaseHook(ghab, NULLHANDLE, HK_SENDMSG, (PFN)SendMsgHook, ghm);
     WinReleaseHook(ghab, NULLHANDLE, HK_INPUT, (PFN)InputHook, ghm);
     DosExitList(EXLST_EXIT, NULL);
 }


 static int Main(void)
 {
     if( !(ghab = WinInitialize(0)) )
         return FALSE;

     if(!WinSetHook(ghab, NULLHANDLE, HK_SENDMSG, (PFN)SendMsgHook, ghm))
         return FALSE;

     if(!WinSetHook(ghab, NULLHANDLE, HK_INPUT, (PFN)InputHook, ghm))
         return FALSE;

     return TRUE;
 }

 int DllInit(unsigned hmod, unsigned termflag )
 {
     if(termflag == 0){
         ghm = hmod;
         DosExitList(EXLST_ADD, (PFNEXITLIST)CleanUp);
         DosBeep(4000, 200);
         return Main();
     }
     return 1;
 }

--- Maximus/2 2.02p1
* Origin: Sol 3/Toronto (905)858-8488 (1:259/414)
SEEN-BY: 105/42 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 259/414 400 99 250/702 3615/50 396/1 270/101 105/103 42 712/515
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.