Create CCF Adapter
Hi all...
i wanna ask about creating an adapter for any external app. to make any action
my first adapter i was created don't work well it just run the constructor ...
Please if anybody have a sample code for adapter (for ex. to set "HI" to textbox) send it to me...
Thanks for all...
[607 byte] By [
?S??μ] at [2008-2-8]
Here is a Very simple example of an external adapter connecting for Notepad..
I have included the content of the .cs file used by my adapter so that you can see the includes and structure of the class. This assumes that you have Notepad configured properly in the CCF Admin Tool
This example is provided AS IS.. it is an example only.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Ccf.Csr;
using Microsoft.Ccf.Common;
using System.Xml;
using System.IO;
namespace NotepadAdapter
{
/// <summary>
/// Notepad interface Adapter
/// </summary>
public class NotesPadAdapter : ApplicationAdapter
{ // Basic Constructor
public NotesPadAdapter(){}
/// <summary>
/// NotifyContextChange Event..
/// This event is called by CCF when the Session / Context changes
/// </summary>
/// <param name="context">CCF Context object</param>
/// <returns>True if continue, False to stop the chain in this adapter here.</returns>
public override bool NotifyContextChange(Context context)
{
IntPtr iptrEditWin = System.IntPtr.Zero;
iptrEditWin = Microsoft.Ccf.Csr.Win32API.FindWindowEx(process.MainWindowHandle, System.IntPtr.Zero, "Edit", "");
if (iptrEditWin != System.IntPtr.Zero)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(context.GetContext());
StringBuilder sb = new StringBuilder();
System.IO.StringWriter sw = new StringWriter(sb);
System.Xml.XmlTextWriter cxm = new XmlTextWriter(sw);
cxm.Formatting = System.Xml.Formatting.Indented;
doc.WriteTo(cxm);
Win32API.SetWindowTextAny(iptrEditWin, string.Format("Context Updated : {0}\r\n{1}", DateTime.Now.ToLocalTime().ToString(), sb.ToString()));
}
return base.NotifyContextChange(context);
}
/// <summary>
/// DoAction event handler.
/// This handler catches Action Events directed at this adapter from CCF
/// </summary>
/// <param name="action">Action Events Args structure.</param>
/// <param name="data">Any Addational String Data</param>
/// <returns>Continue executing actions: true to procceed, false to stop here.</returns>
public override bool DoAction(Action action, ref string data)
{
System.Diagnostics.Trace.WriteLine(String.Format("> ACTION: {0}", action.Name));
return base.DoAction(action, ref data);
}
}
}
Matt B.
Thank you Matt
but i wanna ask about iptrEditWin = Microsoft.Ccf.Csr.Win32API.FindWindowEx(process.MainWindowHandle, System.IntPtr.Zero, "Edit", "");
What did you mean in "Edit" and how we can know the name of other programs
(i think it's return to the Notepab ya?)
In the case of Notepad I used Spy++ to identify the class name of the control, within the process that i was intersted in.
Spy++ is included with Visual Studio
Matt B- MSFT