Solved

SendMessage WM_QUIT to my other App

Posted on 2006-06-22
6
2,174 Views
Last Modified: 2012-05-05
dear experts:-

I'm learning the concept of windows messages from online tutorials, i thought id try a sample program with my own idea. so i created a windows application A, overrided the WndProc function, made it listen for WM_QUIT messages, if it received one I called Application.Exit(). In application B, i enumerated the Process collection to find my application A, using the Process.Handle function i called SendMessage (sending a WM_QUIT) to my application A.

Regardless of doing this my application A still did not close. i am new to the win api and also windows messages, last night out of fustration i deleted the application A and B projects, can someone show me and explain to me how to do this?

if you need me to rewrite how i was currently doing it, i will rewrite and paste here.

i find windows messages an interesting concept and would love to further my knowledge in this.
0
Comment
Question by:Programmer_to_be
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 70 total points
ID: 16959458
Actually, this is done by posting WM_CLOSE message to main application window. This has the same effect as clicking the Close button of a window.
So, in application A you don't need anything special.
In application B, use Process.MainWindowHandle Property to find main window handle, and use PostMessage API to post WM_CLOSE message to it.
BTW, PostMessage is asynchronous and should be default choice for Windows message, unless you need to send pointers or get message return value.
0
 

Author Comment

by:Programmer_to_be
ID: 16959631
alex thank you for your response.

the signature for the PostMessage api function is:-

[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

what values do i send as the wParam and lParam arguments? What is a IntPtr type?
0
 

Author Comment

by:Programmer_to_be
ID: 16959709
when you say PostMessage is asynchronous, does this mean it wont block the application i call PostMessage with? if that is the case, why does it return a bool?

therefore, i should only use SendMessage api if i need to wait for a return value from the function?

i am grasping this concept now, a quick short explanation of the above will be fine.

many thanks for your help.
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 11

Assisted Solution

by:Jase-Coder
Jase-Coder earned 55 total points
ID: 16960100
the value of wParam and lParam can be 0 or null
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16960106
yep set wParam and lParam to null
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16962812
PostMessage can return FALSE if destination window doesn't exist.
WPARAM and LPARAM - you can see their description in MSDN message description. For example, for WM_CLOSED: both parameters are not used, in this case use 0.
About PostMessage and SendMessage - you understand this correctly.
0

Featured Post

Technology Partners: 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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

615 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