Activating the source application window after a DDE LinkExecute

Posted on 2003-03-12
Medium Priority
Last Modified: 2010-04-07
Environment information: W98, VB5
I've created a simple form that starts a source application (ArcView) and is able to perform oeration on the source's data as well as to query the source to obtain some data back. The problem is that I'm unable to make the source get the focus: I'd like the source's window to become active and get on top of the other windows after the request, but it never happens.
Question by:svbeev
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8118117
API: SetForeGroundWindow, BringWindowToTop

Author Comment

ID: 8118185
Sorry, but I'm a COBOLsaur and have no idea how to use your suggestion. In particular, how to load (?) and call  API.

Please be more specific - I won't feel humiliated if you include the code.

Thank you.

Expert Comment

ID: 8118204

Belfry's comment is right: use this code:

' In the declaration section:
Private Declare Function SetForegroundWindow Lib "user32" ( _
      ByVal hwnd As Long) As Long

' Use it like this:
SetForegroundWindow( YourForm.hwnd )

This should bring the window on top.
Hope this helps
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 8118283
My problem is not to bring my VB form on top, but to bring the linked application window on top. I know the linked application name (because I started it with a "shell" command), but I don't know how to refer the corresponding window in the SetForegroundWindow API.

Expert Comment

ID: 8118325

If you know the window caption, you can use this API to get the related HWND:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
      ByVal lpClassName As String, _
      ByVal lpWindowName As String) As Long

Use it like this:

dim hwnd as Long

hwnd = FindWindow( 0, "My caption" )



Author Comment

ID: 8118473
OK, this is the code I use:

Sub cboDocType_Click()
    Dim hwnd As Long
    cmd = "av.GetProject.AddDoc(" & cboDocType & ".make) av.GetActiveDoc.GetWin.Open"
    txtDDE.LinkExecute cmd
    hwnd = FindWindow(0, "ArcView GIS Demo Edition")
    SetForegroundWindow (hwnd)
End Sub

This subroutine runs when I select one line in the listbox. Maybe it's the last instruction that's wrong (I guessed that hwnd had to be used instead of YourForm.hwnd you specified in your first comment); maybe the window caption should be written in a different way (but "ArcView GIS Demo Edition" is what I see in the window...); anyway, so as it is it doesn't work...

Author Comment

ID: 8146256
Hello everybody,
it happens that I found a solution by myself! the instruction AppActivate followed by the window title works just fine, so there's no need for an API to be called.

Thank you, Belfry and marconovaro, for the time you dedicated to my question, but I hope you'll agree if I simply close this topic not awarding these points to anybody.


Accepted Solution

Netminder earned 0 total points
ID: 8147080
User resolved; points refunded and question closed.

EE Admin

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question