Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SendMessage WM_QUIT to my other App

Posted on 2006-06-22
6
Medium Priority
?
2,224 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 280 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
Industry Leaders: 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 220 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

916 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