Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sending a Message manually

Posted on 2004-09-07
5
Medium Priority
?
324 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month20 days, 16 hours left to enroll

810 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