home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / DLL_Toolkit / Source / HTBRadioButton / Radiobutton.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2005-03-02  |  7.6 KB  |  228 lines

  1. //    Radiobutton.cpp : Defines the initialization routines for the DLL and the exported functions
  2. //        High Tech BASIC, Copyright (C) TransEra Corp 1999, All Rights Reserved.
  3. //
  4. /*************************************************************************
  5.  *                                                                       *
  6.  *  Radiobutton DLL (Win32 / MFC)                                        *
  7.  *  Author:      Sven Henze, Tech Soft GmbH                              *
  8.  *  Date:        22-Aug-1999                                             *
  9.  *  Last Update: 28-Sep-1999                                             *
  10.  *                                                                       *
  11.  *  This code is intended for the usage under BASIC for Windows V8.X     *
  12.  *                                                                       *
  13.  *  Version info:                                                        *
  14.  *     22-Aug-1999  V1.0▀ Initial release of DLL                         *
  15.  *                                                                       *
  16.  *************************************************************************/
  17.  
  18.  
  19. #include "stdafx.h"
  20. #include "Radiobutton.h"
  21. #include "RadiobuttonDlg.h"
  22. #include "DialogThread.h"
  23. #include "assert.h"
  24.  
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31.  
  32. #define MINWIDTH 150
  33.  
  34.  
  35. //
  36. //    Note!
  37. //
  38. //        If this DLL is dynamically linked against the MFC
  39. //        DLLs, any functions exported from this DLL which
  40. //        call into MFC must have the AFX_MANAGE_STATE macro
  41. //        added at the very beginning of the function.
  42. //
  43. //        For example:
  44. //
  45. //        extern "C" BOOL PASCAL EXPORT ExportedFunction()
  46. //        {
  47. //            AFX_MANAGE_STATE(AfxGetStaticModuleState());
  48. //            // normal function body here
  49. //        }
  50. //
  51. //        It is very important that this macro appear in each
  52. //        function, prior to any calls into MFC.  This means that
  53. //        it must appear as the first statement within the 
  54. //        function, even before any object variable declarations
  55. //        as their constructors may generate calls into the MFC
  56. //        DLL.
  57. //
  58. //        Please see MFC Technical Notes 33 and 58 for additional
  59. //        details.
  60. //
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CRadioButtonApp
  64.  
  65. BEGIN_MESSAGE_MAP(CRadioButtonApp, CWinApp)
  66.     //{{AFX_MSG_MAP(CRadioButtonApp)
  67.         // NOTE - the ClassWizard will add and remove mapping macros here.
  68.         //    DO NOT EDIT what you see in these blocks of generated code!
  69.     //}}AFX_MSG_MAP
  70. END_MESSAGE_MAP()
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CRadioButtonApp construction
  74.  
  75. CRadioButtonApp::CRadioButtonApp()
  76. {
  77.     // TODO: add construction code here,
  78.     // Place all significant initialization in InitInstance
  79. }
  80.  
  81. /////////////////////////////////////////////////////////////////////////////
  82. // The one and only CRadioButtonApp object
  83.  
  84. CRadioButtonApp theApp;
  85.  
  86.  
  87. //****************************************************************************************************
  88. // begin global variables -- used to communicate between threads and different instances of classes
  89.  
  90.  
  91. RadioButtonDlg * g_pBtnDlg = NULL;            // global pointer to RadioButton dialog used for setting focus and closing
  92. short g_BtnCount;                                // the number of buttons desired
  93. long g_Width;                                    // width of the dialog box
  94. OPTION g_Option;                                // 1 for modal, 2 for threaded variable update, 3 for threaded with signals
  95. CString g_Title;                                // Window title
  96. CString    g_Description;                            // Text above buttons will wrap to two lines if too long
  97. CString    g_Text[10];                                // button text
  98. int m_Radio[10];
  99. short * g_pPress;                                // pointer into HTBasic memory for updateing user input
  100. short save_pressed;
  101. CString g_grouptext;
  102.  
  103.  
  104. //    end global variables
  105. //***************************************************************************************************
  106. //  begin global functions not exported
  107.  
  108. // end global functions not exported
  109. //*****************************************************************************************************
  110. // begin exported functions
  111.  
  112.  
  113. // Showrbutton is the main function for setting up and displaying the button dialog box.  
  114. //    Params:
  115. //        option is a value between 1 and MAXOPTION.  a 1 will call a modal dialog box suspending Program execution and returning
  116. //                the number of the button pushed or a zero if the dialog is closed with no button push.
  117. //        count is the number of radiobuttons from 0 to MAXBUTTON
  118. //        width is the desired width of the dialog window and buttons
  119. //      press is the radiobutton which should be active
  120. //        title is the text for the window title
  121. //        description is the text that will appear above the buttons
  122. //      grouptext is the text for the group frame
  123. //        text1 - text10 is the radiobutton text
  124.  
  125. short Showrbutton(short option,short count,long width,short * pressed, char * title,char * description,char * grouptext,char * text1,char * text2,char * text3
  126.              ,char * text4,char * text5,char * text6,char * text7,char * text8,char * text9,char * text10)
  127. {    AFX_MANAGE_STATE(AfxGetStaticModuleState());
  128.  
  129.     long result = 0;
  130.  
  131.     if (g_pBtnDlg != NULL)                        // RadioButton dialog already active
  132.     {    return((short)result);
  133.     }
  134.  
  135.     if (count < 2 || count > MAXBUTTON)
  136.     {    g_BtnCount = 2;                            // default to 0 Radiobuttons for bad input
  137.     }
  138.     else
  139.     {    g_BtnCount = count;                        // save number of Radiobuttons
  140.     }
  141.  
  142.     g_Width = width;                            // save width
  143.     if (width < MINWIDTH) g_Width = MINWIDTH;
  144.  
  145.     save_pressed = *pressed;                    // save activated radiobutton
  146.  
  147.     if (option < 1 || option > MAXOPTION)
  148.     {    g_Option = modal;                        // default to modal for bad input
  149.     }
  150.     else
  151.     {    g_Option = (OPTION)(option);            // 1 = modal  
  152.     }                                            // 2 = threaded with variable
  153.                                                 // 3 = threaded with signal
  154.  
  155.  
  156.     g_Title = title;
  157.     g_Description = description;
  158.     g_grouptext = grouptext;
  159.     g_Text[0] = text1;
  160.     g_Text[1] = text2;
  161.     g_Text[2] = text3;
  162.     g_Text[3] = text4;
  163.     g_Text[4] = text5;
  164.     g_Text[5] = text6;
  165.     g_Text[6] = text7;
  166.     g_Text[7] = text8;
  167.     g_Text[8] = text9;
  168.     g_Text[9] = text10;
  169.  
  170.     g_pPress = pressed;                            // save pointer to press
  171.     if (g_Option == variable) *g_pPress = (-1)* *g_pPress;
  172.     
  173.     switch (g_Option)
  174.     {    case modal:
  175.         {    RadioButtonDlg Btn;                        // create dialog object
  176.             g_pBtnDlg = &Btn;
  177.             result = Btn.DoModal();    
  178.             g_pBtnDlg = NULL;                    // reset pointer to dialog
  179.             break;
  180.         }
  181.         
  182.         case variable:
  183.         case signal:
  184.         {    CWinThread * pThread = AfxBeginThread(RUNTIME_CLASS (DialogThread));    // create thread to execute dialog
  185.             result = 1;
  186.             break;
  187.         }
  188.  
  189.         default:
  190.             assert(0);
  191.             break;
  192.     }
  193.  
  194.     return((short)result);
  195. }
  196.  
  197.  
  198. // end Showrbutton
  199. //*****************************************************************************************
  200. // Setfocus -- used to bring the RadioButton dialog box to the foreground and activate.
  201.  
  202.  
  203. void Setfocus()
  204. {    
  205.     SetForegroundWindow(g_pBtnDlg->m_hWnd);        // bring window to foreground and activate
  206. }
  207.  
  208.  
  209. // end Setfocus
  210. //*****************************************************************************************
  211. // Closerbutton -- Used to close radiobutton dialog box when running in its own thread.
  212.  
  213.  
  214. void Closerbutton()
  215. {    if (g_pBtnDlg != NULL)
  216.     {    
  217.         // now sets the return value !
  218.         
  219.         g_pBtnDlg->KillTimer(1);                // stop timer from updating dialog
  220.         g_pBtnDlg->EndDialog(0);                // close dialog and allow spawned thread to run out
  221.         g_pBtnDlg = NULL;                        // reset pointer to dialog
  222.     }
  223. }
  224.  
  225.  
  226. // end Closerbutton
  227. //*****************************************************************************************
  228.