home *** CD-ROM | disk | FTP | other *** search
/ .net 1999 December / netCD65.iso / pc / Software / Construc / V4.0 / _SETUP.1 / MessageBox.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-23  |  3.6 KB  |  83 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #include <string.h>
  4. #include "Prompt.h"
  5. #pragma hdrstop
  6. //---------------------------------------------------------------------------
  7. static char * Name = "Message Box Constructor";
  8. static char * Description = "Make pop-up message boxes";
  9. static int    MajorVerNo = 1;
  10. static int    MinorVerNo = 0;                                                 
  11. //---------------------------------------------------------------------------
  12. // All addin dll's should include and export the functions GetInfo and Execute.
  13. // The GetInfo function can simply be copied into each addin.
  14. // The Execute function will be passed the text which is selected in Constructor.
  15. // It should return the text it should be replaced by. If you do not want to
  16. // replace the text, include the selected text onto the end of the additional
  17. // text you want to insert. If you return an empty string, it will be ignored
  18. // as Constructor will assume the user clicked on a Cancel button
  19. //---------------------------------------------------------------------------
  20. USERES("MessageBox.res");
  21. USEFORM("Prompt.cpp", MainForm);
  22. //---------------------------------------------------------------------------
  23. extern "C" __declspec(dllexport) void __stdcall GetInfo(char **, char **, int *, int *);
  24. extern "C" __declspec (dllexport) struct RetVal __stdcall Execute(char *, char *);
  25. //---------------------------------------------------------------------------
  26. typedef struct RetVal {char * Text; bool Selected;} RetVal;
  27. //---------------------------------------------------------------------------
  28. int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
  29. {
  30.     return 1;
  31. }
  32. //---------------------------------------------------------------------------
  33. void __stdcall GetInfo(char ** GetName, char ** GetDescription, int * GetMajorVerNo, int * GetMinorVerNo)
  34. {
  35. // Fill variables with data
  36. *GetName = Name;
  37. *GetDescription = Description;
  38. *GetMajorVerNo = MajorVerNo;
  39. *GetMinorVerNo = MinorVerNo;
  40. }
  41. //---------------------------------------------------------------------------
  42. RetVal __stdcall Execute(char * Text, char * Selected)
  43. {
  44. // Create form
  45. TMainForm *MainForm = new TMainForm(Application);
  46. // Set up initial values of controls in form
  47. MainForm->Type->ItemIndex = 0;
  48. MainForm->OnCancel->ItemIndex = 0;
  49. MainForm->Code->ItemIndex = 0;
  50. // See if document contains body tag
  51. MainForm->RichEdit->Text = Text;
  52. TSearchTypes Options;
  53. MainForm->RichEdit->SelStart = MainForm->RichEdit->FindText("<body", 0, MainForm->RichEdit->Text.Length(), Options);
  54. MainForm->RichEdit->SelLength = 5;
  55. // If it does contain the body tag, enable the option to put the message in the tag
  56. MainForm->Code->Enabled = (MainForm->RichEdit->SelText.AnsiCompareIC("<body") == 0);
  57. // Show the form
  58. MainForm->ShowModal();
  59. RetVal Return;
  60. if (MainForm->ModalResult == ID_OK)
  61.    {
  62.    // If usesr clicked on OK
  63.    if (MainForm->Code->Enabled && MainForm->Code->ItemIndex == 0)
  64.       {
  65.       // If putting message box in body tag, return text for whole document
  66.       Return.Text = MainForm->RichEdit->Text.c_str();
  67.       Return.Selected = false;
  68.       }
  69.    else
  70.        {
  71.        // If putting message box in cursor location, return only message box text
  72.        Return.Text = MainForm->CodeString.c_str();
  73.        Return.Selected = true;
  74.        };
  75.    }
  76. else
  77.     {
  78.     // If user clicked cancel, return an empty string
  79.     Return.Text = "";
  80.     };
  81. return Return;
  82. }
  83. //---------------------------------------------------------------------------