Solved

SendMessage WM_QUIT to my other App

Posted on 2006-06-22
6
2,099 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from 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

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…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

815 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

8 Experts available now in Live!

Get 1:1 Help Now