Problems with VB6 program

Aug 18, 2010 at 3:53 PM
Edited Aug 18, 2010 at 3:54 PM

Hi all!

I want to embed VB6 MDI win app to CCA, but I have the following issues in work this app and use HAT:

- not all controls I can to map from Aplication Inspector

- uses HAT, executeControlAction and others activities in Workflow does no occuring with controls (buttons, menu) that I map

- if I add the first menu item in Menu control map, I have 1 control to all the first menu items from all branches of Menu


Do you know why this problems occures?

Aug 18, 2010 at 5:00 PM


I had some problems that look like yours.

To solve my problems is needed to create a new Adapter extending the DDA ApplicationAdapter .In my DDA i use the methdos of user32.dll to finde the window and controls.

Fo the menu problems, in my DDA i send keyboard events to access the menu like: alt+M+G.

Aug 19, 2010 at 7:49 AM

canikrause, thanks for answer!

It sounds pretty hard :)

Can you please give an example of this work?


Aug 19, 2010 at 3:34 PM
//Here an example that send a enter to a textbox.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Uii.Csr;
using Microsoft.Uii.HostedApplicationToolkit.DataDrivenAdapter;
using System.Drawing;
using System.Runtime.InteropServices;

namespace Example.HAT
    public class Example : ApplicationAdapter

        //this properties is used to SendKey()
        private const byte KEYEVENTF_EXTENDEDKEY = 0x0001;
        private const byte KEYEVENTF_KEYUP = 0x0002;

        //this is the virtual key code for do a RETURN
        private const byte VK_RETURN = 0x0D;

        private IntPtr[] arrIntPtr;
        private IntPtr mainWindow = IntPtr.Zero;
        private int counter = 0;

        public override bool NotifyContextChange(Context context)
            mainWindow = MainWindowHandle;
            return base.NotifyContextChange(context);

        public override bool DoAction(Microsoft.Uii.Csr.Action action, RequestActionEventArgs raArgs)
            IntPtr ptr;
            IntPtr childHwnd = IntPtr.Zero;

            switch (raArgs.Action)
                //Here is an example that when default action is call
                //execute a return in a textbox
                case "default":
                    ptr = MainWindowHandle;

                    //verify if UII catch  the application
                    if (ptr != IntPtr.Zero)
                        //Try to find the textbox of the application
                        //To find use the helper from HAT
                        //take an attetion for the value '3', this value is the order that the control is rendered in your screen
                        //Previusly this order never change. To find this you can use SPY++ or WINCHEAT(the best for me)
                        IntPtr txtBoxHwnd = Win32HelperMethods.FindWindowByCaptionAndClassText(ptr, 0, 0, "", FindWindowMatchType.Ignore, "Edit", FindWindowMatchType.Equals, 3,true);

                        //verify if textbox was found
                        if (txtBoxHwnd != IntPtr.Zero)
                            //now handle the textbox using user32.dll
                            if (SetForegroundWindow(txtBoxHwnd) > 0)
                                //use the method SendKey()

            return base.DoAction(action, raArgs);

        /// <summary>
        /// Send  a key for window
        /// </summary>
        /// <param name="key"></param>
        private void SendKey(byte key)
            //press down de key
            keybd_event(key, 0x45, KEYEVENTF_EXTENDEDKEY, UIntPtr.Zero);
            //release de key
            keybd_event(key, 0x45, KEYEVENTF_KEYUP | KEYEVENTF_EXTENDEDKEY, UIntPtr.Zero);

        /// <summary>
        /// Scan a string and transform to a byte to be sent if keybd_event
        /// </summary>
        /// <param name="txt">string to be scanned</param>
        /// <returns>Array of Bytes</returns>
        public static byte[] ScanStringToByte(string txt)
            List<byte> lstBytes = new List<byte>();
            foreach (char letter in txt)
                byte l = (byte)VkKeyScan(letter);

            return lstBytes.ToArray();

        #region USER32 DLL
        //This is the methods using unmanaged code
        //the user32.dll is have the method that work with windows
        static extern short VkKeyScan(char ch);

        public static extern Int32 SetForegroundWindow(IntPtr hWnd);

        public static extern bool AllowSetForegroundWindow(IntPtr hWnd);

        static extern void keybd_event(byte bVk, byte bScan, uint dwFlags,
           UIntPtr dwExtraInfo);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);


Aug 23, 2010 at 2:04 PM

Hi, canikrause!

Thanks for example.
But how can I apply this project to do my inspectation of interface of VB6 app?

Aug 24, 2010 at 4:20 PM

In your host application you will define the adapter to this class.


Sep 16, 2010 at 1:33 PM

>In your host application you will define the adapter to this class.

Could you please give example of this?

And also questions:

- this code example - it is class library type of project?

- when this provider will placed  how to execute this example?

- bases on this example how to use it in CCA Workflows?

Thanks very much for help.

And I want to ask you again - Would you like to work on our projects associated with CCA for good reward?

Sep 16, 2010 at 8:14 PM

- this code example - it is class library type of project? Yes that´s it!

- when this provider will placed  how to execute this example? This will be set in the hosted application, this image show where

- bases on this example how to use it in CCA Workflows? It´s very simple! When you create a Workflow, you will have many steps for it. For each step you´ll set a action. To  use this action in your custom adapter you just need, inside
of method DoAction() in the Switch Case, add the name of the action.

If you need more help send e-mail to do a livemeeting to show.

Hope Help you!

Oct 8, 2010 at 1:46 PM


I was reading this blog and found this, maybe is usable for you.