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