TextDynamic as Popup Editor (wptextCreateDialog)

Do you have a C++Program which you need a powerful Editor for?
Or do you sell a database application which needs an new editing popup dialog.
With TextDynamic You can add a powerful editor with only a few lines of code.
To do so, the DLL exports a single procedure to create a complete editor window.
There are still various possibilities to customize the editor. Only the DLL is used in this case, no ActiveX or .NET wrapper.
This method has been created to allow editing fast, with a minimum programming interface.

Editor – created with a few lines of code in VS C+
1) Initialisation – C++
// Pointer to TextDynamic
fkt_wptextCreateDialog* wptextCreateDialog;
// Load the DLL and get the method pointer
bool InitTD()
{
static HINSTANCE Engine;
Engine = LoadLibrary(TEXT("WPTextDLL01Demo.dll"));
if(Engine==NULL)return false;
wptextCreateDialog = (fkt_wptextCreateDialog *)GetProcAddress( Engine, "wptextCreateDialog" ); 
if(wptextCreateDialog==NULL)return false;
else return true;
}

Later, in
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
this code is executed:

1) Creation of editor
case WM_CREATE:
{
DefWindowProc(hWnd, message, wParam, lParam);
unsigned long editorw; //not used
static TDCreateDialogParam param; 
if(InitTD())
{ 
param.size = sizeof(param);
param.modes = 1;
param.editor_mode = 4; // with thumbnails
param.editor_xmode = 255; // all features
param.editor_gui1 = 478;
param.editor1_layoutmode = 7; // Full Layout
param.editor1_autozoom = 1; // Width
// We can set all "Memo.SetBProp" flags.
// Using Group=0, ID=11 (bit 11) we activate Image drag&drop
param.Memo1_SetBProp_ADD[0] = (1024 * 2); // Bit 11 -> AcceptFiles
param.pccfile = "{dll}buttons.pcc";
edhwnd = wptextCreateDialog(hWnd, &param, 10, 10, 300, 300, &editorw );
}
 3) Sizing of the editor
case WM_SIZE:
DefWindowProc(hWnd, message, wParam, lParam);
if(edhwnd)
{
RECT Rect;
GetClientRect(hWnd, &Rect);
MoveWindow(edhwnd, Rect.left, Rect.top, Rect.right-Rect.left, Rect.bottom-Rect.top, false);
}
break;
 4) Send commands to editor

Using the editor window handle, it is also possible to send commands to the editor using SendMessage.
Especially easy to use are the “wpa Action” names.
Simply use this message IDs to send the action names to the current, the first or the second editor.
WMP_WPA_PROCESS = 1051; // wparam= char *wpaAction, lparam=parama – for current editor
WMP_WPA_PROCESS_1 = 1052; // wparam= char *wpaAction, lparam=parama – for editor #1
WMP_WPA_PROCESS_2 = 1053; // wparam= char *wpaAction, lparam=parama – for editor #2


This pascal code will show the file open dialog:

SendMessage(EditorHwnd, 1051, Integer(PChar(‘diaOpen’)), 0);

In c++ You can add this code into the message loop to attach load and save menu items.

case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case ID_FILE_LOAD:
SendMessage(edhwnd, 1051, (int)((char *)"diaOpen"), 0);
break;
case ID_FILE_SAVE:
SendMessage(edhwnd, 1051, (int)((char *)"diaSaveAs"), 0);
break;

This message IDs will be useful to send other commands
WMP_EDCOMMAND = 1040; // wparam=commandid, lparam=parameter for EDITOR A
WMP_EDbCOMMAND = 1041; // wparam=commandid, lparam=parameter for EDITOR B
WMP_EDCOMMANDSTR = 1042; // wparam=commandid, lparam=char* for EDITOR A
WMP_EDbCOMMANDSTR = 1043; // wparam=commandid, lparam=char* for EDITOR A
WMP_EDUCOMMANDSTR = 1044; // wparam=commandid, lparam=widechar* for EDITOR A
WMP_EDUbCOMMANDSTR = 1045; // wparam=commandid, lparam=widechar* for EDITOR B


You can use this command IDs to load and save directly to a file:
WPDLL_COM = 9000;
WPDLL_COM_TEXT_LOADFILE = WPDLL_COM + 26; // buffer1=filename, buffer2=format, param=1 for ‘Insert’
WPDLL_COM_TEXT_SAVEFILE = WPDLL_COM + 27; // buffer1=filename, buffer2=format, param=1 for SelectionOnly
WPDLL_COM_TEXT_LOADSTR = WPDLL_COM + 28; // buffer1=str, buffer2=format, param=1 for ‘Insert’
WPDLL_COM_TEXT_SAVESTR = WPDLL_COM + 29; // out: datastring, buffer2=format, param=1 for SelectionOnly

Example – load the file c:test.rtf into the editor.
SendMessage(edhwnd, 1042, 9026,(int)((char *)”c:\TEST.RTF”));
You can also use the COM interface IWPMemo.
This commands are used to retrieve a reference to the respective interface:
WPDLL_COM_Memo1 = 145; // Result := IWPMemo of Editor 1
WPDLL_COM_Memo2 = 146; // Result := IWPMemo of Editor 2


The definition of the Interfaces (TLB) is included in the TextDynamic OCX. You can import this TLB into Your project and autogenerate a the definition code.
Other commands are available on request.