home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / AW2.ZIP / AW.C < prev    next >
Text File  |  1989-11-26  |  9KB  |  395 lines

  1. #define INCL_PM
  2. #define INCL_DOS
  3. #include <os2.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <string.h>
  8. #include "aw.h"
  9. #include "scr.h"
  10. #define max(a,b)    (((a) > (b)) ? (a) : (b))
  11. #define min(a,b)    (((a) < (b)) ? (a) : (b))
  12. #define CSTR    7
  13.  
  14. HAB    hAB;
  15. HMQ    hmqaw;
  16. HWND    hwndaw;
  17. HWND    hwndawFrame;
  18. HHEAP hHeap;
  19. FILEFINDBUF buff ;
  20. struct TTYWND MWnd;
  21.  
  22. CHAR    szClassName[] = "aw";
  23. char far filename[256];
  24. char far pathname[256];
  25. SHORT    iSel = 0;
  26. RECTL    rect;
  27. USHORT all = TRUE;
  28. char drive_str[27][4];
  29. USHORT drive_sel[27];
  30. USHORT num_drive = 0;
  31. LONG SecSem;
  32. TID idThread;
  33. UCHAR cThreadStack[5120];
  34. USHORT busy = FALSE;
  35. USHORT file_attr = 0x0000;
  36.  
  37. SHORT cdecl main( )
  38. {
  39.     QMSG qmsg;
  40.     ULONG ctldata;
  41.     RECTL rect;
  42.  
  43.     hAB = WinInitialize(NULL);
  44.  
  45.     hmqaw = WinCreateMsgQueue(hAB, 0);
  46.     if ((hHeap = WinCreateHeap(0, 0, 0, 0, 0, 0)) == NULL)
  47.     return FALSE;
  48.  
  49.     if (!WinRegisterClass( hAB,
  50.                (PCH)szClassName,
  51.                (PFNWP)awWndProc,
  52.                CS_SYNCPAINT | CS_SIZEREDRAW,
  53.                0))
  54.     return( 0 );
  55.  
  56.     ctldata = FCF_STANDARD  & ~FCF_SHELLPOSITION;;
  57.  
  58.     hwndawFrame = WinCreateStdWindow( HWND_DESKTOP,
  59.                      WS_VISIBLE,
  60.                      &ctldata,
  61.                      (PCH)szClassName,
  62.                      NULL,
  63.                      0L,
  64.                      (HMODULE)NULL,
  65.                      AWICON,
  66.                      (HWND FAR *)&hwndaw );
  67.     WinQueryWindowRect( HWND_DESKTOP, (PRECTL)&rect );
  68.     WinSetWindowPos(hwndawFrame,HWND_TOP,
  69.          (SHORT)rect.xLeft,(SHORT)rect.yTop  - 270,230,
  70.          (SHORT)270,
  71.          SWP_SIZE | SWP_MOVE |SWP_ACTIVATE);
  72.  
  73.     WinShowWindow( hwndawFrame, TRUE );
  74.  
  75.     MWnd.hWnd = hwndaw;
  76.  
  77.     while( WinGetMsg( hAB, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) )
  78.     {
  79.     WinDispatchMsg( hAB, (PQMSG)&qmsg );
  80.     }
  81.     DosSuspendThread(idThread);
  82.     WinDestroyWindow( hwndawFrame );
  83.     WinDestroyMsgQueue( hmqaw );
  84.     WinTerminate( hAB );
  85. }
  86.  
  87. void FAR WndCreate(HWND hWnd)
  88. {
  89.     FONTMETRICS FM;
  90.     HPS hPS;
  91.     short width, height, cwidth, cheight;
  92.  
  93.     DosSemSet(&SecSem);
  94.     if(DosCreateThread(SecondThread,&idThread,cThreadStack + sizeof(cThreadStack)))
  95.     WinAlarm(HWND_DESKTOP,WA_ERROR);
  96.     hPS = WinGetPS(hWnd);
  97.     GpiQueryFontMetrics(hPS, (LONG)sizeof(FONTMETRICS), &FM);
  98.     cwidth = (short)(FM.lMaxBaselineExt + FM.lExternalLeading);
  99.     cheight = (short)FM.lMaxAscender + (short)FM.lMaxDescender;
  100.     WinReleasePS (hPS);
  101.  
  102.     width = (SHORT)WinQuerySysValue(HWND_DESKTOP,SV_CXFULLSCREEN);
  103.     height = (SHORT)WinQuerySysValue(HWND_DESKTOP,SV_CYFULLSCREEN);
  104.     InitWindow(&MWnd,0,0,width,height,cwidth,cheight,FALSE,TRUE,TRUE,0xff);
  105. }
  106.  
  107. MRESULT EXPENTRY awWndProc( hWnd, msg, mp1, mp2 )
  108. HWND   hWnd;
  109. USHORT msg;
  110. MPARAM mp1;
  111. MPARAM mp2;
  112. {
  113.     HPS    hPS;
  114.     if(!busy)
  115.        EnableMenuItem(hwndaw,IDM_PARA,TRUE);
  116.     switch (msg)
  117.     {
  118.     case WM_CREATE:
  119.          WndCreate(hWnd);
  120.          break;
  121.      case WM_COMMAND:
  122.          switch(LOUSHORT(mp1))
  123.          {
  124.           case IDM_EXITAW:
  125.                WinPostMsg( hWnd, WM_QUIT, 0L, 0L );
  126.                break;
  127.           case IDM_RESUME:
  128.                break;
  129.           case IDMABOUT:
  130.                WinDlgBox(HWND_DESKTOP,hWnd,(PFNWP)AboutDlg,NULL,IDD_ABOUT, NULL );
  131.                break;
  132.           case IDM_PARA:
  133.                WinDlgBox(HWND_DESKTOP,hWnd,(PFNWP)ParaDlg,NULL,IDD_PARA, NULL );
  134.                break;
  135.          }
  136.          break;
  137.    case WM_MOVE:
  138.     break;
  139.    case WM_CLOSE:
  140.     WinPostMsg( hWnd, WM_QUIT, 0L, 0L );
  141.     break;
  142.  
  143.     case WM_PAINT:
  144.     hPS = WinBeginPaint( hWnd, (HPS)NULL, (PWRECT)NULL );
  145.     WinQueryWindowRect( hWnd, (PRECTL)&rect );
  146.     WndPaint(&MWnd, hPS,(short)rect.yTop);
  147.     WinEndPaint( hPS );
  148.     break;
  149.  
  150.     case WM_ERASEBACKGROUND:
  151.     return( TRUE );
  152.     break;
  153.  
  154.     case WM_PAINT_TTY:
  155.     Display(&MWnd,strlen(mp1), mp1);
  156.     DosSemClear(&SecSem);
  157.     break;
  158.  
  159.     default:
  160.     return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  161.     break;
  162.     }
  163.     return(0L);
  164. }
  165.  
  166. MRESULT EXPENTRY AboutDlg( hWndDlg, message, mp1, mp2 )
  167. HWND   hWndDlg;
  168. USHORT message;
  169. MPARAM mp1;
  170. MPARAM mp2;
  171. {
  172.     switch( message )
  173.     {
  174.       case WM_COMMAND:          /* the user has pressed a button */
  175.     switch( SHORT1FROMMP( mp1 ) )    /* which button? */
  176.     {
  177.       case DID_OK:
  178.       case DID_CANCEL:
  179.         WinDismissDlg( hWndDlg, TRUE );
  180.         break;
  181.  
  182.       default:
  183.         return( FALSE );
  184.     }
  185.     break;
  186.  
  187.       default:
  188.     return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) );
  189.     }
  190.     return( FALSE );
  191. }
  192.  
  193. MRESULT EXPENTRY ParaDlg( hWndDlg, message, mp1, mp2 )
  194. HWND   hWndDlg;
  195. USHORT message;
  196. MPARAM mp1;
  197. MPARAM mp2;
  198. {
  199.    char drives;
  200.    char str[5];
  201.    USHORT indx;
  202.    USHORT disk;
  203.    ULONG drivemap;
  204.    USHORT con;
  205.  
  206.     switch( message )
  207.     {
  208.     case WM_INITDLG:
  209.         DosQCurDisk(&disk,&drivemap);
  210.         for(drives = 'A'; drives <= 'Z'; drives++)
  211.         {
  212.          if(drivemap & 1)
  213.          {
  214.               str[0] = drives;
  215.               str[1] = ':';
  216.               str[2] = 0;
  217.               WinSendDlgItemMsg( hWndDlg, IDD_LISTBOX, LM_INSERTITEM,
  218.                        (MPARAM)LIT_END, (MPARAM)(PCH)str );
  219.          }
  220.          drivemap >>= 1;
  221.         }
  222.         for(indx = 0;indx < num_drive;indx++)
  223.         WinSendDlgItemMsg( hWndDlg, IDD_LISTBOX, LM_SELECTITEM,
  224.                  (MPARAM)(drive_sel[indx]), (MPARAM)TRUE );
  225.         if(indx == 0)
  226.         WinSendDlgItemMsg( hWndDlg, IDD_LISTBOX, LM_SELECTITEM,
  227.                  (MPARAM)(disk - 1), (MPARAM)TRUE );
  228.         WinSetWindowText(WinWindowFromID(hWndDlg,IDD_FILE),filename);
  229.         if(file_attr & 0x0004)
  230.         WinSendDlgItemMsg(hWndDlg,IDD_SYS,BM_SETCHECK,(MPARAM)TRUE,0L);
  231.         if(file_attr & 0x0002)
  232.         WinSendDlgItemMsg(hWndDlg,IDD_HID,BM_SETCHECK,(MPARAM)TRUE,0L);
  233.         if(all)
  234.         WinSendDlgItemMsg(hWndDlg,IDD_ALL,BM_SETCHECK,(MPARAM)TRUE,0L);
  235.         WinSendDlgItemMsg(hWndDlg,IDD_FILE,EM_SETTEXTLIMIT,(MPARAM)256,0L);
  236.         break;
  237.     case WM_COMMAND:
  238.         switch( SHORT1FROMMP( mp1 ) )
  239.         {
  240.         case DID_OK:
  241.             file_attr = 0x0000;
  242.             all = FALSE;
  243.             WinQueryDlgItemText(hWndDlg,IDD_FILE,sizeof(filename),(PCH)filename);
  244.             iSel =LIT_FIRST;
  245.             for(indx = 0,con = 1;con == 1;indx++)
  246.             {
  247.             iSel =    (SHORT)WinSendDlgItemMsg( hWndDlg, IDD_LISTBOX,
  248.                               LM_QUERYSELECTION,(MPARAM)iSel, 0L);
  249.             if(iSel != LIT_NONE)
  250.             {
  251.                 WinSendDlgItemMsg(hWndDlg,IDD_LISTBOX,LM_QUERYITEMTEXT,
  252.                           MPFROM2SHORT((SHORT)iSel, (SHORT)3), drive_str[indx]);
  253.                 drive_sel[indx] = iSel;
  254.             }
  255.             else
  256.                 con = 0;
  257.             }
  258.             num_drive = indx - 1;
  259.             if(WinSendDlgItemMsg(hWndDlg,IDD_SYS,BM_QUERYCHECK,0L,0L) == 1)
  260.             file_attr = file_attr | 0x0004;
  261.             if(WinSendDlgItemMsg(hWndDlg,IDD_HID,BM_QUERYCHECK,0L,0L) == 1)
  262.             file_attr = file_attr | 0x0002;
  263.             if(WinSendDlgItemMsg(hWndDlg,IDD_ALL,BM_QUERYCHECK,0L,0L) == 1)
  264.             all = TRUE;
  265.             WinDismissDlg( hWndDlg, TRUE );
  266.             Display(&MWnd,21, "\nStarting search...\n");
  267.             busy = TRUE;
  268.             EnableMenuItem(hwndaw,IDM_PARA,FALSE);
  269.             DosSemClear(&SecSem);
  270.             break;
  271.  
  272.         case DID_CANCEL:
  273.             WinDismissDlg( hWndDlg, TRUE );
  274.             break;
  275.  
  276.         default:
  277.             return( FALSE );
  278.         }
  279.         break;
  280.  
  281.      default:
  282.          return( WinDefDlgProc( hWndDlg, message, mp1, mp2 ) );
  283.     }
  284.     return( FALSE );
  285. }
  286.  
  287. VOID FAR SecondThread()
  288. {
  289.    USHORT indx;
  290.  
  291.    while(1)
  292.    {
  293.     DosSemWait(&SecSem,-1L);
  294.     busy = TRUE;
  295.     for(indx= 0; indx < num_drive;indx++)
  296.     {
  297.          find_dir(drive_str[indx]);
  298.     }
  299.     WinPostMsg(hwndaw,WM_PAINT_TTY,"File search complete !!\n",0L);
  300.     WinAlarm(HWND_DESKTOP,WA_NOTE);
  301.     busy = FALSE;
  302.     DosSemSet(&SecSem);
  303.    }
  304. }
  305.  
  306. VOID find_dir(path)
  307. char *path;
  308. {
  309.    char localpath[180];
  310.    USHORT count = 1;
  311.    USHORT handle = 0xFFFF;
  312.  
  313.    strcat(path,"\\");
  314.    strcpy(localpath,path);
  315.    strcat(localpath,"*.*");
  316.    if(DosFindFirst(localpath,&handle,0x0010,&buff,sizeof(buff),&count,0L))
  317.    {
  318.     DosFindClose(handle);
  319.     search_dir(path);
  320.     return;
  321.    }
  322.    if(buff.achName[0] != '.' && (buff.attrFile & 0x0010))
  323.    {
  324.     strcpy(localpath,path);
  325.     strcat(localpath,buff.achName);
  326.     find_dir(localpath);
  327.    }
  328.    while(TRUE)
  329.    {
  330.     if(DosFindNext(handle,&buff,sizeof(buff),&count))
  331.     {
  332.          DosFindClose(handle);
  333.          search_dir(path);
  334.          return;
  335.     }
  336.     if(buff.achName[0] != '.' && (buff.attrFile & 0x0010))
  337.     {
  338.          strcpy(localpath,path);
  339.          strcat(localpath,buff.achName);
  340.          find_dir(localpath);
  341.     }
  342.     }
  343. }
  344.  
  345. VOID search_dir(path)
  346. char *path;
  347. {
  348.    char localpath[180];
  349.    USHORT count = 1;
  350.    USHORT handle = 0xFFFF;
  351.  
  352.    strcpy(localpath,path);
  353.    strcat(localpath,filename);
  354.    strset(buff.achName,0);
  355.    if(DosFindFirst(localpath,&handle,file_attr,&buff,sizeof(buff),&count,0L))
  356.    {
  357.     DosFindClose(handle);
  358.     return;
  359.    }
  360.    if(all || (buff.attrFile & file_attr))
  361.    {
  362.     DosSemWait(&SecSem,-1L);
  363.     sprintf(pathname,"%s%s\n",path,buff.achName);
  364.     DosSemSet(&SecSem);
  365.     WinPostMsg(hwndaw,WM_PAINT_TTY,pathname,0L);
  366.    }
  367.    while(TRUE)
  368.    {
  369.     if(DosFindNext(handle,&buff,sizeof(buff),&count))
  370.     {
  371.          DosFindClose(handle);
  372.          return;
  373.     }
  374.     DosSemWait(&SecSem,-1L);
  375.     if(all || (buff.attrFile & file_attr))
  376.     {
  377.         sprintf(pathname,"%s%s\n",path,buff.achName);
  378.         DosSemSet(&SecSem);
  379.         WinPostMsg(hwndaw,WM_PAINT_TTY,pathname,0L);
  380.     }
  381.    }
  382. }
  383.  
  384. VOID EnableMenuItem(HWND hwnd, SHORT iMenuItem, BOOL bEnable)
  385. {
  386.    HWND hwndParent;
  387.    HWND hwndMenu;
  388.  
  389.    hwndParent = WinQueryWindow(hwnd,QW_PARENT,FALSE);
  390.    hwndMenu = WinWindowFromID(hwndParent,FID_MENU);
  391.    
  392.    WinSendMsg(hwndMenu,MM_SETITEMATTR,(MPARAM)MAKEULONG(iMenuItem,TRUE),
  393.          (MPARAM)MAKEULONG(MIA_DISABLED,bEnable ? 0 : MIA_DISABLED));
  394. }
  395.