Solved

PostMessage... GetMessage???

Posted on 2000-03-07
3
451 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
[X]
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
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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