home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / MQSRC.LZH / MLE_WP.C < prev    next >
C/C++ Source or Header  |  1991-05-05  |  4KB  |  142 lines

  1. #define INCL_WIN
  2. #include <os2.h>
  3. #include <process.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include "mq.h"
  8.  
  9. static FILE *openfile(HWND hwnd)
  10. {
  11.     DLF FileData;
  12.     HFILE hf;
  13.     USHORT rc;
  14.  
  15.     memset(&FileData, 0, sizeof(FileData));
  16.  
  17.     FileData.rgbAction       = 0;
  18.     FileData.rgbFlags        = 0x0010;
  19.     FileData.phFile          = &hf;
  20.     FileData.pszExt          = "\\*";
  21.     FileData.pszTitle        = "File Selector";
  22.     FileData.pszInstructions = "Please choose a TEXT file to read";
  23.     rc = WtiDlgFile(hwnd, &FileData);
  24.     if( rc == 4 )
  25.         return(fdopen(hf, "rb"));
  26.     else{
  27.         return(NULL);
  28.     }
  29. }
  30.  
  31. MRESULT EXPENTRY MleWinProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  32. {
  33.     FILE *fin;
  34.     INSTANCE *inst = WinQueryWindowPtr(hwnd, 0);
  35.  
  36.     switch(msg){
  37.         case WM_ERASEBACKGROUND:
  38.             return((MRESULT)TRUE);
  39.         case WM_SIZE:
  40.             if(inst) WinSetWindowPos(inst->hwndMLE, 0,
  41.                             5,5,
  42.                             SHORT1FROMMP(mp2)-10,
  43.                             SHORT2FROMMP(mp2)-10,
  44.                             SWP_SIZE | SWP_MOVE);
  45.             break;
  46.         case WM_COMMAND:
  47.             switch( SHORT1FROMMP(mp1)){
  48.                 case IDM_OPEN:
  49.                     fin = openfile(hwnd);
  50.                     if(fin && inst->hmqWork){
  51.                         WinPostQueueMsg(inst->hmqWork, WMU_LOADFILE, (MPARAM)fin, 0);
  52.                     }
  53.                     break;
  54.                 case IDM_CLEAR:
  55.                     WinPostQueueMsg(inst->hmqWork, WMU_CLEAR, 0, 0);
  56.                     break;
  57.                 case IDM_HALT:
  58.                     inst->running = FALSE;
  59.                     break;
  60.             }
  61.             break;
  62.         case WMU_DONEFILE:
  63. #if 0
  64.             if( MBID_YES == WinMessageBox(HWND_DESKTOP, hwnd,
  65.                               "Finished.  Load another file?",
  66.                               "Sample App", 0, MB_YESNO | MB_ICONQUESTION)){
  67.                 WinPostMsg(hwnd, WM_COMMAND, MPFROMSHORT(IDM_OPEN), 0);
  68.             }
  69. #endif
  70.             break;
  71.         case WM_CLOSE:
  72.             inst->running = FALSE;
  73.             WinPostQueueMsg(inst->hmqWork, WM_QUIT, 0, 0);
  74.             return(0);  /* this cases the window NOT to close.  We will
  75.                          * close when the other thread sends us a WMU_CLOSE
  76.                          */
  77.             break;
  78.         case WMU_CLOSE:
  79.             free(inst->stack);
  80.             free(inst);
  81.             WinDestroyWindow(inst->hwndFrame);
  82.             break;
  83.         default:
  84.             return(WinDefWindowProc(hwnd, msg, mp1, mp2));
  85.     }
  86.     return(0);
  87. }
  88.  
  89. void OpenNewMleWin(HWND hwnd)
  90. {
  91.     INSTANCE *inst;
  92.     ULONG flstyle;
  93.     SWP swp;
  94.     static SHORT x = 0;
  95.     static int num = 0;
  96.     char title[15];
  97.  
  98.     inst = malloc(sizeof(INSTANCE));
  99.     if(!inst)
  100.         return;
  101.  
  102.     sprintf(title, "Child #%u", ++num);
  103.     flstyle = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX | FCF_MENU;
  104.     inst->hwndFrame = WinCreateStdWindow(hwnd, 0L, &flstyle,
  105.         "MyMLE", title, 0L, 0, ID_CHILD, &inst->hwndClient);
  106.  
  107.     if(!inst->hwndFrame)
  108.         return;
  109.  
  110.     DosSemSet(&inst->semReady);
  111.     inst->stack = malloc(0x1800);
  112.     _beginthread(WorkThread, inst->stack, 0x1800, inst);
  113.     DosSemRequest(&inst->semReady, -1L);   /* wait till thread is ready */
  114.  
  115.     /* set "window words" to our instance data.  This will later
  116.      * be retrieved by WinQueryWindowPtr()
  117.      */
  118.     WinSetWindowPtr(inst->hwndClient, 0, inst);
  119.  
  120.     /* make child fit in parent: */
  121.     WinQueryWindowPos(hwnd, &swp);
  122.     swp.x = swp.y = x;
  123.     x += 10;
  124.     if(x > swp.cx-20)
  125.         x = 0;
  126.     swp.cx = swp.cx * 2 / 3;
  127.     swp.cy = swp.cy * 2 / 3;
  128.     WinSetWindowPos(inst->hwndFrame, 0, swp.x, swp.y, swp.cx, swp.cy,
  129.                     SWP_SIZE | SWP_MOVE);
  130.     WinQueryWindowPos(inst->hwndClient, &swp);
  131.  
  132.     inst->hwndMLE = WinCreateWindow(inst->hwndClient, WC_MLE, NULL,
  133.                           MLS_BORDER | WS_VISIBLE | MLS_VSCROLL | MLS_HSCROLL,
  134.                           5, 5,
  135.                           swp.cx-10, swp.cy-10,
  136.                           inst->hwndClient,
  137.                           HWND_TOP, ID_MLE, NULL, NULL);
  138.  
  139.     WinShowWindow(inst->hwndFrame, TRUE);
  140.     WinSetFocus(HWND_DESKTOP, inst->hwndMLE);
  141. }
  142.