I am in the process of building an application in C# winforms.
If we think along the lines of meta data, I am trying to capture as much information about the user's open sessions as I can.
I have got as far as obtaining all the session info that I require.
Now I am curious as to how much information about the visible on-screen data I can capture.
My instinctive thought was to iterate the controls and seeing if I could capture text boxes and labels.
However, I am struggling.
Looking at documentation, I see there are various 'FindBy' functions, but all of these appear to be designed to be useful only if you know the names of individual controls already.
Does anyone know how I can walk/iterate through all the controls in the user area, and capture their name/value ?
Many Thanks for any tips !
:)
Code so far ....
class sap_helper | |
{ | |
| public static Dictionary<string, SapInfoItem> get_sapInfo() |
| { |
| Dictionary<string, SapInfoItem> sapInfo = new Dictionary<string, SapInfoItem>(); |
| GuiApplication sapGuiApp; |
| SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper(); |
| object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI"); |
| object engine = SapGuilRot.GetType().InvokeMember("GetSCriptingEngine", System.Reflection.BindingFlags.InvokeMethod, |
| null, SapGuilRot, null); |
| sapGuiApp = engine as GuiApplication; |
| int i = sapGuiApp.Children.Count; |
| if (sapGuiApp.Connections.Length > 0) |
| { |
| GuiConnection connection = sapGuiApp.Connections.ElementAt(0) as GuiConnection; |
| foreach (GuiSession child_session in connection.Children) |
| { |
| GuiSession session = child_session as GuiSession; //connection.Children.ElementAt(0) as GuiSession; // populate user defined structure |
| SapInfoItem sii = new SapInfoItem(); |
| sii.system_name = session.Info.SystemName; |
| sii.client = session.Info.Client; |
| sii.program = session.Info.Program; |
| sii.screen_number = session.Info.ScreenNumber; |
| sii.handle = session.ActiveWindow.Handle; |
| sii.transaction = session.Info.Transaction; |
// add structure to dictionary collection
| sapInfo.Add(sii.handle.ToString("X"), sii); |
| } |
| connection = null; |
| } |
| sapGuiApp = null; |
| SapGuilRot = null; |
| sapROTWrapper = null; |
| return sapInfo; |
| } |
|
|
} |