Here is a sample for triggering events from form to form. It's very useful if a control doesn't have a .value-property. I wrote a DLL (named TOOL.DLL) with a call to the VB-Function VBFireEvent. Here it is:

#include <windows.h>
#include "c:\vb\cdk\vbapi.h"

int FAR PASCAL LibMain(HANDLE hInstance,WORD wDataSeg,WORD wHeapSize,LPSTR lpszCmdLine)
{
  if (wHeapSize>0)
    UnlockData(0);
  return 1;
} 

ERR _export CALLBACK FireEvent (HWND hWnd, USHORT index, LPVOID nullPtr)
{ 
  HCTL hCtl;

  hCtl = VBGetHwndControl(hWnd);
  return VBFireEvent(hCtl, index, nullPtr);
}
 
My DEF-File looks like this:

EXETYPE   WINDOWS
CODE         PRELOAD MOVEABLE DISCARDABLE
DATA         PRELOAD MOVEABLE SINGLE
HEAPSIZE  1024
EXPORTS
          WEP PRIVATE
          FireEvent 

In the General-Declaration of my VB-Applikation I added the following declaration:

Declare Sub FireEvent Lib "c:\vb\tool.dll" (ByVal thisHwnd As Integer, ByVal thisIndex As Integer, thisPtr As Long)

The VB-Code looks like this:

  Dim hWnd As Integer
  Dim index As Integer
  Dim ptr As Long
  
  hWnd = formA.comboA.hWnd
  index = 1
  
  x$ = comboB.Text
  temp = SendMessage(hWnd, CB_SELECTSTRING, -1, ByVal x$)

  Call FireEvent(hWnd, index, ptr)

The result: The selected text from Combo-Box B is first selected in Combo-Box A with the SendMessage-Function. Then FireEvent generates a Click-Event on Combo-Box A. It works fast and without any flickering.


Peter