How to send WM_CLOSE

  • Thread starter Thread starter Daan
  • Start date Start date
D

Daan

I have the situation where application A checks if updates for itself
are available. If so, it launches application B to perform the update.
B needs A to shut down in order for this to succeed.

Right now, I use the OpenNETCF ProcessEntry.GetProcesses() and
ProcessEntry.Kill() methods to kill application A, but this gives some
problems sometimes and is not an elegant solution. I've read that it
should be possible to send a WM_CLOSE event from B to A in order to
have A close itself. I just cannot find out how to send such an event.

Both applications are written using C# on the .NET CompactFramework
2.0.
Thanks for any help.
 
I do this too, but I just do this

01: Download upgrade app
02: Run upgrade app
03: Close

"A" closes itself.
 
const uint WM_CLOSE = 0x10;

[DllImport("coredll.dll",EntryPoint="SendMessage", SetLastError=true)]
public static extern int SendMessage(IntPtr hWnd, uint uMsg, int wParam, int
lParam);

SendMessage(hWnd, WM_CLOSE, 0, 0);

Thanks, but I need a little more help with this. After finding out
that DllImport is part of System.Runtime.InteropServices and Message
is Microsoft.WindowsCE.Forms.Message, I now get the following errors:

With the updater application: The name 'hWnd' does not exist in the
current context.
With the main application: no suitable method found to override.

I assume that hWnd should be 'something' that points to the form of my
main application, but how / what value should I give it?
 
Use FindWindow to get the handle of the Form based on it's Text.


--
Chris Tacke - Embedded MVP
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--


Daan said:
const uint WM_CLOSE = 0x10;

[DllImport("coredll.dll",EntryPoint="SendMessage", SetLastError=true)]
public static extern int SendMessage(IntPtr hWnd, uint uMsg, int wParam,
int
lParam);

SendMessage(hWnd, WM_CLOSE, 0, 0);

Thanks, but I need a little more help with this. After finding out
that DllImport is part of System.Runtime.InteropServices and Message
is Microsoft.WindowsCE.Forms.Message, I now get the following errors:

With the updater application: The name 'hWnd' does not exist in the
current context.
With the main application: no suitable method found to override.

I assume that hWnd should be 'something' that points to the form of my
main application, but how / what value should I give it?
 
Or (IntPtr)this.Handle for the first param.

BR

Fabien Decret
Windows Embedded Consultant

ADENEO (ADESET)http://www.adeneo.adetelgroup.com/


Use FindWindow to get the handle of the Form based on it's Text.

--
Chris Tacke - Embedded MVP
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--




const uint WM_CLOSE = 0x10;
[DllImport("coredll.dll",EntryPoint="SendMessage", SetLastError=true)]
public static extern int SendMessage(IntPtr hWnd, uint uMsg, int wParam,
int
lParam);
SendMessage(hWnd, WM_CLOSE, 0, 0);
Thanks, but I need a little more help with this. After finding out
that DllImport is part of System.Runtime.InteropServices and Message
is Microsoft.WindowsCE.Forms.Message, I now get the following errors:
With the updater application: The name 'hWnd' does not exist in the
current context.
With the main application: no suitable method found to override.
I assume that hWnd should be 'something' that points to the form of my
main application, but how / what value should I give it?- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -
 
Sending WM_CLOSE to yourself is not what he's after. If you want that just
call this.Close(). He wants to tell another app to close, so he needs to
get that app's main Form handle.


--
Chris Tacke - Embedded MVP
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--



Or (IntPtr)this.Handle for the first param.

BR

Fabien Decret
Windows Embedded Consultant

ADENEO (ADESET)http://www.adeneo.adetelgroup.com/


Use FindWindow to get the handle of the Form based on it's Text.

--
Chris Tacke - Embedded MVP
OpenNETCF Consulting
Managed Code in the Embedded Worldwww.opennetcf.com
--




const uint WM_CLOSE = 0x10;
[DllImport("coredll.dll",EntryPoint="SendMessage", SetLastError=true)]
public static extern int SendMessage(IntPtr hWnd, uint uMsg, int
wParam,
int
lParam);
SendMessage(hWnd, WM_CLOSE, 0, 0);
Thanks, but I need a little more help with this. After finding out
that DllImport is part of System.Runtime.InteropServices and Message
is Microsoft.WindowsCE.Forms.Message, I now get the following errors:
With the updater application: The name 'hWnd' does not exist in the
current context.
With the main application: no suitable method found to override.
I assume that hWnd should be 'something' that points to the form of my
main application, but how / what value should I give it?- Masquer le
texte des messages précédents -

- Afficher le texte des messages précédents -
 
Sending WM_CLOSE to yourself is not what he's after. If you want that just
call this.Close(). He wants to tell another app to close, so he needs to
get that app's main Form handle.

That's right. Next Friday I will have the time to look into this
again, I hope to figure it out then. So far, I've had no luck getting
the other Form's handle, but I need a little more time to figure out
just how these calls work. Any hints to speed up the work are
appreciated, but thanks for the help so far anyway!

Daan
 
Back
Top