Solved

PeekMessage API

Posted on 1997-08-10
5
574 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
[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
  • 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

730 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