3 Replies - 390 Views - Last Post: 19 July 2014 - 05:36 PM Rate Topic: -----

#1 knutter539  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 31-May 11

Differentiate between multiple applications

Posted 15 July 2014 - 05:28 AM

I need a way to tell two identical instances of a program apart. for instance, if i boot up our companies CAD software twice. i have to find out which one has focus and be able to link it to a plugin toolbar that runs within said software.

Problem:
If i boot up two instances of the CAD app, and i don't actually minimize one of them, my toolbars stack up.

-Each running instance of the software launches it's own instance of my plugin.
-The plugin forms are children of the main window handle.


Thanks,

Is This A Good Question/Topic? 0
  • +

Replies To: Differentiate between multiple applications

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9389
  • View blog
  • Posts: 35,264
  • Joined: 12-June 08

Re: Differentiate between multiple applications

Posted 15 July 2014 - 07:55 AM

Isn't that taken care of with a call to:
  Application.DocumentManager.MdiActiveDocument

?

Example:
http://www.cadalyst....n-autocad-16750
Was This Post Helpful? 0
  • +
  • -

#3 knutter539  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 31-May 11

Re: Differentiate between multiple applications

Posted 15 July 2014 - 10:08 AM

View Postmodi123_1, on 15 July 2014 - 07:55 AM, said:

Isn't that taken care of with a call to:
  Application.DocumentManager.MdiActiveDocument

?

Example:
http://www.cadalyst....n-autocad-16750



I not using AutoCAD so unfortunately i don't think so. This morning i imported the Windows uiAutomation API and have an event that listens for global focus change. here is my standalone app for testing this:



Imports System.Diagnostics
Imports System.Windows.Automation

Public Class Form1

    Public focushandler As AutomationfocusChangedEventHandler = Nothing



    'create the event handler and register it
    Public Sub SubscribeToFocusChange()
        focushandler = New AutomationfocusChangedEventHandler(AddressOf onfocusChange)
        Automation.AddAutomationfocusChangedEventHandler(focushandler)
    End Sub

    ''' Handle the event. 

    Private Sub onfocusChange(ByVal src As Object, ByVal e As AutomationfocusChangedEventArgs)
        Label1.Text = 
    End Sub

    'Cancel Subscription
    Public Sub UnsubscribeFocusChange()
        If (focushandler IsNot Nothing) Then
            Automation.RemoveAutomationfocusChangedEventHandler(focushandler)
        End If
    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        UnsubscribeFocusChange()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        SubscribeToFocusChange()
    End Sub
End Class




My application is "pmill.exe". I am thinking that when the above focus change event fires, i can get a unique ID for that instance of pmill that HAS focus, then loop though all other open pmill.exe instances and minimize/remove topmost property for the process AND its children.
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 329
  • View blog
  • Posts: 995
  • Joined: 01-February 13

Re: Differentiate between multiple applications

Posted 19 July 2014 - 05:36 PM

Hi,
I have read this a few times and i am still confused. Are you trying to tell if your form has focus from within your form? Is this the same form your using as the Plugin?

OR

Are you trying to find which Cad window has focus from within your form? Is this the same form as your plugin? Is the Cad program a 3rd party application?

If this is what your trying to do then can you show the Process Name of the Cad program, not the Window Title but, the Process Name. Also can you post the Process Name of your Form if it is the same one being used as the plugin.

Are you sure that the Parent or owner of your Form is the Cad application? If so, have you done some kind of tests of some sort or read some info somewhere that make you think this? I am just curious because it may help with finding a specific solution. B)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1