Solved

SendMessage WM_QUIT to my other App

Posted on 2006-06-22
6
2,140 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
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!

 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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!
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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