Solved

PostMessage... GetMessage???

Posted on 2000-03-07
3
427 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

705 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

11 Experts available now in Live!

Get 1:1 Help Now