[英]Accessing ComInterface to VB6 OCX Control with win32 handle in c#
目前,我正在自動測試在vb6中開發的舊版應用程序,該應用程序使用了Janus Systems的GridEx2000b控件。
為此,我將Ranorex用作開發測試自動化的最喜歡的工具,以便可以使用c#開發測試代碼。
我現在的問題是自動化GridEx 2000b控件,Ranorex開箱即用不提供任何支持。 因此,我試圖找到一種解決方案,在該解決方案中,我可以使用為控件找到的Win32句柄引用GrixEx控件,以便可以使用組件中的ComInterface來導航控件的自動化。
我有一個解決方案的主意,但我不知道該怎么做,希望大家能為我提供幫助。
該問題的偽代碼:
using GridEX20;
class GridExWrapper
{
public GridEX20.GridEXClass Instance;
public GridExWrapper(IntPtr win32handle)
{
Instance = (GridEX20.GridEXClass)Win32ControlUtilities.GetControlReference(win32Handle);
}
}
class Win32ControlUtilities
{
public static SomeKindOfHandle GetControlReference(IntPtr win32Handle)
{
...
...
...
}
}
我將從Ranorex或其他間諜工具獲得win32handle。 然后,我可以像這樣使用GridExWrapper。
using NUnit.Framework;
class Program
{
[Test]
public void control_should_have_9_items()
{
/// Get win32 handle from Ranorex
IntPtr win32handle = XXXXXX;
int expectedItemCount = 9;
GridEXClass control = new GridExWrapper(win32handle);
Assert.AreEqual(expectedItemCount, control.ItemCount);
}
}
您可以嘗試使用Microsoft UI自動化庫(System.Windows.Automation)來標識控件的屬性。 有時,即使Ranorex失敗了,MSUIA也會設法識別控件,因為它會查看控件的本機屬性以進行識別。 無法保證,但值得一試。 這是有關使用MSUIA的教程的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.