Solved

Sending a Message manually

Posted on 2004-09-07
5
314 Views
Last Modified: 2008-02-01
Well .. again it's me - again another question ;) ..

I have one Application which receives all kinds of messages - especially WM_PAINT and WM_SETFOCUS. Now, from another application I want to send such a message, but I do not want to send WM_PAINT, but well .. something different which does not exist.
On a normal control it shouldn't do anything (so sending WM_SETFOCUS would be completely wrong ;) ) .. only a control which reacts on that message should be affected.

Do I have to do this with a WM_USER Message ? How would I do that ... I'm only interested in the sending Part, I don't care about receiving - cause this already works for WM_PAINT Messages
0
Comment
Question by:somnatic
  • 2
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 11996686
WM_USER is defined as 0x0400, WM_APP is defined as 0x8000.
It is recommended to use WM_APP + n user-defined messages because Microsoft used some messages with value more than WM_USER. To post message to another window you need window handle.

[DllImport("user32", EntryPoint="PostMessage")]
public static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);


PostMessage(hWnd,                // destination window handle
                    0x8001,              // message ID - select what you need
                    0,                      // wParam
                    0);                    // lParam

Destination window must handle this message, otherwise this call doesn't have any effect.
0
 
LVL 4

Author Comment

by:somnatic
ID: 11996745
ha . .found something similar to be working just a few minutes ago ..

One more question: My solution uses SendMessage (from user32.dll) ..

What is the difference between SendMessage and PostMessage
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 11996862
SendMessage is synchronous. Function returns only after destination window handles this message. If destination window is not responding, sender is not responding as well.
PostMessage is asynchronous and returns immidiately.
The rule of thumb is using PostMessage whenever it is possible.
0
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 11997534
0
 
LVL 4

Author Comment

by:somnatic
ID: 12003601
thanks . .that's what I wanted to hear :)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

13 Experts available now in Live!

Get 1:1 Help Now