home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <vcl\vcl.h>
- #include <string.h>
- #include "Prompt.h"
- #pragma hdrstop
- //---------------------------------------------------------------------------
- static char * Name = "Message Box Constructor";
- static char * Description = "Make pop-up message boxes";
- static int MajorVerNo = 1;
- static int MinorVerNo = 0;
- //---------------------------------------------------------------------------
- // All addin dll's should include and export the functions GetInfo and Execute.
- // The GetInfo function can simply be copied into each addin.
- // The Execute function will be passed the text which is selected in Constructor.
- // It should return the text it should be replaced by. If you do not want to
- // replace the text, include the selected text onto the end of the additional
- // text you want to insert. If you return an empty string, it will be ignored
- // as Constructor will assume the user clicked on a Cancel button
- //---------------------------------------------------------------------------
- USERES("MessageBox.res");
- USEFORM("Prompt.cpp", MainForm);
- //---------------------------------------------------------------------------
- extern "C" __declspec(dllexport) void __stdcall GetInfo(char **, char **, int *, int *);
- extern "C" __declspec (dllexport) struct RetVal __stdcall Execute(char *, char *);
- //---------------------------------------------------------------------------
- typedef struct RetVal {char * Text; bool Selected;} RetVal;
- //---------------------------------------------------------------------------
- int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
- {
- return 1;
- }
- //---------------------------------------------------------------------------
- void __stdcall GetInfo(char ** GetName, char ** GetDescription, int * GetMajorVerNo, int * GetMinorVerNo)
- {
- // Fill variables with data
- *GetName = Name;
- *GetDescription = Description;
- *GetMajorVerNo = MajorVerNo;
- *GetMinorVerNo = MinorVerNo;
- }
- //---------------------------------------------------------------------------
- RetVal __stdcall Execute(char * Text, char * Selected)
- {
- // Create form
- TMainForm *MainForm = new TMainForm(Application);
- // Set up initial values of controls in form
- MainForm->Type->ItemIndex = 0;
- MainForm->OnCancel->ItemIndex = 0;
- MainForm->Code->ItemIndex = 0;
- // See if document contains body tag
- MainForm->RichEdit->Text = Text;
- TSearchTypes Options;
- MainForm->RichEdit->SelStart = MainForm->RichEdit->FindText("<body", 0, MainForm->RichEdit->Text.Length(), Options);
- MainForm->RichEdit->SelLength = 5;
- // If it does contain the body tag, enable the option to put the message in the tag
- MainForm->Code->Enabled = (MainForm->RichEdit->SelText.AnsiCompareIC("<body") == 0);
- // Show the form
- MainForm->ShowModal();
- RetVal Return;
- if (MainForm->ModalResult == ID_OK)
- {
- // If usesr clicked on OK
- if (MainForm->Code->Enabled && MainForm->Code->ItemIndex == 0)
- {
- // If putting message box in body tag, return text for whole document
- Return.Text = MainForm->RichEdit->Text.c_str();
- Return.Selected = false;
- }
- else
- {
- // If putting message box in cursor location, return only message box text
- Return.Text = MainForm->CodeString.c_str();
- Return.Selected = true;
- };
- }
- else
- {
- // If user clicked cancel, return an empty string
- Return.Text = "";
- };
- return Return;
- }
- //---------------------------------------------------------------------------