home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / dwnvprx.lzh / DWNVPRX.C < prev    next >
Text File  |  1995-05-02  |  5KB  |  148 lines

  1. /* REXX extension DLL to allow VisPro REXX to manipulate
  2.    PM controls in other ways than supplied with the VisPro REXX
  3.    product.
  4.  
  5.    Copyright (C) 1995, David W. Noon */
  6.  
  7. #define INCL_WINMESSAGEMGR
  8. #define INCL_WINENTRYFIELDS
  9. #define INCL_WINMLE
  10. #define INCL_DOSMISC
  11. #include <os2.h>
  12.  
  13. #define INCL_REXXFUNC
  14. #include <rexxsaa.h>
  15.  
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. /* Inserts for the error message:
  20.       VPRX0001E Incorrect number of arguments passed. Should be %1.
  21.    where %1 gets replaced by the insert string. */
  22. static PCHAR Arg_insert[2] = {"2","3"};
  23.  
  24. /* Inserts for the error message:
  25.       VPRX0003E The %1 argmuent is not an unsigned integer.
  26.    where %1 gets replaced by the insert string. */
  27. static PCHAR Uint_insert[2] = {"second","third"};
  28.  
  29. /* The entry point DwnSetTextLimit() should be called from a REXX exec
  30.    by passing 2 arguments. The first should be the handle of the
  31.    entry field control to which the EM_SETTEXTLIMIT message is to be
  32.    sent. The second is an unsigned integer value representing the
  33.    maximum size of input field the control is to accept.
  34.  
  35.    The return value is a Boolean (0=FALSE, 1=TRUE) as returned 
  36.    by the control.
  37.  
  38.    For example:
  39.         CALL DwnSetTextLimit VpItem(window,'EFIELD','GETHANDLE'),25
  40.    This will set the control labelled EFIELD to accept a maximum of 25
  41.    characters of input.
  42.  
  43.    */
  44.  
  45. ULONG APIENTRY DwnSetTextLimit(PUCHAR Function_name, ULONG argc,
  46.                 RXSTRING argv[], PSZ Queue_name, PRXSTRING Ret_str)
  47.  
  48. {
  49.    MRESULT mrc;
  50.  
  51.    if (argc != 2UL)
  52.    {
  53.       /* Incorrect number of arguments */
  54.       DosGetMessage(&Arg_insert[0],1UL,RXSTRPTR(*Ret_str),RXSTRLEN(*Ret_str),1UL,
  55.             "DWNVPRX.MSG",&(Ret_str->strlength));
  56.    }
  57.    else if (RXSTRLEN(argv[0]) > 10 ||
  58.          strspn(RXSTRPTR(argv[0]),"0123456789") != RXSTRLEN(argv[0]))
  59.    {
  60.       /* First argument is not a handle */
  61.       DosGetMessage(NULL,0UL,RXSTRPTR(*Ret_str),RXSTRLEN(*Ret_str),2UL,
  62.             "DWNVPRX.MSG",&(Ret_str->strlength));
  63.    }
  64.    else if (strspn(RXSTRPTR(argv[1]),"0123456789") != RXSTRLEN(argv[1]))
  65.    {
  66.       /* Second argument is not an unsigned number */
  67.       DosGetMessage(&Uint_insert[0],1UL,RXSTRPTR(*Ret_str),RXSTRLEN(*Ret_str),3UL,
  68.             "DWNVPRX.MSG",&(Ret_str->strlength));
  69.    }
  70.    else
  71.    {
  72.       /* Send the resize message to the entry field control */
  73.       mrc = WinSendMsg((HWND)strtoul(RXSTRPTR(argv[0]),NULL,10),EM_SETTEXTLIMIT,
  74.             MPFROMLONG(atol(RXSTRPTR(argv[1]))),MPFROMSHORT(0));
  75.  
  76.       /* Now format the return code */
  77.       ultoa((ULONG)mrc,RXSTRPTR(*Ret_str),10);
  78.       Ret_str->strlength = strlen(RXSTRPTR(*Ret_str));
  79.    }
  80.  
  81.    return 0UL;
  82. }
  83.  
  84. /* The entry point DwnSetSel() should be called from a REXX exec
  85.    by passing 3 arguments. The first should be the handle of the
  86.    entry field control to which the MLM_SETSEL message is to be
  87.    sent. The second is an unsigned integer value representing the
  88.    anchor point at which text selection is to begin. The third is
  89.    the cursor point at which the text selection is to end. If the
  90.    anchor point and the cursor point are equal, it simply repositions
  91.    the cursor to that point, with no text selected.
  92.  
  93.    The return value is a Boolean (0=FALSE, 1=TRUE) as returned by
  94.    the control.
  95.  
  96.    For example:
  97.         CALL DwnSetSel VpItem(window,'EDITBOX','GETHANDLE'),0,0
  98.    This will position the cursor in the MLE control labelled EDITBOX
  99.    at the top-left corner.
  100.  
  101.    */
  102.  
  103. ULONG APIENTRY DwnSetSel(PUCHAR Function_name, ULONG argc,
  104.                 RXSTRING argv[], PSZ Queue_name, PRXSTRING Ret_str)
  105.  
  106. {
  107.    MRESULT mrc;
  108.  
  109.    if (argc != 3UL)
  110.    {
  111.       /* Incorrect number of arguments */
  112.       DosGetMessage(&Arg_insert[1],1UL,RXSTRPTR(*Ret_str),RXSTRLEN(*Ret_str),1UL,
  113.             "DWNVPRX.MSG",&(Ret_str->strlength));
  114.    }
  115.    else if (RXSTRLEN(argv[0]) > 10 ||
  116.          strspn(RXSTRPTR(argv[0]),"0123456789") != RXSTRLEN(argv[0]))
  117.    {
  118.       /* First argument is not a handle */
  119.       DosGetMessage(NULL,0UL,RXSTRPTR(*Ret_str),RXSTRLEN(*Ret_str),2UL,
  120.             "DWNVPRX.MSG",&(Ret_str->strlength));
  121.    }
  122.    else if (strspn(RXSTRPTR(argv[1]),"0123456789") != RXSTRLEN(argv[1]))
  123.    {
  124.       /* Second argument is not an unsigned number */
  125.       DosGetMessage(&Uint_insert[0],1UL,RXSTRPTR(*Ret_str),RXSTRLEN(*Ret_str),3UL,
  126.             "DWNVPRX.MSG",&(Ret_str->strlength));
  127.    }
  128.    else if (strspn(RXSTRPTR(argv[2]),"0123456789") != RXSTRLEN(argv[2]))
  129.    {
  130.       /* Third argument is not an unsigned number */
  131.       DosGetMessage(&Uint_insert[1],1UL,RXSTRPTR(*Ret_str),RXSTRLEN(*Ret_str),3UL,
  132.             "DWNVPRX.MSG",&(Ret_str->strlength));
  133.    }
  134.    else
  135.    {
  136.       /* Send the text selection message to the multi-line entry field control */
  137.       mrc = WinSendMsg((HWND)strtoul(RXSTRPTR(argv[0]),NULL,10),MLM_SETSEL,
  138.             MPFROMLONG(atol(RXSTRPTR(argv[1]))),
  139.             MPFROMLONG(atol(RXSTRPTR(argv[2]))));
  140.  
  141.       /* Now format the return code */
  142.       ultoa((ULONG)mrc,RXSTRPTR(*Ret_str),10);
  143.       Ret_str->strlength = strlen(RXSTRPTR(*Ret_str));
  144.    }                                                                       
  145.  
  146.    return 0UL;
  147. }
  148.