Solved

SendMessage WM_QUIT to my other App

Posted on 2006-06-22
6
2,056 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
  • 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

17 Experts available now in Live!

Get 1:1 Help Now