home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ETKDLG.ZIP / ESAMPDLG.E < prev    next >
Text File  |  1992-09-25  |  7KB  |  153 lines

  1. --
  2. -- ESAMPDLG.E
  3. --
  4. -- Sample E code that works with SAMPDLG.DLL to create custom dialog boxes
  5. -- from the E macro language.
  6. -- Two examples commands are provided:
  7. --      CreateSample1Dlg - Creates a modeless dialog box.  This box is
  8. --                  -      useful when you wish the user to operate with
  9. --                         the dialog box and the text file simultaneously.
  10. --      CreateSample2Dlg - Creates a application modal dialog box.  This box is
  11. --                  -      useful when it is important to get a response from
  12. --                         the user before continuing with the rest of the macro.
  13. --
  14. --                                          JAC - 3/90
  15.  
  16.  
  17. const SET_ENTRYDATA = 1000          -- WM_COMMAND sub-command number
  18.       HWNDEDIT      = 5
  19.       HWNDEDITFRAME = 6
  20.  
  21. -- Add a submenu to EPM's Action Bar when this module is linked in.
  22. definit
  23.    -- Add to EPM's Action Bar
  24.    samplemenu='default'
  25.    buildsubmenu  samplemenu, 1000, 'Sample', '', 0, 0
  26.    buildmenuitem samplemenu, 1000, 10, 'Modeless Dialog Box Sample', 'CreateSample1Dlg', 0, 0
  27.    buildmenuitem samplemenu, 1000, 20, 'Modal Dialog Box Sample',    'CreateSample2Dlg', 0, 0
  28.    showmenu samplemenu
  29.  
  30. -- CreateSample1Dlg
  31. -- Creates the Modeless dialog box.  That is the dialog box and the
  32. -- edit window can operate asynchronously.
  33. -- Note:  1) dynalink() expects the function that it is calling to be defined
  34. --           as EXPENTRY (FAR PASCAL)
  35. --        2) gethwnd() - returns important handle in E window frame.
  36. --        3) Once this dialog box is created it uses the Sample1MacroProc
  37. --           command to process events.
  38. --                                          JAC - 3/90
  39. defc CreateSample1Dlg
  40.    call dynalink( 'ESAMPDLG',         -- dll name
  41.                   'SAMPLE1DLGCREATE', -- dll function name
  42.                   gethwnd(HWNDEDIT))  -- pass edit window handle
  43.  
  44.    -- done
  45.  
  46. -- This command is used to process events that occur within the DLG box.
  47. -- You can almost think of this as a PM window or dialog procedure.
  48. --                                          JAC - 3/90
  49. defc Sample1MacroProc
  50.    universal hwndDlg         -- set during the processing of the INITDLG action
  51.  
  52.    parse arg action mp1      -- parse arguments into an action and a value
  53.                              -- 'action' is a string describing what just
  54.                              -- happened in the dialog box
  55.                              -- mp1 is used by some actions to give some details
  56.                              -- about the action.
  57.                                       -- **********
  58.    if action='ENTER_PRESSED' then     -- the ENTER button was just pressed.
  59.       -- mp1 contains the data in the entry field of the dialog box.
  60.       -- now we display the data in a PM message box.
  61.       call winmessagebox("Data Entered",mp1)
  62.                                       -- **********
  63.    elseif action='INITDLG' then       -- the Dialog box was just created.
  64.  
  65.       -- mp1 contains the handle to the dialog box just created.
  66.       hwndDlg=mp1
  67.       -- this can be used to initialize the entry field
  68.       Call WinSendMsg( hwndDlg, SET_ENTRYDATA, "Gennaro Cuomo")
  69.  
  70.    elseif action='HELP_PRESSED' then  -- **********
  71.                                       -- the HELP button was just pressed
  72.        -- pop up a message box with the following message.
  73.        call winmessagebox("Help Panel","Your not the only one who needs help!");
  74.  
  75.    endif
  76.  
  77. -- Creates the Modeless dialog box.   That is the macro doesnot continue
  78. -- until the dialog box is closed.
  79. --                                          JAC - 3/90
  80. defc CreateSample2Dlg
  81.    -- allocate string space
  82.    strbuf='                             '
  83.    -- create application modal dialog box. Pass create function edit windw
  84.    -- frame handle and a pointer to a string buffer in which the entry field
  85.    -- contents will be placed.
  86.    call dynalink( 'ESAMPDLG',
  87.                   'SAMPLE2DLGCREATE',
  88.                   gethwnd(HWNDEDITFRAME) ||
  89.                   selector(strbuf)       ||
  90.                   offset(strbuf))
  91.  
  92.    sayerror '<'strbuf'>'  -- display results.
  93.  
  94.  
  95. -- Sends a WM_COMMAND message to Sample dialog box.
  96. defproc WinSendMsg( hwnd, msg, mp1 )
  97.    mp1 = mp1 \0
  98.    call windowmessage(1,  hwnd,
  99.                       32,               -- WM_COMMAND
  100.                       msg,
  101.                       ltoa(offset(mp1) || selector(mp1), 10) )
  102.  
  103.  
  104. --
  105. -- Utility functions follow
  106. --
  107.  
  108. -- this proc calls PM's WinMessageBox function
  109. defproc winmessagebox(caption, text)
  110.  
  111.   msgtype = 4096                                        -- must be system modal.
  112.   if arg(3) then
  113.      msgtype=arg(3) + 4096 * (1 - (arg(3)%4096 - 2 * (arg(3)%8192)))  -- ensure x'1000' on
  114.   endif
  115.   caption = caption\0
  116.   text    = text\0
  117.   return dynalink( 'PMWIN',
  118.                    'WINMESSAGEBOX',
  119.                    atoi(0) || atoi(1) ||   -- Parent
  120.                    atoi(0) || atoi(1) ||   -- Owner
  121.                    selector(text)     ||   -- Text
  122.                    offset(text)       ||
  123.                    selector(caption)  ||   -- Title
  124.                    offset(caption)    ||
  125.                    atoi(0)            ||   -- Window
  126.                    atoi(msgtype) )         -- Style
  127.  
  128. defproc atol_swap(num)
  129.    hwnd=atol(num)
  130.    return substr(hwnd,3,2) || substr(hwnd,1,2)
  131.  
  132. -- Returns the edit window handle, as a 4-digit decimal string.
  133. defproc gethwnd(w)
  134.    hwnd    = atol(getpminfo(w))   /* get edit window handle           */
  135.                                   /* convert string to string pointer */
  136.                                   /* interchange upper two bytes with */
  137.                                   /* lower two bytes. (flip words)    */
  138.  
  139.    return substr(hwnd,3,2) || substr(hwnd,1,2)
  140.  
  141. /*
  142. ┌────────────────────────────────────────────────────────────────────────────┐
  143. │ The following are constants values that are to be used as parameters to    │
  144. │ the getpminfo internal function.                                           │
  145. │                                                                            │
  146. │ HAB           0  PARENTFRAME     4  EDITORMSGAREA      8   EDITVIOPS    12 │
  147. │ OWNERCLIENT   1  EDITCLIENT      5  EDITORVSCROLL      9   EDITTITLEBAR 13 │
  148. │ OWNERFRAME    2  EDITFRAME       6  EDITORHSCROLL      10  EDITCURSOR   14 │
  149. │ PARENTCLIENT  3  EDITSTATUSAREA  7  EDITORINTERPRETER  11                  │
  150. *│                                                                            │
  151. └────────────────────────────────────────────────────────────────────────────┘
  152. */
  153.