home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wpsprg.zip / WPSPRG
Text File  |  1993-05-19  |  61KB  |  2,212 lines

  1.  #--------------------------------------------------------------------------
  2.  # Program name:  Find1.csc      Title: WPS Programming using Mult Proc.
  3.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  4.  #
  5.  # Article:  "Workplace Shell Programming using Multiple Processes"
  6.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  7.  # Phone:  n/a                   Fax:  n/a
  8.  #
  9.  # Description:  The following is a component of the complete source to the
  10.  # above article in the specified issue of OS/2 Developer Magazine.  This
  11.  # source is provided AS-IS without any implied or expressed warranty.
  12.  #
  13.  #--------------------------------------------------------------------------
  14. ##
  15. ## CLASS: Find
  16. ##
  17. ## CLASS HIERARCHY:
  18. ##      SOMObject
  19. ##         WPObject
  20. ##           WPAbstract
  21. ##             Find
  22. ## DESCRIPTION:
  23. ##    This is the find object class.
  24. ##    An instance of this class can be created as a
  25. Workplace
  26. ##    object.
  27. ##
  28. ##
  29. include <wpabs.sc>
  30.  
  31. class: Find,
  32.         external stem = find,
  33.         local,
  34.         external prefix = find_,
  35.         classprefix     = findM_,
  36.         major version = 1,
  37.         minor version = 1;
  38.  
  39. parent: WPAbstract;
  40. passthru: C.h, after;
  41.     #define DebugBo(title, text) \
  42.          WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  43. (PSZ) text , \
  44.                       (PSZ) title, 20, MB_OK │ MB_INFORMATION )
  45. endpassthru;
  46. data:
  47.  HAB          hab;
  48.  HMQ          hmq;
  49.  QMSG         qmsg;
  50.  HWND         Frame;
  51.  
  52. methods:
  53.         override wpInitData;
  54.         override wpDelete;
  55.         override wpModifyPopupMenu;
  56.         override wpMenuItemSelected;
  57.  
  58.  #--------------------------------------------------------------------------
  59.  # Program name:  Find1.mak      Title: WPS Programming using Mult Proc.
  60.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  61.  #
  62.  # Article:  "Workplace Shell Programming using Multiple Processes"
  63.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  64.  # Phone:  n/a                   Fax:  n/a
  65.  #
  66.  # Description:  The following is a component of the complete source to the
  67.  # above article in the specified issue of OS/2 Developer Magazine.  This
  68.  # source is provided AS-IS without any implied or expressed warranty.
  69.  #
  70.  #    To Compile:
  71.  #         C:\FIND>nmake -f find.mak all
  72.  #--------------------------------------------------------------------------
  73.  
  74. #*******************************************
  75. #  Dot directive definition area (usually just suffixes)
  76. #*******************************************
  77.  
  78.  .SUFFIXES: .c .obj .dll .csc .sc .h .ih .ph .psc .rc .res
  79.  
  80. #*******************************************
  81. *******
  82. #  Environment Setup for the component(s).
  83. #*******************************************
  84. *******
  85.  
  86. SOMTEMP=.\somtemp
  87. SCPATH  = d:\toolkt20\sc
  88. HPATH   =d:\toolkt20\c\os2h
  89. LIBPATH =d:\toolkt20\os2lib
  90.  
  91. !if ¢set SMINCLUDE=.;$(SCPATH);| ││ \
  92.     ¢set SMTMP=$(SOMTEMP)| ││ \
  93.     ¢set SMEMIT=ih;h;ph;psc;sc;c|
  94. !endif
  95.  
  96. !if ¢cd $(SOMTEMP)|
  97. !  if ¢md $(SOMTEMP)|
  98. !    error error creating $(SOMTEMP) directory
  99. !  endif
  100. !else
  101. !  if ¢cd ..|
  102. !    error - Couldn't cd .. from $(SOMTEMP) directory
  103. !  endif
  104. !endif
  105.  
  106. #
  107. # Compiler/tools Macros
  108. #
  109.  
  110. CC      = icc /c /Ge- /Gd- /Se /Sp2 /Re /Kb /ss /Ms /Gm+
  111. LINK    = link386
  112. LDFLAGS = /noi /map /nol /nod /exepack /packcode
  113. /packdata /align:16
  114. LIBS    = som.lib os2386.lib dde4mbs.lib dde4nbs.lib
  115.  
  116. #*******************************************
  117. *******
  118. # Set up Macros that will contain all the different
  119. # dependencies for the executables and dlls etc. that
  120. # are generated.
  121. #*******************************************
  122. *******
  123.  
  124. OBJS       =  find.obj finddlg.obj initterm.obj
  125.  
  126. #*******************************************
  127. *******
  128. #   Setup the inference rules for compiling source code
  129. to
  130. #   object code.
  131. #*******************************************
  132. *******
  133.  
  134.  .c.obj:
  135.         $(CC) -I$(HPATH) -c $<
  136.  
  137.  .csc.ih:
  138.         sc -v -r $*.csc
  139.  
  140. all: find.ih find.dll
  141.  
  142. #
  143. # Specific Process Tag
  144. #
  145.  
  146. find.ih:   $*.csc $(HPATH)\wpdataf.h
  147.  
  148. find.obj: $*.ih $*.c $*.h  $*.sc $(HPATH)\wpdataf.h
  149.  
  150. findlg.obj: $*.c $*.h
  151.  
  152. find.dll: $*.def $(OBJS) find.res
  153.          $(LINK) $(LDFLAGS) $(OBJS),$@,,$(LIBS),$*;
  154.          rc $*.res $*.dll
  155.          mapsym find.map
  156.          implib find.lib find.def
  157.  
  158. find.res: find.rc
  159.           rc -r $*.rc $*.res
  160.  
  161. #INCLUDES -C=ih
  162.  
  163.  #--------------------------------------------------------------------------
  164.  # Program name:  Find1.C        Title: WPS Programming using Mult Proc.
  165.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  166.  #
  167.  # Article:  "Workplace Shell Programming using Multiple Processes"
  168.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  169.  # Phone:  n/a                   Fax:  n/a
  170.  #
  171.  # Description:  The following is a component of the complete source to the
  172.  # above article in the specified issue of OS/2 Developer Magazine.  This
  173.  # source is provided AS-IS without any implied or expressed warranty.
  174.  #
  175.  #--------------------------------------------------------------------------
  176. /********************************************
  177. ******
  178.  * NAME: find.c
  179.  *
  180.  * DESCRIPTION:
  181.  *
  182.  * Copyright (c) 1991                        IBM Corporation
  183. \********************************************
  184. ******/
  185.  
  186. #define Find_Class_Source
  187.  
  188. #define INCL_GPI                    /* Selectively include
  189. */
  190. #define INCL_WINFRAMEMGR            /* Frame-manager
  191. function       */
  192. #define INCL_WINSYS                 /* System value & color
  193. function*/
  194. #define INCL_WINERRORS              /* WIN functions error
  195. constants*/
  196. #define INCL_WINDIALOGS             /* Dialog-box
  197. functions         */
  198. #define INCL_WINMESSAGEMGR          /* Message-Mgr.
  199. functions       */
  200. #define INCL_DOSPROCESS             /* Process & thread
  201. support func*/
  202. #define INCL_WIN
  203. #define INCL_DOS
  204. #define INCL_GPIBITMAPS
  205. #define INCL_WPCLASS
  206. #define INCL_WPOBJECT
  207.  
  208. #include <os2.h>
  209. #include <pmwp.h>  /* eventually will be #define
  210. INCL_WINWORKPLACE */
  211.  
  212.  
  213. #include "finddef.h"
  214. #include "find.ih"
  215. #include "find.ph"
  216. #include "finddat.h"
  217.  
  218.  
  219. extern VOID     SOMLINK SOMInitModule( VOID );
  220. extern int      InitializeFind(VOID);
  221. extern BOOL     Findmain(Find *,int,char **);
  222.  
  223.  
  224. /***SOMEXTERN int SOM_TraceLevel = 1; ***/
  225.  
  226. /*-------------------------------------------------
  227. * NAME: SOMInitModule( VOID )
  228. *
  229. * DESCRIPTION:
  230. *  This is the class initialization entry point.
  231. *  This routine will be called during the module
  232. initialization.
  233. *  Applications must add a call to initialize each object
  234. class being
  235. *  furing in the module.  The class initialization call is in
  236. the
  237. *   format:
  238. *
  239. *  <ClassName>NewClass(integer4 majorVersion,
  240. integer4minorVersion)
  241. *
  242. *  where <ClassName> is the name of the new class being
  243. defined.
  244. *
  245. * NOTES:
  246. *  Do NOT call any methods on any of the classes being
  247. instanciated
  248. *  during the processing of SOMInitModule().
  249. *
  250. *  SOMInitModule must be exported in the module
  251. definition file (.DEF)
  252. *  in the format:
  253. *
  254. *      EXPORTS
  255. *          _SOMInitModule
  256. *
  257. \*-------------------------------------------------
  258. */
  259. VOID SOMLINK SOMInitModule()
  260. {
  261.    FindNewClass(Find_MajorVersion,Find_MinorVersion);
  262. }
  263.  
  264.  
  265. int InitializeFind()
  266. {CHAR   ErrorBuffer¢100|;
  267.  
  268.   if (DosLoadModule((PSZ) ErrorBuffer,
  269.                      sizeof(ErrorBuffer),
  270.                     "FIND", &hmodule) )
  271.       return FALSE;
  272.   FindIcon = WinLoadPointer( HWND_DESKTOP, hmodule,
  273. 101 );
  274.   if (FindIcon==(HPOINTER)0)
  275.       DebugBox("FAILURE","!!!load Icon failed");    
  276.  return TRUE;
  277. }
  278.  
  279. /*-------------------------------------------------
  280.  *
  281.  *  OVERRIDE: wpInitData
  282.  *
  283.  *  PURPOSE:
  284.  *    Initialize our state variables. Allocate any extra
  285. memory that
  286.  *    we might need.
  287.  *
  288. ---------------------------------------------------
  289. */
  290. #undef SOM_CurrentClass
  291. #define SOM_CurrentClass SOMInstance
  292. SOM_Scope void   SOMLINK find_wpInitData(Find
  293. *somSelf)
  294. {
  295.  
  296.     /*FindData *somThis = FindGetData(somSelf); */
  297.     FindMethodDebug("Find","Find_wpInitData");
  298.  
  299.     parent_wpInitData(somSelf);
  300.     if (FindIcon)
  301.        _wpSetIcon(somSelf,FindIcon);
  302.     argc   = 1;
  303.     argv¢0|="find";
  304.  
  305.     Findmain(somSelf,1,argv);
  306. }
  307.  
  308.  
  309. SOM_Scope BOOL   SOMLINK
  310. find_wpModifyPopupMenu(Find *somSelf,
  311.                                                 HWND hwndMenu,
  312.                                                 HWND hwndCnr,
  313.                                                 ULONG iPosition)
  314. {
  315.     /* FindData *somThis = FindGetData(somSelf); */
  316.     FindMethodDebug("Find","find_wpModifyPopupMenu");
  317.  
  318.     _wpInsertPopupMenuItems(somSelf,        /*this cases
  319. adds to menu*/
  320.                             hwndMenu,
  321.                             iPosition,
  322.                             hmodule,
  323.                             RC_IDD_FINDMENU,
  324.                             0);
  325.    return
  326. (parent_wpModifyPopupMenu(somSelf,hwndMenu,hwndCnr
  327. ,
  328.                                     iPosition));
  329. }
  330.  
  331.  
  332. SOM_Scope BOOL   SOMLINK
  333. find_wpMenuItemSelected(Find *somSelf,
  334.                                                  HWND hwndFrame,
  335.                                                  ULONG MenuId)
  336. {FindData *somThis = FindGetData(somSelf);
  337. /*required*/
  338.  
  339.  
  340.     FindMethodDebug("Find","find_wpMenuItemSelected");
  341.  
  342.     switch (MenuId) {
  343.        case RC_MI_FIND:
  344.              WinPostMsg(_Frame,WM_COMMAND,
  345.                      (MPARAM)MAKEULONG(FIND,FIND),
  346.                      (MPARAM)0L);
  347.               break;
  348.         default:
  349.  
  350. return(parent_wpMenuItemSelected(somSelf,hwndFrame,
  351. MenuId));
  352.       }
  353.   return(TRUE);
  354. }
  355.  
  356.  
  357. SOM_Scope ULONG   SOMLINK find_wpDelete(Find
  358. *somSelf,
  359.                                         ULONG fConfirmations)
  360. {
  361.     FindData *somThis = FindGetData(somSelf);
  362.     FindMethodDebug("Find","find_wpDelete");
  363.  
  364.     WinPostMsg(_Frame,WM_QUIT,(MPARAM)0,
  365. (MPARAM)0);   /*For
  366. Now Okay*/
  367.     return (parent_wpDelete(somSelf,fConfirmations));
  368. }
  369.  
  370.  #--------------------------------------------------------------------------
  371.  # Program name:  Finddlg1.C     Title: WPS Programming using Mult Proc.
  372.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  373.  #
  374.  # Article:  "Workplace Shell Programming using Multiple Processes"
  375.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  376.  # Phone:  n/a                   Fax:  n/a
  377.  #
  378.  # Description:  The following is a component of the complete source to the
  379.  # above article in the specified issue of OS/2 Developer Magazine.  This
  380.  # source is provided AS-IS without any implied or expressed warranty.
  381.  #
  382.  #--------------------------------------------------------------------------
  383. /********************************************
  384. ******
  385.  * NAME: finddlg.c
  386.  *
  387.  * DESCRIPTION:
  388.  *
  389.  * Copyright (c) 1991 IBM Corporation
  390. *********************************************
  391. ******/
  392. #define INCL_GPI                        /* Selectively include
  393. */
  394. #define INCL_WIN                        /* Selectively include
  395. */
  396. #define INCL_DOS
  397.  
  398. #include <os2.h>
  399. #include <stdio.h>
  400. #include <stdlib.h>
  401. #include <string.h>
  402. #include "finddef.h"
  403. #include "finddat.h"
  404.  
  405. #include "find.ih"
  406.  
  407.  
  408. extern void  FindString(char *filename_p,
  409.                        char *string,
  410.                        unsigned fileattr,
  411.                        HWND list);
  412. extern void  SearchFile(char *filename,char
  413. *string,HWND list);
  414. extern void _Optlink ObjectWindowThread(void *arg);
  415.  
  416. extern MRESULT EXPENTRY DialogProc(HWND   hwndDlg,
  417.                                    USHORT msg,
  418.                                    MPARAM pm1,
  419.                                    MPARAM pm2);
  420. extern MRESULT EXPENTRY ObjectWndProc(
  421.                                       HWND   hWnd,
  422.                                       USHORT msg,
  423.                                       MPARAM pm1,
  424.                                       MPARAM pm2);
  425.  
  426.  
  427. void  SearchFile(
  428.     char          *filename,
  429.     char          *string,
  430.     HWND           list)
  431. {FILE *fp;
  432.  char buffer¢256|;
  433.  char data¢256|;
  434.  char *p;
  435.  BOOL flag=1;
  436.  
  437.  if ( (fp=fopen(filename,"r"))==(FILE *)0)
  438.     return;
  439.  
  440.  while (!feof(fp)){
  441.        fgets(buffer,256,fp);
  442.        if ((p=strchr(buffer,'\n'))!=(char *)0)
  443.            *p=0;
  444.        if (strstr(buffer,string)!=(char *)0)
  445.          {
  446.           if (flag)
  447.              {
  448.               sprintf(data,"####%s####",filename);
  449.               WinSendMsg(list,
  450.                          (ULONG)LM_INSERTITEM,
  451.                          (MPARAM)LIT_END,
  452.                          (MPARAM)data);
  453.               flag=0;
  454.              }
  455.           WinSendMsg(list,
  456.                      (ULONG)LM_INSERTITEM,
  457.                      (MPARAM)LIT_END,
  458.                      (MPARAM)buffer);
  459.          }
  460.  }
  461.  fclose(fp);
  462. }
  463.  
  464. void FindString(
  465.     char          *filename_p,
  466.     char          *string,
  467.     unsigned       fileattr,
  468.     HWND           list)
  469.  
  470. {HDIR            dirhandle=0xFFFF;
  471.  FILEFINDBUF3    resultbuf;
  472.  ULONG           lcount=1;
  473.  char            *p;
  474.  char             buffer¢256|;
  475.  char             path¢256|;
  476.  
  477.  
  478.  strcpy(path,filename_p);
  479.  if ( (p=strrchr(path,'\\'))!=(char *)0)
  480.     *(++p)=0;
  481.  if (p==(char *)0)
  482.    if ( (p=strchr(path,':'))!=(char *)0)
  483.       *(++p)=0;
  484.  
  485.  
  486.  if (DosFindFirst((PSZ)   filename_p,
  487.                   (PHDIR) &dirhandle,
  488.                   (ULONG) fileattr,
  489.                   (PVOID) &resultbuf,
  490.                   (ULONG) sizeof(resultbuf),
  491.                   (PULONG) &lcount,
  492.                   (ULONG) 1)==0)
  493.       {
  494.        do {
  495.           sprintf(buffer,"%s%s",path,resultbuf.achName);
  496.           SearchFile(buffer,string,list);
  497.           }while (DosFindNext((HDIR)  dirhandle,
  498.                               (PVOID) &resultbuf,
  499.                               (ULONG) sizeof(resultbuf),
  500.                               (PULONG) &lcount)==0);
  501.  
  502.  
  503.        DosFindClose(dirhandle);
  504.       }
  505. }
  506.  
  507.  
  508. MRESULT EXPENTRY DialogProc(
  509.        HWND   hwndDlg,
  510.        USHORT msg,
  511.        MPARAM pm1,
  512.        MPARAM pm2)
  513. {char filename¢256|;
  514.  char string¢256|;
  515.  HWND list;
  516.  
  517.   switch (msg) {
  518.      case WM_COMMAND:
  519.           switch (LOUSHORT(pm1)) {
  520.               case IDD_ENTER:
  521.                     list =WinWindowFromID(hwndDlg,IDD_LIST);
  522.                     WinQueryDlgItemText(hwndDlg,
  523.                                         IDD_FILENAME,
  524.                                         255,
  525.                                         (PSZ)filename
  526.                                        );
  527.                     WinQueryDlgItemText(hwndDlg,
  528.                                         IDD_STRING,
  529.                                         255,
  530.                                         (PSZ)string
  531.                                        );
  532.                     FindString(filename,string,(unsigned)0,list);
  533.                     break;
  534.               case IDD_CANCEL:
  535.               default:
  536.                     WinDismissDlg( hwndDlg, FALSE );
  537.                     break;
  538.              }
  539.           break;
  540.      default:
  541.          return(WinDefDlgProc(hwndDlg, msg, pm1, pm2));
  542.     }
  543.   return(MRFROMLONG(NULL));
  544. }
  545.  
  546.  
  547. MRESULT EXPENTRY ObjectWndProc(
  548.              HWND   hWnd,
  549.              USHORT msg,
  550.              MPARAM pm1,
  551.              MPARAM pm2)
  552. {Find     *somSelf;
  553.  FindData *somThis;
  554.  
  555.  
  556.   switch (msg)  {
  557.    case WM_COMMAND:
  558.         somSelf=(Find
  559. *)WinQueryWindowULong(hWnd,QWL_USER);
  560.         somThis = FindGetData(somSelf);
  561.         switch (SHORT1FROMMP(pm1)) {
  562.              case FIND:
  563.                  WinDlgBox((HWND)  HWND_DESKTOP,
  564.                            (HWND)  HWND_DESKTOP,
  565.                            (PFNWP) DialogProc,
  566.                            hmodule,
  567.                            (ULONG) IDD_DLG,
  568.                            (PVOID) 0);
  569.              default: break;
  570.            }
  571.          break;
  572.     default:
  573.          return ((MRESULT)WinDefWindowProc (hWnd, msg,
  574. pm1,
  575. pm2));
  576.    }
  577.   return((MRESULT)0);
  578. }
  579.  
  580.  
  581. void _Optlink ObjectWindowThread(void *arg)
  582. {Find     *somSelf = (Find *) arg;
  583.  FindData *somThis;
  584.  
  585.  
  586.     somThis = FindGetData(somSelf);
  587.  
  588.    _hab = WinInitialize((ULONG)0L);
  589.    _hmq = WinCreateMsgQueue(_hab, (LONG)0L);
  590.     WinRegisterClass(_hab,
  591.                      (PSZ)"FindObjectClass",
  592.                      (PFNWP)ObjectWndProc,
  593.                      (ULONG)0L,
  594.                      (ULONG)4L);
  595.     _Frame = WinCreateWindow(HWND_OBJECT,
  596.                             (PSZ)   "FindObjectClass",
  597.                             (PSZ)   "Object Window",
  598.                             0L,
  599.  
  600. (ULONG)0L,(ULONG)0L,(ULONG)0L,(ULONG)0L,
  601.                             (HWND)0,
  602.                             HWND_TOP,
  603.                             101,
  604.                             (ULONG)0,
  605.                             (PVOID)0);
  606.     WinSetWindowULong(_Frame,             /*For Access
  607. needed*/
  608.                       QWL_USER,
  609.                       (ULONG)somSelf);
  610.     while (WinGetMsg(_hab,
  611.                      (PQMSG)&_qmsg,
  612.                      (HWND)NULL,
  613.                      (ULONG)0L,
  614.                      (ULONG)0L ) ){
  615.         if (_qmsg.msg==WM_QUIT)
  616.             break;
  617.         WinDispatchMsg( _hab, (PQMSG)&_qmsg );
  618.        }
  619.     WinDestroyWindow( _Frame );
  620.     WinDestroyMsgQueue( _hmq );
  621.     WinTerminate( _hab );
  622. }
  623.  
  624.  
  625. BOOL Findmain(
  626.    Find *somSelf,
  627.    int          argc,
  628.    char       **argv)
  629.  
  630. {
  631.  if (_beginthread(ObjectWindowThread,
  632.               (void *)0,
  633.               (unsigned)4*4096,
  634.               (void *)somSelf)==(-1))
  635.      DosBeep(1000,1000);
  636.  return(TRUE);
  637. }
  638.  
  639.  #--------------------------------------------------------------------------
  640.  # Program name:  Initterm1.C    Title: WPS Programming using Mult Proc.
  641.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  642.  #
  643.  # Article:  "Workplace Shell Programming using Multiple Processes"
  644.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  645.  # Phone:  n/a                   Fax:  n/a
  646.  #
  647.  # Description:  The following is a component of the complete source to the
  648.  # above article in the specified issue of OS/2 Developer Magazine.  This
  649.  # source is provided AS-IS without any implied or expressed warranty.
  650.  #
  651.  #--------------------------------------------------------------------------
  652.  
  653. /********************************************
  654. ******
  655.   SPEC:
  656.       DLL init and term module for the Toronto Compiler
  657. *********************************************
  658. ******/
  659.  
  660. #define  INCL_DOSPROCESS
  661.  
  662. #include <stdlib.h>
  663. #include <stdio.h>
  664. #include <os2.h>
  665.  
  666.  
  667. extern BOOL DLLInit( void );
  668. extern BOOL DLLUninit( void );
  669.  
  670. #define DebugBox(title, text) \
  671.          WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  672. (PSZ) text , \
  673.                       (PSZ) title, 20, MB_OK │ MB_INFORMATION )
  674.  
  675.  
  676. /*-------------------------------------------------
  677.  SPEC:
  678.   This routine is called once for this class and not once
  679. for each
  680.   instance
  681.   of this class.  This is for initialization which covers all
  682. instances,
  683.   for example loading strings or icons out of the resource
  684. module.
  685.   DLLUninit should be used to free any resources
  686. allocated during this
  687.   routine.
  688. ---------------------------------------------------
  689. */
  690. BOOL DLLInit()
  691. {
  692.  InitializeFind();
  693.  return(TRUE);
  694. }
  695.  
  696.  
  697. /*-------------------------------------------------
  698.  NAME: DLLUninit( VOID )
  699.  
  700.  DESCRIPTION:
  701.   This is the dynalink module exit routine.
  702.   This routine will be called right before the module is
  703. being unloaded.
  704.  
  705.  NOTES:
  706.   This routine is called once for this class and not once
  707. for each
  708.   instance
  709.   of this class.  This is for cleanup of initialization
  710. which covers all
  711.   instances, for example destroying string or icon
  712. resources that were
  713.   allocated during DLLInit processing.
  714. ---------------------------------------------------
  715. */
  716. BOOL DLLUninit()
  717. {
  718.  return(TRUE);
  719. }
  720.  
  721.  
  722. /*
  723.  * _edcinit is the C-runtime environment init. function.
  724.  * Returns 0 to indicate success and -1 to indicate
  725. failure
  726.  */
  727.   int _CRT_init(void);
  728.  
  729. /*
  730.  * _edcterm is the C-runtime termination function.
  731.  */
  732.   int _CRT_term(unsigned long);
  733.  
  734.  
  735. /*
  736.  * _DLL_InitTerm is the function that tets called by the
  737. operation
  738.  * system
  739.  * loader when it lads and frees the dll for each process
  740. that accesses
  741.  * the dll.
  742.  */
  743. #pragma linkage( _DLL_InitTerm, system )
  744.  
  745. unsigned long _DLL_InitTerm(unsigned long modhandle,
  746. unsigned long
  747. flag)
  748. {
  749.    switch (flag)
  750.      {
  751.      case 0:
  752.         /*
  753.          * Call the C run-time init function before any thing
  754. else.
  755.          */
  756.          if (_CRT_init() == -1)
  757.            return 0UL;
  758.          DLLInit();
  759.  
  760.          break;
  761.  
  762.      case 1:
  763.         /*
  764.          * Call the C run-time termination function.
  765.          */
  766.          DLLUninit();
  767.          _CRT_term(0UL);
  768.          break;
  769.      } /* endswitch */
  770.  
  771.   return 1UL;
  772.  
  773. }
  774.  
  775. APIRET DosGetThreadInfo(PTIB *pptib,PPIB *pppib)
  776. {
  777.      return(DosGetInfoBlocks(pptib,pppib) );
  778. }
  779.  
  780.  
  781.  #--------------------------------------------------------------------------
  782.  # Program name:  Finddat1.C     Title: WPS Programming using Mult Proc.
  783.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  784.  #
  785.  # Article:  "Workplace Shell Programming using Multiple Processes"
  786.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  787.  # Phone:  n/a                   Fax:  n/a
  788.  #
  789.  # Description:  The following is a component of the complete source to the
  790.  # above article in the specified issue of OS/2 Developer Magazine.  This
  791.  # source is provided AS-IS without any implied or expressed warranty.
  792.  #
  793.  #--------------------------------------------------------------------------
  794. int          argc;
  795. char        *argv¢3|;
  796. HMODULE     hmodule;
  797. HPOINTER    FindIcon;
  798.  
  799. FINDDEF1.H
  800.  
  801. #define FIND                  100
  802.  
  803. #define IDD_DLG               200
  804. #define IDD_FILENAME          201
  805. #define IDD_STRING            202
  806. #define IDD_ENTER             203
  807. #define IDD_CANCEL            204
  808. #define IDD_LIST              205
  809.  
  810. #define MENUID_USER_BASE      0
  811. #define RC_IDD_FINDMENU       (MENUID_USER_BASE+1)
  812. #define RC_MI_FIND            100
  813.  
  814. FIND1.RC
  815.  
  816. #define INCL_WIN
  817. #include <os2.h>
  818.  
  819. #include "finddef.h"
  820.  
  821. POINTER 101 find.ico
  822.  
  823.  
  824. MENU RC_IDD_FINDMENU LOADONCALL MOVEABLE
  825. DISCARDABLE
  826. BEGIN
  827.    MENUITEM "Find string", RC_MI_FIND
  828. END
  829.  
  830. DLGTEMPLATE IDD_DLG LOADONCALL MOVEABLE
  831. DISCARDABLE
  832. BEGIN
  833.     DIALOG  "Find dialogbox", IDD_DLG, 58, -17, 165, 106,
  834. WS_VISIBLE,
  835.             FCF_SYSMENU │ FCF_TITLEBAR
  836.     BEGIN
  837.         LTEXT           "Filename", 101, 9, 87, 44, 8
  838.         LTEXT           "String", 102, 23, 72, 30, 8
  839.         ENTRYFIELD      "", IDD_FILENAME, 54, 88, 101,
  840. 8,ES_MARGIN
  841.         ENTRYFIELD      "", IDD_STRING, 54, 71, 101, 8,
  842. ES_MARGIN
  843.         PUSHBUTTON      "Enter", IDD_ENTER, 13, 8, 40, 14
  844.         PUSHBUTTON      "Cancel", IDD_CANCEL, 109, 8, 40,
  845. 14
  846.         LISTBOX         IDD_LIST, 13, 25, 142, 40
  847.     END
  848. END
  849.  
  850. FIND1.DEF
  851.  
  852. ;  FileName: find.def.
  853. ;  Generated using:
  854. ;      SOM Compiler sc: 1.10
  855. ;      SOM Emitter emitdef: 1.10
  856. ; @(#)emit.c 1.10 10/25/91 14:09:30 ¢10/31/91| (c)IBM
  857. Corp.1991
  858. LIBRARY Find INITINSTANCE
  859. DESCRIPTION 'Find Class Library - (c) Copyright IBM
  860. 1991'
  861. PROTMODE
  862. DATA MULTIPLE NONSHARED LOADONCALL
  863. EXPORTS
  864.    SOMInitModule
  865.    FindCClassData
  866.    FindClassData
  867.    FindNewClass
  868.    DialogProc
  869.    ObjectWndProc
  870.  
  871.  #--------------------------------------------------------------------------
  872.  # Program name:  Find2.csc      Title: WPS Programming using Mult Proc.
  873.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  874.  #
  875.  # Article:  "Workplace Shell Programming using Multiple Processes"
  876.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  877.  # Phone:  n/a                   Fax:  n/a
  878.  #
  879.  # Description:  The following is a component of the complete source to the
  880.  # above article in the specified issue of OS/2 Developer Magazine.  This
  881.  # source is provided AS-IS without any implied or expressed warranty.
  882.  #
  883.  #--------------------------------------------------------------------------
  884. ## CLASS: Find
  885. ##
  886. ## CLASS HIERARCHY:
  887. ##      SOMObject
  888. ##         WPObject
  889. ##           WPAbstract
  890. ##             Find
  891. ## DESCRIPTION:
  892. ##    This is the find object class.
  893. ##    An instance of this class can be created as a
  894. Workplace object.
  895. ##
  896. include <wpabs.sc>
  897.  
  898. class: Find,
  899.         external stem = find,
  900.         local,
  901.         external prefix = find_,
  902.         classprefix     = findM_,
  903.         major version = 1,
  904.         minor version = 1;
  905.  
  906. parent: WPAbstract;
  907. passthru: C.h, after;
  908.    #define DebugBox(title, text) \
  909.           WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  910. (PSZ) text , \
  911.                        (PSZ) title, 20, MB_OK │ MB_INFORMATION
  912. )
  913. endpassthru;
  914. ##
  915. ##Instance Data Statement
  916. ##
  917. data:
  918.  HWND         *Frame;
  919.  
  920. methods:
  921.         override wpInitData;
  922.         override wpDelete;
  923.         override wpModifyPopupMenu;
  924.         override wpMenuItemSelected;
  925.  
  926.  #--------------------------------------------------------------------------
  927.  # Program name:  Find2.mak      Title: WPS Programming using Mult Proc.
  928.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  929.  #
  930.  # Article:  "Workplace Shell Programming using Multiple Processes"
  931.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  932.  # Phone:  n/a                   Fax:  n/a
  933.  #
  934.  # Description:  The following is a component of the complete source to the
  935.  # above article in the specified issue of OS/2 Developer Magazine.  This
  936.  # source is provided AS-IS without any implied or expressed warranty.
  937.  #
  938.  #--------------------------------------------------------------------------
  939. #*******************************************
  940. *******
  941. #  Dot directive definition area (usually just suffixes)
  942. #*******************************************
  943. *******
  944.  
  945.  .SUFFIXES: .c .obj .dll .csc .sc .h .ih .ph .psc .rc .res
  946.  
  947. #*******************************************
  948. *******
  949. #  Environment Setup for the component(s).
  950. #*******************************************
  951. *******
  952.  
  953. SOMTEMP=.\somtemp
  954. SCPATH  = d:\toolkt20\sc
  955. HPATH   =d:\toolkt20\c\os2h
  956. LIBPATH =d:\toolkt20\os2lib
  957.  
  958. !if ¢set SMINCLUDE=.;$(SCPATH);| ││ \
  959.     ¢set SMTMP=$(SOMTEMP)| ││ \
  960.     ¢set SMEMIT=ih;h;ph;psc;sc;c|
  961. !endif
  962.  
  963. !if ¢cd $(SOMTEMP)|
  964. !  if ¢md $(SOMTEMP)|
  965. !    error error creating $(SOMTEMP) directory
  966. !  endif
  967. !else
  968. !  if ¢cd ..|
  969. !    error - Couldn't cd .. from $(SOMTEMP) directory
  970. !  endif
  971. !endif
  972.  
  973. #
  974. # Compiler/tools Macros
  975. #
  976.  
  977. CC      = icc /c /Ge- /Gd- /Se /Sp2 /Re /Kb /ss /Ms /Gm+
  978. LINK    = link386
  979. LDFLAGS = /noi /map /nol /nod /exepack /packcode
  980. /packdata /align:16
  981. LIBS    = som.lib os2386.lib dde4mbs.lib dde4nbs.lib
  982.  
  983. #*******************************************
  984. *******
  985. # Set up Macros that will contain all the different
  986. dependencies for
  987. # the executables and dlls etc. that are generated.
  988. #*******************************************
  989. *******
  990.  
  991. OBJS       =  find.obj initterm.obj
  992.  
  993. #*******************************************
  994. *******
  995. #   Setup the inference rules for compiling source code
  996. to
  997. #   object code.
  998. #*******************************************
  999. *******
  1000.  
  1001.  .c.obj:
  1002.         $(CC) -I$(HPATH) -c $<
  1003.  
  1004.  .csc.ih:
  1005.         sc -v -r $*.csc
  1006.  
  1007. all: find.ih find.dll
  1008.  
  1009. #
  1010. # Specific Process Tag
  1011. #
  1012.  
  1013. find.ih:   $*.csc $(HPATH)\wpdataf.h
  1014.  
  1015. find.obj: $*.ih $*.c $*.h  $*.sc $(HPATH)\wpdataf.h
  1016.  
  1017. findlg.obj: $*.c $*.h
  1018.  
  1019. find.dll: $*.def $(OBJS) find.res
  1020.          $(LINK) $(LDFLAGS) $(OBJS),$@,,$(LIBS),$*;
  1021.          rc $*.res $*.dll
  1022.          mapsym find.map
  1023.          implib find.lib find.def
  1024.  
  1025. find.res: find.rc
  1026.           rc -r $*.rc $*.res
  1027.  
  1028. #INCLUDES -C=ih
  1029.  
  1030.  #--------------------------------------------------------------------------
  1031.  # Program name:  Find2.C        Title: WPS Programming using Mult Proc.
  1032.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  1033.  #
  1034.  # Article:  "Workplace Shell Programming using Multiple Processes"
  1035.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  1036.  # Phone:  n/a                   Fax:  n/a
  1037.  #
  1038.  # Description:  The following is a component of the complete source to the
  1039.  # above article in the specified issue of OS/2 Developer Magazine.  This
  1040.  # source is provided AS-IS without any implied or expressed warranty.
  1041.  #
  1042.  #--------------------------------------------------------------------------
  1043. /********************************************
  1044. ******
  1045.  * NAME: find.c
  1046.  *
  1047.  * DESCRIPTION:
  1048.  *
  1049.  * Copyright (c) 1991 IBM Corporation
  1050. \********************************************
  1051. *******/
  1052.  
  1053. #define Find_Class_Source
  1054.  
  1055. #define INCL_GPI                    /* Selectively include
  1056. */
  1057. #define INCL_WINFRAMEMGR            /* Frame-manager
  1058. function       */
  1059. #define INCL_WINSYS                 /* System value & color
  1060. function*/
  1061. #define INCL_WINERRORS              /* WIN functions error
  1062. constants*/
  1063. #define INCL_WINDIALOGS             /* Dialog-box
  1064. functions         */
  1065. #define INCL_WINMESSAGEMGR          /* Message-Mgr.
  1066. functions       */
  1067. #define INCL_DOSPROCESS             /* Process & thread
  1068. support func*/
  1069. #define INCL_WIN
  1070. #define INCL_DOS
  1071. #define INCL_GPIBITMAPS
  1072. #define INCL_WPCLASS
  1073. #define INCL_WPOBJECT
  1074.  
  1075. #include <os2.h>
  1076. #include <pmwp.h>  /* eventually will be #define
  1077. INCL_WINWORKPLACE */
  1078.  
  1079. #include <stdio.h>
  1080. #include <stdlib.h>
  1081. #include <string.h>
  1082. #include <memory.h>
  1083.  
  1084. #include "finddef.h"
  1085. #include "find.ih"
  1086. #include "find.ph"
  1087. #include "finddat.h"
  1088.  
  1089.  
  1090. extern VOID     SOMLINK SOMInitModule( VOID );
  1091. extern int      InitializeFind(VOID);
  1092. extern BOOL     Findmain(Find *,int,char **);
  1093.  
  1094.  
  1095. /***SOMEXTERN int SOM_TraceLevel = 1; ***/
  1096.  
  1097. /*-------------------------------------------------
  1098. * NAME: SOMInitModule( VOID )
  1099. *
  1100. * DESCRIPTION:
  1101. *  This is the class initialization entry point.
  1102. *  This routine will be called during the module
  1103. initialization.
  1104. *  Applications must add a call to initialize each object
  1105. class being
  1106. *  defined in the module.  The class initialization call is
  1107. in the
  1108. *  format:
  1109. *
  1110. * <ClassName>NewClass(integer4 majorVersion,
  1111. integer4minorVersion)
  1112. *
  1113. *  where <ClassName> is the name of the new class being
  1114. defined.
  1115. *
  1116. * NOTES:
  1117. *  Do NOT call any methods on any of the classes being
  1118. instanciated
  1119. *  during the processing of SOMInitModule().
  1120. *
  1121. *  SOMInitModule must be exported in the module
  1122. definition file (.DEF)
  1123. *  in the format:
  1124. *
  1125. *      EXPORTS
  1126. *          _SOMInitModule
  1127. *
  1128. -------------------------------------------------*/
  1129. VOID SOMLINK SOMInitModule()
  1130. {
  1131.    FindNewClass(Find_MajorVersion,Find_MinorVersion);
  1132. }
  1133.  
  1134.  
  1135. int InitializeFind()
  1136. {CHAR   ErrorBuffer¢100|;
  1137.  
  1138.   if (DosLoadModule((PSZ) ErrorBuffer,
  1139.                      sizeof(ErrorBuffer),
  1140.                     "FIND", &hmodule) )
  1141.       return FALSE;
  1142.   FindIcon = WinLoadPointer( HWND_DESKTOP, hmodule,
  1143. 101 );
  1144.   if (FindIcon==(HPOINTER)0)
  1145.       DebugBox("FAILURE","!!!load Icon failed");
  1146.  return TRUE;
  1147. }
  1148.  
  1149. /*-------------------------------------------------
  1150.  *
  1151.  *  OVERRIDE: wpInitData
  1152.  *
  1153.  *  PURPOSE:
  1154.  *    Initialize our state variables. Allocate any extra
  1155. memory that
  1156.  *    we might need.
  1157.  *
  1158. ---------------------------------------------------
  1159. */
  1160. #undef SOM_CurrentClass
  1161. #define SOM_CurrentClass SOMInstance
  1162. SOM_Scope void   SOMLINK find_wpInitData(Find
  1163. *somSelf)
  1164. {char        sharename¢256|;
  1165.  char        Errorbuffer¢60|;
  1166.  char        parms¢256|;
  1167.  RESULTCODES result;
  1168.  FindData   *somThis = FindGetData(somSelf);
  1169.  
  1170.  
  1171.     FindMethodDebug("Find","Find_wpInitData");
  1172.  
  1173.     parent_wpInitData(somSelf);
  1174.     if (FindIcon)
  1175.        _wpSetIcon(somSelf,FindIcon);
  1176.  
  1177.     _Frame = (HWND *)0;                /*initialize*/
  1178.  
  1179. sprintf(sharename,"\\SHAREMEM\\%lX.FND",(ULONG)somS
  1180. elf);
  1181.     DosAllocSharedMem((PPVOID)&_Frame,
  1182.                        sharename,
  1183.                        4096,
  1184.                        PAG_COMMIT│PAG_READ│PAG_WRITE);
  1185.  
  1186.     memset(&parms,0,sizeof(parms));   /*parms format*/
  1187.     strcpy(parms,"find");
  1188.     sprintf(parms+5,"%s",sharename);
  1189.     DosExecPgm(Errorbuffer,
  1190.                sizeof(Errorbuffer),
  1191.                EXEC_ASYNC,
  1192.                parms,                     /*somSelf addr arg */
  1193.                0,
  1194.                &result,
  1195.                "FINDDLG.EXE");
  1196. }
  1197.  
  1198.  
  1199. SOM_Scope BOOL   SOMLINK
  1200. find_wpModifyPopupMenu(Find *somSelf,
  1201.                                                 HWND hwndMenu,
  1202.                                                 HWND hwndCnr,
  1203.                                                 ULONG iPosition)
  1204. {
  1205.     /* FindData *somThis = FindGetData(somSelf); */
  1206.     FindMethodDebug("Find","find_wpModifyPopupMenu");
  1207.  
  1208.     _wpInsertPopupMenuItems(somSelf,        /*this cases
  1209. adds to menu*/
  1210.                             hwndMenu,
  1211.                             iPosition,
  1212.                             hmodule,
  1213.                             RC_IDD_FINDMENU,
  1214.                             0);
  1215.  
  1216.      return(parent_wpModifyPopupMenu(somSelf,
  1217.                                      hwndMenu,
  1218.                                      hwndCnr,
  1219.                                      iPosition));
  1220. }
  1221.  
  1222.  
  1223. SOM_Scope BOOL   SOMLINK
  1224. find_wpMenuItemSelected(Find *somSelf,
  1225.                                                  HWND hwndFrame,
  1226.                                                  ULONG MenuId)
  1227. {FindData *somThis = FindGetData(somSelf);
  1228. /*required*/
  1229.  
  1230.  
  1231.     FindMethodDebug("Find","find_wpMenuItemSelected");
  1232.  
  1233.     switch (MenuId) {
  1234.        case RC_MI_FIND:
  1235.              if (_Frame!=(HWND)0)
  1236.                 WinPostMsg(*_Frame,WM_COMMAND,
  1237.                           (MPARAM)MAKEULONG(FIND,FIND),
  1238.                           (MPARAM)0L);
  1239.              break;
  1240.         default:
  1241.  
  1242. return(parent_wpMenuItemSelected(somSelf,hwndFrame,
  1243. MenuId));
  1244.       }
  1245.  return(TRUE);
  1246. }
  1247.  
  1248.  
  1249. SOM_Scope ULONG   SOMLINK find_wpDelete(Find
  1250. *somSelf,
  1251.                                         ULONG fConfirmations)
  1252. {
  1253.     FindData *somThis = FindGetData(somSelf);
  1254.     FindMethodDebug("Find","find_wpDelete");
  1255.  
  1256.     if (_Frame!=(HWND)0)
  1257.        WinPostMsg(*_Frame,WM_QUIT,(MPARAM)0,
  1258. (MPARAM)0);/*For Now Okay*/
  1259.     return (parent_wpDelete(somSelf,fConfirmations));
  1260. }
  1261.  
  1262.  #--------------------------------------------------------------------------
  1263.  # Program name:  Find2.def      Title: WPS Programming using Mult Proc.
  1264.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  1265.  #
  1266.  # Article:  "Workplace Shell Programming using Multiple Processes"
  1267.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  1268.  # Phone:  n/a                   Fax:  n/a
  1269.  #
  1270.  # Description:  The following is a component of the complete source to the
  1271.  # above article in the specified issue of OS/2 Developer Magazine.  This
  1272.  # source is provided AS-IS without any implied or expressed warranty.
  1273.  #
  1274.  #--------------------------------------------------------------------------
  1275. ;  FileName: find.def.
  1276. ;  Generated using:
  1277. ;      SOM Compiler sc: 1.10
  1278. ;      SOM Emitter emitdef: 1.10
  1279. ; @(#)emit.c 1.10 10/25/91 14:09:30 ¢10/31/91| (c)IBM
  1280. Corp.1991
  1281. LIBRARY Find INITINSTANCE
  1282. DESCRIPTION 'Find Class Library - (c) Copyright IBM
  1283. 1991'
  1284. PROTMODE
  1285. DATA MULTIPLE NONSHARED LOADONCALL
  1286. EXPORTS
  1287.    SOMInitModule
  1288.    FindCClassData
  1289.    FindClassData
  1290.    FindNewClass
  1291.  
  1292.  #--------------------------------------------------------------------------
  1293.  # Program name:  Finddlg2.mak   Title: WPS Programming using Mult Proc.
  1294.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  1295.  #
  1296.  # Article:  "Workplace Shell Programming using Multiple Processes"
  1297.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  1298.  # Phone:  n/a                   Fax:  n/a
  1299.  #
  1300.  # Description:  The following is a component of the complete source to the
  1301.  # above article in the specified issue of OS/2 Developer Magazine.  This
  1302.  # source is provided AS-IS without any implied or expressed warranty.
  1303.  #
  1304.  #--------------------------------------------------------------------------
  1305.  .SUFFIXES: .c .obj .dll .csc .sc .h .ih .ph .psc .rc .res
  1306.  
  1307. #*******************************************
  1308. *******
  1309. #  Environment Setup for the component(s).
  1310. #*******************************************
  1311. *******
  1312.  
  1313. SOMTEMP=.\somtemp
  1314. SCPATH  = d:\toolkt20\sc
  1315. HPATH   =d:\toolkt20\c\os2h
  1316. LIBPATH =d:\toolkt20\os2lib
  1317.  
  1318.  
  1319. #
  1320. # Compiler/tools Macros
  1321. #
  1322.  
  1323. CC     = icc /c /Ti /G3 /Ge /Gs /Kb
  1324. LINK   = link386
  1325. LDFLAGS= /co /noi /map /nol /nod /exepack /packcode
  1326. /packdata /align:16
  1327. LIBS   = os2386.lib dde4sbs.lib dde4nbs.lib
  1328.  
  1329.  
  1330. OBJS       =  finddlg.obj
  1331.  
  1332.  
  1333.  .c.obj:
  1334.         $(CC) -I$(HPATH) -c $<
  1335.  
  1336. all: finddlg.exe
  1337.  
  1338.  
  1339. findlg.obj: $*.c $*.h
  1340.  
  1341. finddlg.exe: $*.def $(OBJS) find.res
  1342.          $(LINK) $(LDFLAGS) $(OBJS),$@,,$(LIBS),$*;
  1343.          rc find.res $*.exe
  1344.  
  1345. find.res: find.rc
  1346.           rc -r find.rc find.res
  1347.  
  1348. #INCLUDES -C=ih
  1349.  
  1350.  #--------------------------------------------------------------------------
  1351.  # Program name:  Finddlg2.C     Title: WPS Programming using Mult Proc.
  1352.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  1353.  #
  1354.  # Article:  "Workplace Shell Programming using Multiple Processes"
  1355.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  1356.  # Phone:  n/a                   Fax:  n/a
  1357.  #
  1358.  # Description:  The following is a component of the complete source to the
  1359.  # above article in the specified issue of OS/2 Developer Magazine.  This
  1360.  # source is provided AS-IS without any implied or expressed warranty.
  1361.  #
  1362.  #--------------------------------------------------------------------------
  1363. /********************************************
  1364. ******
  1365.  * NAME: finddlg.c
  1366.  *
  1367.  * DESCRIPTION:
  1368.  *
  1369.  * Copyright (c) 1991 IBM Corporation
  1370. *********************************************
  1371. ******/
  1372. #define INCL_GPI                        /* Selectively include
  1373. */
  1374. #define INCL_WIN                        /* Selectively include
  1375. */
  1376. #define INCL_DOS
  1377.  
  1378.  
  1379. #include <os2.h>
  1380. #include <stdio.h>
  1381. #include <stdlib.h>
  1382. #include <string.h>
  1383. #include "finddef.h"
  1384. #include "finddat.h"
  1385.  
  1386.  
  1387. extern void  FindString(char *filename_p,
  1388.                        char *string,
  1389.                        unsigned fileattr,
  1390.                        HWND list);
  1391. extern void  SearchFile(char *filename,char
  1392. *string,HWND list);
  1393. extern MRESULT EXPENTRY DialogProc(HWND   hwndDlg,
  1394.                                    USHORT msg,
  1395.                                    MPARAM pm1,
  1396.                                    MPARAM pm2);
  1397. extern MRESULT EXPENTRY ObjectWndProc(
  1398.                                       HWND   hWnd,
  1399.                                       USHORT msg,
  1400.                                       MPARAM pm1,
  1401.                                       MPARAM pm2);
  1402.  
  1403. HAB          _hab;
  1404. HMQ          _hmq;
  1405. QMSG         _qmsg;
  1406. HWND         _Frame;
  1407.  
  1408.  
  1409.  
  1410. void  SearchFile(
  1411.     char          *filename,
  1412.     char          *string,
  1413.     HWND           list)
  1414. {FILE *fp;
  1415.  char buffer¢256|;
  1416.  char data¢256|;
  1417.  char *p;
  1418.  BOOL flag=1;
  1419.  
  1420.  if ( (fp=fopen(filename,"r"))==(FILE *)0)
  1421.     return;
  1422.  
  1423.  while (!feof(fp)){
  1424.        fgets(buffer,256,fp);
  1425.        if ((p=strchr(buffer,'\n'))!=(char *)0)
  1426.            *p=0;
  1427.        if (strstr(buffer,string)!=(char *)0)
  1428.          {
  1429.           if (flag)
  1430.              {
  1431.               sprintf(data,"####%s####",filename);
  1432.               WinSendMsg(list,
  1433.                          (ULONG)LM_INSERTITEM,
  1434.                          (MPARAM)LIT_END,
  1435.                          (MPARAM)data);
  1436.               flag=0;
  1437.              }
  1438.           WinSendMsg(list,
  1439.                      (ULONG)LM_INSERTITEM,
  1440.                      (MPARAM)LIT_END,
  1441.                      (MPARAM)buffer);
  1442.          }
  1443.  }
  1444.  fclose(fp);
  1445. }
  1446.  
  1447.  
  1448. void FindString(
  1449.     char          *filename_p,
  1450.     char          *string,
  1451.     unsigned       fileattr,
  1452.     HWND           list)
  1453.  
  1454. {HDIR            dirhandle=0xFFFF;
  1455.  FILEFINDBUF3    resultbuf;
  1456.  ULONG           lcount=1;
  1457.  char            *p;
  1458.  char             buffer¢256|;
  1459.  char             path¢256|;
  1460.  
  1461.  
  1462.  strcpy(path,filename_p);
  1463.  if ( (p=strrchr(path,'\\'))!=(char *)0)
  1464.     *(++p)=0;
  1465.  if (p==(char *)0)
  1466.    if ( (p=strchr(path,':'))!=(char *)0)
  1467.       *(++p)=0;
  1468.  
  1469.  
  1470.  if (DosFindFirst((PSZ)   filename_p,
  1471.                   (PHDIR) &dirhandle,
  1472.                   (ULONG) fileattr,
  1473.                   (PVOID) &resultbuf,
  1474.                   (ULONG) sizeof(resultbuf),
  1475.                   (PULONG) &lcount,
  1476.                   (ULONG) 1)==0)
  1477.       {
  1478.        do {
  1479.           sprintf(buffer,"%s%s",path,resultbuf.achName);
  1480.           SearchFile(buffer,string,list);
  1481.           }while (DosFindNext((HDIR)  dirhandle,
  1482.                               (PVOID) &resultbuf,
  1483.                               (ULONG) sizeof(resultbuf),
  1484.                               (PULONG) &lcount)==0);
  1485.  
  1486.  
  1487.        DosFindClose(dirhandle);
  1488.       }
  1489. }
  1490.  
  1491. MRESULT EXPENTRY DialogProc(
  1492.        HWND   hwndDlg,
  1493.        USHORT msg,
  1494.        MPARAM pm1,
  1495.        MPARAM pm2)
  1496. {char filename¢256|;
  1497.  char string¢256|;
  1498.  HWND list;
  1499.  
  1500.   switch (msg) {
  1501.      case WM_COMMAND:
  1502.           switch (LOUSHORT(pm1)) {
  1503.               case IDD_ENTER:
  1504.                     list =WinWindowFromID(hwndDlg,IDD_LIST);
  1505.                     WinQueryDlgItemText(hwndDlg,
  1506.                                         IDD_FILENAME,
  1507.                                         255,
  1508.                                         (PSZ)filename
  1509.                                        );
  1510.                     WinQueryDlgItemText(hwndDlg,
  1511.                                         IDD_STRING,
  1512.                                         255,
  1513.                                         (PSZ)string
  1514.                                        );
  1515.                     FindString(filename,string,(unsigned)0,list);
  1516.                     break;
  1517.               case IDD_CANCEL:
  1518.               default:
  1519.                     WinDismissDlg( hwndDlg, FALSE );
  1520.                     break;
  1521.              }
  1522.           break;
  1523.      default:
  1524.          return(WinDefDlgProc(hwndDlg, msg, pm1, pm2));
  1525.     }
  1526.   return(MRFROMLONG(NULL));
  1527. }
  1528.  
  1529. MRESULT EXPENTRY ObjectWndProc(
  1530.              HWND   hWnd,
  1531.              USHORT msg,
  1532.              MPARAM pm1,
  1533.              MPARAM pm2)
  1534. {
  1535.  
  1536.   switch (msg)  {
  1537.    case WM_COMMAND:
  1538.         switch (SHORT1FROMMP(pm1)) {
  1539.              case FIND:
  1540.                  WinDlgBox((HWND)  HWND_DESKTOP,
  1541.                            (HWND)  HWND_DESKTOP,
  1542.                            (PFNWP) DialogProc,
  1543.                            0L,
  1544.                            (ULONG) IDD_DLG,
  1545.                            (PVOID) 0);
  1546.              default: break;
  1547.            }
  1548.          break;
  1549.     default:
  1550.          return ((MRESULT)WinDefWindowProc (hWnd, msg,
  1551. pm1,
  1552. pm2));
  1553.    }
  1554.   return((MRESULT)0);
  1555. }
  1556.  
  1557.  
  1558. int main(int    argc,
  1559.          char **argv)
  1560. {HWND  *shared;
  1561.  int    rc;
  1562.  
  1563.     DosBeep(100,100);         /*Indicate that it has been
  1564. started*/
  1565.  
  1566.     if (argc<2)
  1567.        exit(-1);
  1568.  
  1569.     if (rc=DosGetNamedSharedMem((PPVOID)&shared,
  1570.                                 argv¢1|,
  1571.                                 PAG_READ│PAG_WRITE))
  1572.        exit(-1);
  1573.  
  1574.    _hab = WinInitialize((ULONG)0L);
  1575.    _hmq = WinCreateMsgQueue(_hab, (LONG)0L);
  1576.     WinRegisterClass(_hab,
  1577.                      (PSZ)"FindObjectClass",
  1578.                      (PFNWP)ObjectWndProc,
  1579.                      (ULONG)0L,
  1580.                      (ULONG)4L);
  1581.     *shared=
  1582.     _Frame = WinCreateWindow(HWND_OBJECT,
  1583.                             (PSZ)   "FindObjectClass",
  1584.                             (PSZ)   "Object Window",
  1585.                             0L,
  1586.  
  1587. (ULONG)0L,(ULONG)0L,(ULONG)0L,(ULONG)0L,
  1588.                             (HWND)0,
  1589.                             HWND_TOP,
  1590.                             101,
  1591.                             (ULONG)0,
  1592.                             (PVOID)0);
  1593.  
  1594.     while (WinGetMsg(_hab,
  1595.                      (PQMSG)&_qmsg,
  1596.                      (HWND)NULL,
  1597.                      (ULONG)0L,
  1598.                      (ULONG)0L ) ){
  1599.         if (_qmsg.msg==WM_QUIT)
  1600.             break;
  1601.         WinDispatchMsg( _hab, (PQMSG)&_qmsg );
  1602.        }
  1603. DosBeep(1000,1000);                    /*indicate that it has
  1604. ended*/
  1605.     WinDestroyWindow( _Frame );
  1606.     WinDestroyMsgQueue( _hmq );
  1607.     WinTerminate( _hab );
  1608. }
  1609.  
  1610.  #--------------------------------------------------------------------------
  1611.  # Program name:  Finddlg2.def   Title: WPS Programming using Mult Proc.
  1612.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  1613.  #
  1614.  # Article:  "Workplace Shell Programming using Multiple Processes"
  1615.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  1616.  # Phone:  n/a                   Fax:  n/a
  1617.  #
  1618.  # Description:  The following is a component of the complete source to the
  1619.  # above article in the specified issue of OS/2 Developer Magazine.  This
  1620.  # source is provided AS-IS without any implied or expressed warranty.
  1621.  #
  1622.  #--------------------------------------------------------------------------
  1623. NAME    FINDDLG WINDOWAPI
  1624.  
  1625. DESCRIPTION 'Winthorn Application'
  1626.  
  1627. STUB    'OS2STUB.EXE'
  1628.  
  1629. CODE    MOVEABLE
  1630. DATA    MOVEABLE MULTIPLE
  1631.  
  1632. HEAPSIZE  8192
  1633. STACKSIZE 8192
  1634.  
  1635. EXPORTS
  1636.    DialogProc
  1637.    ObjectWndProc
  1638.  
  1639.  #--------------------------------------------------------------------------
  1640.  # Program name:  Find3.csc      Title: WPS Programming using Mult Proc.
  1641.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  1642.  #
  1643.  # Article:  "Workplace Shell Programming using Multiple Processes"
  1644.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  1645.  # Phone:  n/a                   Fax:  n/a
  1646.  #
  1647.  # Description:  The following is a component of the complete source to the
  1648.  # above article in the specified issue of OS/2 Developer Magazine.  This
  1649.  # source is provided AS-IS without any implied or expressed warranty.
  1650.  #
  1651.  #--------------------------------------------------------------------------
  1652. ##
  1653. ## Note: Any comments to go public should be preceeded
  1654. with '--'
  1655. ##       Any comments to remain private should be
  1656. preceeded with '#'
  1657. ##
  1658. ##
  1659. ## CLASS: Find
  1660. ##
  1661. ## CLASS HIERARCHY:
  1662. ##      SOMObject
  1663. ##         WPObject
  1664. ##           WPAbstract
  1665. ##             Find
  1666. ## DESCRIPTION:
  1667. ##    This is the find object class.
  1668. ##    An instance of this class can be created as a
  1669. Workplace object.
  1670. ##
  1671. ##
  1672. include <wpabs.sc>
  1673.  
  1674. class: Find,
  1675.         external stem = find,
  1676.         local,
  1677.         external prefix = find_,
  1678.         classprefix     = findM_,
  1679.         major version = 1,
  1680.         minor version = 1;
  1681.  
  1682. parent: WPAbstract;
  1683. passthru: C.h, after;
  1684.     #define DebugBox(title, text) \
  1685.       WinMessageBox(HWND_DESKTOP,HWND_DESKTOP,
  1686. (PSZ) text ,\
  1687.                    (PSZ) title, 20, MB_OK │ MB_INFORMATION )
  1688. endpassthru;
  1689. data:
  1690.  HWND          Frame;
  1691.  CHAR          instancename¢256|;
  1692.  
  1693. methods:
  1694.         override wpInitData;
  1695.         override wpDelete;
  1696.         override wpModifyPopupMenu;
  1697.         override wpMenuItemSelected;
  1698.  
  1699.  #--------------------------------------------------------------------------
  1700.  # Program name:  Find3.c        Title: WPS Programming using Mult Proc.
  1701.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  1702.  #
  1703.  # Article:  "Workplace Shell Programming using Multiple Processes"
  1704.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  1705.  # Phone:  n/a                   Fax:  n/a
  1706.  #
  1707.  # Description:  The following is a component of the complete source to the
  1708.  # above article in the specified issue of OS/2 Developer Magazine.  This
  1709.  # source is provided AS-IS without any implied or expressed warranty.
  1710.  #
  1711.  #--------------------------------------------------------------------------
  1712. /********************************************
  1713. ******
  1714.  * NAME: find.c
  1715.  * DESCRIPTION:
  1716.  *
  1717.  * Copyright (c) 1991 IBM Corporation
  1718. \********************************************
  1719. ******/
  1720.  
  1721.  
  1722. #define Find_Class_Source
  1723.  
  1724. #define INCL_GPI                    /* Selectively include
  1725. */
  1726. #define INCL_WINFRAMEMGR            /* Frame-manager
  1727. function       */
  1728. #define INCL_WINSYS                 /* System value & color
  1729. function*/
  1730. #define INCL_WINERRORS              /* WIN functions error
  1731. constants*/
  1732. #define INCL_WINDIALOGS             /* Dialog-box
  1733. functions         */
  1734. #define INCL_WINMESSAGEMGR          /* Message-Mgr.
  1735. functions       */
  1736. #define INCL_DOSPROCESS             /* Process & thread
  1737. support func*/
  1738. #define INCL_WIN
  1739. #define INCL_DOS
  1740. #define INCL_GPIBITMAPS
  1741. #define INCL_WPCLASS
  1742. #define INCL_WPOBJECT
  1743.  
  1744. #include <os2.h>
  1745. #include <pmwp.h>  /* eventually will be #define
  1746. INCL_WINWORKPLACE */
  1747.  
  1748. #include <stdio.h>
  1749. #include <stdlib.h>
  1750. #include <string.h>
  1751. #include <memory.h>
  1752.  
  1753. #include "finddef.h"
  1754. #include "find.ih"
  1755. #include "find.ph"
  1756. #include "finddat.h"
  1757.  
  1758.  
  1759. extern VOID     SOMLINK SOMInitModule( VOID );
  1760. extern int      InitializeFind(VOID);
  1761. extern BOOL     Findmain(Find *,int,char **);
  1762. extern BOOL     GetObjectWindow(Find *somSelf);  /*new
  1763. code*/
  1764.  
  1765.  
  1766. /***SOMEXTERN int SOM_TraceLevel = 1; ***/
  1767.  
  1768. /*-------------------------------------------------
  1769. *
  1770. * NAME: SOMInitModule( VOID )
  1771. *
  1772. * DESCRIPTION:
  1773. *  This is the class initialization entry point.
  1774. *  This routine will be called during the module
  1775. initialization.
  1776. *  Applications must add a call to initialize each object
  1777. class being
  1778. *  defined in the module.  The class initialization call is
  1779. in the
  1780. *  format:
  1781. *
  1782. * <ClassName>NewClass(integer4 majorVersion,
  1783. integer4minorVersion)
  1784. *
  1785. *  where <ClassName> is the name of the new class being
  1786. defined.
  1787. *
  1788. * NOTES:
  1789. *  Do NOT call any methods on any of the classes being
  1790. instanciated
  1791. *  during
  1792. *  the processing of SOMInitModule().
  1793. *
  1794. *  SOMInitModule must be exported in the module
  1795. definition file (.DEF)
  1796. *  in the format:
  1797. *
  1798. *      EXPORTS
  1799. *          _SOMInitModule
  1800. *
  1801. \*-------------------------------------------------
  1802. */
  1803. VOID SOMLINK SOMInitModule()
  1804. {
  1805.    FindNewClass(Find_MajorVersion,Find_MinorVersion);
  1806. }
  1807.  
  1808.  
  1809. int InitializeFind()
  1810. {CHAR   ErrorBuffer¢100|;
  1811.  
  1812.   if (DosLoadModule((PSZ) ErrorBuffer,
  1813.                      sizeof(ErrorBuffer),
  1814.                     "FIND", &hmodule) )
  1815.       return FALSE;
  1816.   FindIcon = WinLoadPointer( HWND_DESKTOP, hmodule,
  1817. 101 );
  1818.   if (FindIcon==(HPOINTER)0)
  1819.       DebugBox("FAILURE","!!!load Icon failed");
  1820.  return TRUE;
  1821. }
  1822.  
  1823.  
  1824. BOOL GetObjectWindow(Find *somSelf)  /*new code*/
  1825. {HENUM henum;
  1826.  HWND  hwnd;
  1827.  CHAR  name¢256|;
  1828.  FindData   *somThis = FindGetData(somSelf);
  1829.  
  1830.  
  1831.  if (_Frame!=(HWND)0)
  1832.     return(TRUE);
  1833.  henum = WinBeginEnumWindows(HWND_OBJECT);
  1834.  while (hwnd= WinGetNextWindow(henum)) {
  1835.     WinQueryClassName(hwnd,sizeof(name),name);
  1836.     if (strcmp(name,_instancename)==0)
  1837.        {
  1838.         _Frame=hwnd;
  1839.         WinEndEnumWindows(henum);
  1840.         return(TRUE);
  1841.        }
  1842.  }
  1843.  WinEndEnumWindows(henum);
  1844.  return(FALSE);
  1845. }
  1846.  
  1847.  
  1848. /*-------------------------------------------------
  1849.  *
  1850.  *  OVERRIDE: wpInitData
  1851.  *
  1852.  *  PURPOSE:
  1853.  *    Initialize our state variables. Allocate any extra
  1854. memory that
  1855.  *    we might need.
  1856.  *
  1857. ---------------------------------------------------
  1858. */
  1859. #undef SOM_CurrentClass
  1860. #define SOM_CurrentClass SOMInstance
  1861. SOM_Scope void   SOMLINK find_wpInitData(Find
  1862. *somSelf)
  1863. {char        Errorbuffer¢60|;
  1864.  char        parms¢256|;
  1865.  RESULTCODES result;
  1866.  
  1867.  FindData   *somThis = FindGetData(somSelf);
  1868.  
  1869.  
  1870.     FindMethodDebug("Find","Find_wpInitData");
  1871.  
  1872.     parent_wpInitData(somSelf);
  1873.     if (FindIcon)
  1874.        _wpSetIcon(somSelf,FindIcon);
  1875.  
  1876.     _Frame       = (HWND)0;                         /*new code*/
  1877.      sprintf(_instancename,"FindClass%d",somSelf);
  1878. /*new code*/
  1879.  
  1880.     memset(&parms,0,sizeof(parms));   /*parms format*/
  1881.     strcpy(parms,"find");
  1882.     sprintf(parms+5,"%s",_instancename);
  1883.     DosExecPgm(Errorbuffer,
  1884.                sizeof(Errorbuffer),
  1885.                EXEC_ASYNC,
  1886.                parms,                     /*somSelf addr arg */
  1887.                0,
  1888.                &result,
  1889.                "FINDDLG.EXE");
  1890. }
  1891.  
  1892.  
  1893. SOM_Scope BOOL   SOMLINK
  1894. find_wpModifyPopupMenu(Find *somSelf,
  1895.                    HWND hwndMenu,
  1896.                    HWND hwndCnr,
  1897.                    ULONG iPosition)
  1898. {
  1899.     /* FindData *somThis = FindGetData(somSelf); */
  1900.     FindMethodDebug("Find","find_wpModifyPopupMenu");
  1901.  
  1902.     _wpInsertPopupMenuItems(somSelf,        /*this cases
  1903. adds to menu*/
  1904.                             hwndMenu,
  1905.                             iPosition,
  1906.                             hmodule,
  1907.                             RC_IDD_FINDMENU,
  1908.                             0);
  1909.   return (parent_wpModifyPopupMenu(somSelf,
  1910.                                    hwndMenu,
  1911.                                    hwndCnr,
  1912.                                    iPosition));
  1913. }
  1914.  
  1915.  
  1916. SOM_Scope BOOL   SOMLINK
  1917. find_wpMenuItemSelected(Find *somSelf,
  1918.                 HWND hwndFrame,
  1919.                 ULONG MenuId)
  1920. {FindData *somThis = FindGetData(somSelf);
  1921. /*required*/
  1922.  
  1923.  
  1924.     FindMethodDebug("Find","find_wpMenuItemSelected");
  1925.  
  1926.     switch (MenuId) {
  1927.        case RC_MI_FIND:
  1928.              if (GetObjectWindow(somSelf))        /*new
  1929. code*/
  1930.                 WinPostMsg(_Frame,WM_COMMAND,
  1931.                           (MPARAM)MAKEULONG(FIND,FIND),
  1932.                           (MPARAM)0L);
  1933.              break;
  1934.         default:
  1935.                return(parent_wpMenuItemSelected(somSelf,
  1936.                                                 hwndFrame,
  1937.                                                 MenuId));
  1938.       }
  1939.    return(TRUE);
  1940. }
  1941.  
  1942.  
  1943. SOM_Scope ULONG   SOMLINK find_wpDelete(Find
  1944. *somSelf,
  1945.    ULONG fConfirmations)
  1946. {
  1947.     FindData *somThis = FindGetData(somSelf);
  1948.     FindMethodDebug("Find","find_wpDelete");
  1949.  
  1950.    if (GetObjectWindow(somSelf))                      /*new
  1951. code*/
  1952.       WinPostMsg(_Frame,WM_QUIT,(MPARAM)0,
  1953. (MPARAM)0);/*ForNow Okay*/
  1954.    return (parent_wpDelete(somSelf,fConfirmations));
  1955. }
  1956.  
  1957.  #--------------------------------------------------------------------------
  1958.  # Program name:  Finddlg3.c     Title: WPS Programming using Mult Proc.
  1959.  # OS/2 Developer Magazine       Issue:  Spring '93, page 60
  1960.  #
  1961.  # Article:  "Workplace Shell Programming using Multiple Processes"
  1962.  # Author:  Richard Redpath, Sue Henshaw, Joe Coulombe
  1963.  # Phone:  n/a                   Fax:  n/a
  1964.  #
  1965.  # Description:  The following is a component of the complete source to the
  1966.  # above article in the specified issue of OS/2 Developer Magazine.  This
  1967.  # source is provided AS-IS without any implied or expressed warranty.
  1968.  #
  1969.  #--------------------------------------------------------------------------
  1970.  
  1971. /********************************************
  1972. ******
  1973.  * NAME: finddlg.c
  1974.  *
  1975.  * DESCRIPTION:
  1976.  *
  1977.  * Copyright (c) 1991 IBM Corporation
  1978. *********************************************
  1979. *******/
  1980. #define INCL_GPI                        /* Selectively include
  1981. */
  1982. #define INCL_WIN                        /* Selectively include
  1983. */
  1984. #define INCL_DOS
  1985.  
  1986.  
  1987. #include <os2.h>
  1988. #include <stdio.h>
  1989. #include <stdlib.h>
  1990. #include <string.h>
  1991. #include "finddef.h"
  1992. #include "finddat.h"
  1993.  
  1994.  
  1995. extern void  FindString(char *filename_p,
  1996.                        char *string,
  1997.                        unsigned fileattr,
  1998.                        HWND list);
  1999. extern void  SearchFile(char *filename,char
  2000. *string,HWND list);
  2001. extern MRESULT EXPENTRY DialogProc(HWND   hwndDlg,
  2002.                                    USHORT msg,
  2003.                                    MPARAM pm1,
  2004.                                    MPARAM pm2);
  2005. extern MRESULT EXPENTRY ObjectWndProc(
  2006.                                       HWND   hWnd,
  2007.                                       USHORT msg,
  2008.                                       MPARAM pm1,
  2009.                                       MPARAM pm2);
  2010.  
  2011. HAB          _hab;
  2012. HMQ          _hmq;
  2013. QMSG         _qmsg;
  2014. HWND         _Frame;
  2015.  
  2016.  
  2017. void  SearchFile(
  2018.     char          *filename,
  2019.     char          *string,
  2020.     HWND           list)
  2021. {FILE *fp;
  2022.  char buffer¢256|;
  2023.  char data¢256|;
  2024.  char *p;
  2025.  BOOL flag=1;
  2026.  
  2027.  if ( (fp=fopen(filename,"r"))==(FILE *)0)
  2028.     return;
  2029.  
  2030.  while (!feof(fp)){
  2031.        fgets(buffer,256,fp);
  2032.        if ((p=strchr(buffer,'\n'))!=(char *)0)
  2033.            *p=0;
  2034.        if (strstr(buffer,string)!=(char *)0)
  2035.          {
  2036.           if (flag)
  2037.              {
  2038.               sprintf(data,"####%s####",filename);
  2039.               WinSendMsg(list,
  2040.                          (ULONG)LM_INSERTITEM,
  2041.                          (MPARAM)LIT_END,
  2042.                          (MPARAM)data);
  2043.               flag=0;
  2044.              }
  2045.           WinSendMsg(list,
  2046.                      (ULONG)LM_INSERTITEM,
  2047.                      (MPARAM)LIT_END,
  2048.                      (MPARAM)buffer);
  2049.          }
  2050.  }
  2051.  fclose(fp);
  2052. }
  2053.  
  2054.  
  2055. void FindString(
  2056.     char          *filename_p,
  2057.     char          *string,
  2058.     unsigned       fileattr,
  2059.     HWND           list)
  2060.  
  2061. {HDIR            dirhandle=0xFFFF;
  2062.  FILEFINDBUF3    resultbuf;
  2063.  ULONG           lcount=1;
  2064.  char            *p;
  2065.  char             buffer¢256|;
  2066.  char             path¢256|;
  2067.  
  2068.  
  2069.  strcpy(path,filename_p);
  2070.  if ( (p=strrchr(path,'\\'))!=(char *)0)
  2071.     *(++p)=0;
  2072.  if (p==(char *)0)
  2073.    if ( (p=strchr(path,':'))!=(char *)0)
  2074.       *(++p)=0;
  2075.  
  2076.  
  2077.  if (DosFindFirst((PSZ)   filename_p,
  2078.                   (PHDIR) &dirhandle,
  2079.                   (ULONG) fileattr,
  2080.                   (PVOID) &resultbuf,
  2081.                   (ULONG) sizeof(resultbuf),
  2082.                   (PULONG) &lcount,
  2083.                   (ULONG) 1)==0)
  2084.       {
  2085.        do {
  2086.           sprintf(buffer,"%s%s",path,resultbuf.achName);
  2087.           SearchFile(buffer,string,list);
  2088.           }while (DosFindNext((HDIR)  dirhandle,
  2089.                               (PVOID) &resultbuf,
  2090.                               (ULONG) sizeof(resultbuf),
  2091.                               (PULONG) &lcount)==0);
  2092.  
  2093.  
  2094.        DosFindClose(dirhandle);
  2095.       }
  2096. }
  2097.  
  2098.  
  2099. MRESULT EXPENTRY DialogProc(
  2100.        HWND   hwndDlg,
  2101.        USHORT msg,
  2102.        MPARAM pm1,
  2103.        MPARAM pm2)
  2104. {char filename¢256|;
  2105.  char string¢256|;
  2106.  HWND list;
  2107.  
  2108.   switch (msg) {
  2109.      case WM_COMMAND:
  2110.           switch (LOUSHORT(pm1)) {
  2111.               case IDD_ENTER:
  2112.                     list =WinWindowFromID(hwndDlg,IDD_LIST);
  2113.                     WinQueryDlgItemText(hwndDlg,
  2114.                                         IDD_FILENAME,
  2115.                                         255,
  2116.                                         (PSZ)filename
  2117.                                        );
  2118.                     WinQueryDlgItemText(hwndDlg,
  2119.                                         IDD_STRING,
  2120.                                         255,
  2121.                                         (PSZ)string
  2122.                                        );
  2123.                     FindString(filename,string,(unsigned)0,list);
  2124.                     break;
  2125.               case IDD_CANCEL:
  2126.               default:
  2127.                     WinDismissDlg( hwndDlg, FALSE );
  2128.                     break;
  2129.              }
  2130.           break;
  2131.      default:
  2132.          return(WinDefDlgProc(hwndDlg, msg, pm1, pm2));
  2133.     }
  2134.   return(MRFROMLONG(NULL));
  2135. }
  2136.  
  2137.  
  2138. MRESULT EXPENTRY ObjectWndProc(
  2139.              HWND   hWnd,
  2140.              USHORT msg,
  2141.              MPARAM pm1,
  2142.              MPARAM pm2)
  2143. {
  2144.  
  2145.   switch (msg)  {
  2146.    case WM_COMMAND:
  2147.         switch (SHORT1FROMMP(pm1)) {
  2148.              case FIND:
  2149.                  WinDlgBox((HWND)  HWND_DESKTOP,
  2150.                            (HWND)  HWND_DESKTOP,
  2151.                            (PFNWP) DialogProc,
  2152.                            0L,
  2153.                            (ULONG) IDD_DLG,
  2154.                            (PVOID) 0);
  2155.              default: break;
  2156.            }
  2157.          break;
  2158.     default:
  2159.       return
  2160. ((MRESULT)WinDefWindowProc(hWnd,msg,pm1,pm2));
  2161.    }
  2162.   return((MRESULT)0);
  2163. }
  2164.  
  2165.  
  2166. int main(int    argc,
  2167.          char **argv)
  2168. {int    rc;
  2169.  
  2170.     DosBeep(100,100);          /*Indicate that it has been
  2171. started*/
  2172.  
  2173.     if (argc<2)
  2174.        exit(-1);
  2175.  
  2176.    _hab = WinInitialize((ULONG)0L);
  2177.    _hmq = WinCreateMsgQueue(_hab, (LONG)0L);
  2178.     WinRegisterClass(_hab,
  2179.                      (PSZ)argv¢1|,                    /*new code*/
  2180.                      (PFNWP)ObjectWndProc,
  2181.                      (ULONG)0L,
  2182.                      (ULONG)4L);
  2183.     _Frame = WinCreateWindow(HWND_OBJECT,
  2184.                             (PSZ)   argv¢1|,           /*new code*/
  2185.                             (PSZ)   "Object Window",
  2186.                             0L,
  2187.  
  2188. (ULONG)0L,(ULONG)0L,(ULONG)0L,(ULONG)0L,
  2189.                             (HWND)0,
  2190.                             HWND_TOP,
  2191.                             101,
  2192.                             (ULONG)0,
  2193.                             (PVOID)0);
  2194.  
  2195.     while (WinGetMsg(_hab,
  2196.                      (PQMSG)&_qmsg,
  2197.                      (HWND)NULL,
  2198.                      (ULONG)0L,
  2199.                      (ULONG)0L ) ){
  2200.         if (_qmsg.msg==WM_QUIT)
  2201.             break;
  2202.         WinDispatchMsg( _hab, (PQMSG)&_qmsg );
  2203.        }
  2204.     DosBeep(1000,1000);             /*indicate that it has
  2205. ended*/
  2206.     WinDestroyWindow( _Frame );
  2207.     WinDestroyMsgQueue( _hmq );
  2208.     WinTerminate( _hab );
  2209. }
  2210.  
  2211.  
  2212.