home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / kvfon1.exe / PHONEDLG.H < prev    next >
C/C++ Source or Header  |  1994-11-02  |  12KB  |  388 lines

  1. /****************************************************************************
  2. **    File:    PHONEDLG.H
  3. **
  4. **    Desc:    Include files for the dialpad program.
  5. **
  6. **    This file is an include file for the dialpad program.  It contains the
  7. **    dialog source code for the dial pad, along with all of its functionality.
  8. **
  9. **    It is written for OWL 2.0 with Borland C++ 4.x.  To compile this program,
  10. **    create a project in BC4.x, similar to the .IDE project file included.
  11. **
  12. **        DISCLAIMER
  13. **
  14. **    Novell, Inc. makes no representations or warranties with respect to
  15. **    any NetWare software, and specifically disclaims any express or
  16. **    implied warranties of merchantability, title, or fitness for a
  17. **    particular purpose.
  18. **
  19. **    You may use this sample code in your own programs.
  20. **
  21. **    Distribution of any NetWare software is forbidden without the
  22. **    express written consent of Novell, Inc.  Further, Novell reserves
  23. **    the right to discontinue distribution of any NetWare software.
  24. **
  25. **    Novell is not responsible for lost profits or revenue, loss of use
  26. **    of the software, loss of data, costs of re-creating lost data, the
  27. **    cost of any substitute equipment or program, or claims by any party
  28. **    other than you.  Novell strongly recommends a backup be made before
  29. **    any software is installed.   Technical support for this software
  30. **    may be provided at the discretion of Novell.
  31. **
  32. **    Programmers:
  33. **
  34. **        Ini    Who                        Firm
  35. **        -----------------------------------------------------------------------
  36. **        KVW    Kevin V White        Novell Developer Support.
  37. **
  38. **    History:
  39. **
  40. **        When        Who    What
  41. **        -----------------------------------------------------------------------
  42. **        11-2        KVW    First code release
  43. */
  44.  
  45. /****************************************************************************
  46. **    This is the dial pad dialog's class.
  47. */
  48. class TPhoneDlg:public TDialog
  49. {
  50.     public:
  51.         char numToDial[30];
  52.         short entryIndex;
  53.         DeviceID_t callerExt;
  54.         ACSHandle_t globalACSHandle;
  55.         CSTAEvent_t eventBuffer;
  56.         unsigned short eventBufferSize;
  57.         unsigned short numEvents;
  58.         DeviceID_t callee;
  59.         ConnectionID_t callID;
  60.         RetCode_t    rCode;
  61.         InvokeID_t    invokeID;
  62.  
  63.         TEdit *numberEntryWindow;
  64.  
  65.         TPhoneDlg(TWindow *parent,TResId resId,ACSHandle_t *acsHandle,
  66.             DeviceID_t *userExt);
  67.         void SetupWindow();
  68.         void CleanupWindow();
  69.         void CmDial1();
  70.         void CmDial2();
  71.         void CmDial3();
  72.         void CmDial4();
  73.         void CmDial5();
  74.         void CmDial6();
  75.         void CmDial7();
  76.         void CmDial8();
  77.         void CmDial9();
  78.         void CmDial0();
  79.         void CmDialNumber();
  80.         void CmHangup();
  81.         void CmHelp();
  82.         void CmClearEntry();
  83.  
  84.     DECLARE_RESPONSE_TABLE(TPhoneDlg);
  85. };
  86.  
  87. /****************************************************************************
  88. **    this is how OWL adds message handling to the windows message loop
  89. */
  90. DEFINE_RESPONSE_TABLE1(TPhoneDlg,TDialog)
  91.     EV_COMMAND(IDC_1,CmDial1),
  92.     EV_COMMAND(IDC_2,CmDial2),
  93.     EV_COMMAND(IDC_3,CmDial3),
  94.     EV_COMMAND(IDC_4,CmDial4),
  95.     EV_COMMAND(IDC_5,CmDial5),
  96.     EV_COMMAND(IDC_6,CmDial6),
  97.     EV_COMMAND(IDC_7,CmDial7),
  98.     EV_COMMAND(IDC_8,CmDial8),
  99.     EV_COMMAND(IDC_9,CmDial9),
  100.     EV_COMMAND(IDC_10,CmDial0),
  101.     EV_COMMAND(IDC_DIAL,CmDialNumber),
  102.     EV_COMMAND(IDC_HANGUP,CmHangup),
  103.     EV_COMMAND(IDC_HELP,CmHelp),
  104.     EV_COMMAND(IDC_CLEARENTRY,CmClearEntry),
  105. END_RESPONSE_TABLE;
  106.  
  107. /****************************************************************************
  108. **    constructor for the dial pad dialog
  109. */
  110. TPhoneDlg::TPhoneDlg(TWindow *parent,TResId resId,ACSHandle_t *acsHandle,
  111.     DeviceID_t *userExt)
  112.     :TDialog(parent,resId),TWindow(parent)
  113. {
  114.     /*------------------------------------------------------------------------
  115.     **    callerExt is the user's extension
  116.     ** numToDial is a string built from the number the user dials
  117.     **    entryIndex is the position in the array for the next digit dialed
  118.     ** globalACSHandle is the acshandle we receive in the constructor
  119.     */
  120.     strcpy(callerExt,*userExt);
  121.     numToDial[0]=0;
  122.     entryIndex=0;
  123.     strcpy(callerExt,*userExt);
  124.     globalACSHandle=*acsHandle;
  125.     eventBufferSize=sizeof(CSTAEvent_t);
  126. }
  127.  
  128. /****************************************************************************
  129. ** SetupWindow is called when the dialog window is created
  130. */
  131. void TPhoneDlg::SetupWindow()
  132. {
  133.     /*------------------------------------------------------------------------
  134.     ** first, call the parent's SetupWindow
  135.     */
  136.     TDialog::SetupWindow();
  137.  
  138.     /*------------------------------------------------------------------------
  139.     ** create an alias to the text box in the dialog, as the alias will be
  140.     ** easier to enter text into and retrieve text from than the dialog
  141.     */
  142.     numberEntryWindow=new TEdit(this,IDC_NUMDISPLAY,30);
  143.     numberEntryWindow->Create();
  144. }
  145.  
  146. /****************************************************************************
  147. **    CleanupWindow is called when the window is destroyed.  We just use it to
  148. ** free the memory allocated to our TEdit alias in SetupWindow, then call
  149. **    the parent's CleanupWindow
  150. */
  151. void TPhoneDlg::CleanupWindow()
  152. {
  153.     delete numberEntryWindow;
  154.  
  155.     TDialog::CleanupWindow();
  156. }
  157.  
  158. /****************************************************************************
  159. **    these functinos are used when the user presses one of the buttons corres-
  160. **    ponding to the digits on the phone dial pad.  In each one, we want to store
  161. **    the digit the user enters, increment the index into the character array,
  162. **    and then redisplay the string in the text window.
  163. */
  164.  
  165. void TPhoneDlg::CmDial1()
  166. {
  167.     if(entryIndex<28)
  168.     {
  169.         numToDial[entryIndex++]='1';
  170.         numToDial[entryIndex]=0;
  171.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  172.     }
  173. }
  174.  
  175. void TPhoneDlg::CmDial2()
  176. {
  177.     if(entryIndex<28)
  178.     {
  179.         numToDial[entryIndex++]='2';
  180.         numToDial[entryIndex]=0;
  181.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  182.     }
  183. }
  184.  
  185. void TPhoneDlg::CmDial3()
  186. {
  187.     if(entryIndex<28)
  188.     {
  189.         numToDial[entryIndex++]='3';
  190.         numToDial[entryIndex]=0;
  191.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  192.     }
  193. }
  194.  
  195. void TPhoneDlg::CmDial4()
  196. {
  197.     if(entryIndex<28)
  198.     {
  199.         numToDial[entryIndex++]='4';
  200.         numToDial[entryIndex]=0;
  201.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  202.     }
  203. }
  204.  
  205. void TPhoneDlg::CmDial5()
  206. {
  207.     if(entryIndex<28)
  208.     {
  209.         numToDial[entryIndex++]='5';
  210.         numToDial[entryIndex]=0;
  211.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  212.     }
  213. }
  214.  
  215. void TPhoneDlg::CmDial6()
  216. {
  217.     if(entryIndex<28)
  218.     {
  219.         numToDial[entryIndex++]='6';
  220.         numToDial[entryIndex]=0;
  221.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  222.     }
  223. }
  224.  
  225. void TPhoneDlg::CmDial7()
  226. {
  227.     if(entryIndex<28)
  228.     {
  229.         numToDial[entryIndex++]='7';
  230.         numToDial[entryIndex]=0;
  231.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  232.     }
  233. }
  234.  
  235. void TPhoneDlg::CmDial8()
  236. {
  237.     if(entryIndex<28)
  238.     {
  239.         numToDial[entryIndex++]='8';
  240.         numToDial[entryIndex]=0;
  241.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  242.     }
  243. }
  244.  
  245. void TPhoneDlg::CmDial9()
  246. {
  247.     if(entryIndex<28)
  248.     {
  249.         numToDial[entryIndex++]='9';
  250.         numToDial[entryIndex]=0;
  251.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  252.     }
  253. }
  254.  
  255. void TPhoneDlg::CmDial0()
  256. {
  257.     if(entryIndex<28)
  258.     {
  259.         numToDial[entryIndex++]='0';
  260.         numToDial[entryIndex]=0;
  261.         SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  262.     }
  263. }
  264.  
  265. /****************************************************************************
  266. **    Here we dial the number the user has entered.
  267. */
  268. void TPhoneDlg::CmDialNumber()
  269. {
  270.     BOOL done=FALSE;
  271.  
  272.     /*------------------------------------------------------------------------
  273.     **    has the user actually pressed the digits to make a number to dial?
  274.     */
  275.     if(numToDial[0]!=0)
  276.     {
  277.         /*---------------------------------------------------------------------
  278.         **    get the number dialed, and make the call.
  279.         */
  280.         strcpy(callee,numToDial);
  281.         rCode=cstaMakeCall(globalACSHandle,invokeID,&callerExt,&callee,NULL);
  282.         /*---------------------------------------------------------------------
  283.         **    if MakeCall was successful, it will return the invokeID (above 0)
  284.         */
  285.         if(rCode>0)
  286.         {
  287.             /*------------------------------------------------------------------
  288.             **    We enter a poll loop, waiting for our event to confirm the makecall
  289.             */
  290.             while(!done)
  291.             {
  292.                 /*---------------------------------------------------------------
  293.                 **    first, very important, set the event buffer size to pass to
  294.                 ** getEventPoll.  If we don't reset it each time, it may be too
  295.                 ** small to get our event, and we will never get our make call
  296.                 ** confirmation event
  297.                 */
  298.                 eventBufferSize=sizeof(CSTAEvent_t);
  299.                 /*---------------------------------------------------------------
  300.                 **    get the event, and check its type
  301.                 */
  302.                 rCode=acsGetEventPoll(globalACSHandle,&eventBuffer,&eventBufferSize,
  303.                     NULL,&numEvents);
  304.                 if(rCode==ACSPOSITIVE_ACK)
  305.                 {
  306.                     if(eventBuffer.eventHeader.eventType==CSTA_MAKE_CALL_CONF)
  307.                     {
  308.                         /*---------------------------------------------------------
  309.                         **    if it's the right event type, the callID is stored in
  310.                         ** the confirmation event structure, which we will need to
  311.                         ** store so that the user can hangup on the call later.  Then,
  312.                         **    we'll enable the Hangup button.
  313.                         */
  314.                         callID=eventBuffer.event.cstaConfirmation.u.makeCall.newCall;
  315.                         ::EnableWindow(GetDlgItem(IDC_HANGUP),1);
  316.                         done=TRUE;
  317.                     }
  318.                 }
  319.                 else if(rCode==ACSERR_NOMESSAGE)
  320.                 {
  321.                     done=FALSE;
  322.                 }
  323.                 else
  324.                 {
  325.                     /*------------------------------------------------------------
  326.                     ** we can't get the event that the call was made successfully,
  327.                     **    so disable the Hangup button.
  328.                     */
  329.                     ::EnableWindow(GetDlgItem(IDC_HANGUP),0);
  330.                     done=TRUE;
  331.                 }
  332.             }
  333.         }
  334.         else
  335.         {
  336.             MessageBox("Unable to make call","TS Error!");
  337.         }
  338.     }
  339.  
  340. }
  341.  
  342. /****************************************************************************
  343. **    the user wants to hangup on a call.  Note that this will only work on a
  344. **    call that the user created, as we have to have a valid callID.  If that
  345. ** call was already cleared, well, we won't know about it, and will try to
  346. ** hang up on it anyway.  That won't gpf or anything, but it would be a nice
  347. ** enhancement to monitor the device, and clear the hangup button if the call
  348. ** happens to be cleared by the user, and not through this program.
  349. */
  350. void TPhoneDlg::CmHangup()
  351. {
  352.     /*------------------------------------------------------------------------
  353.     **    try to hangup on the call. we don't bother confirming that it worked,
  354.     ** as we don't really care.  One way or the other, we're going to disable
  355.     ** the hangup button afterwards.
  356.     */
  357.     rCode=cstaClearCall(globalACSHandle,invokeID,&callID,NULL);
  358.     if(rCode>0)
  359.     {
  360.         ::EnableWindow(GetDlgItem(IDC_HANGUP),0);
  361.     }
  362. }
  363.  
  364. /****************************************************************************
  365. **    the user presed help.  Display help as a simple dialog with text.  If this
  366. **    were a more complex program, it would be nice to have a normal windows
  367. ** help file to use.
  368. */
  369. void TPhoneDlg::CmHelp()
  370. {
  371.     MessageBox("KVPhone is used as a dialpad for your phone with NetWare"
  372.                     " Telephony Services.\n\nUse the mouse to dial a number, then"
  373.                     " select Dial. \n\nWhen on a phone conversation that you have"
  374.                     " created, you may press Hangup to clear the call.  \n\nPress"
  375.                     " Clear to clear the number display box to enter a new number."
  376.                     ,"KVPhone Help");
  377. }
  378.  
  379. /****************************************************************************
  380. **    this is called to clear the number and start entering a new number to dial
  381. */
  382. void TPhoneDlg::CmClearEntry()
  383. {
  384.     numToDial[0]=0;
  385.     entryIndex=0;
  386.     SetDlgItemText(IDC_NUMDISPLAY,numToDial);
  387. }
  388.