Solved

Sending a Message manually

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Events in static methods 3 50
Problem to error 4 45
Word Directory is not in the drop down list 4 25
Web Form VB.Net  import CSV 4 26
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

15 Experts available now in Live!

Get 1:1 Help Now