Solved

Sending a Message manually

Posted on 2004-09-07
5
316 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

785 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