Solved

PostMessage... GetMessage???

Posted on 2000-03-07
3
429 Views
Last Modified: 2006-11-17
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
Comment
Question by:HellSlayer
3 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2594268
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
 
LVL 32

Accepted Solution

by:
Erick37 earned 70 total points
ID: 2594281
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
 

Author Comment

by:HellSlayer
ID: 2602685
Really cool sample without any API !!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
z = x + y – 1 6 67
How does CurrentUser work? 10 31
How to measure sizes and angles in scanned images ? 3 51
Problem to With line 4 37
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

930 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now