Question : SendKeys to a minimzed window

I'm using VBA code in an Access 2000 form to control a CAD program (Bentley's
MicroStation) that is running in its own window.

When this form loads, the VBA code in its On Load event launches the CAD
program with the following code:

Public g_lngBentleyWindowHandle As Long
Public g_lngBentleyPID As Long

 Private Sub Form_Load()
       g_lngBentleyPID = _
            Shell("C:\program files\Bentley\program\view\BentleyView.exe
m:\dgn", 1)
        g_lngBentleyWindowHandle = HwndFromProcessID(g_lngBentleyPID)
End Sub

Public Function HwndFromProcessID(ProcessID As Long) As Long
' returns hwnd, based on Karl E. Peterson's code, he is using
'   ProcessID returned from Shell VB function
   Dim hWndJob As Long, PID As Long
   hWndJob = FindWindow(vbNullString, vbNullString)
   Do Until hWndJob = 0
      If GetParent(hWndJob) = 0 Then
         Call GetWindowThreadProcessId(hWndJob, PID)
         If PID = ProcessID Then Exit Do
      End If
      hWndJob = GetWindow(hWndJob, GW_HWNDNEXT)
   Loop
   HwndFromProcessID = hWndJob
End Function

After the form loads: the CAD program is launched, its PID is saved in the
global variable g_lngBentleyPID, its window handle is saved in the global
variable g_lngBentleyWindowHandle.

When the user clicks on the "View" command button on the form, the VBA code
in its On Click event uses SendKeys to send keystrokes to the CAD program to
open a drawing file.

Private Sub cmdView_Click()
    AppActivate g_lngBentleyPID
    SendKeys "{ESC}{ESC}{ESC}{ESC}", True
    SendKeys "rd="
    SendKeys "m:\dgn\"
    SendKeys Me!Drawing & "{ENTER}"
End Sub

This all works fine as long as the user has not minimized the CAD program
window.

If the CAD window is minimized, AppActivate and SendKeys have no effect.
I've tried adding ShowWindow before the AppActivate:

    ShowWindow g_lngBentleyWindowHandle, SW_RESTORE
    AppActivate g_lngBentleyPID
    SendKeys "{ESC}{ESC}{ESC}{ESC}", True
    SendKeys "rd="
    SendKeys "m:\dgn\"
    SendKeys Me!Drawing & "{ENTER}"

This resulted in the SendKeys still not working when the CAD window is
minimized and a "DDE Server Window" appearing in the task bar.

I've also tried each of the following code lines in place of the ShowWindow
code line with no success.
    Call SetForegroundWindow(g_lngBentleyWindowHandle)

    Call BringWindowToTop(g_lngBentleyWindowHandle)

    Call SendMessage(g_lngBentleyWindowHandle, WM_SYSCOMMAND, _
          SC_RESTORE, 0)

Can anyone help me solve this problem?

Thanks

Answer : SendKeys to a minimzed window

looks like you can code directly into the app with VB / VBA ...
http://www.bentley.com/en-US/Products/Bentley+PowerMap/Features+and+Benefits/Extensible+Platform.htm

their discussion group summary specifically mentions programming support / techniques.
http://www.bentley.com/en-US/Community/Discussion+Groups/

Steve
Random Solutions  
 
programming4us programming4us