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

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