home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / asci20b1.zip / dtype.c < prev    next >
Text File  |  1999-05-21  |  3KB  |  89 lines

  1. /* dtype.c: DirectType Module */
  2. /* This module includes everything that has to do with DirectType. DirectType
  3.    is a way to insert characters directly into another application. It is meant
  4.    for people who want to type long texts with a lot of characters that are
  5.    difficult to insert.
  6. */
  7.  
  8. #define INCL_WIN
  9. #define INCL_WINHOOKS
  10. #define INCL_PM
  11. #define INCL_GPI
  12. #include <os2.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include "ascii.h"
  17. #include "dtype.h"
  18.  
  19. /* At the moment I don't know exactly how I will do this, I hope it will be
  20.    sufficient to just post a message to the application.
  21.    At least I need a dialogbox, and therefore a Window Procedure, and I need
  22.    a procedure to send the WM_CHAR message to the receiving application.
  23. */
  24.  
  25.  
  26. // Window procedure for the DirectType dialogbox
  27. // Is called by the system
  28. MRESULT EXPENTRY DirectTypeProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  29. {
  30. // Declaration of variables
  31. USHORT ControlID;
  32. APIRET rc;
  33. ULONG cbItems, ulBufSize, i;
  34. static PSWBLOCK pSwBlock;
  35. SWENTRY p;
  36. switch (msg)
  37.    {
  38.    case WM_INITDLG:
  39.       // Initialization
  40.       // Query all the programs and fill the listbox with their names
  41.       // Query the number of items in the switchlist
  42.       cbItems=WinQuerySwitchList(hab, NULL, 0);
  43.       // Calculate needed memory
  44.       ulBufSize=(cbItems*sizeof(SWENTRY))+sizeof(HSWITCH);
  45.       // and allocate it
  46.       rc=DosAllocMem(pSwBlock, ulBufSize, PAG_COMMIT | PAG_READ | PAG_WRITE);
  47.       if (rc!=0)
  48.          {
  49.          WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Not enough memory", "Error", MB_OK | MB_ERROR);
  50.          WinSendMsg(hwnd, WM_CLOSE, 0L, 0L);
  51.          }
  52.       cbItems=WinQuerySwitchList(hab, pSwBlock, ulBufSize);
  53.       // Populate listbox
  54.       p=pSwBlock->aswentry;
  55.       for (i=0; i<pSwBlock->cswentry; i++, p++)
  56.          {
  57.          WinSendMsg(WinWindowFromID(hwnd, LB_PROGRAMS), LIT_END, p->szSwTitle);
  58.          }
  59.       break;
  60.    case WM_COMMAND:
  61.       // Commands from controls
  62.       // Resource ID of control
  63.       ControlID=SHORT1FROMMP(mp1);
  64.       switch (ControlID)
  65.          {
  66.          case PB_OK:
  67.             // Pushbutton pressed
  68.             // Close the About dialogbox
  69.             // Send the WM_CLOSE message
  70.             WinSendMsg(hwnd, WM_CLOSE, 0L, 0L);
  71.             break;
  72.          }
  73.       break;
  74.    case WM_CLOSE:
  75.       // Close the dialogbox
  76.       // Dismiss the dialogbox
  77.       WinDismissDlg(hwnd, TRUE);
  78.       // Note we now do not send a WM_QUIT message, if we did so, we would close all of the application
  79.       break;
  80.    default:
  81.       // Let the default window procedure handle messages we didn't handle
  82.       return WinDefDlgProc(hwnd, msg, mp1, mp2);
  83.    }
  84. // All messages are handled
  85. return (MRESULT)FALSE;
  86. }
  87.  
  88.  
  89.