Solved

PeekMessage API

Posted on 1997-08-10
5
573 Views
Last Modified: 2008-03-04
can someone show me the use of this api?
i need something like that:
two programs.
the first sends message to the second program
the second program, using peekmessage, or getmessage
gets it, and shows a msgbox...
very simple interface.
one with a button, which sends a message
and one the waits to the message.
0
Comment
Question by:msiman
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:y96andha
ID: 1430154
You won't be able to use this in VB. This type of message is used for all window management, such as moving or sizing a window or whenever keys are pressed. VB retrieves all messages itself using GetMessage, and they'll never stay in the queue enough time for you to pick them up.

Try DDE instead, thats a much easier way to send messages between applications.
0
 
LVL 2

Author Comment

by:msiman
ID: 1430155
i guess the answer is ok, but not full:
could you show me a very simple piece of code
that creats dde connection, between two programs,
and transfer any data between them?
MSIMAN
0
 
LVL 5

Accepted Solution

by:
y96andha earned 30 total points
ID: 1430156
OK, here it comes:

Create a project with a label on a form and set the LinkMode property of the form to source. Name this project RECEIVER, make an exe file and start it.

Create a second project with an edit box and a command button on a form containing this code:

Sub Command1_Click
    Text1.LinkTopic = "RECEIVER|Form1"
    Text1.LinkItem = "Label1"
    Text1.LinkMode = 2
    Text1.LinkPoke
    Text1.LinkMode = 0
End Sub


When you run the second project, you can enter text in the textbox and then click the command button to make the text appear in the first program.

When using this in a real project, you can make the controls hidden, and use the Label1_Changed event to receive the messages.

0
 
LVL 2

Author Comment

by:msiman
ID: 1430157
i graded you, but still i have a small quesstion regarding
the code.
in command1_click event, on line 2, the RECIEVER,
is it the other program caption or EXE filename?
msiman
0
 
LVL 5

Expert Comment

by:y96andha
ID: 1430158
It is the module name, which mostly is the same as the EXE file name but not always. From the help topic "LinkTopic Property":

The application element that the destination application uses, which is either the Visual Basic project filename without the .VBP extension (if you're running your application in the Visual Basic development environment) or the Visual Basic application filename without the .EXE extension (if you're running your application as a stand-alone executable file).  The EXEName property of the App object provides this string in your Visual Basic code unless the filename was changed by the user.  (EXEName always returns the actual filename of the application on disk; DDE always uses the original name that was specified in the Make EXE dialog box.)
      
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
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…

839 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