Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

PostMessage... GetMessage???

I want the new instance of an app to send a message to the old one.

For example I start MyProg by clicking "first.txt". After that I click on "second.txt" and I want the new MyProg to do something like :

PostMessage(oldMyProgHandle, WM_COMMAND, 0&, "second.txt")


But how do I Get the message ??
0
HellSlayer
Asked:
HellSlayer
1 Solution
 
mcriderCommented:
You need to create a message handler (windows hook) See the following microsoft KB articles:

HOWTO: Build a Windows Message Handler with AddressOf in VB
http://support.microsoft.com/support/kb/articles/q170/5/70.ASP?LNG=ENG&SA=MSDN&FR=0 

HOWTO: Pass String Data Between Applications Using SendMessage
http://support.microsoft.com/support/kb/articles/Q176/0/58.ASP?LNG=ENG&SA=MSDN&FR=0 

HOWTO: Hook Into a Window's Messages Using AddressOf
http://support.microsoft.com/support/kb/articles/Q168/7/95.asp?LNG=ENG&SA=MSDN&FR=0 


Cheers!®©

0
 
Erick37Commented:
If you are trying to open associated files with one instance of your program, use DDE.  This sample code will populate a listbox with filenames as you double click the associated file.

Place Label1 and List1 on Form1:

Option Explicit

Private Sub Form_Load()
    ' At design time set Form's LinkMode property = 1 (Source)
    If App.PrevInstance Then
        On Error Resume Next
        Label1.LinkTopic = App.EXEName & "|cmdLine"
        Label1.LinkItem = ""
        Label1.LinkMode = vbLinkManual
        Label1.LinkExecute Command
        If Err Then
            MsgBox Err.Description, vbOKOnly, "Error " & CStr(Err.Number)
        Else
            Unload Me
            Exit Sub
        End If
    End If
    'First instance:
    Label1.Visible = False
    Show
    List1.AddItem Command
    Me.LinkTopic = "cmdLine" ' wait for "cmdLine" links
End Sub

Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
    'Command lines from other instances
    'will be passed thru CmdString
    List1.AddItem CmdStr
    Cancel = False
End Sub

Private Sub Form_Terminate()
    Beep
End Sub
 
0
 
HellSlayerAuthor Commented:
Really cool sample without any API !!!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now